From f1e99ea09209f97d2c2081e6f9a25900a38c8c90 Mon Sep 17 00:00:00 2001 From: kelvingoodson Date: Mon, 28 Jul 2008 14:30:12 +0000 Subject: merge of commit 643011 from 1.1 branch git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@680370 13f79535-47bb-0310-9956-ffa450edef68 --- java/sdo/impl/pom.xml | 13 + .../sdo/helper/BaseSDOExtendedMetaDataImpl.java | 334 +- .../tuscany/sdo/helper/BaseSDOXSDEcoreBuilder.java | 3542 +++++++++--------- .../sdo/helper/CrossScopeCopyHelperImpl.java | 510 +-- .../sdo/helper/DefaultHelperContextImpl.java | 144 +- .../apache/tuscany/sdo/helper/SDOHelperImpl.java | 1060 +++--- .../org/apache/tuscany/sdo/impl/EventImpl.java | 156 +- .../org/apache/tuscany/sdo/impl/ListenerBase.java | 66 +- .../sdo/model/internal/InternalFactory.java | 104 +- .../model/internal/impl/InternalFactoryImpl.java | 592 +-- .../apache/tuscany/sdo/model/xml/XMLFactory.java | 122 +- .../org/apache/tuscany/sdo/model/xml/XMLInfo.java | 184 +- .../tuscany/sdo/model/xml/impl/XMLFactoryImpl.java | 682 ++-- .../tuscany/sdo/model/xml/impl/XMLInfoImpl.java | 512 +-- .../tuscany/sdo/util/StreamDeserializer.java | 184 +- .../apache/tuscany/sdo/util/VirtualSequence.java | 1560 ++++---- .../resource/ChangeSummaryStreamDeserializer.java | 1326 +++---- .../resource/ChangeSummaryStreamSerializer.java | 1380 +++---- .../resource/RecordedEventXMLStreamReader.java | 1736 ++++----- .../tuscany/sdo/util/resource/SDODeserializer.java | 680 ++-- java/sdo/impl/src/main/resources/META-INF/NOTICE | 1 - .../impl/src/main/resources/META-INF/README.txt | 4 +- .../impl/src/main/resources/xml/sdoInternal.xsd | 66 +- .../main/resources/xml/sdoModelChangeSummary.xsd | 56 +- .../ExpectedExceptionFactory.java | 140 +- .../ExpectedException/ExpectedExceptionType.java | 1572 ++++---- .../ExpectedException/SequenceReadOnlyType.java | 316 +- .../impl/ExpectedExceptionFactoryImpl.java | 1158 +++--- .../impl/ExpectedExceptionTypeImpl.java | 3364 +++++++++--------- .../impl/SequenceReadOnlyTypeImpl.java | 708 ++-- .../apache/tuscany/sdo/test/BoundsTestCase.java | 156 +- .../sdo/test/ChangeSummaryPropertyTestCase.java | 438 +-- .../tuscany/sdo/test/CrossScopeCopyTestCase.java | 948 ++--- .../sdo/test/DataObjectGetListTestCase.java | 258 +- .../test/DefineOpenContentPropertyTestCase.java | 266 +- .../sdo/test/DeserializationNoSchemaTestCase.java | 248 +- .../tuscany/sdo/test/DupElementTestCase.java | 198 +- .../sdo/test/DynamicTypesComparisonTestCase.java | 512 +-- .../sdo/test/ExpectedExceptionsTestCase.java | 3754 ++++++++++---------- .../sdo/test/JavaSerializeDeserializeTestCase.java | 594 ++-- .../test/MetadataInstancePropertiesTestCase.java | 486 +-- .../sdo/test/NeverStaleChangeSummaryTestCase.java | 150 +- .../tuscany/sdo/test/NotificationTestCase.java | 372 +- .../apache/tuscany/sdo/test/SequenceTestCase.java | 200 +- .../tuscany/sdo/test/SerializeTypesTestCase.java | 380 +- .../tuscany/sdo/test/TypeHelperTestCase.java | 90 +- .../tuscany/sdo/test/XMLLoadOptionsTestCase.java | 384 +- .../tuscany/sdo/test/XMLSaveOptionsTestCase.java | 294 +- .../sdo/test/XMLUnknownPropertiesTestCase.java | 264 +- .../test/resources/TypePropertyMetadataInfo.xsd | 194 +- java/sdo/impl/src/test/resources/bounds.xsd | 90 +- java/sdo/impl/src/test/resources/dupelement.xsd | 78 +- .../impl/src/test/resources/expectedExceptions.xsd | 134 +- .../src/test/resources/openContentProperty.xml | 22 +- java/sdo/impl/src/test/resources/sdoModel.xsd | 56 +- java/sdo/impl/src/test/resources/shallowquote1.xml | 58 +- java/sdo/impl/src/test/resources/simple2.xsd | 82 +- .../src/test/resources/simpleWithChangeSummary.xml | 54 +- .../resources/simpleWithChangeSummaryUndone.xml | 36 +- .../src/test/resources/substitutionValues1.xml | 46 +- .../src/test/resources/substitutionValues2.xml | 46 +- 61 files changed, 16586 insertions(+), 16574 deletions(-) (limited to 'java/sdo/impl') diff --git a/java/sdo/impl/pom.xml b/java/sdo/impl/pom.xml index 2d2896613a..ba0549cce6 100644 --- a/java/sdo/impl/pom.xml +++ b/java/sdo/impl/pom.xml @@ -121,6 +121,19 @@ + + maven-jar-plugin + + + + org.apache + 1.1-incubating + 1.4 + 1.4 + + + + org.apache.maven.plugins maven-jar-plugin diff --git a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/BaseSDOExtendedMetaDataImpl.java b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/BaseSDOExtendedMetaDataImpl.java index 422f5342d8..88c714f8bf 100644 --- a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/BaseSDOExtendedMetaDataImpl.java +++ b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/BaseSDOExtendedMetaDataImpl.java @@ -1,167 +1,167 @@ -/** - * - * 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.helper; - -import org.eclipse.emf.ecore.EAttribute; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EClassifier; -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.emf.ecore.EReference; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecore.ETypedElement; -import org.eclipse.emf.ecore.EcoreFactory; -import org.eclipse.emf.ecore.EcorePackage; -import org.eclipse.emf.ecore.util.BasicExtendedMetaData; -import org.eclipse.emf.ecore.util.ExtendedMetaData; -import org.eclipse.emf.ecore.xml.type.XMLTypePackage; - -/** - * A BasicExtendedMetaData that uses a supplied (SDO) ecore factory to create properties and types. - */ -public class BaseSDOExtendedMetaDataImpl extends BasicExtendedMetaData -{ - protected EcoreFactory ecoreFactory = EcoreFactory.eINSTANCE; - protected DemandMetaData demandMetaData = new DemandMetaData(); - - public static class DemandMetaData { - EClassifier getEObject() { return EcorePackage.eINSTANCE.getEObject(); } - EClassifier getAnyType() { return XMLTypePackage.eINSTANCE.getAnyType(); } - EClassifier getAnySimpleType() { return XMLTypePackage.eINSTANCE.getAnySimpleType(); } - EClassifier getXMLTypeDocumentRoot() { return XMLTypePackage.eINSTANCE.getXMLTypeDocumentRoot(); } - } - - public BaseSDOExtendedMetaDataImpl(EPackage.Registry registry) - { - super(registry); - } - - public EPackage demandPackage(String namespace) - { - EPackage ePackage = demandRegistry.getEPackage(namespace); - if (ePackage == null) - { - ePackage = ecoreFactory.createEPackage(); - ePackage.setNsURI(namespace); - setQualified(ePackage, namespace != null); - if (namespace != null) - { - ePackage.setNsPrefix - (namespace.equals(ExtendedMetaData.XMLNS_URI) ? - namespace.equals(ExtendedMetaData.XML_URI) ? - "xml" : - "xmlns" : - computePrefix(namespace)); - } - demandRegistry.put(namespace, ePackage); - - // demandDocumentRoot(ePackage); - - EClass documentRootEClass = ecoreFactory.createEClass(); - documentRootEClass.getESuperTypes().add(demandMetaData.getXMLTypeDocumentRoot()); - documentRootEClass.setName("DocumentRoot"); - ePackage.getEClassifiers().add(documentRootEClass); - setDocumentRoot(documentRootEClass); - } - return ePackage; - } - - public EClassifier demandType(String namespace, String name) - { - EPackage ePackage = demandPackage(namespace); - EClassifier eClassifier = getType(ePackage, name); - if (eClassifier != null) - { - return eClassifier; - } - else - { - EClass eClass = ecoreFactory.createEClass(); - eClass.setName(name); - eClass.getESuperTypes().add(demandMetaData.getAnyType()); - setContentKind(eClass, MIXED_CONTENT); - ePackage.getEClassifiers().add(eClass); - return eClass; - } - } - - public EStructuralFeature demandFeature(String namespace, String name, boolean isElement, boolean isReference) - { - EPackage ePackage = demandPackage(namespace); - EClass documentRootEClass = getDocumentRoot(ePackage); - EStructuralFeature eStructuralFeature = - isElement ? - getLocalElement(documentRootEClass, namespace, name) : - getLocalAttribute(documentRootEClass, namespace, name); - if (eStructuralFeature != null) - { - return eStructuralFeature; - } - else - { - if (isReference) - { - EReference eReference = ecoreFactory.createEReference(); - eReference.setContainment(isElement); - eReference.setEType(demandMetaData.getEObject()); - eReference.setName(name); - eReference.setDerived(true); - eReference.setTransient(true); - eReference.setVolatile(true); - documentRootEClass.getEStructuralFeatures().add(eReference); - - setFeatureKind(eReference, isElement ? ELEMENT_FEATURE : ATTRIBUTE_FEATURE); - setNamespace(eReference, namespace); - - // Mark the bound as unspecified so that it won't be considered many - // but can nevertheless be recognized as being unspecified and perhaps still be treat as many. - // - if (isElement) - { - eReference.setUpperBound(ETypedElement.UNSPECIFIED_MULTIPLICITY); - } - - return eReference; - } - else - { - EAttribute eAttribute = ecoreFactory.createEAttribute(); - eAttribute.setName(name); - eAttribute.setEType(demandMetaData.getAnySimpleType()); - eAttribute.setDerived(true); - eAttribute.setTransient(true); - eAttribute.setVolatile(true); - documentRootEClass.getEStructuralFeatures().add(eAttribute); - - setFeatureKind(eAttribute, isElement ? ELEMENT_FEATURE : ATTRIBUTE_FEATURE); - setNamespace(eAttribute, namespace); - - // Mark the bound as unspecified so that it won't be considered many - // but can nevertheless be recognized as being unspecified and perhaps still be treat as many. - // - if (isElement) - { - eAttribute.setUpperBound(ETypedElement.UNSPECIFIED_MULTIPLICITY); - } - - return eAttribute; - } - } - } -} +/** + * + * 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.helper; + +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.ETypedElement; +import org.eclipse.emf.ecore.EcoreFactory; +import org.eclipse.emf.ecore.EcorePackage; +import org.eclipse.emf.ecore.util.BasicExtendedMetaData; +import org.eclipse.emf.ecore.util.ExtendedMetaData; +import org.eclipse.emf.ecore.xml.type.XMLTypePackage; + +/** + * A BasicExtendedMetaData that uses a supplied (SDO) ecore factory to create properties and types. + */ +public class BaseSDOExtendedMetaDataImpl extends BasicExtendedMetaData +{ + protected EcoreFactory ecoreFactory = EcoreFactory.eINSTANCE; + protected DemandMetaData demandMetaData = new DemandMetaData(); + + public static class DemandMetaData { + EClassifier getEObject() { return EcorePackage.eINSTANCE.getEObject(); } + EClassifier getAnyType() { return XMLTypePackage.eINSTANCE.getAnyType(); } + EClassifier getAnySimpleType() { return XMLTypePackage.eINSTANCE.getAnySimpleType(); } + EClassifier getXMLTypeDocumentRoot() { return XMLTypePackage.eINSTANCE.getXMLTypeDocumentRoot(); } + } + + public BaseSDOExtendedMetaDataImpl(EPackage.Registry registry) + { + super(registry); + } + + public EPackage demandPackage(String namespace) + { + EPackage ePackage = demandRegistry.getEPackage(namespace); + if (ePackage == null) + { + ePackage = ecoreFactory.createEPackage(); + ePackage.setNsURI(namespace); + setQualified(ePackage, namespace != null); + if (namespace != null) + { + ePackage.setNsPrefix + (namespace.equals(ExtendedMetaData.XMLNS_URI) ? + namespace.equals(ExtendedMetaData.XML_URI) ? + "xml" : + "xmlns" : + computePrefix(namespace)); + } + demandRegistry.put(namespace, ePackage); + + // demandDocumentRoot(ePackage); + + EClass documentRootEClass = ecoreFactory.createEClass(); + documentRootEClass.getESuperTypes().add(demandMetaData.getXMLTypeDocumentRoot()); + documentRootEClass.setName("DocumentRoot"); + ePackage.getEClassifiers().add(documentRootEClass); + setDocumentRoot(documentRootEClass); + } + return ePackage; + } + + public EClassifier demandType(String namespace, String name) + { + EPackage ePackage = demandPackage(namespace); + EClassifier eClassifier = getType(ePackage, name); + if (eClassifier != null) + { + return eClassifier; + } + else + { + EClass eClass = ecoreFactory.createEClass(); + eClass.setName(name); + eClass.getESuperTypes().add(demandMetaData.getAnyType()); + setContentKind(eClass, MIXED_CONTENT); + ePackage.getEClassifiers().add(eClass); + return eClass; + } + } + + public EStructuralFeature demandFeature(String namespace, String name, boolean isElement, boolean isReference) + { + EPackage ePackage = demandPackage(namespace); + EClass documentRootEClass = getDocumentRoot(ePackage); + EStructuralFeature eStructuralFeature = + isElement ? + getLocalElement(documentRootEClass, namespace, name) : + getLocalAttribute(documentRootEClass, namespace, name); + if (eStructuralFeature != null) + { + return eStructuralFeature; + } + else + { + if (isReference) + { + EReference eReference = ecoreFactory.createEReference(); + eReference.setContainment(isElement); + eReference.setEType(demandMetaData.getEObject()); + eReference.setName(name); + eReference.setDerived(true); + eReference.setTransient(true); + eReference.setVolatile(true); + documentRootEClass.getEStructuralFeatures().add(eReference); + + setFeatureKind(eReference, isElement ? ELEMENT_FEATURE : ATTRIBUTE_FEATURE); + setNamespace(eReference, namespace); + + // Mark the bound as unspecified so that it won't be considered many + // but can nevertheless be recognized as being unspecified and perhaps still be treat as many. + // + if (isElement) + { + eReference.setUpperBound(ETypedElement.UNSPECIFIED_MULTIPLICITY); + } + + return eReference; + } + else + { + EAttribute eAttribute = ecoreFactory.createEAttribute(); + eAttribute.setName(name); + eAttribute.setEType(demandMetaData.getAnySimpleType()); + eAttribute.setDerived(true); + eAttribute.setTransient(true); + eAttribute.setVolatile(true); + documentRootEClass.getEStructuralFeatures().add(eAttribute); + + setFeatureKind(eAttribute, isElement ? ELEMENT_FEATURE : ATTRIBUTE_FEATURE); + setNamespace(eAttribute, namespace); + + // Mark the bound as unspecified so that it won't be considered many + // but can nevertheless be recognized as being unspecified and perhaps still be treat as many. + // + if (isElement) + { + eAttribute.setUpperBound(ETypedElement.UNSPECIFIED_MULTIPLICITY); + } + + return eAttribute; + } + } + } +} diff --git a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/BaseSDOXSDEcoreBuilder.java b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/BaseSDOXSDEcoreBuilder.java index f21a3398b7..3d297fa671 100644 --- a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/BaseSDOXSDEcoreBuilder.java +++ b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/BaseSDOXSDEcoreBuilder.java @@ -1,1771 +1,1771 @@ -/** - * - * 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.helper; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.emf.ecore.EAttribute; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EClassifier; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.emf.ecore.EEnum; -import org.eclipse.emf.ecore.EOperation; -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.emf.ecore.EParameter; -import org.eclipse.emf.ecore.EReference; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecore.ETypedElement; -import org.eclipse.emf.ecore.EcoreFactory; -import org.eclipse.emf.ecore.EcorePackage; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.emf.ecore.util.ExtendedMetaData; -import org.eclipse.emf.ecore.xml.type.XMLTypePackage; -import org.eclipse.xsd.XSDAnnotation; -import org.eclipse.xsd.XSDAttributeDeclaration; -import org.eclipse.xsd.XSDAttributeUse; -import org.eclipse.xsd.XSDComplexTypeContent; -import org.eclipse.xsd.XSDComplexTypeDefinition; -import org.eclipse.xsd.XSDComponent; -import org.eclipse.xsd.XSDContentTypeCategory; -import org.eclipse.xsd.XSDDerivationMethod; -import org.eclipse.xsd.XSDElementDeclaration; -import org.eclipse.xsd.XSDFeature; -import org.eclipse.xsd.XSDLengthFacet; -import org.eclipse.xsd.XSDMaxLengthFacet; -import org.eclipse.xsd.XSDMinLengthFacet; -import org.eclipse.xsd.XSDModelGroup; -import org.eclipse.xsd.XSDModelGroupDefinition; -import org.eclipse.xsd.XSDNamedComponent; -import org.eclipse.xsd.XSDParticle; -import org.eclipse.xsd.XSDSchema; -import org.eclipse.xsd.XSDSimpleTypeDefinition; -import org.eclipse.xsd.XSDTerm; -import org.eclipse.xsd.XSDTypeDefinition; -import org.eclipse.xsd.XSDVariety; -import org.eclipse.xsd.XSDWildcard; -import org.eclipse.xsd.ecore.XSDEcoreBuilder; -import org.eclipse.xsd.util.XSDConstants; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * An XSDEcoreBuilder that uses a supplied (SDO) ecore factory to create properties and types. - */ -public class BaseSDOXSDEcoreBuilder extends XSDEcoreBuilder -{ - protected EcorePackage ecorePackage = EcorePackage.eINSTANCE; - protected EcoreFactory ecoreFactory = EcoreFactory.eINSTANCE; - - public BaseSDOXSDEcoreBuilder(ExtendedMetaData extendedMetaData) - { - super(extendedMetaData); - } - - private void createDocumentRoot(XSDSchema xsdSchema, EPackage ePackage) { - EClass documentEClass = ecoreFactory.createEClass(); - String name = getEcoreAttribute(xsdSchema, "documentRoot"); - if (name == null) - { - name = "DocumentRoot"; - } - documentEClass.setName(name); - - extendedMetaData.setDocumentRoot(documentEClass); - - ePackage.getEClassifiers().add(documentEClass); - - createFeature - (documentEClass, - "mixed", - ecorePackage.getEFeatureMapEntry(), - null, - 0, - -1); - - EStructuralFeature xmlnsPrefixMapFeature = - createFeature - (documentEClass, - "xMLNSPrefixMap", - ecorePackage.getEStringToStringMapEntry(), - null, - 0, - -1); - extendedMetaData.setName(xmlnsPrefixMapFeature, "xmlns:prefix"); - - EStructuralFeature xsiSchemaLocationMapFeature = - createFeature - (documentEClass, - "xSISchemaLocation", - ecorePackage.getEStringToStringMapEntry(), - null, - 0, - -1); - extendedMetaData.setName(xsiSchemaLocationMapFeature, "xsi:schemaLocation"); - } - - public EPackage getEPackage(XSDNamedComponent xsdNamedComponent) - { - XSDSchema containingXSDSchema = xsdNamedComponent.getSchema(); - if (containingXSDSchema != null && !xsdSchemas.contains(containingXSDSchema)) - { - xsdSchemas.add(containingXSDSchema); - addInput(containingXSDSchema); - validate(containingXSDSchema); - } - - String targetNamespace = - containingXSDSchema == null ? - xsdNamedComponent.getTargetNamespace() : - containingXSDSchema.getTargetNamespace(); - EPackage ePackage = (EPackage)targetNamespaceToEPackageMap.get(targetNamespace); - if (ePackage == null) - { - ePackage = ecoreFactory.createEPackage(); - setAnnotations(ePackage, containingXSDSchema); - addOutput(ePackage); - if (targetNamespace == null) - { - if (containingXSDSchema == null) - { - containingXSDSchema = rootSchema; - } - ePackage.setName(validName(containingXSDSchema.eResource().getURI().trimFileExtension().lastSegment(), true)); - ePackage.setNsURI(containingXSDSchema.eResource().getURI().toString()); - - // Also register against the nsURI for the case that the target namespace is null. - // - // extendedMetaData.putPackage(ePackage.getNsURI(), ePackage); - } - else - { - String qualifiedPackageName = qualifiedPackageName(targetNamespace); - ePackage.setName(qualifiedPackageName); - ePackage.setNsURI(targetNamespace); - } - - String nsPrefix = ePackage.getName(); - int index = nsPrefix.lastIndexOf('.'); - nsPrefix = index == -1 ? nsPrefix : nsPrefix.substring(index + 1); - - // http://www.w3.org/TR/REC-xml-names/#xmlReserved - // Namespace Constraint: Leading "XML" - // Prefixes beginning with the three-letter sequence x, m, l, in any case combination, - // are reserved for use by XML and XML-related specifications. - // - if (nsPrefix.toLowerCase().startsWith("xml")) - { - nsPrefix = "_" + nsPrefix; - } - ePackage.setNsPrefix(nsPrefix); - - extendedMetaData.setQualified(ePackage, targetNamespace != null); - extendedMetaData.putPackage(targetNamespace, ePackage); - - targetNamespaceToEPackageMap.put(targetNamespace, ePackage); - - createDocumentRoot(xsdNamedComponent.getSchema(), ePackage); - } - - return ePackage; - } - - protected EClassifier computeEClassifier(XSDTypeDefinition xsdTypeDefinition) - { - if (xsdTypeDefinition == null) - { - return getBuiltInEClassifier(rootSchema.getSchemaForSchemaNamespace(), "anySimpleType"); - } - else if (xsdTypeDefinition instanceof XSDSimpleTypeDefinition) - { - return computeEDataType((XSDSimpleTypeDefinition)xsdTypeDefinition); - } - else - { - return computeEClass((XSDComplexTypeDefinition)xsdTypeDefinition); - } - } - - protected EDataType computeEDataType(XSDSimpleTypeDefinition xsdSimpleTypeDefinition) - { - if (xsdSimpleTypeDefinition == null) - { - return (EDataType)getBuiltInEClassifier(rootSchema.getSchemaForSchemaNamespace(), "anySimpleType"); - } - else if (XSDConstants.isSchemaForSchemaNamespace(xsdSimpleTypeDefinition.getTargetNamespace())) - { - String name = xsdSimpleTypeDefinition.getName(); - if (name != null) - { - EDataType result = (EDataType)getBuiltInEClassifier(xsdSimpleTypeDefinition.getTargetNamespace(), "anyType".equals(name) ? "anySimpleType" : name); - if (result != null) - { - return result; - } - } - } - else if (xsdSimpleTypeDefinition.getContainer() == null) - { - return (EDataType)getBuiltInEClassifier(rootSchema.getSchemaForSchemaNamespace(), "anySimpleType"); - } - - String explicitInstanceClassName = getEcoreAttribute(xsdSimpleTypeDefinition, "instanceClass"); - if (explicitInstanceClassName != null) - { - EDataType eDataType = ecoreFactory.createEDataType(); - setAnnotations(eDataType, xsdSimpleTypeDefinition); - - String aliasName = getEcoreAttribute(xsdSimpleTypeDefinition, "name"); - if (aliasName == null) - { - aliasName = validAliasName(xsdSimpleTypeDefinition, true); - } - eDataType.setName(aliasName); - extendedMetaData.setName(eDataType, xsdSimpleTypeDefinition.getAliasName()); - - eDataType.setInstanceClassName(explicitInstanceClassName); - - EPackage ePackage = getEPackage(xsdSimpleTypeDefinition); - addToSortedList(ePackage.getEClassifiers(), eDataType); - - checkForPrimitive(xsdSimpleTypeDefinition, eDataType); - - handleFacets(xsdSimpleTypeDefinition, eDataType); - - String constraints = getEcoreAttribute(xsdSimpleTypeDefinition, "constraints"); - if (constraints != null) - { - EcoreUtil.setAnnotation(eDataType, EcorePackage.eNS_URI, "constraints", constraints); - } - - if ("false".equals(getEcoreAttribute(xsdSimpleTypeDefinition, "serializable"))) - { - eDataType.setSerializable(false); - } - return eDataType; - } - else - { - EEnum eEnum = computeEEnum(xsdSimpleTypeDefinition); - if (eEnum != null) - { - return eEnum; - } - else - { - XSDSimpleTypeDefinition baseTypeDefinition = xsdSimpleTypeDefinition.getBaseTypeDefinition(); - if (baseTypeDefinition != null) - { - EDataType eDataType = ecoreFactory.createEDataType(); - setAnnotations(eDataType, xsdSimpleTypeDefinition); - - String name = getEcoreAttribute(xsdSimpleTypeDefinition, "name"); - if (name == null) - { - name = validAliasName(xsdSimpleTypeDefinition, true); - } - - eDataType.setName(name); - extendedMetaData.setName(eDataType, xsdSimpleTypeDefinition.getAliasName()); - - EPackage ePackage = getEPackage(xsdSimpleTypeDefinition); - addToSortedList(ePackage.getEClassifiers(), eDataType); - - if (baseTypeDefinition.getVariety() != xsdSimpleTypeDefinition.getVariety()) - { - if (xsdSimpleTypeDefinition.getVariety() == XSDVariety.LIST_LITERAL) - { - EDataType itemEDataType = getEDataType(xsdSimpleTypeDefinition.getItemTypeDefinition()); - extendedMetaData.setItemType(eDataType, itemEDataType); - eDataType.setInstanceClassName("java.util.List"); - } - else - { - String instanceClassName = null; - List memberTypes = new ArrayList(); - for (Iterator i = xsdSimpleTypeDefinition.getMemberTypeDefinitions().iterator(); i.hasNext(); ) - { - XSDSimpleTypeDefinition memberTypeDefinition = (XSDSimpleTypeDefinition)i.next(); - EDataType memberEDataType = getEDataType(memberTypeDefinition); - memberTypes.add(memberEDataType); - String memberInstanceClassName = memberEDataType.getInstanceClassName(); - if (memberInstanceClassName == null && memberEDataType instanceof EEnum) - { - memberInstanceClassName = "org.eclipse.emf.common.util.Enumerator"; - } - if (instanceClassName == null) - { - instanceClassName = memberInstanceClassName; - } - else if (instanceClassName != memberInstanceClassName) - { - instanceClassName = "java.lang.Object"; - } - } - extendedMetaData.setMemberTypes(eDataType, memberTypes); - eDataType.setInstanceClassName(instanceClassName); - } - } - else - { - EDataType baseEDataType = getEDataType(baseTypeDefinition); - extendedMetaData.setBaseType(eDataType, baseEDataType); - String instanceClassName = getInstanceClassName(xsdSimpleTypeDefinition, baseEDataType); - eDataType.setInstanceClassName - (instanceClassName == null ? - "org.eclipse.emf.common.util.Enumerator" : - instanceClassName); - } - - checkForPrimitive(xsdSimpleTypeDefinition, eDataType); - handleFacets(xsdSimpleTypeDefinition, eDataType); - - String constraints = getEcoreAttribute(xsdSimpleTypeDefinition, "constraints"); - if (constraints != null) - { - EcoreUtil.setAnnotation(eDataType, EcorePackage.eNS_URI, "constraints", constraints); - } - - if ("false".equals(getEcoreAttribute(xsdSimpleTypeDefinition, "serializable"))) - { - eDataType.setSerializable(false); - } - - return eDataType; - } - } - return (EDataType)getBuiltInEClassifier(rootSchema.getSchemaForSchemaNamespace(), "anySimpleType"); - } - } - - protected void checkForPrimitive(EDataType eDataType) - { - int index = PRIMITIVES.indexOf(eDataType.getInstanceClassName()); - if (index != -1 || eDataType instanceof EEnum) - { - EDataType eDataTypeObject = ecoreFactory.createEDataType(); - eDataTypeObject.setName(eDataType.getName() + "Object"); - if (index != -1) - { - eDataTypeObject.setInstanceClassName(PRIMITIVE_WRAPPERS[index]); - } - else - { - eDataTypeObject.setInstanceClassName("org.eclipse.emf.common.util.Enumerator"); - } - extendedMetaData.setName(eDataTypeObject, extendedMetaData.getName(eDataType) + ":Object"); - addToSortedList(eDataType.getEPackage().getEClassifiers(), eDataTypeObject); - extendedMetaData.setBaseType(eDataTypeObject, eDataType); - - typeToTypeObjectMap.put(eDataType, eDataTypeObject); - } - } - - public EClass computeEClass(XSDComplexTypeDefinition xsdComplexTypeDefinition) - { - if (xsdComplexTypeDefinition == null) - { - return (EClass)getBuiltInEClassifier(rootSchema.getSchemaForSchemaNamespace(), "anyType"); - } - else if (XSDConstants.isSchemaForSchemaNamespace(xsdComplexTypeDefinition.getTargetNamespace())) - { - String name = xsdComplexTypeDefinition.getName(); - if (name != null) - { - EClass result = (EClass)getBuiltInEClassifier(xsdComplexTypeDefinition.getTargetNamespace(), name); - if (result != null) - { - return result; - } - } - } - else if (xsdComplexTypeDefinition.getContainer() == null) - { - return (EClass)getBuiltInEClassifier(rootSchema.getSchemaForSchemaNamespace(), "anyType"); - } - - EClass eClass = ecoreFactory.createEClass(); - setAnnotations(eClass, xsdComplexTypeDefinition); - // Do this early to prevent recursive loop. - xsdComponentToEModelElementMap.put(xsdComplexTypeDefinition, eClass); - - if ("true".equals(getEcoreAttribute(xsdComplexTypeDefinition, "interface"))) - { - eClass.setInterface(true); - } - - String instanceClassName = getEcoreAttribute(xsdComplexTypeDefinition, "instanceClass"); - if (instanceClassName != null) - { - eClass.setInstanceClassName(instanceClassName); - } - - String aliasName = getEcoreAttribute(xsdComplexTypeDefinition, "name"); - if (aliasName == null) - { - aliasName = validAliasName(xsdComplexTypeDefinition, true); - } - eClass.setName(aliasName); - extendedMetaData.setName(eClass, xsdComplexTypeDefinition.getAliasName()); - - String constraints = getEcoreAttribute(xsdComplexTypeDefinition, "constraints"); - if (constraints != null) - { - EcoreUtil.setAnnotation(eClass, EcorePackage.eNS_URI, "constraints", constraints); - } - - EPackage ePackage = getEPackage(xsdComplexTypeDefinition); - addToSortedList(ePackage.getEClassifiers(), eClass); - - if (xsdComplexTypeDefinition.isAbstract()) - { - eClass.setAbstract(true); - } - - EClass baseClass = null; - XSDTypeDefinition baseTypeDefinition = xsdComplexTypeDefinition.getBaseTypeDefinition(); - if (!baseTypeDefinition.isCircular()) - { - EClassifier baseType = getEClassifier(baseTypeDefinition); - if (baseType instanceof EClass && baseType != ecorePackage.getEObject()) - { - eClass.getESuperTypes().add(baseClass = (EClass)baseType); - } - } - - boolean isRestriction = - !eClass.getESuperTypes().isEmpty() && - xsdComplexTypeDefinition.getDerivationMethod() == XSDDerivationMethod.RESTRICTION_LITERAL; - - for (Iterator i = getEcoreTypeQNamesAttribute(xsdComplexTypeDefinition, "implements").iterator(); i.hasNext(); ) - { - XSDTypeDefinition mixin = (XSDTypeDefinition)i.next(); - if (!XSDConstants.isURType(mixin)) - { - EClassifier mixinType = getEClassifier(mixin); - if (mixinType instanceof EClass && mixinType != ecorePackage.getEObject()) - { - eClass.getESuperTypes().add(mixinType); - } - } - } - - // 51210 - // EAnnotation contentParticle = null; - - if (xsdComplexTypeDefinition.getContentTypeCategory() == XSDContentTypeCategory.SIMPLE_LITERAL) - { - extendedMetaData.setContentKind(eClass, ExtendedMetaData.SIMPLE_CONTENT); - if (!"SimpleAnyType".equals(eClass.getName()) || !XMLTypePackage.eNS_URI.equals(eClass.getEPackage().getNsURI())) - { - if (eClass.getEAllStructuralFeatures().isEmpty()) - { - XSDComplexTypeContent xsdComplexTypeContent = xsdComplexTypeDefinition.getContent(); - String name = getEcoreAttribute(xsdComplexTypeContent, "name"); - if (name == null) - { - name = "value"; - } - createFeature - (eClass, - null, - name, - xsdComplexTypeContent, - false); - } - else - { - XSDSimpleTypeDefinition xsdSimpleTypeDefinition = xsdComplexTypeDefinition.getSimpleType(); - getEClassifier(xsdSimpleTypeDefinition); - } - } - } - else - { - EStructuralFeature globalGroup = null; - boolean isMixed = xsdComplexTypeDefinition.getContentTypeCategory() == XSDContentTypeCategory.MIXED_LITERAL; - String featureMapName = getEcoreAttribute(xsdComplexTypeDefinition, "featureMap"); - if (eClass.getESuperTypes().isEmpty() ? - "true".equals(getEcoreAttribute(xsdComplexTypeDefinition, "mixed")) : - extendedMetaData.getMixedFeature((EClass)eClass.getESuperTypes().get(0)) != null) - { - isMixed = true; - } - extendedMetaData.setContentKind - (eClass, - isMixed ? - ExtendedMetaData.MIXED_CONTENT : - xsdComplexTypeDefinition.getContentTypeCategory() == XSDContentTypeCategory.EMPTY_LITERAL ? - ExtendedMetaData.EMPTY_CONTENT : - ExtendedMetaData.ELEMENT_ONLY_CONTENT); - if (isMixed) - { - EStructuralFeature mixedFeature = extendedMetaData.getMixedFeature(eClass); - if (mixedFeature == null) - { - if (featureMapName == null) - { - featureMapName = "mixed"; - } - mixedFeature = - createFeature - (eClass, - featureMapName, - ecorePackage.getEFeatureMapEntry(), - null, - 0, - -1); - extendedMetaData.setName(mixedFeature, ":mixed"); - } - } - else - { - globalGroup = extendedMetaData.getElement(eClass, null, ":group"); - if (globalGroup == null && featureMapName != null && eClass.getESuperTypes().isEmpty()) - { - globalGroup = - createFeature - (eClass, - featureMapName, - ecorePackage.getEFeatureMapEntry(), - null, - 0, - -1); - extendedMetaData.setName(globalGroup, ":group"); - extendedMetaData.setFeatureKind(globalGroup, ExtendedMetaData.GROUP_FEATURE); - } - } - - if (xsdComplexTypeDefinition.getContent() != null) - { - // 51210 - // Map particleMap = new HashMap(); - Map groups = new HashMap(); - List particleInformation = collectParticles((XSDParticle)xsdComplexTypeDefinition.getContent()); - for (Iterator i = particleInformation.iterator(); i.hasNext(); ) - { - EffectiveOccurrence effectiveOccurrence = (EffectiveOccurrence)i.next(); - XSDParticle xsdParticle = effectiveOccurrence.xsdParticle; - EStructuralFeature group = (EStructuralFeature)groups.get(effectiveOccurrence.xsdModelGroup); - XSDTerm xsdTerm = xsdParticle.getTerm(); - EStructuralFeature eStructuralFeature = null; - String name = getEcoreAttribute(xsdParticle, "name"); - if (xsdTerm instanceof XSDModelGroup) - { - if (!isRestriction) - { - XSDModelGroup xsdModelGroup = (XSDModelGroup)xsdTerm; - if (name == null) - { - name = getEcoreAttribute(xsdParticle, "featureMap"); - if (name == null) - { - name = getEcoreAttribute(xsdModelGroup, "name"); - if (name == null) - { - name = getEcoreAttribute(xsdModelGroup, "featureMap"); - if (name == null) - { - if (xsdModelGroup.getContainer() instanceof XSDModelGroupDefinition) - { - XSDModelGroupDefinition xsdModelGroupDefinition = (XSDModelGroupDefinition)xsdModelGroup.getContainer(); - name = getEcoreAttribute(xsdModelGroupDefinition, "name"); - if (name == null) - { - name = validName(xsdModelGroupDefinition.getName(), true); - } - } - else - { - name = "group"; - } - } - } - } - } - - eStructuralFeature = - createFeature - (eClass, - name, - ecorePackage.getEFeatureMapEntry(), - xsdParticle, - 0, - -1); - groups.put(xsdTerm, eStructuralFeature); - extendedMetaData.setName(eStructuralFeature, name + ":" + eClass.getEAllStructuralFeatures().indexOf(eStructuralFeature)); - } - } - else if (xsdTerm instanceof XSDWildcard) - { - if (!isRestriction) - { - if (name == null) - { - name = getEcoreAttribute(xsdTerm, "name"); - if (name == null) - { - name = "any"; - } - } - eStructuralFeature = - createFeature - (eClass, - name, - ecorePackage.getEFeatureMapEntry(), - xsdParticle, - effectiveOccurrence.minOccurs, - effectiveOccurrence.maxOccurs); - // 51210 - // particleMap.put(xsdParticle, eStructuralFeature); - } - } - else - { - XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)xsdTerm; - - boolean isRedundant = false; - if (isRestriction) - { - isRedundant = - extendedMetaData.getElement - (baseClass, xsdElementDeclaration.getTargetNamespace(), xsdElementDeclaration.getName()) != null; - - if (!isRedundant) - { - group = - extendedMetaData.getElementWildcardAffiliation - (baseClass, xsdElementDeclaration.getTargetNamespace(), xsdElementDeclaration.getName()); - } - } - - if (!isRedundant) - { - if (name == null) - { - name = getEcoreAttribute(xsdElementDeclaration, "name"); - if (name == null) - { - name = validName(xsdElementDeclaration.getName(), true); - } - } - - String groupName = getEcoreAttribute(xsdParticle, "featureMap"); - if (groupName == null) - { - groupName = getEcoreAttribute(xsdElementDeclaration, "featureMap"); - } - - if (!"".equals(groupName) && - (groupName != null || - xsdElementDeclaration.isAbstract() || - xsdElementDeclaration.getSubstitutionGroup().size() > 1)) - { - if (groupName == null) - { - groupName = name + "Group"; - } - eStructuralFeature = - createFeature - (eClass, - groupName, - ecorePackage.getEFeatureMapEntry(), - xsdParticle, - effectiveOccurrence.minOccurs, - effectiveOccurrence.maxOccurs); - - eStructuralFeature.setChangeable(true); - - extendedMetaData.setFeatureKind(eStructuralFeature, ExtendedMetaData.GROUP_FEATURE); - extendedMetaData.setName(eStructuralFeature, xsdElementDeclaration.getName() + ":group"); - - if (group != null) - { - extendedMetaData.setGroup(eStructuralFeature, group); - eStructuralFeature.setDerived(true); - eStructuralFeature.setTransient(true); - eStructuralFeature.setVolatile(true); - } - else if (isMixed) - { - eStructuralFeature.setDerived(true); - eStructuralFeature.setTransient(true); - eStructuralFeature.setVolatile(true); - } - else if (globalGroup != null) - { - extendedMetaData.setGroup(eStructuralFeature, globalGroup); - eStructuralFeature.setDerived(true); - eStructuralFeature.setTransient(true); - eStructuralFeature.setVolatile(true); - } - - group = eStructuralFeature; - } - - eStructuralFeature = - createFeature(eClass, xsdElementDeclaration, name, xsdParticle, effectiveOccurrence.minOccurs, effectiveOccurrence.maxOccurs); - // 51210 - // particleMap.put(xsdParticle, eStructuralFeature); - - // If the group is turned off, we better make the feature changeable. - // - if (!eStructuralFeature.isChangeable() && group == null && getEcoreAttribute(xsdParticle, xsdElementDeclaration, "changeable") == null) - { - eStructuralFeature.setChangeable(true); - } - } - } - - if (eStructuralFeature != null) - { - if (group != null) - { - extendedMetaData.setGroup(eStructuralFeature, group); - eStructuralFeature.setDerived(true); - eStructuralFeature.setTransient(true); - eStructuralFeature.setVolatile(true); - } - else if (isMixed) - { - eStructuralFeature.setDerived(true); - eStructuralFeature.setTransient(true); - eStructuralFeature.setVolatile(true); - } - else if (globalGroup != null) - { - extendedMetaData.setGroup(eStructuralFeature, globalGroup); - eStructuralFeature.setDerived(true); - eStructuralFeature.setTransient(true); - eStructuralFeature.setVolatile(true); - } - } - } - - // 51210 - // contentParticle = computeParticleConstraints(eClass, particleMap, (XSDParticle)xsdComplexTypeDefinition.getContent()); - } - } - - // 51210 - // EAnnotation attributeParticle = null; - // if (isRestriction) - // { - // attributeParticle = ecoreFactory.createEAnnotation(); - // attributeParticle.setSource("attributes"); - // } - - XSDWildcard baseXSDWildcard = null; - Collection baseAttributeUses = Collections.EMPTY_LIST; - Map baseAttributeURIs = new HashMap(); - if (baseTypeDefinition instanceof XSDComplexTypeDefinition) - { - XSDComplexTypeDefinition complexBaseTypeDefinition = (XSDComplexTypeDefinition)baseTypeDefinition; - baseXSDWildcard = complexBaseTypeDefinition.getAttributeWildcard(); - baseAttributeUses = complexBaseTypeDefinition.getAttributeUses(); - for (Iterator i = baseAttributeUses.iterator(); i.hasNext(); ) - { - XSDAttributeUse xsdAttributeUse = (XSDAttributeUse)i.next(); - baseAttributeURIs.put(xsdAttributeUse.getAttributeDeclaration().getURI(), xsdAttributeUse); - } - } - - for (Iterator i = getAttributeUses(xsdComplexTypeDefinition).iterator(); i.hasNext(); ) - { - XSDAttributeUse xsdAttributeUse = (XSDAttributeUse)i.next(); - XSDAttributeDeclaration xsdAttributeDeclaration = xsdAttributeUse.getAttributeDeclaration(); - if (baseAttributeURIs.remove(xsdAttributeDeclaration.getURI()) == null) - { - String name = getEcoreAttribute(xsdAttributeUse, "name"); - if (name == null) - { - name = getEcoreAttribute(xsdAttributeDeclaration, "name"); - } - if (name == null) - { - name = validName(xsdAttributeDeclaration.getName(), true); - } - - EStructuralFeature eStructuralFeature = - createFeature(eClass, xsdAttributeDeclaration, name, xsdAttributeUse, xsdAttributeUse.isRequired()); - - if (isRestriction) - { - EStructuralFeature attributeWildcardEStructuralFeature = - extendedMetaData.getAttributeWildcardAffiliation - (baseClass, xsdAttributeDeclaration.getTargetNamespace(), xsdAttributeDeclaration.getName()); - if (attributeWildcardEStructuralFeature != null) - { - extendedMetaData.setGroup(eStructuralFeature, attributeWildcardEStructuralFeature); - eStructuralFeature.setDerived(true); - eStructuralFeature.setTransient(true); - eStructuralFeature.setVolatile(true); - } - } - } - /* 51210 - else if (isRestriction && !baseAttributeUses.contains(xsdAttributeUse)) - { - EStructuralFeature eStructuralFeature = - extendedMetaData.getAttribute(eClass, xsdAttributeDeclaration.getTargetNamespace(), xsdAttributeDeclaration.getName()); - if (eStructuralFeature != null) - { - EAnnotation attributeEAnnotation = ecoreFactory.createEAnnotation(); - if (xsdAttributeUse.isRequired()) - { - attributeEAnnotation.getDetails().put("minOccurs", "1"); - } - attributeEAnnotation.getReferences().add(eStructuralFeature); - - if (xsdAttributeDeclaration.getTypeDefinition() != null) - { - EClassifier type = getEClassifier(xsdAttributeDeclaration.getTypeDefinition()); - if (type != eStructuralFeature.getEType() && type != null) - { - attributeEAnnotation.getReferences().add(type); - } - } - - attributeParticle.getContents().add(attributeEAnnotation); - } - } - */ - } - - /* 51210 - if (isRestriction && !baseAttributeURIs.isEmpty()) - { - for (Iterator i = baseAttributeURIs.values().iterator(); i.hasNext(); ) - { - XSDAttributeUse xsdAttributeUse = (XSDAttributeUse)i.next(); - XSDAttributeDeclaration xsdAttributeDeclaration = xsdAttributeUse.getAttributeDeclaration(); - EStructuralFeature eStructuralFeature = - extendedMetaData.getAttribute(eClass, xsdAttributeDeclaration.getTargetNamespace(), xsdAttributeDeclaration.getName()); - if (eStructuralFeature != null) - { - EAnnotation attributeEAnnotation = ecoreFactory.createEAnnotation(); - attributeEAnnotation.getReferences().add(eStructuralFeature); - attributeEAnnotation.getDetails().put("maxOccurs", "0"); - attributeParticle.getContents().add(attributeEAnnotation); - } - } - } - */ - - XSDWildcard xsdWildcard = xsdComplexTypeDefinition.getAttributeWildcard(); - if (xsdWildcard != null && baseXSDWildcard != xsdWildcard || XSDConstants.isURType(xsdComplexTypeDefinition)) - { - if (isRestriction && !XSDConstants.isURType(xsdComplexTypeDefinition)) - { - // 51210 - // attributeParticle.getDetails().put - // ("wildcard", BasicExtendedMetaData.getEncodedWildcards(xsdComplexTypeDefinition.getTargetNamespace(), getWildcards(xsdWildcard))); - } - else - { - String name = getEcoreAttribute(xsdWildcard, "name"); - if (name == null) - { - name = "anyAttribute"; - } - createFeature - (eClass, - name, - ecorePackage.getEFeatureMapEntry(), - xsdWildcard, - 0, - -1); - } - } - - if (isRestriction) - { - // 51210 - // EAnnotation restrictionParticle = ecoreFactory.createEAnnotation(); - // restrictionParticle.setSource("restriction"); - // if (contentParticle != null) - // { - // restrictionParticle.getContents().add(contentParticle); - // } - // if (!attributeParticle.getContents().isEmpty() || !attributeParticle.getDetails().isEmpty()) - // { - // restrictionParticle.getContents().add(attributeParticle); - // } - // contentParticle = restrictionParticle; - - int baseContentKind = extendedMetaData.getContentKind((EClass)eClass.getESuperTypes().get(0)); - if (baseContentKind == ExtendedMetaData.MIXED_CONTENT && - xsdComplexTypeDefinition.getContentTypeCategory() == XSDContentTypeCategory.SIMPLE_LITERAL) - { - extendedMetaData.setContentKind(eClass, ExtendedMetaData.SIMPLE_CONTENT); - EStructuralFeature eStructuralFeature = - createFeature - (eClass, - "rawValue", - getBuiltInEClassifier(xsdComplexTypeDefinition.getSchema().getSchemaForSchemaNamespace(), "string"), - null, - 0, - 1); - eStructuralFeature.setDerived(true); - eStructuralFeature.setTransient(true); - eStructuralFeature.setVolatile(true); - - eStructuralFeature = - createFeature - (eClass, - "value", - getBuiltInEClassifier(xsdComplexTypeDefinition.getSchema().getSchemaForSchemaNamespace(), "anySimpleType"), - null, - 0, - 1); - eStructuralFeature.setDerived(true); - eStructuralFeature.setTransient(true); - eStructuralFeature.setVolatile(true); - - if ("SimpleAnyType".equals(eClass.getName()) && XMLTypePackage.eNS_URI.equals(eClass.getEPackage().getNsURI())) - { - eStructuralFeature = - createFeature - (eClass, - "instanceType", - ecorePackage.getEDataType(), - null, - 1, - 1); - - ((EReference)eStructuralFeature).setResolveProxies(false); - } - } - else - { - extendedMetaData.setContentKind(eClass, baseContentKind); - } - } - - // 51210 - // extendedMetaData.setContent(eClass, contentParticle); - - XSDAnnotation xsdAnnotation = xsdComplexTypeDefinition.getAnnotation(); - if (xsdAnnotation != null) - { - List applicationInformationList = xsdAnnotation.getApplicationInformation(EcorePackage.eNS_URI); - for (Iterator i = applicationInformationList.iterator(); i.hasNext(); ) - { - Element applicationInformation = (Element)i.next(); - if ("operations".equals(applicationInformation.getAttributeNS(EcorePackage.eNS_URI, "key"))) - { - for (Iterator j = getElements(applicationInformation, "operation").iterator(); j.hasNext(); ) - { - EOperation eOperation = ecoreFactory.createEOperation(); - Element operation = (Element)j.next(); - String operationName = operation.getAttributeNS(null, "name"); - eOperation.setName(operationName); - XSDTypeDefinition returnType = getEcoreTypeQNameAttribute(xsdComplexTypeDefinition, operation, null, "type"); - if (returnType != null) - { - EClassifier returnEType = getEClassifier(returnType); - eOperation.setEType(returnEType); - } - - List exceptions = getEcoreTypeQNamesAttribute(xsdComplexTypeDefinition, operation, null, "exceptions"); - for (Iterator k = exceptions.iterator(); k.hasNext(); ) - { - XSDTypeDefinition exceptionTypeDefinition = (XSDTypeDefinition)k.next(); - eOperation.getEExceptions().add(getEClassifier(exceptionTypeDefinition)); - } - - for (Iterator k = getElements(operation, "parameter").iterator(); k.hasNext(); ) - { - EParameter eParameter = ecoreFactory.createEParameter(); - Element parameter = (Element)k.next(); - String paramaterName = parameter.getAttributeNS(null, "name"); - XSDTypeDefinition parameterType = getEcoreTypeQNameAttribute(xsdComplexTypeDefinition, parameter, null, "type"); - EClassifier parameterEType = getEClassifier(parameterType); - eParameter.setName(paramaterName); - eParameter.setEType(parameterEType); - - populateETypedElement(eParameter, parameter); - eOperation.getEParameters().add(eParameter); - } - - List body = getElements(operation, "body"); - if (!body.isEmpty()) - { - EcoreUtil.setAnnotation(eOperation, "http://www.eclipse.org/emf/2002/GenModel", "body", getText((Element)body.get(0))); - } - - populateETypedElement(eOperation, operation); - eClass.getEOperations().add(eOperation); - } - } - } - } - return eClass; - } - - private String getText(Element element) - { - StringBuffer text = new StringBuffer(); - for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) - { - switch (node.getNodeType()) - { - case Node.TEXT_NODE: - case Node.CDATA_SECTION_NODE: - { - text.append(node.getNodeValue()); - } - } - } - return text.toString(); - } - - private List getElements(Element element, String localName) - { - List result = new ArrayList(); - for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) - { - if (node.getNodeType() == Node.ELEMENT_NODE) - { - Element child = (Element)node; - if (localName.equals(child.getLocalName()) && child.getNamespaceURI() == null) - { - result.add(child); - } - } - } - return result; - } - - protected EStructuralFeature createFeature - (EClass eClass, String name, EClassifier type, XSDComponent xsdComponent, int minOccurs, int maxOccurs) - { - if (xsdComponent != null) - { - XSDSchema containingXSDSchema = xsdComponent.getSchema(); - if (containingXSDSchema != null && !xsdSchemas.contains(containingXSDSchema)) - { - xsdSchemas.add(containingXSDSchema); - addInput(containingXSDSchema); - validate(containingXSDSchema); - } - } - else if (extendedMetaData.getContentKind(eClass) == ExtendedMetaData.MIXED_CONTENT) - { - if (type == ecorePackage.getEFeatureMapEntry()) - { - EAttribute eAttribute = ecoreFactory.createEAttribute(); - setAnnotations(eAttribute, xsdComponent); - eAttribute.setName(Character.toLowerCase(name.charAt(0)) + name.substring(1)); - eAttribute.setUnique(false); - eAttribute.setEType(type); - eAttribute.setLowerBound(minOccurs); - eAttribute.setUpperBound(maxOccurs); - eClass.getEStructuralFeatures().add(eAttribute); - extendedMetaData.setFeatureKind(eAttribute, ExtendedMetaData.ELEMENT_WILDCARD_FEATURE); - extendedMetaData.setName(eAttribute, ":" + eAttribute.getName()); - return eAttribute; - } - else - { - EReference eReference = ecoreFactory.createEReference(); - setAnnotations(eReference, xsdComponent); - eReference.setName(name); - eReference.setEType(ecorePackage.getEStringToStringMapEntry()); - eReference.setLowerBound(0); - eReference.setUpperBound(-1); - eReference.setContainment(true); - eReference.setResolveProxies(false); - eReference.setTransient(true); - eClass.getEStructuralFeatures().add(eReference); - extendedMetaData.setFeatureKind(eReference, ExtendedMetaData.ATTRIBUTE_FEATURE); - return eReference; - } - } - - if (type instanceof EClass) - { - EReference eReference = ecoreFactory.createEReference(); - setAnnotations(eReference, xsdComponent); - eReference.setName(Character.toLowerCase(name.charAt(0)) + name.substring(1)); - eReference.setEType(type); - eReference.setLowerBound(minOccurs); - eReference.setUpperBound(maxOccurs); - - eClass.getEStructuralFeatures().add(eReference); - if (xsdComponent == null || xsdComponent instanceof XSDSimpleTypeDefinition) - { - extendedMetaData.setName(eReference, ":" + eClass.getEAllStructuralFeatures().indexOf(eReference)); - extendedMetaData.setFeatureKind(eReference, ExtendedMetaData.SIMPLE_FEATURE); - eReference.setResolveProxies(!isLocalReferenceType((XSDSimpleTypeDefinition)xsdComponent)); - } - else - { - map(xsdComponent, eReference); - if (xsdComponent instanceof XSDParticle) - { - eReference.setContainment(true); - eReference.setResolveProxies(false); - - XSDParticle xsdParticle = (XSDParticle)xsdComponent; - - XSDTerm xsdTerm = ((XSDParticle)xsdComponent).getTerm(); - if (xsdTerm instanceof XSDElementDeclaration) - { - XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)xsdTerm; - extendedMetaData.setFeatureKind(eReference, ExtendedMetaData.ELEMENT_FEATURE); - extendedMetaData.setName(eReference, xsdElementDeclaration.getName()); - extendedMetaData.setNamespace(eReference, xsdElementDeclaration.getTargetNamespace()); - - XSDTypeDefinition xsdType = getEffectiveTypeDefinition(xsdParticle, xsdElementDeclaration); - if (xsdType instanceof XSDSimpleTypeDefinition) - { - eReference.setContainment(false); - eReference.setResolveProxies(!isLocalReferenceType((XSDSimpleTypeDefinition)xsdType)); - } - - if (maxOccurs == 1 && xsdElementDeclaration.isNillable()) - { - eReference.setUnsettable(true); - } - - if (xsdElementDeclaration.isAbstract()) - { - eReference.setChangeable(false); - } - - String opposite = getEcoreAttribute(xsdParticle, "opposite"); - if (opposite != null) - { - eReferenceToOppositeNameMap.put(eReference, opposite); - } - } - else if (xsdTerm instanceof XSDWildcard) - { - // EATM shouldn't happen - XSDWildcard xsdWildcard = (XSDWildcard)xsdTerm; - extendedMetaData.setFeatureKind(eReference, ExtendedMetaData.ELEMENT_WILDCARD_FEATURE); - extendedMetaData.setWildcards(eReference, getWildcards(xsdWildcard)); - extendedMetaData.setProcessingKind(eReference, xsdWildcard.getProcessContents().getValue() + 1); - extendedMetaData.setName(eReference, ":" + eClass.getEAllStructuralFeatures().indexOf(eReference)); - } - else - { - extendedMetaData.setFeatureKind(eReference, ExtendedMetaData.GROUP_FEATURE); - extendedMetaData.setName(eReference, ":" + eClass.getEAllStructuralFeatures().indexOf(eReference)); - } - } - else if (xsdComponent instanceof XSDElementDeclaration) - { - XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)xsdComponent; - eReference.setContainment(true); - eReference.setResolveProxies(false); - extendedMetaData.setFeatureKind(eReference, ExtendedMetaData.ELEMENT_FEATURE); - extendedMetaData.setName(eReference, xsdElementDeclaration.getName()); - extendedMetaData.setNamespace(eReference, xsdElementDeclaration.getTargetNamespace()); - - XSDElementDeclaration substitutionGroupAffiliation = xsdElementDeclaration.getSubstitutionGroupAffiliation(); - if (substitutionGroupAffiliation != null) - { - EStructuralFeature affiliation = getEStructuralFeature(substitutionGroupAffiliation); - extendedMetaData.setAffiliation(eReference, affiliation); - } - XSDTypeDefinition xsdType = getEffectiveTypeDefinition(null, xsdElementDeclaration); - if (xsdType instanceof XSDSimpleTypeDefinition) - { - eReference.setResolveProxies(!isLocalReferenceType((XSDSimpleTypeDefinition)xsdType)); - } - - if (maxOccurs == 1 && xsdElementDeclaration.isNillable()) - { - eReference.setUnsettable(true); - } - - if (xsdElementDeclaration.isAbstract()) - { - eReference.setChangeable(false); - } - } - else if (xsdComponent instanceof XSDAttributeUse) - { - String opposite = getEcoreAttribute(xsdComponent, "opposite"); - if (opposite != null) - { - eReferenceToOppositeNameMap.put(eReference, opposite); - } - - XSDAttributeUse xsdAttributeUse = (XSDAttributeUse)xsdComponent; - XSDAttributeDeclaration xsdAttributeDeclaration = xsdAttributeUse.getAttributeDeclaration(); - extendedMetaData.setFeatureKind(eReference, ExtendedMetaData.ATTRIBUTE_FEATURE); - extendedMetaData.setName(eReference, xsdAttributeDeclaration.getName()); - extendedMetaData.setNamespace(eReference, xsdAttributeDeclaration.getTargetNamespace()); - eReference.setResolveProxies - (!isLocalReferenceType((XSDSimpleTypeDefinition)getEffectiveTypeDefinition(xsdAttributeUse, xsdAttributeDeclaration))); - } - else if (xsdComponent instanceof XSDAttributeDeclaration) - { - XSDAttributeDeclaration xsdAttributeDeclaration = (XSDAttributeDeclaration)xsdComponent; - extendedMetaData.setFeatureKind(eReference, ExtendedMetaData.ATTRIBUTE_FEATURE); - extendedMetaData.setName(eReference, xsdAttributeDeclaration.getName()); - extendedMetaData.setNamespace(eReference, xsdAttributeDeclaration.getTargetNamespace()); - eReference.setResolveProxies - (!isLocalReferenceType((XSDSimpleTypeDefinition)getEffectiveTypeDefinition(null, xsdAttributeDeclaration))); - } - } - - return eReference; - } - else - { - EAttribute eAttribute = ecoreFactory.createEAttribute(); - setAnnotations(eAttribute, xsdComponent); - eAttribute.setName(Character.toLowerCase(name.charAt(0)) + name.substring(1)); - eAttribute.setUnique(false); - eAttribute.setEType(type); - eAttribute.setLowerBound(minOccurs); - eAttribute.setUpperBound(maxOccurs); - eClass.getEStructuralFeatures().add(eAttribute); - - if (xsdComponent == null || xsdComponent instanceof XSDSimpleTypeDefinition) - { - extendedMetaData.setName(eAttribute, ":" + eClass.getEAllStructuralFeatures().indexOf(eAttribute)); - extendedMetaData.setFeatureKind(eAttribute, ExtendedMetaData.SIMPLE_FEATURE); - } - else - { - map(xsdComponent, eAttribute); - if (xsdComponent instanceof XSDAttributeUse) - { - XSDAttributeUse xsdAttributeUse = (XSDAttributeUse)xsdComponent; - XSDAttributeDeclaration xsdAttributeDeclaration = xsdAttributeUse.getAttributeDeclaration(); - extendedMetaData.setFeatureKind(eAttribute, ExtendedMetaData.ATTRIBUTE_FEATURE); - extendedMetaData.setName(eAttribute, xsdAttributeDeclaration.getName()); - extendedMetaData.setNamespace(eAttribute, xsdAttributeDeclaration.getTargetNamespace()); - - String defaultValue = getEcoreAttribute(xsdComponent, "default"); - if (defaultValue == null) - { - defaultValue = xsdAttributeUse.getLexicalValue(); - } - eAttribute.setDefaultValueLiteral(defaultValue); - initialize(eAttribute, (XSDSimpleTypeDefinition)getEffectiveTypeDefinition(xsdAttributeUse, xsdAttributeDeclaration)); - } - else if (xsdComponent instanceof XSDAttributeDeclaration) - { - XSDAttributeDeclaration xsdAttributeDeclaration = (XSDAttributeDeclaration)xsdComponent; - extendedMetaData.setFeatureKind(eAttribute, ExtendedMetaData.ATTRIBUTE_FEATURE); - extendedMetaData.setName(eAttribute, xsdAttributeDeclaration.getName()); - extendedMetaData.setNamespace(eAttribute, xsdAttributeDeclaration.getTargetNamespace()); - - eAttribute.setDefaultValueLiteral(xsdAttributeDeclaration.getLexicalValue()); - initialize(eAttribute, (XSDSimpleTypeDefinition)getEffectiveTypeDefinition(null, xsdAttributeDeclaration)); - } - else if (xsdComponent instanceof XSDParticle) - { - XSDTerm xsdTerm = ((XSDParticle)xsdComponent).getTerm(); - if (xsdTerm instanceof XSDElementDeclaration) - { - XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)xsdTerm; - extendedMetaData.setFeatureKind(eAttribute, ExtendedMetaData.ELEMENT_FEATURE); - extendedMetaData.setName(eAttribute, xsdElementDeclaration.getName()); - extendedMetaData.setNamespace(eAttribute, xsdElementDeclaration.getTargetNamespace()); - - eAttribute.setDefaultValueLiteral(xsdElementDeclaration.getLexicalValue()); - XSDTypeDefinition xsdType = getEffectiveTypeDefinition(xsdComponent, xsdElementDeclaration); - if (xsdType instanceof XSDSimpleTypeDefinition) - { - initialize(eAttribute, (XSDSimpleTypeDefinition)xsdType); - } - - if (xsdElementDeclaration.isNillable()) - { - if (!canSupportNull((EDataType)type)) - { - eAttribute.setEType(type = (EDataType)typeToTypeObjectMap.get(type)); - } - if (maxOccurs == 1) - { - eAttribute.setUnsettable(true); - } - } - - if (xsdElementDeclaration.isAbstract()) - { - eAttribute.setChangeable(false); - } - } - else if (xsdTerm instanceof XSDWildcard) - { - XSDWildcard xsdWildcard = (XSDWildcard)xsdTerm; - extendedMetaData.setFeatureKind(eAttribute, ExtendedMetaData.ELEMENT_WILDCARD_FEATURE); - extendedMetaData.setWildcards(eAttribute, getWildcards(xsdWildcard)); - extendedMetaData.setProcessingKind(eAttribute, xsdWildcard.getProcessContents().getValue() + 1); - extendedMetaData.setName(eAttribute, ":" + eClass.getEAllStructuralFeatures().indexOf(eAttribute)); - } - else - { - extendedMetaData.setFeatureKind(eAttribute, ExtendedMetaData.GROUP_FEATURE); - } - } - else if (xsdComponent instanceof XSDWildcard) - { - XSDWildcard xsdWildcard = (XSDWildcard)xsdComponent; - extendedMetaData.setFeatureKind(eAttribute, ExtendedMetaData.ATTRIBUTE_WILDCARD_FEATURE); - extendedMetaData.setWildcards(eAttribute, getWildcards(xsdWildcard)); - extendedMetaData.setProcessingKind(eAttribute, xsdWildcard.getProcessContents().getValue() + 1); - extendedMetaData.setName(eAttribute, ":" + eClass.getEAllStructuralFeatures().indexOf(eAttribute)); - } - else if (xsdComponent instanceof XSDElementDeclaration) - { - XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)xsdComponent; - extendedMetaData.setFeatureKind(eAttribute, ExtendedMetaData.ELEMENT_FEATURE); - extendedMetaData.setName(eAttribute, xsdElementDeclaration.getName()); - extendedMetaData.setNamespace(eAttribute, xsdElementDeclaration.getTargetNamespace()); - - eAttribute.setDefaultValueLiteral(xsdElementDeclaration.getLexicalValue()); - XSDTypeDefinition xsdType = getEffectiveTypeDefinition(null, xsdElementDeclaration); - if (xsdType instanceof XSDSimpleTypeDefinition) - { - initialize(eAttribute, (XSDSimpleTypeDefinition)xsdType); - } - - XSDElementDeclaration substitutionGroupAffiliation = xsdElementDeclaration.getSubstitutionGroupAffiliation(); - if (substitutionGroupAffiliation != null) - { - EStructuralFeature affiliation = getEStructuralFeature(substitutionGroupAffiliation); - extendedMetaData.setAffiliation(eAttribute, affiliation); - } - - if (xsdElementDeclaration.isNillable() && !canSupportNull((EDataType)type)) - { - eAttribute.setEType(type = (EDataType)typeToTypeObjectMap.get(type)); - if (maxOccurs == 1) - { - eAttribute.setUnsettable(true); - } - } - - if (xsdElementDeclaration.isAbstract()) - { - eAttribute.setChangeable(false); - } - } - } - - if (maxOccurs == 1 && (type.getDefaultValue() != null || eAttribute.getDefaultValueLiteral() != null)) - { - eAttribute.setUnsettable(true); - } - - return eAttribute; - } - } - - protected XSDTypeDefinition getEffectiveTypeDefinition(XSDComponent xsdComponent, XSDFeature xsdFeature) - { - return xsdFeature == null ? - ((XSDComplexTypeDefinition)xsdComponent.eContainer()).getSimpleType() : xsdFeature.getType(); - } - - protected EStructuralFeature createFeature - (EClass eClass, XSDElementDeclaration xsdElementDeclaration, String name, XSDComponent xsdComponent, int minOccurs, int maxOccurs) - { - XSDTypeDefinition elementTypeDefinition = getEffectiveTypeDefinition(xsdComponent, xsdElementDeclaration); - EClassifier eClassifier = getEClassifier(elementTypeDefinition); - - XSDTypeDefinition referenceType = getEcoreTypeQNameAttribute(xsdComponent, "reference"); - if (referenceType == null) - { - referenceType = getEcoreTypeQNameAttribute(xsdElementDeclaration, "reference"); - } - if (referenceType != null) - { - EClassifier referenceClassifier = getEClassifier(referenceType); - boolean needsHolder = false; - if (elementTypeDefinition instanceof XSDSimpleTypeDefinition) - { - XSDSimpleTypeDefinition xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition)elementTypeDefinition; - if (xsdSimpleTypeDefinition.getVariety() == XSDVariety.LIST_LITERAL) - { - needsHolder = true; - - EPackage holderPackage = getEPackage(xsdElementDeclaration); - String holderName = xsdElementDeclaration.getName() + ":holder"; - EClass holderClass = (EClass)extendedMetaData.getType(holderPackage, holderName); - if (holderClass == null) - { - // Create a holder class like an anonymous complex type. - // - holderClass = ecoreFactory.createEClass(); - setAnnotations(holderClass, xsdElementDeclaration); - holderClass.setName(validName(holderName, true)); - extendedMetaData.setName(holderClass, holderName); - extendedMetaData.setContentKind(holderClass, ExtendedMetaData.SIMPLE_CONTENT); - - addToSortedList(holderPackage.getEClassifiers(), holderClass); - - EReference holderReference = - (EReference)createFeature - (holderClass, - "value", - referenceClassifier, - null, - 0, - -1); - - holderReference.setResolveProxies(!isLocalReferenceType(xsdSimpleTypeDefinition)); - } - referenceClassifier = holderClass; - } - } - EStructuralFeature result = - createFeature - (eClass, - name, - referenceClassifier, - xsdComponent, - minOccurs, - maxOccurs); - ((EReference)result).setContainment(needsHolder); - if (needsHolder) - { - ((EReference)result).setUnsettable(false); - ((EReference)result).setResolveProxies(false); - } - initialize(result, xsdElementDeclaration, xsdComponent); - return result; - } - else - { - EStructuralFeature result = - createFeature - (eClass, - name, - eClassifier, - xsdComponent, - minOccurs, - maxOccurs); - initialize(result, xsdElementDeclaration, xsdComponent); - return result; - } - } - - protected EStructuralFeature createFeature - (EClass eClass, XSDAttributeDeclaration xsdAttributeDeclaration, String name, XSDComponent xsdComponent, boolean isRequired) - { - XSDSimpleTypeDefinition attributeTypeDefinition = (XSDSimpleTypeDefinition)getEffectiveTypeDefinition(xsdComponent, xsdAttributeDeclaration); - if (attributeTypeDefinition == null) - { - attributeTypeDefinition = xsdComponent.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("anySimpleType"); - } - - XSDTypeDefinition referenceType = getEcoreTypeQNameAttribute(xsdComponent, "reference"); - if (referenceType == null && xsdAttributeDeclaration != null) - { - referenceType = getEcoreTypeQNameAttribute(xsdAttributeDeclaration, "reference"); - } - if (referenceType != null) - { - int lowerBound = isRequired ? 1 : 0; - int upperBound = 1; - if (attributeTypeDefinition.getVariety() == XSDVariety.LIST_LITERAL) - { - XSDLengthFacet xsdLengthFacet = attributeTypeDefinition.getEffectiveLengthFacet(); - if (isRequired) - { - if (xsdLengthFacet != null) - { - lowerBound = xsdLengthFacet.getValue(); - } - else - { - XSDMinLengthFacet xsdMinLengthFacet = attributeTypeDefinition.getEffectiveMinLengthFacet(); - if (xsdMinLengthFacet != null) - { - lowerBound = xsdMinLengthFacet.getValue(); - } - } - } - if (xsdLengthFacet != null) - { - upperBound = xsdLengthFacet.getValue(); - } - else - { - XSDMaxLengthFacet xsdMaxLengthFacet = attributeTypeDefinition.getEffectiveMaxLengthFacet(); - if (xsdMaxLengthFacet != null) - { - upperBound = xsdMaxLengthFacet.getValue(); - } - else - { - upperBound = -1; - } - } - } - - EClassifier referenceClassifier = getEClassifier(referenceType); - EStructuralFeature result = - createFeature - (eClass, - name, - referenceClassifier, - xsdComponent, - lowerBound, - upperBound); - initialize(result, xsdAttributeDeclaration, xsdComponent); - return result; - } - else - { - boolean isMany = - attributeTypeDefinition.getVariety() == XSDVariety.LIST_LITERAL && - xsdComponent instanceof XSDAttributeUse && - "true".equals(getEcoreAttribute(xsdComponent, "many")); - if (isMany) - { - EDataType eDataType = getEDataType(attributeTypeDefinition.getItemTypeDefinition()); - XSDLengthFacet xsdLengthFacet = attributeTypeDefinition.getEffectiveLengthFacet(); - int lowerBound = isRequired ? 1 : 0; - int upperBound = -1; - if (isRequired) - { - if (xsdLengthFacet != null) - { - lowerBound = xsdLengthFacet.getValue(); - } - else - { - XSDMinLengthFacet xsdMinLengthFacet = attributeTypeDefinition.getEffectiveMinLengthFacet(); - if (xsdMinLengthFacet != null) - { - lowerBound = xsdMinLengthFacet.getValue(); - } - } - } - if (xsdLengthFacet != null) - { - upperBound = xsdLengthFacet.getValue(); - } - else - { - XSDMaxLengthFacet xsdMaxLengthFacet = attributeTypeDefinition.getEffectiveMaxLengthFacet(); - if (xsdMaxLengthFacet != null) - { - upperBound = xsdMaxLengthFacet.getValue(); - } - } - EStructuralFeature result = - createFeature - (eClass, - name, - eDataType, - xsdComponent, - lowerBound, - upperBound); - initialize(result, xsdAttributeDeclaration, xsdComponent); - return result; - } - else - { - EDataType eDataType = getEDataType(attributeTypeDefinition); - EStructuralFeature result = - createFeature - (eClass, - name, - eDataType, - xsdComponent, - isRequired ? 1 : 0, - 1); - initialize(result, xsdAttributeDeclaration, xsdComponent); - return result; - } - } - } - - public EStructuralFeature getEStructuralFeature(XSDFeature xsdFeature) - { - if ("true".equals(getEcoreAttribute(xsdFeature, "ignore"))) return null; - EStructuralFeature eStructuralFeature = (EStructuralFeature)xsdComponentToEModelElementMap.get(xsdFeature); - if (eStructuralFeature == null) - { - EPackage ePackage = getEPackage(xsdFeature); - EClass documentEClass = extendedMetaData.getDocumentRoot(ePackage); - if (documentEClass == null) - { - createDocumentRoot(xsdFeature.getSchema(), ePackage); - } - - String name = getEcoreAttribute(xsdFeature, "name"); - if (name == null) - { - name= validName(xsdFeature.getName(), true); - } - - if (xsdFeature instanceof XSDElementDeclaration) - { - // Mark the bound as unspecified so that it won't be considered many - // but can nevertheless be recognized as being unspecified and perhaps still be treat as many. - // - EStructuralFeature result = - createFeature(documentEClass, (XSDElementDeclaration)xsdFeature, name, xsdFeature, 0, ETypedElement.UNSPECIFIED_MULTIPLICITY); - - result.setDerived(true); - result.setTransient(true); - result.setVolatile(true); - return result; - } - else - { - EStructuralFeature result = - createFeature(documentEClass, (XSDAttributeDeclaration)xsdFeature, name, xsdFeature, false); - return result; - } - } - - return eStructuralFeature; - } - - public void generate(XSDSchema xsdSchema) - { - this.rootSchema = xsdSchema; - if (xsdSchemas.add(xsdSchema)) - { - addInput(xsdSchema); - validate(xsdSchema); - } - - Collection visitedElementDeclarations = new ArrayList(); - Collection elementDeclarations = new ArrayList(xsdSchema.getElementDeclarations()); - - Collection visitedAttributeDeclarations = new ArrayList(); - Collection attributeDeclarations = new ArrayList(xsdSchema.getAttributeDeclarations()); - - Collection visitedTypeDefinitions = new ArrayList(); - Collection typeDefinitions = new ArrayList(xsdSchema.getTypeDefinitions()); - - while (!elementDeclarations.isEmpty() || !attributeDeclarations.isEmpty() || !typeDefinitions.isEmpty()) - { - for (Iterator i = elementDeclarations.iterator(); i.hasNext(); ) - { - XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)i.next(); - getEStructuralFeature(xsdElementDeclaration); - } - visitedElementDeclarations.addAll(elementDeclarations); - elementDeclarations = new ArrayList(xsdSchema.getElementDeclarations()); - elementDeclarations.removeAll(visitedElementDeclarations); - - for (Iterator i = attributeDeclarations.iterator(); i.hasNext(); ) - { - XSDAttributeDeclaration xsdAttributeDeclaration = (XSDAttributeDeclaration)i.next(); - if (!XSDConstants.isSchemaInstanceNamespace(xsdAttributeDeclaration.getTargetNamespace())) - { - getEStructuralFeature(xsdAttributeDeclaration); - } - } - visitedAttributeDeclarations.addAll(attributeDeclarations); - attributeDeclarations = new ArrayList(xsdSchema.getAttributeDeclarations()); - attributeDeclarations.removeAll(visitedAttributeDeclarations); - - for (Iterator i = typeDefinitions.iterator(); i.hasNext(); ) - { - XSDTypeDefinition xsdTypeDefinition = (XSDTypeDefinition)i.next(); - getEClassifier(xsdTypeDefinition); - } - visitedTypeDefinitions.addAll(typeDefinitions); - typeDefinitions = new ArrayList(xsdSchema.getTypeDefinitions()); - typeDefinitions.removeAll(visitedTypeDefinitions); - } - - resolveNameConflicts(); - - for (Iterator i = xsdSchemas.iterator(); i.hasNext(); ) - { - XSDSchema generatedXSDSchema = (XSDSchema)i.next(); - EPackage ePackage = (EPackage)targetNamespaceToEPackageMap.get(generatedXSDSchema.getTargetNamespace()); - if (ePackage != null) - { - String packageName= getEcoreAttribute(generatedXSDSchema, "package"); - if (packageName != null) - { - ePackage.setName(packageName); - } - String packageNsPrefix= getEcoreAttribute(generatedXSDSchema, "nsPrefix"); - if (packageNsPrefix != null) - { - ePackage.setNsPrefix(packageNsPrefix); - } - } - } - - for (Iterator i = eReferenceToOppositeNameMap.entrySet().iterator(); i.hasNext(); ) - { - Map.Entry entry = (Map.Entry)i.next(); - EReference eReference = (EReference)entry.getKey(); - String opposite = (String)entry.getValue(); - EClass oppositeEClass = eReference.getEReferenceType(); - if (eReference.getEOpposite() == null) - { - EStructuralFeature eOppositeFeature = oppositeEClass.getEStructuralFeature(opposite); - - // Match by XML name if this fails. - if (eOppositeFeature == null) - { - for (Iterator j = oppositeEClass.getEAllStructuralFeatures().iterator(); j.hasNext(); ) - { - EStructuralFeature feature = (EStructuralFeature)j.next(); - if (opposite.equals(extendedMetaData.getName(feature))) - { - eOppositeFeature = feature; - break; - } - } - } - - if (eOppositeFeature instanceof EReference) - { - EReference eOpposite = (EReference)eOppositeFeature; - eOpposite.setEOpposite(eReference); - eReference.setEOpposite(eOpposite); - } - } - - if (eReference.getEOpposite() == null && eReference.isContainment()) - { - EReference eOpposite = ecoreFactory.createEReference(); - eOpposite.setName(opposite); - eOpposite.setEType(eReference.getEContainingClass()); - eOpposite.setLowerBound(0); - eOpposite.setEOpposite(eReference); - eReference.setEOpposite(eOpposite); - eOpposite.setTransient(true); - oppositeEClass.getEStructuralFeatures().add(eOpposite); - } - } - - eReferenceToOppositeNameMap.clear(); - } - -} +/** + * + * 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.helper; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EDataType; +import org.eclipse.emf.ecore.EEnum; +import org.eclipse.emf.ecore.EOperation; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EParameter; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.ETypedElement; +import org.eclipse.emf.ecore.EcoreFactory; +import org.eclipse.emf.ecore.EcorePackage; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.ecore.util.ExtendedMetaData; +import org.eclipse.emf.ecore.xml.type.XMLTypePackage; +import org.eclipse.xsd.XSDAnnotation; +import org.eclipse.xsd.XSDAttributeDeclaration; +import org.eclipse.xsd.XSDAttributeUse; +import org.eclipse.xsd.XSDComplexTypeContent; +import org.eclipse.xsd.XSDComplexTypeDefinition; +import org.eclipse.xsd.XSDComponent; +import org.eclipse.xsd.XSDContentTypeCategory; +import org.eclipse.xsd.XSDDerivationMethod; +import org.eclipse.xsd.XSDElementDeclaration; +import org.eclipse.xsd.XSDFeature; +import org.eclipse.xsd.XSDLengthFacet; +import org.eclipse.xsd.XSDMaxLengthFacet; +import org.eclipse.xsd.XSDMinLengthFacet; +import org.eclipse.xsd.XSDModelGroup; +import org.eclipse.xsd.XSDModelGroupDefinition; +import org.eclipse.xsd.XSDNamedComponent; +import org.eclipse.xsd.XSDParticle; +import org.eclipse.xsd.XSDSchema; +import org.eclipse.xsd.XSDSimpleTypeDefinition; +import org.eclipse.xsd.XSDTerm; +import org.eclipse.xsd.XSDTypeDefinition; +import org.eclipse.xsd.XSDVariety; +import org.eclipse.xsd.XSDWildcard; +import org.eclipse.xsd.ecore.XSDEcoreBuilder; +import org.eclipse.xsd.util.XSDConstants; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * An XSDEcoreBuilder that uses a supplied (SDO) ecore factory to create properties and types. + */ +public class BaseSDOXSDEcoreBuilder extends XSDEcoreBuilder +{ + protected EcorePackage ecorePackage = EcorePackage.eINSTANCE; + protected EcoreFactory ecoreFactory = EcoreFactory.eINSTANCE; + + public BaseSDOXSDEcoreBuilder(ExtendedMetaData extendedMetaData) + { + super(extendedMetaData); + } + + private void createDocumentRoot(XSDSchema xsdSchema, EPackage ePackage) { + EClass documentEClass = ecoreFactory.createEClass(); + String name = getEcoreAttribute(xsdSchema, "documentRoot"); + if (name == null) + { + name = "DocumentRoot"; + } + documentEClass.setName(name); + + extendedMetaData.setDocumentRoot(documentEClass); + + ePackage.getEClassifiers().add(documentEClass); + + createFeature + (documentEClass, + "mixed", + ecorePackage.getEFeatureMapEntry(), + null, + 0, + -1); + + EStructuralFeature xmlnsPrefixMapFeature = + createFeature + (documentEClass, + "xMLNSPrefixMap", + ecorePackage.getEStringToStringMapEntry(), + null, + 0, + -1); + extendedMetaData.setName(xmlnsPrefixMapFeature, "xmlns:prefix"); + + EStructuralFeature xsiSchemaLocationMapFeature = + createFeature + (documentEClass, + "xSISchemaLocation", + ecorePackage.getEStringToStringMapEntry(), + null, + 0, + -1); + extendedMetaData.setName(xsiSchemaLocationMapFeature, "xsi:schemaLocation"); + } + + public EPackage getEPackage(XSDNamedComponent xsdNamedComponent) + { + XSDSchema containingXSDSchema = xsdNamedComponent.getSchema(); + if (containingXSDSchema != null && !xsdSchemas.contains(containingXSDSchema)) + { + xsdSchemas.add(containingXSDSchema); + addInput(containingXSDSchema); + validate(containingXSDSchema); + } + + String targetNamespace = + containingXSDSchema == null ? + xsdNamedComponent.getTargetNamespace() : + containingXSDSchema.getTargetNamespace(); + EPackage ePackage = (EPackage)targetNamespaceToEPackageMap.get(targetNamespace); + if (ePackage == null) + { + ePackage = ecoreFactory.createEPackage(); + setAnnotations(ePackage, containingXSDSchema); + addOutput(ePackage); + if (targetNamespace == null) + { + if (containingXSDSchema == null) + { + containingXSDSchema = rootSchema; + } + ePackage.setName(validName(containingXSDSchema.eResource().getURI().trimFileExtension().lastSegment(), true)); + ePackage.setNsURI(containingXSDSchema.eResource().getURI().toString()); + + // Also register against the nsURI for the case that the target namespace is null. + // + // extendedMetaData.putPackage(ePackage.getNsURI(), ePackage); + } + else + { + String qualifiedPackageName = qualifiedPackageName(targetNamespace); + ePackage.setName(qualifiedPackageName); + ePackage.setNsURI(targetNamespace); + } + + String nsPrefix = ePackage.getName(); + int index = nsPrefix.lastIndexOf('.'); + nsPrefix = index == -1 ? nsPrefix : nsPrefix.substring(index + 1); + + // http://www.w3.org/TR/REC-xml-names/#xmlReserved + // Namespace Constraint: Leading "XML" + // Prefixes beginning with the three-letter sequence x, m, l, in any case combination, + // are reserved for use by XML and XML-related specifications. + // + if (nsPrefix.toLowerCase().startsWith("xml")) + { + nsPrefix = "_" + nsPrefix; + } + ePackage.setNsPrefix(nsPrefix); + + extendedMetaData.setQualified(ePackage, targetNamespace != null); + extendedMetaData.putPackage(targetNamespace, ePackage); + + targetNamespaceToEPackageMap.put(targetNamespace, ePackage); + + createDocumentRoot(xsdNamedComponent.getSchema(), ePackage); + } + + return ePackage; + } + + protected EClassifier computeEClassifier(XSDTypeDefinition xsdTypeDefinition) + { + if (xsdTypeDefinition == null) + { + return getBuiltInEClassifier(rootSchema.getSchemaForSchemaNamespace(), "anySimpleType"); + } + else if (xsdTypeDefinition instanceof XSDSimpleTypeDefinition) + { + return computeEDataType((XSDSimpleTypeDefinition)xsdTypeDefinition); + } + else + { + return computeEClass((XSDComplexTypeDefinition)xsdTypeDefinition); + } + } + + protected EDataType computeEDataType(XSDSimpleTypeDefinition xsdSimpleTypeDefinition) + { + if (xsdSimpleTypeDefinition == null) + { + return (EDataType)getBuiltInEClassifier(rootSchema.getSchemaForSchemaNamespace(), "anySimpleType"); + } + else if (XSDConstants.isSchemaForSchemaNamespace(xsdSimpleTypeDefinition.getTargetNamespace())) + { + String name = xsdSimpleTypeDefinition.getName(); + if (name != null) + { + EDataType result = (EDataType)getBuiltInEClassifier(xsdSimpleTypeDefinition.getTargetNamespace(), "anyType".equals(name) ? "anySimpleType" : name); + if (result != null) + { + return result; + } + } + } + else if (xsdSimpleTypeDefinition.getContainer() == null) + { + return (EDataType)getBuiltInEClassifier(rootSchema.getSchemaForSchemaNamespace(), "anySimpleType"); + } + + String explicitInstanceClassName = getEcoreAttribute(xsdSimpleTypeDefinition, "instanceClass"); + if (explicitInstanceClassName != null) + { + EDataType eDataType = ecoreFactory.createEDataType(); + setAnnotations(eDataType, xsdSimpleTypeDefinition); + + String aliasName = getEcoreAttribute(xsdSimpleTypeDefinition, "name"); + if (aliasName == null) + { + aliasName = validAliasName(xsdSimpleTypeDefinition, true); + } + eDataType.setName(aliasName); + extendedMetaData.setName(eDataType, xsdSimpleTypeDefinition.getAliasName()); + + eDataType.setInstanceClassName(explicitInstanceClassName); + + EPackage ePackage = getEPackage(xsdSimpleTypeDefinition); + addToSortedList(ePackage.getEClassifiers(), eDataType); + + checkForPrimitive(xsdSimpleTypeDefinition, eDataType); + + handleFacets(xsdSimpleTypeDefinition, eDataType); + + String constraints = getEcoreAttribute(xsdSimpleTypeDefinition, "constraints"); + if (constraints != null) + { + EcoreUtil.setAnnotation(eDataType, EcorePackage.eNS_URI, "constraints", constraints); + } + + if ("false".equals(getEcoreAttribute(xsdSimpleTypeDefinition, "serializable"))) + { + eDataType.setSerializable(false); + } + return eDataType; + } + else + { + EEnum eEnum = computeEEnum(xsdSimpleTypeDefinition); + if (eEnum != null) + { + return eEnum; + } + else + { + XSDSimpleTypeDefinition baseTypeDefinition = xsdSimpleTypeDefinition.getBaseTypeDefinition(); + if (baseTypeDefinition != null) + { + EDataType eDataType = ecoreFactory.createEDataType(); + setAnnotations(eDataType, xsdSimpleTypeDefinition); + + String name = getEcoreAttribute(xsdSimpleTypeDefinition, "name"); + if (name == null) + { + name = validAliasName(xsdSimpleTypeDefinition, true); + } + + eDataType.setName(name); + extendedMetaData.setName(eDataType, xsdSimpleTypeDefinition.getAliasName()); + + EPackage ePackage = getEPackage(xsdSimpleTypeDefinition); + addToSortedList(ePackage.getEClassifiers(), eDataType); + + if (baseTypeDefinition.getVariety() != xsdSimpleTypeDefinition.getVariety()) + { + if (xsdSimpleTypeDefinition.getVariety() == XSDVariety.LIST_LITERAL) + { + EDataType itemEDataType = getEDataType(xsdSimpleTypeDefinition.getItemTypeDefinition()); + extendedMetaData.setItemType(eDataType, itemEDataType); + eDataType.setInstanceClassName("java.util.List"); + } + else + { + String instanceClassName = null; + List memberTypes = new ArrayList(); + for (Iterator i = xsdSimpleTypeDefinition.getMemberTypeDefinitions().iterator(); i.hasNext(); ) + { + XSDSimpleTypeDefinition memberTypeDefinition = (XSDSimpleTypeDefinition)i.next(); + EDataType memberEDataType = getEDataType(memberTypeDefinition); + memberTypes.add(memberEDataType); + String memberInstanceClassName = memberEDataType.getInstanceClassName(); + if (memberInstanceClassName == null && memberEDataType instanceof EEnum) + { + memberInstanceClassName = "org.eclipse.emf.common.util.Enumerator"; + } + if (instanceClassName == null) + { + instanceClassName = memberInstanceClassName; + } + else if (instanceClassName != memberInstanceClassName) + { + instanceClassName = "java.lang.Object"; + } + } + extendedMetaData.setMemberTypes(eDataType, memberTypes); + eDataType.setInstanceClassName(instanceClassName); + } + } + else + { + EDataType baseEDataType = getEDataType(baseTypeDefinition); + extendedMetaData.setBaseType(eDataType, baseEDataType); + String instanceClassName = getInstanceClassName(xsdSimpleTypeDefinition, baseEDataType); + eDataType.setInstanceClassName + (instanceClassName == null ? + "org.eclipse.emf.common.util.Enumerator" : + instanceClassName); + } + + checkForPrimitive(xsdSimpleTypeDefinition, eDataType); + handleFacets(xsdSimpleTypeDefinition, eDataType); + + String constraints = getEcoreAttribute(xsdSimpleTypeDefinition, "constraints"); + if (constraints != null) + { + EcoreUtil.setAnnotation(eDataType, EcorePackage.eNS_URI, "constraints", constraints); + } + + if ("false".equals(getEcoreAttribute(xsdSimpleTypeDefinition, "serializable"))) + { + eDataType.setSerializable(false); + } + + return eDataType; + } + } + return (EDataType)getBuiltInEClassifier(rootSchema.getSchemaForSchemaNamespace(), "anySimpleType"); + } + } + + protected void checkForPrimitive(EDataType eDataType) + { + int index = PRIMITIVES.indexOf(eDataType.getInstanceClassName()); + if (index != -1 || eDataType instanceof EEnum) + { + EDataType eDataTypeObject = ecoreFactory.createEDataType(); + eDataTypeObject.setName(eDataType.getName() + "Object"); + if (index != -1) + { + eDataTypeObject.setInstanceClassName(PRIMITIVE_WRAPPERS[index]); + } + else + { + eDataTypeObject.setInstanceClassName("org.eclipse.emf.common.util.Enumerator"); + } + extendedMetaData.setName(eDataTypeObject, extendedMetaData.getName(eDataType) + ":Object"); + addToSortedList(eDataType.getEPackage().getEClassifiers(), eDataTypeObject); + extendedMetaData.setBaseType(eDataTypeObject, eDataType); + + typeToTypeObjectMap.put(eDataType, eDataTypeObject); + } + } + + public EClass computeEClass(XSDComplexTypeDefinition xsdComplexTypeDefinition) + { + if (xsdComplexTypeDefinition == null) + { + return (EClass)getBuiltInEClassifier(rootSchema.getSchemaForSchemaNamespace(), "anyType"); + } + else if (XSDConstants.isSchemaForSchemaNamespace(xsdComplexTypeDefinition.getTargetNamespace())) + { + String name = xsdComplexTypeDefinition.getName(); + if (name != null) + { + EClass result = (EClass)getBuiltInEClassifier(xsdComplexTypeDefinition.getTargetNamespace(), name); + if (result != null) + { + return result; + } + } + } + else if (xsdComplexTypeDefinition.getContainer() == null) + { + return (EClass)getBuiltInEClassifier(rootSchema.getSchemaForSchemaNamespace(), "anyType"); + } + + EClass eClass = ecoreFactory.createEClass(); + setAnnotations(eClass, xsdComplexTypeDefinition); + // Do this early to prevent recursive loop. + xsdComponentToEModelElementMap.put(xsdComplexTypeDefinition, eClass); + + if ("true".equals(getEcoreAttribute(xsdComplexTypeDefinition, "interface"))) + { + eClass.setInterface(true); + } + + String instanceClassName = getEcoreAttribute(xsdComplexTypeDefinition, "instanceClass"); + if (instanceClassName != null) + { + eClass.setInstanceClassName(instanceClassName); + } + + String aliasName = getEcoreAttribute(xsdComplexTypeDefinition, "name"); + if (aliasName == null) + { + aliasName = validAliasName(xsdComplexTypeDefinition, true); + } + eClass.setName(aliasName); + extendedMetaData.setName(eClass, xsdComplexTypeDefinition.getAliasName()); + + String constraints = getEcoreAttribute(xsdComplexTypeDefinition, "constraints"); + if (constraints != null) + { + EcoreUtil.setAnnotation(eClass, EcorePackage.eNS_URI, "constraints", constraints); + } + + EPackage ePackage = getEPackage(xsdComplexTypeDefinition); + addToSortedList(ePackage.getEClassifiers(), eClass); + + if (xsdComplexTypeDefinition.isAbstract()) + { + eClass.setAbstract(true); + } + + EClass baseClass = null; + XSDTypeDefinition baseTypeDefinition = xsdComplexTypeDefinition.getBaseTypeDefinition(); + if (!baseTypeDefinition.isCircular()) + { + EClassifier baseType = getEClassifier(baseTypeDefinition); + if (baseType instanceof EClass && baseType != ecorePackage.getEObject()) + { + eClass.getESuperTypes().add(baseClass = (EClass)baseType); + } + } + + boolean isRestriction = + !eClass.getESuperTypes().isEmpty() && + xsdComplexTypeDefinition.getDerivationMethod() == XSDDerivationMethod.RESTRICTION_LITERAL; + + for (Iterator i = getEcoreTypeQNamesAttribute(xsdComplexTypeDefinition, "implements").iterator(); i.hasNext(); ) + { + XSDTypeDefinition mixin = (XSDTypeDefinition)i.next(); + if (!XSDConstants.isURType(mixin)) + { + EClassifier mixinType = getEClassifier(mixin); + if (mixinType instanceof EClass && mixinType != ecorePackage.getEObject()) + { + eClass.getESuperTypes().add(mixinType); + } + } + } + + // 51210 + // EAnnotation contentParticle = null; + + if (xsdComplexTypeDefinition.getContentTypeCategory() == XSDContentTypeCategory.SIMPLE_LITERAL) + { + extendedMetaData.setContentKind(eClass, ExtendedMetaData.SIMPLE_CONTENT); + if (!"SimpleAnyType".equals(eClass.getName()) || !XMLTypePackage.eNS_URI.equals(eClass.getEPackage().getNsURI())) + { + if (eClass.getEAllStructuralFeatures().isEmpty()) + { + XSDComplexTypeContent xsdComplexTypeContent = xsdComplexTypeDefinition.getContent(); + String name = getEcoreAttribute(xsdComplexTypeContent, "name"); + if (name == null) + { + name = "value"; + } + createFeature + (eClass, + null, + name, + xsdComplexTypeContent, + false); + } + else + { + XSDSimpleTypeDefinition xsdSimpleTypeDefinition = xsdComplexTypeDefinition.getSimpleType(); + getEClassifier(xsdSimpleTypeDefinition); + } + } + } + else + { + EStructuralFeature globalGroup = null; + boolean isMixed = xsdComplexTypeDefinition.getContentTypeCategory() == XSDContentTypeCategory.MIXED_LITERAL; + String featureMapName = getEcoreAttribute(xsdComplexTypeDefinition, "featureMap"); + if (eClass.getESuperTypes().isEmpty() ? + "true".equals(getEcoreAttribute(xsdComplexTypeDefinition, "mixed")) : + extendedMetaData.getMixedFeature((EClass)eClass.getESuperTypes().get(0)) != null) + { + isMixed = true; + } + extendedMetaData.setContentKind + (eClass, + isMixed ? + ExtendedMetaData.MIXED_CONTENT : + xsdComplexTypeDefinition.getContentTypeCategory() == XSDContentTypeCategory.EMPTY_LITERAL ? + ExtendedMetaData.EMPTY_CONTENT : + ExtendedMetaData.ELEMENT_ONLY_CONTENT); + if (isMixed) + { + EStructuralFeature mixedFeature = extendedMetaData.getMixedFeature(eClass); + if (mixedFeature == null) + { + if (featureMapName == null) + { + featureMapName = "mixed"; + } + mixedFeature = + createFeature + (eClass, + featureMapName, + ecorePackage.getEFeatureMapEntry(), + null, + 0, + -1); + extendedMetaData.setName(mixedFeature, ":mixed"); + } + } + else + { + globalGroup = extendedMetaData.getElement(eClass, null, ":group"); + if (globalGroup == null && featureMapName != null && eClass.getESuperTypes().isEmpty()) + { + globalGroup = + createFeature + (eClass, + featureMapName, + ecorePackage.getEFeatureMapEntry(), + null, + 0, + -1); + extendedMetaData.setName(globalGroup, ":group"); + extendedMetaData.setFeatureKind(globalGroup, ExtendedMetaData.GROUP_FEATURE); + } + } + + if (xsdComplexTypeDefinition.getContent() != null) + { + // 51210 + // Map particleMap = new HashMap(); + Map groups = new HashMap(); + List particleInformation = collectParticles((XSDParticle)xsdComplexTypeDefinition.getContent()); + for (Iterator i = particleInformation.iterator(); i.hasNext(); ) + { + EffectiveOccurrence effectiveOccurrence = (EffectiveOccurrence)i.next(); + XSDParticle xsdParticle = effectiveOccurrence.xsdParticle; + EStructuralFeature group = (EStructuralFeature)groups.get(effectiveOccurrence.xsdModelGroup); + XSDTerm xsdTerm = xsdParticle.getTerm(); + EStructuralFeature eStructuralFeature = null; + String name = getEcoreAttribute(xsdParticle, "name"); + if (xsdTerm instanceof XSDModelGroup) + { + if (!isRestriction) + { + XSDModelGroup xsdModelGroup = (XSDModelGroup)xsdTerm; + if (name == null) + { + name = getEcoreAttribute(xsdParticle, "featureMap"); + if (name == null) + { + name = getEcoreAttribute(xsdModelGroup, "name"); + if (name == null) + { + name = getEcoreAttribute(xsdModelGroup, "featureMap"); + if (name == null) + { + if (xsdModelGroup.getContainer() instanceof XSDModelGroupDefinition) + { + XSDModelGroupDefinition xsdModelGroupDefinition = (XSDModelGroupDefinition)xsdModelGroup.getContainer(); + name = getEcoreAttribute(xsdModelGroupDefinition, "name"); + if (name == null) + { + name = validName(xsdModelGroupDefinition.getName(), true); + } + } + else + { + name = "group"; + } + } + } + } + } + + eStructuralFeature = + createFeature + (eClass, + name, + ecorePackage.getEFeatureMapEntry(), + xsdParticle, + 0, + -1); + groups.put(xsdTerm, eStructuralFeature); + extendedMetaData.setName(eStructuralFeature, name + ":" + eClass.getEAllStructuralFeatures().indexOf(eStructuralFeature)); + } + } + else if (xsdTerm instanceof XSDWildcard) + { + if (!isRestriction) + { + if (name == null) + { + name = getEcoreAttribute(xsdTerm, "name"); + if (name == null) + { + name = "any"; + } + } + eStructuralFeature = + createFeature + (eClass, + name, + ecorePackage.getEFeatureMapEntry(), + xsdParticle, + effectiveOccurrence.minOccurs, + effectiveOccurrence.maxOccurs); + // 51210 + // particleMap.put(xsdParticle, eStructuralFeature); + } + } + else + { + XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)xsdTerm; + + boolean isRedundant = false; + if (isRestriction) + { + isRedundant = + extendedMetaData.getElement + (baseClass, xsdElementDeclaration.getTargetNamespace(), xsdElementDeclaration.getName()) != null; + + if (!isRedundant) + { + group = + extendedMetaData.getElementWildcardAffiliation + (baseClass, xsdElementDeclaration.getTargetNamespace(), xsdElementDeclaration.getName()); + } + } + + if (!isRedundant) + { + if (name == null) + { + name = getEcoreAttribute(xsdElementDeclaration, "name"); + if (name == null) + { + name = validName(xsdElementDeclaration.getName(), true); + } + } + + String groupName = getEcoreAttribute(xsdParticle, "featureMap"); + if (groupName == null) + { + groupName = getEcoreAttribute(xsdElementDeclaration, "featureMap"); + } + + if (!"".equals(groupName) && + (groupName != null || + xsdElementDeclaration.isAbstract() || + xsdElementDeclaration.getSubstitutionGroup().size() > 1)) + { + if (groupName == null) + { + groupName = name + "Group"; + } + eStructuralFeature = + createFeature + (eClass, + groupName, + ecorePackage.getEFeatureMapEntry(), + xsdParticle, + effectiveOccurrence.minOccurs, + effectiveOccurrence.maxOccurs); + + eStructuralFeature.setChangeable(true); + + extendedMetaData.setFeatureKind(eStructuralFeature, ExtendedMetaData.GROUP_FEATURE); + extendedMetaData.setName(eStructuralFeature, xsdElementDeclaration.getName() + ":group"); + + if (group != null) + { + extendedMetaData.setGroup(eStructuralFeature, group); + eStructuralFeature.setDerived(true); + eStructuralFeature.setTransient(true); + eStructuralFeature.setVolatile(true); + } + else if (isMixed) + { + eStructuralFeature.setDerived(true); + eStructuralFeature.setTransient(true); + eStructuralFeature.setVolatile(true); + } + else if (globalGroup != null) + { + extendedMetaData.setGroup(eStructuralFeature, globalGroup); + eStructuralFeature.setDerived(true); + eStructuralFeature.setTransient(true); + eStructuralFeature.setVolatile(true); + } + + group = eStructuralFeature; + } + + eStructuralFeature = + createFeature(eClass, xsdElementDeclaration, name, xsdParticle, effectiveOccurrence.minOccurs, effectiveOccurrence.maxOccurs); + // 51210 + // particleMap.put(xsdParticle, eStructuralFeature); + + // If the group is turned off, we better make the feature changeable. + // + if (!eStructuralFeature.isChangeable() && group == null && getEcoreAttribute(xsdParticle, xsdElementDeclaration, "changeable") == null) + { + eStructuralFeature.setChangeable(true); + } + } + } + + if (eStructuralFeature != null) + { + if (group != null) + { + extendedMetaData.setGroup(eStructuralFeature, group); + eStructuralFeature.setDerived(true); + eStructuralFeature.setTransient(true); + eStructuralFeature.setVolatile(true); + } + else if (isMixed) + { + eStructuralFeature.setDerived(true); + eStructuralFeature.setTransient(true); + eStructuralFeature.setVolatile(true); + } + else if (globalGroup != null) + { + extendedMetaData.setGroup(eStructuralFeature, globalGroup); + eStructuralFeature.setDerived(true); + eStructuralFeature.setTransient(true); + eStructuralFeature.setVolatile(true); + } + } + } + + // 51210 + // contentParticle = computeParticleConstraints(eClass, particleMap, (XSDParticle)xsdComplexTypeDefinition.getContent()); + } + } + + // 51210 + // EAnnotation attributeParticle = null; + // if (isRestriction) + // { + // attributeParticle = ecoreFactory.createEAnnotation(); + // attributeParticle.setSource("attributes"); + // } + + XSDWildcard baseXSDWildcard = null; + Collection baseAttributeUses = Collections.EMPTY_LIST; + Map baseAttributeURIs = new HashMap(); + if (baseTypeDefinition instanceof XSDComplexTypeDefinition) + { + XSDComplexTypeDefinition complexBaseTypeDefinition = (XSDComplexTypeDefinition)baseTypeDefinition; + baseXSDWildcard = complexBaseTypeDefinition.getAttributeWildcard(); + baseAttributeUses = complexBaseTypeDefinition.getAttributeUses(); + for (Iterator i = baseAttributeUses.iterator(); i.hasNext(); ) + { + XSDAttributeUse xsdAttributeUse = (XSDAttributeUse)i.next(); + baseAttributeURIs.put(xsdAttributeUse.getAttributeDeclaration().getURI(), xsdAttributeUse); + } + } + + for (Iterator i = getAttributeUses(xsdComplexTypeDefinition).iterator(); i.hasNext(); ) + { + XSDAttributeUse xsdAttributeUse = (XSDAttributeUse)i.next(); + XSDAttributeDeclaration xsdAttributeDeclaration = xsdAttributeUse.getAttributeDeclaration(); + if (baseAttributeURIs.remove(xsdAttributeDeclaration.getURI()) == null) + { + String name = getEcoreAttribute(xsdAttributeUse, "name"); + if (name == null) + { + name = getEcoreAttribute(xsdAttributeDeclaration, "name"); + } + if (name == null) + { + name = validName(xsdAttributeDeclaration.getName(), true); + } + + EStructuralFeature eStructuralFeature = + createFeature(eClass, xsdAttributeDeclaration, name, xsdAttributeUse, xsdAttributeUse.isRequired()); + + if (isRestriction) + { + EStructuralFeature attributeWildcardEStructuralFeature = + extendedMetaData.getAttributeWildcardAffiliation + (baseClass, xsdAttributeDeclaration.getTargetNamespace(), xsdAttributeDeclaration.getName()); + if (attributeWildcardEStructuralFeature != null) + { + extendedMetaData.setGroup(eStructuralFeature, attributeWildcardEStructuralFeature); + eStructuralFeature.setDerived(true); + eStructuralFeature.setTransient(true); + eStructuralFeature.setVolatile(true); + } + } + } + /* 51210 + else if (isRestriction && !baseAttributeUses.contains(xsdAttributeUse)) + { + EStructuralFeature eStructuralFeature = + extendedMetaData.getAttribute(eClass, xsdAttributeDeclaration.getTargetNamespace(), xsdAttributeDeclaration.getName()); + if (eStructuralFeature != null) + { + EAnnotation attributeEAnnotation = ecoreFactory.createEAnnotation(); + if (xsdAttributeUse.isRequired()) + { + attributeEAnnotation.getDetails().put("minOccurs", "1"); + } + attributeEAnnotation.getReferences().add(eStructuralFeature); + + if (xsdAttributeDeclaration.getTypeDefinition() != null) + { + EClassifier type = getEClassifier(xsdAttributeDeclaration.getTypeDefinition()); + if (type != eStructuralFeature.getEType() && type != null) + { + attributeEAnnotation.getReferences().add(type); + } + } + + attributeParticle.getContents().add(attributeEAnnotation); + } + } + */ + } + + /* 51210 + if (isRestriction && !baseAttributeURIs.isEmpty()) + { + for (Iterator i = baseAttributeURIs.values().iterator(); i.hasNext(); ) + { + XSDAttributeUse xsdAttributeUse = (XSDAttributeUse)i.next(); + XSDAttributeDeclaration xsdAttributeDeclaration = xsdAttributeUse.getAttributeDeclaration(); + EStructuralFeature eStructuralFeature = + extendedMetaData.getAttribute(eClass, xsdAttributeDeclaration.getTargetNamespace(), xsdAttributeDeclaration.getName()); + if (eStructuralFeature != null) + { + EAnnotation attributeEAnnotation = ecoreFactory.createEAnnotation(); + attributeEAnnotation.getReferences().add(eStructuralFeature); + attributeEAnnotation.getDetails().put("maxOccurs", "0"); + attributeParticle.getContents().add(attributeEAnnotation); + } + } + } + */ + + XSDWildcard xsdWildcard = xsdComplexTypeDefinition.getAttributeWildcard(); + if (xsdWildcard != null && baseXSDWildcard != xsdWildcard || XSDConstants.isURType(xsdComplexTypeDefinition)) + { + if (isRestriction && !XSDConstants.isURType(xsdComplexTypeDefinition)) + { + // 51210 + // attributeParticle.getDetails().put + // ("wildcard", BasicExtendedMetaData.getEncodedWildcards(xsdComplexTypeDefinition.getTargetNamespace(), getWildcards(xsdWildcard))); + } + else + { + String name = getEcoreAttribute(xsdWildcard, "name"); + if (name == null) + { + name = "anyAttribute"; + } + createFeature + (eClass, + name, + ecorePackage.getEFeatureMapEntry(), + xsdWildcard, + 0, + -1); + } + } + + if (isRestriction) + { + // 51210 + // EAnnotation restrictionParticle = ecoreFactory.createEAnnotation(); + // restrictionParticle.setSource("restriction"); + // if (contentParticle != null) + // { + // restrictionParticle.getContents().add(contentParticle); + // } + // if (!attributeParticle.getContents().isEmpty() || !attributeParticle.getDetails().isEmpty()) + // { + // restrictionParticle.getContents().add(attributeParticle); + // } + // contentParticle = restrictionParticle; + + int baseContentKind = extendedMetaData.getContentKind((EClass)eClass.getESuperTypes().get(0)); + if (baseContentKind == ExtendedMetaData.MIXED_CONTENT && + xsdComplexTypeDefinition.getContentTypeCategory() == XSDContentTypeCategory.SIMPLE_LITERAL) + { + extendedMetaData.setContentKind(eClass, ExtendedMetaData.SIMPLE_CONTENT); + EStructuralFeature eStructuralFeature = + createFeature + (eClass, + "rawValue", + getBuiltInEClassifier(xsdComplexTypeDefinition.getSchema().getSchemaForSchemaNamespace(), "string"), + null, + 0, + 1); + eStructuralFeature.setDerived(true); + eStructuralFeature.setTransient(true); + eStructuralFeature.setVolatile(true); + + eStructuralFeature = + createFeature + (eClass, + "value", + getBuiltInEClassifier(xsdComplexTypeDefinition.getSchema().getSchemaForSchemaNamespace(), "anySimpleType"), + null, + 0, + 1); + eStructuralFeature.setDerived(true); + eStructuralFeature.setTransient(true); + eStructuralFeature.setVolatile(true); + + if ("SimpleAnyType".equals(eClass.getName()) && XMLTypePackage.eNS_URI.equals(eClass.getEPackage().getNsURI())) + { + eStructuralFeature = + createFeature + (eClass, + "instanceType", + ecorePackage.getEDataType(), + null, + 1, + 1); + + ((EReference)eStructuralFeature).setResolveProxies(false); + } + } + else + { + extendedMetaData.setContentKind(eClass, baseContentKind); + } + } + + // 51210 + // extendedMetaData.setContent(eClass, contentParticle); + + XSDAnnotation xsdAnnotation = xsdComplexTypeDefinition.getAnnotation(); + if (xsdAnnotation != null) + { + List applicationInformationList = xsdAnnotation.getApplicationInformation(EcorePackage.eNS_URI); + for (Iterator i = applicationInformationList.iterator(); i.hasNext(); ) + { + Element applicationInformation = (Element)i.next(); + if ("operations".equals(applicationInformation.getAttributeNS(EcorePackage.eNS_URI, "key"))) + { + for (Iterator j = getElements(applicationInformation, "operation").iterator(); j.hasNext(); ) + { + EOperation eOperation = ecoreFactory.createEOperation(); + Element operation = (Element)j.next(); + String operationName = operation.getAttributeNS(null, "name"); + eOperation.setName(operationName); + XSDTypeDefinition returnType = getEcoreTypeQNameAttribute(xsdComplexTypeDefinition, operation, null, "type"); + if (returnType != null) + { + EClassifier returnEType = getEClassifier(returnType); + eOperation.setEType(returnEType); + } + + List exceptions = getEcoreTypeQNamesAttribute(xsdComplexTypeDefinition, operation, null, "exceptions"); + for (Iterator k = exceptions.iterator(); k.hasNext(); ) + { + XSDTypeDefinition exceptionTypeDefinition = (XSDTypeDefinition)k.next(); + eOperation.getEExceptions().add(getEClassifier(exceptionTypeDefinition)); + } + + for (Iterator k = getElements(operation, "parameter").iterator(); k.hasNext(); ) + { + EParameter eParameter = ecoreFactory.createEParameter(); + Element parameter = (Element)k.next(); + String paramaterName = parameter.getAttributeNS(null, "name"); + XSDTypeDefinition parameterType = getEcoreTypeQNameAttribute(xsdComplexTypeDefinition, parameter, null, "type"); + EClassifier parameterEType = getEClassifier(parameterType); + eParameter.setName(paramaterName); + eParameter.setEType(parameterEType); + + populateETypedElement(eParameter, parameter); + eOperation.getEParameters().add(eParameter); + } + + List body = getElements(operation, "body"); + if (!body.isEmpty()) + { + EcoreUtil.setAnnotation(eOperation, "http://www.eclipse.org/emf/2002/GenModel", "body", getText((Element)body.get(0))); + } + + populateETypedElement(eOperation, operation); + eClass.getEOperations().add(eOperation); + } + } + } + } + return eClass; + } + + private String getText(Element element) + { + StringBuffer text = new StringBuffer(); + for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) + { + switch (node.getNodeType()) + { + case Node.TEXT_NODE: + case Node.CDATA_SECTION_NODE: + { + text.append(node.getNodeValue()); + } + } + } + return text.toString(); + } + + private List getElements(Element element, String localName) + { + List result = new ArrayList(); + for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) + { + if (node.getNodeType() == Node.ELEMENT_NODE) + { + Element child = (Element)node; + if (localName.equals(child.getLocalName()) && child.getNamespaceURI() == null) + { + result.add(child); + } + } + } + return result; + } + + protected EStructuralFeature createFeature + (EClass eClass, String name, EClassifier type, XSDComponent xsdComponent, int minOccurs, int maxOccurs) + { + if (xsdComponent != null) + { + XSDSchema containingXSDSchema = xsdComponent.getSchema(); + if (containingXSDSchema != null && !xsdSchemas.contains(containingXSDSchema)) + { + xsdSchemas.add(containingXSDSchema); + addInput(containingXSDSchema); + validate(containingXSDSchema); + } + } + else if (extendedMetaData.getContentKind(eClass) == ExtendedMetaData.MIXED_CONTENT) + { + if (type == ecorePackage.getEFeatureMapEntry()) + { + EAttribute eAttribute = ecoreFactory.createEAttribute(); + setAnnotations(eAttribute, xsdComponent); + eAttribute.setName(Character.toLowerCase(name.charAt(0)) + name.substring(1)); + eAttribute.setUnique(false); + eAttribute.setEType(type); + eAttribute.setLowerBound(minOccurs); + eAttribute.setUpperBound(maxOccurs); + eClass.getEStructuralFeatures().add(eAttribute); + extendedMetaData.setFeatureKind(eAttribute, ExtendedMetaData.ELEMENT_WILDCARD_FEATURE); + extendedMetaData.setName(eAttribute, ":" + eAttribute.getName()); + return eAttribute; + } + else + { + EReference eReference = ecoreFactory.createEReference(); + setAnnotations(eReference, xsdComponent); + eReference.setName(name); + eReference.setEType(ecorePackage.getEStringToStringMapEntry()); + eReference.setLowerBound(0); + eReference.setUpperBound(-1); + eReference.setContainment(true); + eReference.setResolveProxies(false); + eReference.setTransient(true); + eClass.getEStructuralFeatures().add(eReference); + extendedMetaData.setFeatureKind(eReference, ExtendedMetaData.ATTRIBUTE_FEATURE); + return eReference; + } + } + + if (type instanceof EClass) + { + EReference eReference = ecoreFactory.createEReference(); + setAnnotations(eReference, xsdComponent); + eReference.setName(Character.toLowerCase(name.charAt(0)) + name.substring(1)); + eReference.setEType(type); + eReference.setLowerBound(minOccurs); + eReference.setUpperBound(maxOccurs); + + eClass.getEStructuralFeatures().add(eReference); + if (xsdComponent == null || xsdComponent instanceof XSDSimpleTypeDefinition) + { + extendedMetaData.setName(eReference, ":" + eClass.getEAllStructuralFeatures().indexOf(eReference)); + extendedMetaData.setFeatureKind(eReference, ExtendedMetaData.SIMPLE_FEATURE); + eReference.setResolveProxies(!isLocalReferenceType((XSDSimpleTypeDefinition)xsdComponent)); + } + else + { + map(xsdComponent, eReference); + if (xsdComponent instanceof XSDParticle) + { + eReference.setContainment(true); + eReference.setResolveProxies(false); + + XSDParticle xsdParticle = (XSDParticle)xsdComponent; + + XSDTerm xsdTerm = ((XSDParticle)xsdComponent).getTerm(); + if (xsdTerm instanceof XSDElementDeclaration) + { + XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)xsdTerm; + extendedMetaData.setFeatureKind(eReference, ExtendedMetaData.ELEMENT_FEATURE); + extendedMetaData.setName(eReference, xsdElementDeclaration.getName()); + extendedMetaData.setNamespace(eReference, xsdElementDeclaration.getTargetNamespace()); + + XSDTypeDefinition xsdType = getEffectiveTypeDefinition(xsdParticle, xsdElementDeclaration); + if (xsdType instanceof XSDSimpleTypeDefinition) + { + eReference.setContainment(false); + eReference.setResolveProxies(!isLocalReferenceType((XSDSimpleTypeDefinition)xsdType)); + } + + if (maxOccurs == 1 && xsdElementDeclaration.isNillable()) + { + eReference.setUnsettable(true); + } + + if (xsdElementDeclaration.isAbstract()) + { + eReference.setChangeable(false); + } + + String opposite = getEcoreAttribute(xsdParticle, "opposite"); + if (opposite != null) + { + eReferenceToOppositeNameMap.put(eReference, opposite); + } + } + else if (xsdTerm instanceof XSDWildcard) + { + // EATM shouldn't happen + XSDWildcard xsdWildcard = (XSDWildcard)xsdTerm; + extendedMetaData.setFeatureKind(eReference, ExtendedMetaData.ELEMENT_WILDCARD_FEATURE); + extendedMetaData.setWildcards(eReference, getWildcards(xsdWildcard)); + extendedMetaData.setProcessingKind(eReference, xsdWildcard.getProcessContents().getValue() + 1); + extendedMetaData.setName(eReference, ":" + eClass.getEAllStructuralFeatures().indexOf(eReference)); + } + else + { + extendedMetaData.setFeatureKind(eReference, ExtendedMetaData.GROUP_FEATURE); + extendedMetaData.setName(eReference, ":" + eClass.getEAllStructuralFeatures().indexOf(eReference)); + } + } + else if (xsdComponent instanceof XSDElementDeclaration) + { + XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)xsdComponent; + eReference.setContainment(true); + eReference.setResolveProxies(false); + extendedMetaData.setFeatureKind(eReference, ExtendedMetaData.ELEMENT_FEATURE); + extendedMetaData.setName(eReference, xsdElementDeclaration.getName()); + extendedMetaData.setNamespace(eReference, xsdElementDeclaration.getTargetNamespace()); + + XSDElementDeclaration substitutionGroupAffiliation = xsdElementDeclaration.getSubstitutionGroupAffiliation(); + if (substitutionGroupAffiliation != null) + { + EStructuralFeature affiliation = getEStructuralFeature(substitutionGroupAffiliation); + extendedMetaData.setAffiliation(eReference, affiliation); + } + XSDTypeDefinition xsdType = getEffectiveTypeDefinition(null, xsdElementDeclaration); + if (xsdType instanceof XSDSimpleTypeDefinition) + { + eReference.setResolveProxies(!isLocalReferenceType((XSDSimpleTypeDefinition)xsdType)); + } + + if (maxOccurs == 1 && xsdElementDeclaration.isNillable()) + { + eReference.setUnsettable(true); + } + + if (xsdElementDeclaration.isAbstract()) + { + eReference.setChangeable(false); + } + } + else if (xsdComponent instanceof XSDAttributeUse) + { + String opposite = getEcoreAttribute(xsdComponent, "opposite"); + if (opposite != null) + { + eReferenceToOppositeNameMap.put(eReference, opposite); + } + + XSDAttributeUse xsdAttributeUse = (XSDAttributeUse)xsdComponent; + XSDAttributeDeclaration xsdAttributeDeclaration = xsdAttributeUse.getAttributeDeclaration(); + extendedMetaData.setFeatureKind(eReference, ExtendedMetaData.ATTRIBUTE_FEATURE); + extendedMetaData.setName(eReference, xsdAttributeDeclaration.getName()); + extendedMetaData.setNamespace(eReference, xsdAttributeDeclaration.getTargetNamespace()); + eReference.setResolveProxies + (!isLocalReferenceType((XSDSimpleTypeDefinition)getEffectiveTypeDefinition(xsdAttributeUse, xsdAttributeDeclaration))); + } + else if (xsdComponent instanceof XSDAttributeDeclaration) + { + XSDAttributeDeclaration xsdAttributeDeclaration = (XSDAttributeDeclaration)xsdComponent; + extendedMetaData.setFeatureKind(eReference, ExtendedMetaData.ATTRIBUTE_FEATURE); + extendedMetaData.setName(eReference, xsdAttributeDeclaration.getName()); + extendedMetaData.setNamespace(eReference, xsdAttributeDeclaration.getTargetNamespace()); + eReference.setResolveProxies + (!isLocalReferenceType((XSDSimpleTypeDefinition)getEffectiveTypeDefinition(null, xsdAttributeDeclaration))); + } + } + + return eReference; + } + else + { + EAttribute eAttribute = ecoreFactory.createEAttribute(); + setAnnotations(eAttribute, xsdComponent); + eAttribute.setName(Character.toLowerCase(name.charAt(0)) + name.substring(1)); + eAttribute.setUnique(false); + eAttribute.setEType(type); + eAttribute.setLowerBound(minOccurs); + eAttribute.setUpperBound(maxOccurs); + eClass.getEStructuralFeatures().add(eAttribute); + + if (xsdComponent == null || xsdComponent instanceof XSDSimpleTypeDefinition) + { + extendedMetaData.setName(eAttribute, ":" + eClass.getEAllStructuralFeatures().indexOf(eAttribute)); + extendedMetaData.setFeatureKind(eAttribute, ExtendedMetaData.SIMPLE_FEATURE); + } + else + { + map(xsdComponent, eAttribute); + if (xsdComponent instanceof XSDAttributeUse) + { + XSDAttributeUse xsdAttributeUse = (XSDAttributeUse)xsdComponent; + XSDAttributeDeclaration xsdAttributeDeclaration = xsdAttributeUse.getAttributeDeclaration(); + extendedMetaData.setFeatureKind(eAttribute, ExtendedMetaData.ATTRIBUTE_FEATURE); + extendedMetaData.setName(eAttribute, xsdAttributeDeclaration.getName()); + extendedMetaData.setNamespace(eAttribute, xsdAttributeDeclaration.getTargetNamespace()); + + String defaultValue = getEcoreAttribute(xsdComponent, "default"); + if (defaultValue == null) + { + defaultValue = xsdAttributeUse.getLexicalValue(); + } + eAttribute.setDefaultValueLiteral(defaultValue); + initialize(eAttribute, (XSDSimpleTypeDefinition)getEffectiveTypeDefinition(xsdAttributeUse, xsdAttributeDeclaration)); + } + else if (xsdComponent instanceof XSDAttributeDeclaration) + { + XSDAttributeDeclaration xsdAttributeDeclaration = (XSDAttributeDeclaration)xsdComponent; + extendedMetaData.setFeatureKind(eAttribute, ExtendedMetaData.ATTRIBUTE_FEATURE); + extendedMetaData.setName(eAttribute, xsdAttributeDeclaration.getName()); + extendedMetaData.setNamespace(eAttribute, xsdAttributeDeclaration.getTargetNamespace()); + + eAttribute.setDefaultValueLiteral(xsdAttributeDeclaration.getLexicalValue()); + initialize(eAttribute, (XSDSimpleTypeDefinition)getEffectiveTypeDefinition(null, xsdAttributeDeclaration)); + } + else if (xsdComponent instanceof XSDParticle) + { + XSDTerm xsdTerm = ((XSDParticle)xsdComponent).getTerm(); + if (xsdTerm instanceof XSDElementDeclaration) + { + XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)xsdTerm; + extendedMetaData.setFeatureKind(eAttribute, ExtendedMetaData.ELEMENT_FEATURE); + extendedMetaData.setName(eAttribute, xsdElementDeclaration.getName()); + extendedMetaData.setNamespace(eAttribute, xsdElementDeclaration.getTargetNamespace()); + + eAttribute.setDefaultValueLiteral(xsdElementDeclaration.getLexicalValue()); + XSDTypeDefinition xsdType = getEffectiveTypeDefinition(xsdComponent, xsdElementDeclaration); + if (xsdType instanceof XSDSimpleTypeDefinition) + { + initialize(eAttribute, (XSDSimpleTypeDefinition)xsdType); + } + + if (xsdElementDeclaration.isNillable()) + { + if (!canSupportNull((EDataType)type)) + { + eAttribute.setEType(type = (EDataType)typeToTypeObjectMap.get(type)); + } + if (maxOccurs == 1) + { + eAttribute.setUnsettable(true); + } + } + + if (xsdElementDeclaration.isAbstract()) + { + eAttribute.setChangeable(false); + } + } + else if (xsdTerm instanceof XSDWildcard) + { + XSDWildcard xsdWildcard = (XSDWildcard)xsdTerm; + extendedMetaData.setFeatureKind(eAttribute, ExtendedMetaData.ELEMENT_WILDCARD_FEATURE); + extendedMetaData.setWildcards(eAttribute, getWildcards(xsdWildcard)); + extendedMetaData.setProcessingKind(eAttribute, xsdWildcard.getProcessContents().getValue() + 1); + extendedMetaData.setName(eAttribute, ":" + eClass.getEAllStructuralFeatures().indexOf(eAttribute)); + } + else + { + extendedMetaData.setFeatureKind(eAttribute, ExtendedMetaData.GROUP_FEATURE); + } + } + else if (xsdComponent instanceof XSDWildcard) + { + XSDWildcard xsdWildcard = (XSDWildcard)xsdComponent; + extendedMetaData.setFeatureKind(eAttribute, ExtendedMetaData.ATTRIBUTE_WILDCARD_FEATURE); + extendedMetaData.setWildcards(eAttribute, getWildcards(xsdWildcard)); + extendedMetaData.setProcessingKind(eAttribute, xsdWildcard.getProcessContents().getValue() + 1); + extendedMetaData.setName(eAttribute, ":" + eClass.getEAllStructuralFeatures().indexOf(eAttribute)); + } + else if (xsdComponent instanceof XSDElementDeclaration) + { + XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)xsdComponent; + extendedMetaData.setFeatureKind(eAttribute, ExtendedMetaData.ELEMENT_FEATURE); + extendedMetaData.setName(eAttribute, xsdElementDeclaration.getName()); + extendedMetaData.setNamespace(eAttribute, xsdElementDeclaration.getTargetNamespace()); + + eAttribute.setDefaultValueLiteral(xsdElementDeclaration.getLexicalValue()); + XSDTypeDefinition xsdType = getEffectiveTypeDefinition(null, xsdElementDeclaration); + if (xsdType instanceof XSDSimpleTypeDefinition) + { + initialize(eAttribute, (XSDSimpleTypeDefinition)xsdType); + } + + XSDElementDeclaration substitutionGroupAffiliation = xsdElementDeclaration.getSubstitutionGroupAffiliation(); + if (substitutionGroupAffiliation != null) + { + EStructuralFeature affiliation = getEStructuralFeature(substitutionGroupAffiliation); + extendedMetaData.setAffiliation(eAttribute, affiliation); + } + + if (xsdElementDeclaration.isNillable() && !canSupportNull((EDataType)type)) + { + eAttribute.setEType(type = (EDataType)typeToTypeObjectMap.get(type)); + if (maxOccurs == 1) + { + eAttribute.setUnsettable(true); + } + } + + if (xsdElementDeclaration.isAbstract()) + { + eAttribute.setChangeable(false); + } + } + } + + if (maxOccurs == 1 && (type.getDefaultValue() != null || eAttribute.getDefaultValueLiteral() != null)) + { + eAttribute.setUnsettable(true); + } + + return eAttribute; + } + } + + protected XSDTypeDefinition getEffectiveTypeDefinition(XSDComponent xsdComponent, XSDFeature xsdFeature) + { + return xsdFeature == null ? + ((XSDComplexTypeDefinition)xsdComponent.eContainer()).getSimpleType() : xsdFeature.getType(); + } + + protected EStructuralFeature createFeature + (EClass eClass, XSDElementDeclaration xsdElementDeclaration, String name, XSDComponent xsdComponent, int minOccurs, int maxOccurs) + { + XSDTypeDefinition elementTypeDefinition = getEffectiveTypeDefinition(xsdComponent, xsdElementDeclaration); + EClassifier eClassifier = getEClassifier(elementTypeDefinition); + + XSDTypeDefinition referenceType = getEcoreTypeQNameAttribute(xsdComponent, "reference"); + if (referenceType == null) + { + referenceType = getEcoreTypeQNameAttribute(xsdElementDeclaration, "reference"); + } + if (referenceType != null) + { + EClassifier referenceClassifier = getEClassifier(referenceType); + boolean needsHolder = false; + if (elementTypeDefinition instanceof XSDSimpleTypeDefinition) + { + XSDSimpleTypeDefinition xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition)elementTypeDefinition; + if (xsdSimpleTypeDefinition.getVariety() == XSDVariety.LIST_LITERAL) + { + needsHolder = true; + + EPackage holderPackage = getEPackage(xsdElementDeclaration); + String holderName = xsdElementDeclaration.getName() + ":holder"; + EClass holderClass = (EClass)extendedMetaData.getType(holderPackage, holderName); + if (holderClass == null) + { + // Create a holder class like an anonymous complex type. + // + holderClass = ecoreFactory.createEClass(); + setAnnotations(holderClass, xsdElementDeclaration); + holderClass.setName(validName(holderName, true)); + extendedMetaData.setName(holderClass, holderName); + extendedMetaData.setContentKind(holderClass, ExtendedMetaData.SIMPLE_CONTENT); + + addToSortedList(holderPackage.getEClassifiers(), holderClass); + + EReference holderReference = + (EReference)createFeature + (holderClass, + "value", + referenceClassifier, + null, + 0, + -1); + + holderReference.setResolveProxies(!isLocalReferenceType(xsdSimpleTypeDefinition)); + } + referenceClassifier = holderClass; + } + } + EStructuralFeature result = + createFeature + (eClass, + name, + referenceClassifier, + xsdComponent, + minOccurs, + maxOccurs); + ((EReference)result).setContainment(needsHolder); + if (needsHolder) + { + ((EReference)result).setUnsettable(false); + ((EReference)result).setResolveProxies(false); + } + initialize(result, xsdElementDeclaration, xsdComponent); + return result; + } + else + { + EStructuralFeature result = + createFeature + (eClass, + name, + eClassifier, + xsdComponent, + minOccurs, + maxOccurs); + initialize(result, xsdElementDeclaration, xsdComponent); + return result; + } + } + + protected EStructuralFeature createFeature + (EClass eClass, XSDAttributeDeclaration xsdAttributeDeclaration, String name, XSDComponent xsdComponent, boolean isRequired) + { + XSDSimpleTypeDefinition attributeTypeDefinition = (XSDSimpleTypeDefinition)getEffectiveTypeDefinition(xsdComponent, xsdAttributeDeclaration); + if (attributeTypeDefinition == null) + { + attributeTypeDefinition = xsdComponent.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("anySimpleType"); + } + + XSDTypeDefinition referenceType = getEcoreTypeQNameAttribute(xsdComponent, "reference"); + if (referenceType == null && xsdAttributeDeclaration != null) + { + referenceType = getEcoreTypeQNameAttribute(xsdAttributeDeclaration, "reference"); + } + if (referenceType != null) + { + int lowerBound = isRequired ? 1 : 0; + int upperBound = 1; + if (attributeTypeDefinition.getVariety() == XSDVariety.LIST_LITERAL) + { + XSDLengthFacet xsdLengthFacet = attributeTypeDefinition.getEffectiveLengthFacet(); + if (isRequired) + { + if (xsdLengthFacet != null) + { + lowerBound = xsdLengthFacet.getValue(); + } + else + { + XSDMinLengthFacet xsdMinLengthFacet = attributeTypeDefinition.getEffectiveMinLengthFacet(); + if (xsdMinLengthFacet != null) + { + lowerBound = xsdMinLengthFacet.getValue(); + } + } + } + if (xsdLengthFacet != null) + { + upperBound = xsdLengthFacet.getValue(); + } + else + { + XSDMaxLengthFacet xsdMaxLengthFacet = attributeTypeDefinition.getEffectiveMaxLengthFacet(); + if (xsdMaxLengthFacet != null) + { + upperBound = xsdMaxLengthFacet.getValue(); + } + else + { + upperBound = -1; + } + } + } + + EClassifier referenceClassifier = getEClassifier(referenceType); + EStructuralFeature result = + createFeature + (eClass, + name, + referenceClassifier, + xsdComponent, + lowerBound, + upperBound); + initialize(result, xsdAttributeDeclaration, xsdComponent); + return result; + } + else + { + boolean isMany = + attributeTypeDefinition.getVariety() == XSDVariety.LIST_LITERAL && + xsdComponent instanceof XSDAttributeUse && + "true".equals(getEcoreAttribute(xsdComponent, "many")); + if (isMany) + { + EDataType eDataType = getEDataType(attributeTypeDefinition.getItemTypeDefinition()); + XSDLengthFacet xsdLengthFacet = attributeTypeDefinition.getEffectiveLengthFacet(); + int lowerBound = isRequired ? 1 : 0; + int upperBound = -1; + if (isRequired) + { + if (xsdLengthFacet != null) + { + lowerBound = xsdLengthFacet.getValue(); + } + else + { + XSDMinLengthFacet xsdMinLengthFacet = attributeTypeDefinition.getEffectiveMinLengthFacet(); + if (xsdMinLengthFacet != null) + { + lowerBound = xsdMinLengthFacet.getValue(); + } + } + } + if (xsdLengthFacet != null) + { + upperBound = xsdLengthFacet.getValue(); + } + else + { + XSDMaxLengthFacet xsdMaxLengthFacet = attributeTypeDefinition.getEffectiveMaxLengthFacet(); + if (xsdMaxLengthFacet != null) + { + upperBound = xsdMaxLengthFacet.getValue(); + } + } + EStructuralFeature result = + createFeature + (eClass, + name, + eDataType, + xsdComponent, + lowerBound, + upperBound); + initialize(result, xsdAttributeDeclaration, xsdComponent); + return result; + } + else + { + EDataType eDataType = getEDataType(attributeTypeDefinition); + EStructuralFeature result = + createFeature + (eClass, + name, + eDataType, + xsdComponent, + isRequired ? 1 : 0, + 1); + initialize(result, xsdAttributeDeclaration, xsdComponent); + return result; + } + } + } + + public EStructuralFeature getEStructuralFeature(XSDFeature xsdFeature) + { + if ("true".equals(getEcoreAttribute(xsdFeature, "ignore"))) return null; + EStructuralFeature eStructuralFeature = (EStructuralFeature)xsdComponentToEModelElementMap.get(xsdFeature); + if (eStructuralFeature == null) + { + EPackage ePackage = getEPackage(xsdFeature); + EClass documentEClass = extendedMetaData.getDocumentRoot(ePackage); + if (documentEClass == null) + { + createDocumentRoot(xsdFeature.getSchema(), ePackage); + } + + String name = getEcoreAttribute(xsdFeature, "name"); + if (name == null) + { + name= validName(xsdFeature.getName(), true); + } + + if (xsdFeature instanceof XSDElementDeclaration) + { + // Mark the bound as unspecified so that it won't be considered many + // but can nevertheless be recognized as being unspecified and perhaps still be treat as many. + // + EStructuralFeature result = + createFeature(documentEClass, (XSDElementDeclaration)xsdFeature, name, xsdFeature, 0, ETypedElement.UNSPECIFIED_MULTIPLICITY); + + result.setDerived(true); + result.setTransient(true); + result.setVolatile(true); + return result; + } + else + { + EStructuralFeature result = + createFeature(documentEClass, (XSDAttributeDeclaration)xsdFeature, name, xsdFeature, false); + return result; + } + } + + return eStructuralFeature; + } + + public void generate(XSDSchema xsdSchema) + { + this.rootSchema = xsdSchema; + if (xsdSchemas.add(xsdSchema)) + { + addInput(xsdSchema); + validate(xsdSchema); + } + + Collection visitedElementDeclarations = new ArrayList(); + Collection elementDeclarations = new ArrayList(xsdSchema.getElementDeclarations()); + + Collection visitedAttributeDeclarations = new ArrayList(); + Collection attributeDeclarations = new ArrayList(xsdSchema.getAttributeDeclarations()); + + Collection visitedTypeDefinitions = new ArrayList(); + Collection typeDefinitions = new ArrayList(xsdSchema.getTypeDefinitions()); + + while (!elementDeclarations.isEmpty() || !attributeDeclarations.isEmpty() || !typeDefinitions.isEmpty()) + { + for (Iterator i = elementDeclarations.iterator(); i.hasNext(); ) + { + XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration)i.next(); + getEStructuralFeature(xsdElementDeclaration); + } + visitedElementDeclarations.addAll(elementDeclarations); + elementDeclarations = new ArrayList(xsdSchema.getElementDeclarations()); + elementDeclarations.removeAll(visitedElementDeclarations); + + for (Iterator i = attributeDeclarations.iterator(); i.hasNext(); ) + { + XSDAttributeDeclaration xsdAttributeDeclaration = (XSDAttributeDeclaration)i.next(); + if (!XSDConstants.isSchemaInstanceNamespace(xsdAttributeDeclaration.getTargetNamespace())) + { + getEStructuralFeature(xsdAttributeDeclaration); + } + } + visitedAttributeDeclarations.addAll(attributeDeclarations); + attributeDeclarations = new ArrayList(xsdSchema.getAttributeDeclarations()); + attributeDeclarations.removeAll(visitedAttributeDeclarations); + + for (Iterator i = typeDefinitions.iterator(); i.hasNext(); ) + { + XSDTypeDefinition xsdTypeDefinition = (XSDTypeDefinition)i.next(); + getEClassifier(xsdTypeDefinition); + } + visitedTypeDefinitions.addAll(typeDefinitions); + typeDefinitions = new ArrayList(xsdSchema.getTypeDefinitions()); + typeDefinitions.removeAll(visitedTypeDefinitions); + } + + resolveNameConflicts(); + + for (Iterator i = xsdSchemas.iterator(); i.hasNext(); ) + { + XSDSchema generatedXSDSchema = (XSDSchema)i.next(); + EPackage ePackage = (EPackage)targetNamespaceToEPackageMap.get(generatedXSDSchema.getTargetNamespace()); + if (ePackage != null) + { + String packageName= getEcoreAttribute(generatedXSDSchema, "package"); + if (packageName != null) + { + ePackage.setName(packageName); + } + String packageNsPrefix= getEcoreAttribute(generatedXSDSchema, "nsPrefix"); + if (packageNsPrefix != null) + { + ePackage.setNsPrefix(packageNsPrefix); + } + } + } + + for (Iterator i = eReferenceToOppositeNameMap.entrySet().iterator(); i.hasNext(); ) + { + Map.Entry entry = (Map.Entry)i.next(); + EReference eReference = (EReference)entry.getKey(); + String opposite = (String)entry.getValue(); + EClass oppositeEClass = eReference.getEReferenceType(); + if (eReference.getEOpposite() == null) + { + EStructuralFeature eOppositeFeature = oppositeEClass.getEStructuralFeature(opposite); + + // Match by XML name if this fails. + if (eOppositeFeature == null) + { + for (Iterator j = oppositeEClass.getEAllStructuralFeatures().iterator(); j.hasNext(); ) + { + EStructuralFeature feature = (EStructuralFeature)j.next(); + if (opposite.equals(extendedMetaData.getName(feature))) + { + eOppositeFeature = feature; + break; + } + } + } + + if (eOppositeFeature instanceof EReference) + { + EReference eOpposite = (EReference)eOppositeFeature; + eOpposite.setEOpposite(eReference); + eReference.setEOpposite(eOpposite); + } + } + + if (eReference.getEOpposite() == null && eReference.isContainment()) + { + EReference eOpposite = ecoreFactory.createEReference(); + eOpposite.setName(opposite); + eOpposite.setEType(eReference.getEContainingClass()); + eOpposite.setLowerBound(0); + eOpposite.setEOpposite(eReference); + eReference.setEOpposite(eOpposite); + eOpposite.setTransient(true); + oppositeEClass.getEStructuralFeatures().add(eOpposite); + } + } + + eReferenceToOppositeNameMap.clear(); + } + +} diff --git a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/CrossScopeCopyHelperImpl.java b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/CrossScopeCopyHelperImpl.java index b7a5534800..3f51876035 100644 --- a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/CrossScopeCopyHelperImpl.java +++ b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/CrossScopeCopyHelperImpl.java @@ -1,255 +1,255 @@ -/** - * - * 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.helper; - -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.emf.ecore.EAttribute; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EReference; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.emf.ecore.util.FeatureMap; -import org.eclipse.emf.ecore.util.FeatureMapUtil; -import org.eclipse.emf.ecore.util.InternalEList; -import org.eclipse.emf.ecore.util.EcoreUtil.Copier; - -import commonj.sdo.DataObject; -import commonj.sdo.Type; -import commonj.sdo.helper.CopyHelper; -import commonj.sdo.helper.TypeHelper; - -/** - * A CopyHelper implementation that creates the copy objects in a specific metadata scope. - * The target scope must contain a compatible version of the Types needed to create the copy objects. - */ -public class CrossScopeCopyHelperImpl implements CopyHelper -{ - protected TypeHelper scope; - - public CrossScopeCopyHelperImpl(TypeHelper targetScope) - { - scope = targetScope; - } - - public DataObject copyShallow(DataObject dataObject) - { - Copier copier = new CrossScopeCopier() - { - protected void copyContainment(EReference eReference, EObject eObject, EObject copyEObject) - { - } - protected void copyAttribute(EAttribute eAttribute, EObject eObject, EObject copyEObject) - { - if (eObject.eIsSet(eAttribute) && !FeatureMapUtil.isFeatureMap(eAttribute)) - { - super.copyAttribute(eAttribute,eObject,copyEObject); - } - } - }; - EObject result = copier.copy((EObject)dataObject); - copier.copyReferences(); - return (DataObject)result; - } - - public DataObject copy(DataObject dataObject) - { - Copier copier = new CrossScopeCopier(); - DataObject result = (DataObject)copier.copy((EObject)dataObject); - copier.copyReferences(); - return (DataObject)result; - } - - protected class CrossScopeCopier extends EcoreUtil.Copier - { - protected boolean useOriginalReferences = false; - - protected EClass getTarget(EClass eClass) - { - EClass target = (EClass)get(eClass); - if (target == null) - { - Type type = (Type)eClass; - target = (EClass)scope.getType(type.getURI(), type.getName()); - } - return target; - } - - protected EStructuralFeature getTarget(EStructuralFeature eStructuralFeature) - { - EClass eClass = getTarget(eStructuralFeature.getEContainingClass()); - EStructuralFeature targetEf = eClass.getEStructuralFeature(eStructuralFeature.getName()); - return targetEf; - } - - /** - * This Method WILL BE REMOVED when EMF 3.0 is available - */ - public void copyReferences() - { - for (Iterator i = entrySet().iterator(); i.hasNext();) - { - Map.Entry entry = (Map.Entry)i.next(); - EObject eObject = (EObject)entry.getKey(); - EObject copyEObject = (EObject)entry.getValue(); - EClass eClass = eObject.eClass(); - for (int j = 0, size = eClass.getFeatureCount(); j < size; ++j) - { - EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature(j); - if (eStructuralFeature.isChangeable() && !eStructuralFeature.isDerived()) - { - if (eStructuralFeature instanceof EReference) - { - EReference eReference = (EReference)eStructuralFeature; - if (!eReference.isContainment() && !eReference.isContainer()) - { - copyReference(eReference, eObject, copyEObject); - } - } - else if (FeatureMapUtil.isFeatureMap(eStructuralFeature)) - { - FeatureMap featureMap = (FeatureMap)eObject.eGet(eStructuralFeature); - FeatureMap copyFeatureMap = (FeatureMap)copyEObject.eGet(getTarget(eStructuralFeature)); - int copyFeatureMapSize = copyFeatureMap.size(); - for (int k = 0, featureMapSize = featureMap.size(); k < featureMapSize; ++k) - { - EStructuralFeature feature = featureMap.getEStructuralFeature(k); - if (feature instanceof EReference) - { - Object referencedEObject = featureMap.getValue(k); - Object copyReferencedEObject = get(referencedEObject); - if (copyReferencedEObject == null && referencedEObject != null) - { - EReference reference = (EReference)feature; - if (!useOriginalReferences || reference.isContainment() || reference.getEOpposite() != null) - { - continue; - } - copyReferencedEObject = referencedEObject; - } - // If we can't add it, it must aleady be in the list so find it and move it to the end. - // - if (!copyFeatureMap.add(feature, copyReferencedEObject)) - { - for (int l = 0; l < copyFeatureMapSize; ++l) - { - if (copyFeatureMap.getEStructuralFeature(l) == feature && copyFeatureMap.getValue(l) == copyReferencedEObject) - { - copyFeatureMap.move(copyFeatureMap.size() - 1, l); - --copyFeatureMapSize; - break; - } - } - } - } - else - { - copyFeatureMap.add(featureMap.get(k)); - } - } - } - } - } - } - } - - /** - * This Method WILL BE REMOVED when EMF 3.0 is available - */ - protected void copyReference(EReference eReference, EObject eObject, EObject copyEObject) - { - if (eObject.eIsSet(eReference)) - { - if (eReference.isMany()) - { - InternalEList source = (InternalEList)eObject.eGet(eReference); - InternalEList target = (InternalEList)copyEObject.eGet(getTarget(eReference)); - if (source.isEmpty()) - { - target.clear(); - } - else - { - boolean isBidirectional = eReference.getEOpposite() != null; - int index = 0; - for (Iterator k = resolveProxies ? source.iterator() : source.basicIterator(); k.hasNext();) - { - Object referencedEObject = k.next(); - Object copyReferencedEObject = get(referencedEObject); - if (copyReferencedEObject == null) - { - if (useOriginalReferences && !isBidirectional) - { - target.addUnique(index, referencedEObject); - ++index; - } - } - else - { - if (isBidirectional) - { - int position = target.indexOf(copyReferencedEObject); - if (position == -1) - { - target.addUnique(index, copyReferencedEObject); - } - else if (index != position) - { - target.move(index, copyReferencedEObject); - } - } - else - { - target.addUnique(index, copyReferencedEObject); - } - ++index; - } - } - } - } - else - { - Object referencedEObject = eObject.eGet(eReference, resolveProxies); - if (referencedEObject == null) - { - copyEObject.eSet(getTarget(eReference), null); - } - else - { - Object copyReferencedEObject = get(referencedEObject); - if (copyReferencedEObject == null) - { - if (useOriginalReferences && eReference.getEOpposite() == null) - { - copyEObject.eSet(getTarget(eReference), referencedEObject); - } - } - else - { - copyEObject.eSet(getTarget(eReference), copyReferencedEObject); - } - } - } - } - } - } -} +/** + * + * 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.helper; + +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.ecore.util.FeatureMap; +import org.eclipse.emf.ecore.util.FeatureMapUtil; +import org.eclipse.emf.ecore.util.InternalEList; +import org.eclipse.emf.ecore.util.EcoreUtil.Copier; + +import commonj.sdo.DataObject; +import commonj.sdo.Type; +import commonj.sdo.helper.CopyHelper; +import commonj.sdo.helper.TypeHelper; + +/** + * A CopyHelper implementation that creates the copy objects in a specific metadata scope. + * The target scope must contain a compatible version of the Types needed to create the copy objects. + */ +public class CrossScopeCopyHelperImpl implements CopyHelper +{ + protected TypeHelper scope; + + public CrossScopeCopyHelperImpl(TypeHelper targetScope) + { + scope = targetScope; + } + + public DataObject copyShallow(DataObject dataObject) + { + Copier copier = new CrossScopeCopier() + { + protected void copyContainment(EReference eReference, EObject eObject, EObject copyEObject) + { + } + protected void copyAttribute(EAttribute eAttribute, EObject eObject, EObject copyEObject) + { + if (eObject.eIsSet(eAttribute) && !FeatureMapUtil.isFeatureMap(eAttribute)) + { + super.copyAttribute(eAttribute,eObject,copyEObject); + } + } + }; + EObject result = copier.copy((EObject)dataObject); + copier.copyReferences(); + return (DataObject)result; + } + + public DataObject copy(DataObject dataObject) + { + Copier copier = new CrossScopeCopier(); + DataObject result = (DataObject)copier.copy((EObject)dataObject); + copier.copyReferences(); + return (DataObject)result; + } + + protected class CrossScopeCopier extends EcoreUtil.Copier + { + protected boolean useOriginalReferences = false; + + protected EClass getTarget(EClass eClass) + { + EClass target = (EClass)get(eClass); + if (target == null) + { + Type type = (Type)eClass; + target = (EClass)scope.getType(type.getURI(), type.getName()); + } + return target; + } + + protected EStructuralFeature getTarget(EStructuralFeature eStructuralFeature) + { + EClass eClass = getTarget(eStructuralFeature.getEContainingClass()); + EStructuralFeature targetEf = eClass.getEStructuralFeature(eStructuralFeature.getName()); + return targetEf; + } + + /** + * This Method WILL BE REMOVED when EMF 3.0 is available + */ + public void copyReferences() + { + for (Iterator i = entrySet().iterator(); i.hasNext();) + { + Map.Entry entry = (Map.Entry)i.next(); + EObject eObject = (EObject)entry.getKey(); + EObject copyEObject = (EObject)entry.getValue(); + EClass eClass = eObject.eClass(); + for (int j = 0, size = eClass.getFeatureCount(); j < size; ++j) + { + EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature(j); + if (eStructuralFeature.isChangeable() && !eStructuralFeature.isDerived()) + { + if (eStructuralFeature instanceof EReference) + { + EReference eReference = (EReference)eStructuralFeature; + if (!eReference.isContainment() && !eReference.isContainer()) + { + copyReference(eReference, eObject, copyEObject); + } + } + else if (FeatureMapUtil.isFeatureMap(eStructuralFeature)) + { + FeatureMap featureMap = (FeatureMap)eObject.eGet(eStructuralFeature); + FeatureMap copyFeatureMap = (FeatureMap)copyEObject.eGet(getTarget(eStructuralFeature)); + int copyFeatureMapSize = copyFeatureMap.size(); + for (int k = 0, featureMapSize = featureMap.size(); k < featureMapSize; ++k) + { + EStructuralFeature feature = featureMap.getEStructuralFeature(k); + if (feature instanceof EReference) + { + Object referencedEObject = featureMap.getValue(k); + Object copyReferencedEObject = get(referencedEObject); + if (copyReferencedEObject == null && referencedEObject != null) + { + EReference reference = (EReference)feature; + if (!useOriginalReferences || reference.isContainment() || reference.getEOpposite() != null) + { + continue; + } + copyReferencedEObject = referencedEObject; + } + // If we can't add it, it must aleady be in the list so find it and move it to the end. + // + if (!copyFeatureMap.add(feature, copyReferencedEObject)) + { + for (int l = 0; l < copyFeatureMapSize; ++l) + { + if (copyFeatureMap.getEStructuralFeature(l) == feature && copyFeatureMap.getValue(l) == copyReferencedEObject) + { + copyFeatureMap.move(copyFeatureMap.size() - 1, l); + --copyFeatureMapSize; + break; + } + } + } + } + else + { + copyFeatureMap.add(featureMap.get(k)); + } + } + } + } + } + } + } + + /** + * This Method WILL BE REMOVED when EMF 3.0 is available + */ + protected void copyReference(EReference eReference, EObject eObject, EObject copyEObject) + { + if (eObject.eIsSet(eReference)) + { + if (eReference.isMany()) + { + InternalEList source = (InternalEList)eObject.eGet(eReference); + InternalEList target = (InternalEList)copyEObject.eGet(getTarget(eReference)); + if (source.isEmpty()) + { + target.clear(); + } + else + { + boolean isBidirectional = eReference.getEOpposite() != null; + int index = 0; + for (Iterator k = resolveProxies ? source.iterator() : source.basicIterator(); k.hasNext();) + { + Object referencedEObject = k.next(); + Object copyReferencedEObject = get(referencedEObject); + if (copyReferencedEObject == null) + { + if (useOriginalReferences && !isBidirectional) + { + target.addUnique(index, referencedEObject); + ++index; + } + } + else + { + if (isBidirectional) + { + int position = target.indexOf(copyReferencedEObject); + if (position == -1) + { + target.addUnique(index, copyReferencedEObject); + } + else if (index != position) + { + target.move(index, copyReferencedEObject); + } + } + else + { + target.addUnique(index, copyReferencedEObject); + } + ++index; + } + } + } + } + else + { + Object referencedEObject = eObject.eGet(eReference, resolveProxies); + if (referencedEObject == null) + { + copyEObject.eSet(getTarget(eReference), null); + } + else + { + Object copyReferencedEObject = get(referencedEObject); + if (copyReferencedEObject == null) + { + if (useOriginalReferences && eReference.getEOpposite() == null) + { + copyEObject.eSet(getTarget(eReference), referencedEObject); + } + } + else + { + copyEObject.eSet(getTarget(eReference), copyReferencedEObject); + } + } + } + } + } + } +} diff --git a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/DefaultHelperContextImpl.java b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/DefaultHelperContextImpl.java index a8804e9e5d..f7ac22632a 100644 --- a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/DefaultHelperContextImpl.java +++ b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/DefaultHelperContextImpl.java @@ -1,72 +1,72 @@ -/** - * - * 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.helper; - -import java.util.Map; -import java.util.WeakHashMap; - -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.emf.ecore.impl.EPackageRegistryImpl; - -public class DefaultHelperContextImpl extends HelperContextImpl { - public DefaultHelperContextImpl(final boolean extensibleNamespaces) { - super(new SDOExtendedMetaDataImpl(new SDOPackageRegistryDelegator()), extensibleNamespaces); - } - - public DefaultHelperContextImpl(final boolean extensibleNamespaces, final Map options) { - super(new SDOExtendedMetaDataImpl(new SDOPackageRegistryDelegator()), extensibleNamespaces, options); - } - - protected static class SDOPackageRegistryDelegator extends EPackageRegistryImpl.Delegator { - /** - * A map from class loader to its associated registry. - */ - protected Map classLoaderToRegistryMap = new WeakHashMap(); - - /** - * Returns the package registry associated with the given class loader. - * @param classLoader the class loader. - * @return the package registry associated with the given class loader. - */ - public synchronized EPackage.Registry getRegistry(final ClassLoader classLoader) - { - EPackage.Registry result = (EPackage.Registry)classLoaderToRegistryMap.get(classLoader); - if (result == null) - { - if (classLoader == null) - { - result = HelperContextImpl.getBuiltInModelRegistry(); - } - else - { - result = new EPackageRegistryImpl(getRegistry(classLoader.getParent())); - classLoaderToRegistryMap.put(classLoader, result); - } - } - return result; - } - - protected EPackage.Registry delegateRegistry(final ClassLoader classLoader) - { - return getRegistry(classLoader); - } - } -} +/** + * + * 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.helper; + +import java.util.Map; +import java.util.WeakHashMap; + +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.impl.EPackageRegistryImpl; + +public class DefaultHelperContextImpl extends HelperContextImpl { + public DefaultHelperContextImpl(final boolean extensibleNamespaces) { + super(new SDOExtendedMetaDataImpl(new SDOPackageRegistryDelegator()), extensibleNamespaces); + } + + public DefaultHelperContextImpl(final boolean extensibleNamespaces, final Map options) { + super(new SDOExtendedMetaDataImpl(new SDOPackageRegistryDelegator()), extensibleNamespaces, options); + } + + protected static class SDOPackageRegistryDelegator extends EPackageRegistryImpl.Delegator { + /** + * A map from class loader to its associated registry. + */ + protected Map classLoaderToRegistryMap = new WeakHashMap(); + + /** + * Returns the package registry associated with the given class loader. + * @param classLoader the class loader. + * @return the package registry associated with the given class loader. + */ + public synchronized EPackage.Registry getRegistry(final ClassLoader classLoader) + { + EPackage.Registry result = (EPackage.Registry)classLoaderToRegistryMap.get(classLoader); + if (result == null) + { + if (classLoader == null) + { + result = HelperContextImpl.getBuiltInModelRegistry(); + } + else + { + result = new EPackageRegistryImpl(getRegistry(classLoader.getParent())); + classLoaderToRegistryMap.put(classLoader, result); + } + } + return result; + } + + protected EPackage.Registry delegateRegistry(final ClassLoader classLoader) + { + return getRegistry(classLoader); + } + } +} diff --git a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java index 3efd8d03b7..922f092845 100644 --- a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java +++ b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java @@ -1,530 +1,530 @@ -/** - * - * 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.helper; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.tuscany.sdo.SDOExtendedMetaData; -import org.apache.tuscany.sdo.SDOFactory; -import org.apache.tuscany.sdo.SimpleAnyTypeDataObject; -import org.apache.tuscany.sdo.api.SDOHelper; -import org.apache.tuscany.sdo.api.XMLStreamHelper; -import org.apache.tuscany.sdo.api.EventListener; -import org.apache.tuscany.sdo.impl.ClassImpl; -import org.apache.tuscany.sdo.impl.DataGraphImpl; -import org.apache.tuscany.sdo.impl.DynamicDataObjectImpl; -import org.apache.tuscany.sdo.model.ModelFactory; -import org.apache.tuscany.sdo.model.impl.ModelFactoryImpl; -import org.apache.tuscany.sdo.spi.SDOHelperBase; -import org.apache.tuscany.sdo.util.DataObjectUtil; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notifier; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.common.util.UniqueEList; -import org.eclipse.emf.ecore.EAnnotation; -import org.eclipse.emf.ecore.EAttribute; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EClassifier; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.emf.ecore.EModelElement; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.emf.ecore.EReference; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecore.ETypedElement; -import org.eclipse.emf.ecore.EcoreFactory; -import org.eclipse.emf.ecore.EcorePackage; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.emf.ecore.util.ExtendedMetaData; -import org.eclipse.emf.ecore.util.FeatureMap; -import org.eclipse.emf.ecore.util.FeatureMapUtil; -import org.eclipse.emf.ecore.xmi.XMLResource; - -import commonj.sdo.DataGraph; -import commonj.sdo.DataObject; -import commonj.sdo.Property; -import commonj.sdo.Sequence; -import commonj.sdo.Type; -import commonj.sdo.helper.CopyHelper; -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.TypeHelper; -import commonj.sdo.impl.HelperProvider; - -public class SDOHelperImpl extends SDOHelperBase implements SDOHelper, SDOHelper.MetaDataBuilder { - - public DataObject createDataTypeWrapper(Type dataType, Object value) { - SimpleAnyTypeDataObject simpleAnyType = SDOFactory.eINSTANCE.createSimpleAnyTypeDataObject(); - simpleAnyType.setInstanceType((EDataType)dataType); - simpleAnyType.setValue(value); - return simpleAnyType; - } - - public Object createFromString(Type dataType, String literal) { - return EcoreUtil.createFromString((EDataType)dataType, literal); - } - - public String convertToString(Type dataType, Object value) { - return EcoreUtil.convertToString((EDataType)dataType, value); - } - - public Type getXSDSDOType(String xsdType) { - Type type = null; - String name = (String)xsdToSdoMappings.get(xsdType); - if (name != null) - type = (Type)((ModelFactoryImpl)ModelFactory.INSTANCE).getEClassifier(name); - return type; - } - - public Sequence getSubstitutionValues(DataObject dataObject, Property head) { - final EStructuralFeature group = ExtendedMetaData.INSTANCE.getGroup((EStructuralFeature)head); - return null == group ? null : (Sequence)((FeatureMap.Internal)((EObject)dataObject).eGet(group)).getWrapper(); - } - - public Type getJavaSDOType(Class javaClass) { - String name = (String)javaToSdoMappings.get(javaClass); - if (name != null) { - return (Type)((ModelFactoryImpl)ModelFactory.INSTANCE).getEClassifier(name); - } - return null; - } - - public boolean isRequired(Property property) { - return ((EStructuralFeature)property).isRequired(); - } - - public int getUpperBound(Property property) { - return ((EStructuralFeature)property).getUpperBound(); - } - - public int getLowerBound(Property property) { - return ((EStructuralFeature)property).getLowerBound(); - } - - public List getEnumerationFacet(Type type) { - List instProps = type.getInstanceProperties(); - String propertyName = "enumeration"; - Property enumProperty = null; - - for (int i = 0; i < instProps.size(); i++) - { - Property prop = (Property)instProps.get(i); - if (propertyName.equals(prop.getName())) - enumProperty = prop; - } - - return (List)DataObjectUtil.getMetaObjectInstanceProperty((EModelElement)type, enumProperty); - } - - public List getPatternFacet(Type type) { - List instProps = type.getInstanceProperties(); - String propertyName = "pattern"; - Property patternProperty = null; - - for (int i = 0; i < instProps.size(); i++) - { - Property prop = (Property)instProps.get(i); - if (propertyName.equals(prop.getName())) - patternProperty = prop; - } - - return (List)DataObjectUtil.getMetaObjectInstanceProperty((EModelElement)type, patternProperty); - } - - public boolean isMany(Property property, DataObject context) { - return FeatureMapUtil.isMany((EObject)context, (EStructuralFeature)property); - } - - public DataGraph createDataGraph() { - return SDOFactory.eINSTANCE.createDataGraph(); - } - - public void setRootObject(DataGraph dataGraph, DataObject rootObject) { - ((DataGraphImpl)dataGraph).setERootObject((EObject)rootObject); - } - - public static DataGraph loadDataGraph(InputStream inputStream, Map options) throws IOException { - ResourceSet resourceSet = DataObjectUtil.createResourceSet(); - Resource resource = resourceSet.createResource(URI.createURI("all.datagraph")); - resource.load(inputStream, options); - return (DataGraph)resource.getContents().get(0); - } - - static final Object LOADING_SCOPE = XMLResource.OPTION_EXTENDED_META_DATA; - - protected void registerLoadingScope(Map options, TypeHelper scope) { - Object extendedMetaData = ((TypeHelperImpl)scope).getExtendedMetaData(); - options.put(LOADING_SCOPE, extendedMetaData); - } - - public DataGraph loadDataGraph(InputStream inputStream, Map options, HelperContext scope) throws IOException { - if (scope == null) { - scope = HelperProvider.getDefaultContext(); - } - TypeHelper th = scope.getTypeHelper(); - DataGraph result = null; - if (th == null || th == TypeHelper.INSTANCE) { - result = loadDataGraph(inputStream, options); - } else if (options == null) { - options = new HashMap(); - registerLoadingScope(options, th); - result = loadDataGraph(inputStream, options); - } else if (options.containsKey(LOADING_SCOPE)) { - Object restore = options.get(LOADING_SCOPE); - registerLoadingScope(options, th); - try { - result = loadDataGraph(inputStream, options); - } finally { - options.put(LOADING_SCOPE, restore); - } - } else { - registerLoadingScope(options, th); - try { - result = loadDataGraph(inputStream, options); - } finally { - options.remove(LOADING_SCOPE); - } - } - return result; - } - - public void saveDataGraph(DataGraph dataGraph, OutputStream outputStream, Map options) throws IOException { - ((DataGraphImpl)dataGraph).getDataGraphResource().save(outputStream, options); - } - - public void registerDataGraphTypes(DataGraph dataGraph, List/* Type */types) { - // if (types == null) - // types = SDOUtil.getDataGraphTypes(dataGraph); - - Set/* EPackage */packages = new HashSet(); - for (final Iterator iterator = types.iterator(); iterator.hasNext();) { - EClassifier type = (EClassifier)iterator.next(); - packages.add(type.getEPackage()); - } - - ResourceSet resourceSet = ((DataGraphImpl)dataGraph).getResourceSet(); - - for (Iterator iterator = packages.iterator(); iterator.hasNext();) { - EPackage typePackage = (EPackage)iterator.next(); - Resource resource = typePackage.eResource(); - if (resource == null) { - resource = resourceSet.createResource(URI.createURI(".ecore")); - resource.setURI(URI.createURI(typePackage.getNsURI())); - resource.getContents().add(typePackage); - } else if (resource.getResourceSet() != resourceSet) - resourceSet.getResources().add(resource); - } - } - - public HelperContext createHelperContext() { - return new HelperContextImpl(false, null); - } - - public HelperContext createHelperContext(boolean extensibleNamespaces) { - return new HelperContextImpl(extensibleNamespaces); - } - - public HelperContext createHelperContext(Map options) { - return new HelperContextImpl(false, options); - } - - public HelperContext createHelperContext(boolean extensibleNamespaces, Map options) { - return new HelperContextImpl(extensibleNamespaces, options); - } - - - public CopyHelper createCrossScopeCopyHelper(HelperContext hc) { - return new CrossScopeCopyHelperImpl(hc.getTypeHelper()); - } - - - public XMLStreamHelper createXMLStreamHelper(HelperContext hc) { - return ((HelperContextImpl)hc).getXMLStreamHelper(); - } - - - public List getTypes(HelperContext hc, String uri) { - - EPackage ePackage = ((HelperContextImpl)hc).getExtendedMetaData().getPackage(uri); - if (ePackage != null) { - return new ArrayList(ePackage.getEClassifiers()); - } - return null; - } - - public List getOpenContentProperties(DataObject dataObject) { - List result = new UniqueEList(); - ((ClassImpl)dataObject.getType()).addOpenProperties((EObject)dataObject, result); - return result; - } - - public boolean isDocumentRoot(Type type) { - return "".equals(SDOExtendedMetaData.INSTANCE.getName((EClassifier)type)); - } - - - public Type createType(HelperContext hc, String uri, String name, boolean isDataType) { - ExtendedMetaData extendedMetaData = ((HelperContextImpl)hc).getExtendedMetaData(); - if ("".equals(uri)) - uri = null; // FB - - EPackage ePackage = extendedMetaData.getPackage(uri); - if (ePackage == null) { - ePackage = EcoreFactory.eINSTANCE.createEPackage(); - ePackage.setEFactoryInstance(new DynamicDataObjectImpl.FactoryImpl()); - ePackage.setNsURI(uri); - String packagePrefix = uri != null ? URI.createURI(uri).trimFileExtension().lastSegment() : ""; // FB - ePackage.setName(packagePrefix); - ePackage.setNsPrefix(packagePrefix); - extendedMetaData.putPackage(uri, ePackage); - } - - EClassifier eClassifier = ePackage.getEClassifier(name); - if (eClassifier != null) // already defined? - { - // throw new IllegalArgumentException(); - return null; - } - - if (name != null) { - eClassifier = - isDataType ? (EClassifier)SDOFactory.eINSTANCE.createDataType() : (EClassifier)SDOFactory.eINSTANCE - .createClass(); - eClassifier.setName(name); - } else { - eClassifier = DataObjectUtil.createDocumentRoot(); - } - - ePackage.getEClassifiers().add(eClassifier); - - return (Type)eClassifier; - } - - public void addBaseType(Type type, Type baseType) { - ((EClass)type).getESuperTypes().add(baseType); - } - - public void addAliasName(Type type, String aliasName) { - throw new UnsupportedOperationException(); // TODO: implement this - // method properly - // type.getAliasNames().add(aliasName); - } - - public void setOpen(Type type, boolean isOpen) { - if (isOpen == type.isOpen()) - return; - - if (isOpen) { - EAttribute eAttribute = (EAttribute)SDOFactory.eINSTANCE.createAttribute(); - ((EClass)type).getEStructuralFeatures().add(eAttribute); - - eAttribute.setName("any"); - eAttribute.setUnique(false); - eAttribute.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY); - eAttribute.setEType(EcorePackage.eINSTANCE.getEFeatureMapEntry()); - ExtendedMetaData.INSTANCE.setFeatureKind(eAttribute, ExtendedMetaData.ELEMENT_WILDCARD_FEATURE); - ExtendedMetaData.INSTANCE.setProcessingKind(eAttribute, ExtendedMetaData.LAX_PROCESSING); - ExtendedMetaData.INSTANCE.setWildcards(eAttribute, Collections.singletonList("##any")); - - // FB TBD Add an "anyAttribute" EAttribute as well. - - if (ExtendedMetaData.INSTANCE.getMixedFeature((EClass)type) != null) { - eAttribute.setDerived(true); - eAttribute.setTransient(true); - eAttribute.setVolatile(true); - } - } else { - EClass eClass = (EClass)type; - EAttribute any = (EAttribute)eClass.getEStructuralFeature("any"); - eClass.getEStructuralFeatures().remove(any); - } - } - - public void setSequenced(Type type, boolean isSequenced) { - // currently, we require setSequenced to be called first, before - // anything else is added to the type. - if (type.isDataType() || !type.getProperties().isEmpty()) { - if (type.getName() != "DocumentRoot") // document root is a - // special case - throw new IllegalArgumentException(); - } - - if (isSequenced) { - EClass eClass = (EClass)type; - ExtendedMetaData.INSTANCE.setContentKind(eClass, ExtendedMetaData.MIXED_CONTENT); - EAttribute mixedFeature = (EAttribute)SDOFactory.eINSTANCE.createAttribute(); - mixedFeature.setName("mixed"); - mixedFeature.setUnique(false); - mixedFeature.setEType(EcorePackage.eINSTANCE.getEFeatureMapEntry()); - mixedFeature.setLowerBound(0); - mixedFeature.setUpperBound(-1); - // eClass.getEStructuralFeatures().add(mixedFeature); - ((ClassImpl)eClass).setSequenceFeature(mixedFeature); - ExtendedMetaData.INSTANCE.setFeatureKind(mixedFeature, ExtendedMetaData.ELEMENT_WILDCARD_FEATURE); - ExtendedMetaData.INSTANCE.setName(mixedFeature, ":mixed"); - } else { - // nothing to do, because of current restriction that setSequence - // must be called first. - } - } - - public void setAbstract(Type type, boolean isAbstract) { - ((EClass)type).setAbstract(isAbstract); - } - - public void setJavaClassName(Type type, String javaClassName) { - ((EClassifier)type).setInstanceClassName(javaClassName); - } - - public Property createProperty(Type containingType, String name, Type propertyType) { - EStructuralFeature eStructuralFeature = - propertyType.isDataType() ? (EStructuralFeature)SDOFactory.eINSTANCE.createAttribute() - : (EStructuralFeature)SDOFactory.eINSTANCE.createReference(); - - eStructuralFeature.setName(name); - eStructuralFeature.setEType((EClassifier)propertyType); - ((EClass)containingType).getEStructuralFeatures().add(eStructuralFeature); - - if ("".equals(ExtendedMetaData.INSTANCE.getName((EClass)containingType))) // DocumentRoot - // containingType? - { - ExtendedMetaData.INSTANCE.setNamespace(eStructuralFeature, containingType.getURI()); - //FB???eStructuralFeature.setUnique(false); - //FB???eStructuralFeature.setUpperBound(ETypedElement.UNSPECIFIED_MULTIPLICITY); - } - - if (ExtendedMetaData.INSTANCE.getMixedFeature((EClass)containingType) != null) { - eStructuralFeature.setDerived(true); - eStructuralFeature.setTransient(true); - eStructuralFeature.setVolatile(true); - ExtendedMetaData.INSTANCE.setFeatureKind(eStructuralFeature, ExtendedMetaData.ELEMENT_FEATURE); - } else { - // By default, a SDO property is an XSD element - ExtendedMetaData.INSTANCE.setFeatureKind(eStructuralFeature, ExtendedMetaData.ELEMENT_FEATURE); - } - - return (Property)eStructuralFeature; - } - - public void setPropertyXMLKind(Property property, boolean isXmlElement) { - if (isXmlElement) { - ExtendedMetaData.INSTANCE.setFeatureKind((EStructuralFeature)property, ExtendedMetaData.ELEMENT_FEATURE); - } - else { - ExtendedMetaData.INSTANCE.setFeatureKind((EStructuralFeature)property, ExtendedMetaData.ATTRIBUTE_FEATURE); - } - } - - - public Property createOpenContentProperty(HelperContext hc, String uri, String name, Type type) - { - ExtendedMetaData extendedMetaData = ((HelperContextImpl)hc).getExtendedMetaData(); - - // get/create document root - EPackage ePackage = extendedMetaData.getPackage(uri); - Type documentRoot = ePackage != null ? (Type)extendedMetaData.getType(ePackage, "") : null; - if (documentRoot == null) { - documentRoot = createType(hc, uri, null, false); - } - - // Determine if property already exists - Property newProperty = documentRoot.getProperty(name); - if (newProperty == null) { - // Create the new property 'under' the document root..... - newProperty = createProperty(documentRoot, name, type); - } else { - // if property already exists, validate the expected type - if (!newProperty.getType().equals(type)) - throw new IllegalArgumentException(); - } - return newProperty; - } - - - public void addAliasName(Property property, String aliasName) { - throw new UnsupportedOperationException(); // TODO: implement this - // method properly - // property.getAliasNames().add(aliasName); - } - - public void setMany(Property property, boolean isMany) { - ((EStructuralFeature)property).setUpperBound(isMany ? EStructuralFeature.UNBOUNDED_MULTIPLICITY : 1); - } - - public void setContainment(Property property, boolean isContainment) { - ((EReference)property).setContainment(isContainment); - } - - public void setDefault(Property property, String defaultValue) { - ((EStructuralFeature)property).setDefaultValueLiteral(defaultValue); - } - - public void setReadOnly(Property property, boolean isReadOnly) { - ((EStructuralFeature)property).setChangeable(!isReadOnly); - } - - public void setOpposite(Property property, Property opposite) { - ((EReference)property).setEOpposite((EReference)opposite); - } - - public void addTypeInstanceProperty(Type definedType, Property instanceProperty, Object value) { - addInstanceProperty((EModelElement)definedType, instanceProperty, value); - } - - public void addPropertyInstanceProperty(Property definedProperty, Property instanceProperty, Object value) { - addInstanceProperty((EModelElement)definedProperty, instanceProperty, value); - } - - protected void addInstanceProperty(EModelElement metaObject, Property property, Object value) { - String uri = property.getContainingType().getURI(); - EAnnotation eAnnotation = metaObject.getEAnnotation(uri); - if (eAnnotation == null) { - eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation(); - eAnnotation.setSource(uri); - metaObject.getEAnnotations().add(eAnnotation); - } - // TODO if (property.isMany()) ... // convert list of values - String stringValue = convertToString(property.getType(), value); - eAnnotation.getDetails().put(property.getName(), stringValue); - } - - - public void addChangeListener(DataObject dob, EventListener listener) { - // Adapter l = (Adapter)listener; - ((Notifier)dob).eAdapters().add(listener); - } - - public void removeChangeListener(DataObject dob, EventListener listener) { - ((Notifier)dob).eAdapters().remove(listener); - } - - -} +/** + * + * 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.helper; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.tuscany.sdo.SDOExtendedMetaData; +import org.apache.tuscany.sdo.SDOFactory; +import org.apache.tuscany.sdo.SimpleAnyTypeDataObject; +import org.apache.tuscany.sdo.api.SDOHelper; +import org.apache.tuscany.sdo.api.XMLStreamHelper; +import org.apache.tuscany.sdo.api.EventListener; +import org.apache.tuscany.sdo.impl.ClassImpl; +import org.apache.tuscany.sdo.impl.DataGraphImpl; +import org.apache.tuscany.sdo.impl.DynamicDataObjectImpl; +import org.apache.tuscany.sdo.model.ModelFactory; +import org.apache.tuscany.sdo.model.impl.ModelFactoryImpl; +import org.apache.tuscany.sdo.spi.SDOHelperBase; +import org.apache.tuscany.sdo.util.DataObjectUtil; +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.Notifier; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.common.util.UniqueEList; +import org.eclipse.emf.ecore.EAnnotation; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EDataType; +import org.eclipse.emf.ecore.EModelElement; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.ETypedElement; +import org.eclipse.emf.ecore.EcoreFactory; +import org.eclipse.emf.ecore.EcorePackage; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.ecore.util.ExtendedMetaData; +import org.eclipse.emf.ecore.util.FeatureMap; +import org.eclipse.emf.ecore.util.FeatureMapUtil; +import org.eclipse.emf.ecore.xmi.XMLResource; + +import commonj.sdo.DataGraph; +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Sequence; +import commonj.sdo.Type; +import commonj.sdo.helper.CopyHelper; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.impl.HelperProvider; + +public class SDOHelperImpl extends SDOHelperBase implements SDOHelper, SDOHelper.MetaDataBuilder { + + public DataObject createDataTypeWrapper(Type dataType, Object value) { + SimpleAnyTypeDataObject simpleAnyType = SDOFactory.eINSTANCE.createSimpleAnyTypeDataObject(); + simpleAnyType.setInstanceType((EDataType)dataType); + simpleAnyType.setValue(value); + return simpleAnyType; + } + + public Object createFromString(Type dataType, String literal) { + return EcoreUtil.createFromString((EDataType)dataType, literal); + } + + public String convertToString(Type dataType, Object value) { + return EcoreUtil.convertToString((EDataType)dataType, value); + } + + public Type getXSDSDOType(String xsdType) { + Type type = null; + String name = (String)xsdToSdoMappings.get(xsdType); + if (name != null) + type = (Type)((ModelFactoryImpl)ModelFactory.INSTANCE).getEClassifier(name); + return type; + } + + public Sequence getSubstitutionValues(DataObject dataObject, Property head) { + final EStructuralFeature group = ExtendedMetaData.INSTANCE.getGroup((EStructuralFeature)head); + return null == group ? null : (Sequence)((FeatureMap.Internal)((EObject)dataObject).eGet(group)).getWrapper(); + } + + public Type getJavaSDOType(Class javaClass) { + String name = (String)javaToSdoMappings.get(javaClass); + if (name != null) { + return (Type)((ModelFactoryImpl)ModelFactory.INSTANCE).getEClassifier(name); + } + return null; + } + + public boolean isRequired(Property property) { + return ((EStructuralFeature)property).isRequired(); + } + + public int getUpperBound(Property property) { + return ((EStructuralFeature)property).getUpperBound(); + } + + public int getLowerBound(Property property) { + return ((EStructuralFeature)property).getLowerBound(); + } + + public List getEnumerationFacet(Type type) { + List instProps = type.getInstanceProperties(); + String propertyName = "enumeration"; + Property enumProperty = null; + + for (int i = 0; i < instProps.size(); i++) + { + Property prop = (Property)instProps.get(i); + if (propertyName.equals(prop.getName())) + enumProperty = prop; + } + + return (List)DataObjectUtil.getMetaObjectInstanceProperty((EModelElement)type, enumProperty); + } + + public List getPatternFacet(Type type) { + List instProps = type.getInstanceProperties(); + String propertyName = "pattern"; + Property patternProperty = null; + + for (int i = 0; i < instProps.size(); i++) + { + Property prop = (Property)instProps.get(i); + if (propertyName.equals(prop.getName())) + patternProperty = prop; + } + + return (List)DataObjectUtil.getMetaObjectInstanceProperty((EModelElement)type, patternProperty); + } + + public boolean isMany(Property property, DataObject context) { + return FeatureMapUtil.isMany((EObject)context, (EStructuralFeature)property); + } + + public DataGraph createDataGraph() { + return SDOFactory.eINSTANCE.createDataGraph(); + } + + public void setRootObject(DataGraph dataGraph, DataObject rootObject) { + ((DataGraphImpl)dataGraph).setERootObject((EObject)rootObject); + } + + public static DataGraph loadDataGraph(InputStream inputStream, Map options) throws IOException { + ResourceSet resourceSet = DataObjectUtil.createResourceSet(); + Resource resource = resourceSet.createResource(URI.createURI("all.datagraph")); + resource.load(inputStream, options); + return (DataGraph)resource.getContents().get(0); + } + + static final Object LOADING_SCOPE = XMLResource.OPTION_EXTENDED_META_DATA; + + protected void registerLoadingScope(Map options, TypeHelper scope) { + Object extendedMetaData = ((TypeHelperImpl)scope).getExtendedMetaData(); + options.put(LOADING_SCOPE, extendedMetaData); + } + + public DataGraph loadDataGraph(InputStream inputStream, Map options, HelperContext scope) throws IOException { + if (scope == null) { + scope = HelperProvider.getDefaultContext(); + } + TypeHelper th = scope.getTypeHelper(); + DataGraph result = null; + if (th == null || th == TypeHelper.INSTANCE) { + result = loadDataGraph(inputStream, options); + } else if (options == null) { + options = new HashMap(); + registerLoadingScope(options, th); + result = loadDataGraph(inputStream, options); + } else if (options.containsKey(LOADING_SCOPE)) { + Object restore = options.get(LOADING_SCOPE); + registerLoadingScope(options, th); + try { + result = loadDataGraph(inputStream, options); + } finally { + options.put(LOADING_SCOPE, restore); + } + } else { + registerLoadingScope(options, th); + try { + result = loadDataGraph(inputStream, options); + } finally { + options.remove(LOADING_SCOPE); + } + } + return result; + } + + public void saveDataGraph(DataGraph dataGraph, OutputStream outputStream, Map options) throws IOException { + ((DataGraphImpl)dataGraph).getDataGraphResource().save(outputStream, options); + } + + public void registerDataGraphTypes(DataGraph dataGraph, List/* Type */types) { + // if (types == null) + // types = SDOUtil.getDataGraphTypes(dataGraph); + + Set/* EPackage */packages = new HashSet(); + for (final Iterator iterator = types.iterator(); iterator.hasNext();) { + EClassifier type = (EClassifier)iterator.next(); + packages.add(type.getEPackage()); + } + + ResourceSet resourceSet = ((DataGraphImpl)dataGraph).getResourceSet(); + + for (Iterator iterator = packages.iterator(); iterator.hasNext();) { + EPackage typePackage = (EPackage)iterator.next(); + Resource resource = typePackage.eResource(); + if (resource == null) { + resource = resourceSet.createResource(URI.createURI(".ecore")); + resource.setURI(URI.createURI(typePackage.getNsURI())); + resource.getContents().add(typePackage); + } else if (resource.getResourceSet() != resourceSet) + resourceSet.getResources().add(resource); + } + } + + public HelperContext createHelperContext() { + return new HelperContextImpl(false, null); + } + + public HelperContext createHelperContext(boolean extensibleNamespaces) { + return new HelperContextImpl(extensibleNamespaces); + } + + public HelperContext createHelperContext(Map options) { + return new HelperContextImpl(false, options); + } + + public HelperContext createHelperContext(boolean extensibleNamespaces, Map options) { + return new HelperContextImpl(extensibleNamespaces, options); + } + + + public CopyHelper createCrossScopeCopyHelper(HelperContext hc) { + return new CrossScopeCopyHelperImpl(hc.getTypeHelper()); + } + + + public XMLStreamHelper createXMLStreamHelper(HelperContext hc) { + return ((HelperContextImpl)hc).getXMLStreamHelper(); + } + + + public List getTypes(HelperContext hc, String uri) { + + EPackage ePackage = ((HelperContextImpl)hc).getExtendedMetaData().getPackage(uri); + if (ePackage != null) { + return new ArrayList(ePackage.getEClassifiers()); + } + return null; + } + + public List getOpenContentProperties(DataObject dataObject) { + List result = new UniqueEList(); + ((ClassImpl)dataObject.getType()).addOpenProperties((EObject)dataObject, result); + return result; + } + + public boolean isDocumentRoot(Type type) { + return "".equals(SDOExtendedMetaData.INSTANCE.getName((EClassifier)type)); + } + + + public Type createType(HelperContext hc, String uri, String name, boolean isDataType) { + ExtendedMetaData extendedMetaData = ((HelperContextImpl)hc).getExtendedMetaData(); + if ("".equals(uri)) + uri = null; // FB + + EPackage ePackage = extendedMetaData.getPackage(uri); + if (ePackage == null) { + ePackage = EcoreFactory.eINSTANCE.createEPackage(); + ePackage.setEFactoryInstance(new DynamicDataObjectImpl.FactoryImpl()); + ePackage.setNsURI(uri); + String packagePrefix = uri != null ? URI.createURI(uri).trimFileExtension().lastSegment() : ""; // FB + ePackage.setName(packagePrefix); + ePackage.setNsPrefix(packagePrefix); + extendedMetaData.putPackage(uri, ePackage); + } + + EClassifier eClassifier = ePackage.getEClassifier(name); + if (eClassifier != null) // already defined? + { + // throw new IllegalArgumentException(); + return null; + } + + if (name != null) { + eClassifier = + isDataType ? (EClassifier)SDOFactory.eINSTANCE.createDataType() : (EClassifier)SDOFactory.eINSTANCE + .createClass(); + eClassifier.setName(name); + } else { + eClassifier = DataObjectUtil.createDocumentRoot(); + } + + ePackage.getEClassifiers().add(eClassifier); + + return (Type)eClassifier; + } + + public void addBaseType(Type type, Type baseType) { + ((EClass)type).getESuperTypes().add(baseType); + } + + public void addAliasName(Type type, String aliasName) { + throw new UnsupportedOperationException(); // TODO: implement this + // method properly + // type.getAliasNames().add(aliasName); + } + + public void setOpen(Type type, boolean isOpen) { + if (isOpen == type.isOpen()) + return; + + if (isOpen) { + EAttribute eAttribute = (EAttribute)SDOFactory.eINSTANCE.createAttribute(); + ((EClass)type).getEStructuralFeatures().add(eAttribute); + + eAttribute.setName("any"); + eAttribute.setUnique(false); + eAttribute.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY); + eAttribute.setEType(EcorePackage.eINSTANCE.getEFeatureMapEntry()); + ExtendedMetaData.INSTANCE.setFeatureKind(eAttribute, ExtendedMetaData.ELEMENT_WILDCARD_FEATURE); + ExtendedMetaData.INSTANCE.setProcessingKind(eAttribute, ExtendedMetaData.LAX_PROCESSING); + ExtendedMetaData.INSTANCE.setWildcards(eAttribute, Collections.singletonList("##any")); + + // FB TBD Add an "anyAttribute" EAttribute as well. + + if (ExtendedMetaData.INSTANCE.getMixedFeature((EClass)type) != null) { + eAttribute.setDerived(true); + eAttribute.setTransient(true); + eAttribute.setVolatile(true); + } + } else { + EClass eClass = (EClass)type; + EAttribute any = (EAttribute)eClass.getEStructuralFeature("any"); + eClass.getEStructuralFeatures().remove(any); + } + } + + public void setSequenced(Type type, boolean isSequenced) { + // currently, we require setSequenced to be called first, before + // anything else is added to the type. + if (type.isDataType() || !type.getProperties().isEmpty()) { + if (type.getName() != "DocumentRoot") // document root is a + // special case + throw new IllegalArgumentException(); + } + + if (isSequenced) { + EClass eClass = (EClass)type; + ExtendedMetaData.INSTANCE.setContentKind(eClass, ExtendedMetaData.MIXED_CONTENT); + EAttribute mixedFeature = (EAttribute)SDOFactory.eINSTANCE.createAttribute(); + mixedFeature.setName("mixed"); + mixedFeature.setUnique(false); + mixedFeature.setEType(EcorePackage.eINSTANCE.getEFeatureMapEntry()); + mixedFeature.setLowerBound(0); + mixedFeature.setUpperBound(-1); + // eClass.getEStructuralFeatures().add(mixedFeature); + ((ClassImpl)eClass).setSequenceFeature(mixedFeature); + ExtendedMetaData.INSTANCE.setFeatureKind(mixedFeature, ExtendedMetaData.ELEMENT_WILDCARD_FEATURE); + ExtendedMetaData.INSTANCE.setName(mixedFeature, ":mixed"); + } else { + // nothing to do, because of current restriction that setSequence + // must be called first. + } + } + + public void setAbstract(Type type, boolean isAbstract) { + ((EClass)type).setAbstract(isAbstract); + } + + public void setJavaClassName(Type type, String javaClassName) { + ((EClassifier)type).setInstanceClassName(javaClassName); + } + + public Property createProperty(Type containingType, String name, Type propertyType) { + EStructuralFeature eStructuralFeature = + propertyType.isDataType() ? (EStructuralFeature)SDOFactory.eINSTANCE.createAttribute() + : (EStructuralFeature)SDOFactory.eINSTANCE.createReference(); + + eStructuralFeature.setName(name); + eStructuralFeature.setEType((EClassifier)propertyType); + ((EClass)containingType).getEStructuralFeatures().add(eStructuralFeature); + + if ("".equals(ExtendedMetaData.INSTANCE.getName((EClass)containingType))) // DocumentRoot + // containingType? + { + ExtendedMetaData.INSTANCE.setNamespace(eStructuralFeature, containingType.getURI()); + //FB???eStructuralFeature.setUnique(false); + //FB???eStructuralFeature.setUpperBound(ETypedElement.UNSPECIFIED_MULTIPLICITY); + } + + if (ExtendedMetaData.INSTANCE.getMixedFeature((EClass)containingType) != null) { + eStructuralFeature.setDerived(true); + eStructuralFeature.setTransient(true); + eStructuralFeature.setVolatile(true); + ExtendedMetaData.INSTANCE.setFeatureKind(eStructuralFeature, ExtendedMetaData.ELEMENT_FEATURE); + } else { + // By default, a SDO property is an XSD element + ExtendedMetaData.INSTANCE.setFeatureKind(eStructuralFeature, ExtendedMetaData.ELEMENT_FEATURE); + } + + return (Property)eStructuralFeature; + } + + public void setPropertyXMLKind(Property property, boolean isXmlElement) { + if (isXmlElement) { + ExtendedMetaData.INSTANCE.setFeatureKind((EStructuralFeature)property, ExtendedMetaData.ELEMENT_FEATURE); + } + else { + ExtendedMetaData.INSTANCE.setFeatureKind((EStructuralFeature)property, ExtendedMetaData.ATTRIBUTE_FEATURE); + } + } + + + public Property createOpenContentProperty(HelperContext hc, String uri, String name, Type type) + { + ExtendedMetaData extendedMetaData = ((HelperContextImpl)hc).getExtendedMetaData(); + + // get/create document root + EPackage ePackage = extendedMetaData.getPackage(uri); + Type documentRoot = ePackage != null ? (Type)extendedMetaData.getType(ePackage, "") : null; + if (documentRoot == null) { + documentRoot = createType(hc, uri, null, false); + } + + // Determine if property already exists + Property newProperty = documentRoot.getProperty(name); + if (newProperty == null) { + // Create the new property 'under' the document root..... + newProperty = createProperty(documentRoot, name, type); + } else { + // if property already exists, validate the expected type + if (!newProperty.getType().equals(type)) + throw new IllegalArgumentException(); + } + return newProperty; + } + + + public void addAliasName(Property property, String aliasName) { + throw new UnsupportedOperationException(); // TODO: implement this + // method properly + // property.getAliasNames().add(aliasName); + } + + public void setMany(Property property, boolean isMany) { + ((EStructuralFeature)property).setUpperBound(isMany ? EStructuralFeature.UNBOUNDED_MULTIPLICITY : 1); + } + + public void setContainment(Property property, boolean isContainment) { + ((EReference)property).setContainment(isContainment); + } + + public void setDefault(Property property, String defaultValue) { + ((EStructuralFeature)property).setDefaultValueLiteral(defaultValue); + } + + public void setReadOnly(Property property, boolean isReadOnly) { + ((EStructuralFeature)property).setChangeable(!isReadOnly); + } + + public void setOpposite(Property property, Property opposite) { + ((EReference)property).setEOpposite((EReference)opposite); + } + + public void addTypeInstanceProperty(Type definedType, Property instanceProperty, Object value) { + addInstanceProperty((EModelElement)definedType, instanceProperty, value); + } + + public void addPropertyInstanceProperty(Property definedProperty, Property instanceProperty, Object value) { + addInstanceProperty((EModelElement)definedProperty, instanceProperty, value); + } + + protected void addInstanceProperty(EModelElement metaObject, Property property, Object value) { + String uri = property.getContainingType().getURI(); + EAnnotation eAnnotation = metaObject.getEAnnotation(uri); + if (eAnnotation == null) { + eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation(); + eAnnotation.setSource(uri); + metaObject.getEAnnotations().add(eAnnotation); + } + // TODO if (property.isMany()) ... // convert list of values + String stringValue = convertToString(property.getType(), value); + eAnnotation.getDetails().put(property.getName(), stringValue); + } + + + public void addChangeListener(DataObject dob, EventListener listener) { + // Adapter l = (Adapter)listener; + ((Notifier)dob).eAdapters().add(listener); + } + + public void removeChangeListener(DataObject dob, EventListener listener) { + ((Notifier)dob).eAdapters().remove(listener); + } + + +} diff --git a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/EventImpl.java b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/EventImpl.java index a99ccb6ebe..206a3c1fbf 100644 --- a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/EventImpl.java +++ b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/EventImpl.java @@ -1,78 +1,78 @@ -/** - * - * 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.impl; - -import org.apache.tuscany.sdo.api.Event; -import org.eclipse.emf.common.notify.Notification; - -import commonj.sdo.Property; - - -public class EventImpl implements Event { - - protected Notification emfEvent; - protected Object notifier; - - public EventImpl(Notification notification) - { - this.emfEvent = notification; - } - - public Object getNotifier() - { - return notifier == null ? emfEvent.getNotifier() : notifier; - } - - public int getEventType() - { - return emfEvent.getEventType(); - } - - - public Property getProperty() - { - return (Property)emfEvent.getFeature(); - } - - public Object getOldValue() - { - return emfEvent.getOldValue(); - } - - public Object getNewValue() - { - return emfEvent.getNewValue(); - } - - public boolean wasSet() - { - return emfEvent.wasSet(); - } - - public boolean isTouch() - { - return emfEvent.isTouch(); - } - - public int getPosition() - { - return emfEvent.getPosition(); - } -} +/** + * + * 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.impl; + +import org.apache.tuscany.sdo.api.Event; +import org.eclipse.emf.common.notify.Notification; + +import commonj.sdo.Property; + + +public class EventImpl implements Event { + + protected Notification emfEvent; + protected Object notifier; + + public EventImpl(Notification notification) + { + this.emfEvent = notification; + } + + public Object getNotifier() + { + return notifier == null ? emfEvent.getNotifier() : notifier; + } + + public int getEventType() + { + return emfEvent.getEventType(); + } + + + public Property getProperty() + { + return (Property)emfEvent.getFeature(); + } + + public Object getOldValue() + { + return emfEvent.getOldValue(); + } + + public Object getNewValue() + { + return emfEvent.getNewValue(); + } + + public boolean wasSet() + { + return emfEvent.wasSet(); + } + + public boolean isTouch() + { + return emfEvent.isTouch(); + } + + public int getPosition() + { + return emfEvent.getPosition(); + } +} diff --git a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/ListenerBase.java b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/ListenerBase.java index db840b11ff..986628bbc9 100644 --- a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/ListenerBase.java +++ b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/ListenerBase.java @@ -1,33 +1,33 @@ -/** - * - * 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.impl; - -import org.apache.tuscany.sdo.api.Event; -import org.apache.tuscany.sdo.api.EventListener; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; - -public abstract class ListenerBase extends AdapterImpl implements EventListener { - - public void notifyChanged(Notification msg) { - Event e = new EventImpl(msg); - eventNotification(e); - } -} +/** + * + * 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.impl; + +import org.apache.tuscany.sdo.api.Event; +import org.apache.tuscany.sdo.api.EventListener; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.impl.AdapterImpl; + +public abstract class ListenerBase extends AdapterImpl implements EventListener { + + public void notifyChanged(Notification msg) { + Event e = new EventImpl(msg); + eventNotification(e); + } +} diff --git a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/internal/InternalFactory.java b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/internal/InternalFactory.java index 4776cb958f..061d082b1d 100644 --- a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/internal/InternalFactory.java +++ b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/internal/InternalFactory.java @@ -1,52 +1,52 @@ -/** - * - * 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.model.internal; - -import commonj.sdo.helper.HelperContext; - - -/** - * - * The Factory for the model. - * It provides a create method for each non-abstract class of the model. - * - * @generated - */ -public interface InternalFactory -{ - - /** - * The singleton instance of the factory. - * - * - * @generated - */ - InternalFactory INSTANCE = org.apache.tuscany.sdo.model.internal.impl.InternalFactoryImpl.init(); - - /** - * Registers the types supported by this Factory within the supplied scope.argument - * - * - * @param scope an instance of HelperContext used to manage the scoping of types. - * @generated - */ - public void register(HelperContext scope); - -} //InternalFactory +/** + * + * 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.model.internal; + +import commonj.sdo.helper.HelperContext; + + +/** + * + * The Factory for the model. + * It provides a create method for each non-abstract class of the model. + * + * @generated + */ +public interface InternalFactory +{ + + /** + * The singleton instance of the factory. + * + * + * @generated + */ + InternalFactory INSTANCE = org.apache.tuscany.sdo.model.internal.impl.InternalFactoryImpl.init(); + + /** + * Registers the types supported by this Factory within the supplied scope.argument + * + * + * @param scope an instance of HelperContext used to manage the scoping of types. + * @generated + */ + public void register(HelperContext scope); + +} //InternalFactory diff --git a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/internal/impl/InternalFactoryImpl.java b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/internal/impl/InternalFactoryImpl.java index 4517f4a2a9..06d002ea74 100644 --- a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/internal/impl/InternalFactoryImpl.java +++ b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/internal/impl/InternalFactoryImpl.java @@ -1,296 +1,296 @@ -/** - * - * 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.model.internal.impl; - -import commonj.sdo.helper.HelperContext; -import org.apache.tuscany.sdo.helper.TypeHelperImpl; - -import commonj.sdo.DataObject; -import commonj.sdo.Property; -import commonj.sdo.Type; - -import org.apache.tuscany.sdo.impl.FactoryBase; - -import org.apache.tuscany.sdo.model.internal.*; -import org.eclipse.emf.ecore.xml.type.XMLTypeFactory; - -/** - * - * An implementation of the commonj.sdo.internal model factory. - * This model is generated from sdoInternal.xsd, in the tuscany-sdo-impl project. - * Until the SDO code generator supports regen/merge, follow the following steps to regenerate this model: - * 1. Regenerate the model into a temporary directory: - * XSD2JavaGenerator -generateBuiltIn http://www.apache.org/tuscany/commonj.sdo.internal -targetDirectory -javaPackage org.apache.tuscany.sdo.model.internal /src/main/resources/xml/sdoInternal.xsd - * 2. Delete all the createXXXFromString() and convertXXXToString() methods in the newly generated InternalFactoryImpl and - * replace them with the ones from this file (resolve any missing imports). - * 3. Comment out all simple depedencies (SDOUtil.registerStaticTypes calls) in the init() method. - * 4. Make sure the top of each generated file contains the ASF License. - * 5. Move this JavaDoc comment into the newly generated ModelFactoryImpl class. - * - * @generated - */ -public class InternalFactoryImpl extends FactoryBase implements InternalFactory -{ - - /** - * The package namespace URI. - * - * - * @generated - */ - public static final String NAMESPACE_URI = "http://www.apache.org/tuscany/commonj.sdo.internal"; - - /** - * The package namespace name. - * - * - * @generated - */ - public static final String NAMESPACE_PREFIX = "internal"; - - /** - * The version of the generator pattern used to generate this class. - * - * - * @generated - */ - public static final String PATTERN_VERSION = "1.2"; - - public static final int BASE64_BYTES = 1; - public static final int QNAME = 2; - - /** - * Creates an instance of the factory. - * - * - * @generated - */ - public InternalFactoryImpl() - { - super(NAMESPACE_URI, NAMESPACE_PREFIX, "org.apache.tuscany.sdo.model.internal"); - } - - /** - * Registers the Factory instance so that it is available within the supplied scope. - * @argument scope a HelperContext instance that will make the types supported by this Factory available. - * - * - * @generated - */ - public void register(HelperContext scope) - { - if(scope == null) { - throw new IllegalArgumentException("Scope can not be null"); - } - - //Register dependent packages with provided scope - - // Initialize this package - TypeHelperImpl th = (TypeHelperImpl)scope.getTypeHelper(); - th.getExtendedMetaData().putPackage(NAMESPACE_URI, this); - } - - /** - * - * - * @generated - */ - public DataObject create(int typeNumber) - { - switch (typeNumber) - { - default: - return super.create(typeNumber); - } - } - - /** - * - * - * @generated - */ - public Object createFromString(int typeNumber, String initialValue) - { - switch (typeNumber) - { - case BASE64_BYTES: - return createBase64BytesFromString(initialValue); - case QNAME: - return createQNameFromString(initialValue); - default: - throw new IllegalArgumentException("The type number '" + typeNumber + "' is not a valid datatype"); - } - } - - /** - * - * - * @generated - */ - public String convertToString(int typeNumber, Object instanceValue) - { - switch (typeNumber) - { - case BASE64_BYTES: - return convertBase64BytesToString(instanceValue); - case QNAME: - return convertQNameToString(instanceValue); - default: - throw new IllegalArgumentException("The type number '" + typeNumber + "' is not a valid datatype"); - } - } - - // Following creates and initializes SDO metadata for the supported types. - protected Type base64BytesType = null; - - public Type getBase64Bytes() - { - return base64BytesType; - } - - protected Type qNameType = null; - - public Type getQName() - { - return qNameType; - } - - - private static InternalFactoryImpl instance = null; - public static InternalFactoryImpl init() - { - if (instance != null ) return instance; - instance = new InternalFactoryImpl(); - - // Initialize dependent packages - - // Create package meta-data objects - instance.createMetaData(); - - // Initialize created meta-data - instance.initializeMetaData(); - - // Mark meta-data to indicate it can't be changed - //theInternalFactoryImpl.freeze(); //FB do we need to freeze / should we freeze ???? - - return instance; - } - - private boolean isCreated = false; - - public void createMetaData() - { - if (isCreated) return; - isCreated = true; - - // Create data types - base64BytesType = createType(true, BASE64_BYTES ); - qNameType = createType(true, QNAME ); - } - - private boolean isInitialized = false; - - public void initializeMetaData() - { - if (isInitialized) return; - isInitialized = true; - Property property = null; - - // Add supertypes to types - - // Initialize types and properties - // Initialize data types - initializeType(base64BytesType, byte[].class, "Base64Bytes", true, false); - setInstanceProperty (base64BytesType, "commonj.sdo/java", "instanceClass", "byte[]"); - - initializeType(qNameType, String.class, "QName", true, false); - setInstanceProperty (qNameType, "commonj.sdo/java", "instanceClass", "java.lang.String"); - - createXSDMetaData(); - } - - protected void createXSDMetaData() - { - super.initXSD(); - - Property property = null; - - - addXSDMapping - (base64BytesType, - new String[] - { - "name", "Base64Bytes" - }); - - addXSDMapping - (qNameType, - new String[] - { - "name", "QName" - }); - - } - - /** - * - * - * @generated NOT - */ - public byte[] createBase64BytesFromString(String initialValue) - { - return XMLTypeFactory.eINSTANCE.createBase64Binary(initialValue); - } - - /** - * - * - * @generated NOT - */ - public String convertBase64BytesToString(Object instanceValue) - { - if (instanceValue instanceof byte[]) { - return XMLTypeFactory.eINSTANCE.convertBase64Binary((byte[])instanceValue); - } else { - return XMLTypeFactory.eINSTANCE.convertBase64Binary(instanceValue.toString().getBytes()); - } - } - - /** - * - * - * @generated - */ - public String createQNameFromString(String initialValue) - { - return (String)super.createFromString(QNAME, initialValue); - } - - /** - * - * - * @generated - */ - public String convertQNameToString(Object instanceValue) - { - return super.convertToString(QNAME, instanceValue); - } - -} //InternalFactoryImpl +/** + * + * 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.model.internal.impl; + +import commonj.sdo.helper.HelperContext; +import org.apache.tuscany.sdo.helper.TypeHelperImpl; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Type; + +import org.apache.tuscany.sdo.impl.FactoryBase; + +import org.apache.tuscany.sdo.model.internal.*; +import org.eclipse.emf.ecore.xml.type.XMLTypeFactory; + +/** + * + * An implementation of the commonj.sdo.internal model factory. + * This model is generated from sdoInternal.xsd, in the tuscany-sdo-impl project. + * Until the SDO code generator supports regen/merge, follow the following steps to regenerate this model: + * 1. Regenerate the model into a temporary directory: + * XSD2JavaGenerator -generateBuiltIn http://www.apache.org/tuscany/commonj.sdo.internal -targetDirectory -javaPackage org.apache.tuscany.sdo.model.internal /src/main/resources/xml/sdoInternal.xsd + * 2. Delete all the createXXXFromString() and convertXXXToString() methods in the newly generated InternalFactoryImpl and + * replace them with the ones from this file (resolve any missing imports). + * 3. Comment out all simple depedencies (SDOUtil.registerStaticTypes calls) in the init() method. + * 4. Make sure the top of each generated file contains the ASF License. + * 5. Move this JavaDoc comment into the newly generated ModelFactoryImpl class. + * + * @generated + */ +public class InternalFactoryImpl extends FactoryBase implements InternalFactory +{ + + /** + * The package namespace URI. + * + * + * @generated + */ + public static final String NAMESPACE_URI = "http://www.apache.org/tuscany/commonj.sdo.internal"; + + /** + * The package namespace name. + * + * + * @generated + */ + public static final String NAMESPACE_PREFIX = "internal"; + + /** + * The version of the generator pattern used to generate this class. + * + * + * @generated + */ + public static final String PATTERN_VERSION = "1.2"; + + public static final int BASE64_BYTES = 1; + public static final int QNAME = 2; + + /** + * Creates an instance of the factory. + * + * + * @generated + */ + public InternalFactoryImpl() + { + super(NAMESPACE_URI, NAMESPACE_PREFIX, "org.apache.tuscany.sdo.model.internal"); + } + + /** + * Registers the Factory instance so that it is available within the supplied scope. + * @argument scope a HelperContext instance that will make the types supported by this Factory available. + * + * + * @generated + */ + public void register(HelperContext scope) + { + if(scope == null) { + throw new IllegalArgumentException("Scope can not be null"); + } + + //Register dependent packages with provided scope + + // Initialize this package + TypeHelperImpl th = (TypeHelperImpl)scope.getTypeHelper(); + th.getExtendedMetaData().putPackage(NAMESPACE_URI, this); + } + + /** + * + * + * @generated + */ + public DataObject create(int typeNumber) + { + switch (typeNumber) + { + default: + return super.create(typeNumber); + } + } + + /** + * + * + * @generated + */ + public Object createFromString(int typeNumber, String initialValue) + { + switch (typeNumber) + { + case BASE64_BYTES: + return createBase64BytesFromString(initialValue); + case QNAME: + return createQNameFromString(initialValue); + default: + throw new IllegalArgumentException("The type number '" + typeNumber + "' is not a valid datatype"); + } + } + + /** + * + * + * @generated + */ + public String convertToString(int typeNumber, Object instanceValue) + { + switch (typeNumber) + { + case BASE64_BYTES: + return convertBase64BytesToString(instanceValue); + case QNAME: + return convertQNameToString(instanceValue); + default: + throw new IllegalArgumentException("The type number '" + typeNumber + "' is not a valid datatype"); + } + } + + // Following creates and initializes SDO metadata for the supported types. + protected Type base64BytesType = null; + + public Type getBase64Bytes() + { + return base64BytesType; + } + + protected Type qNameType = null; + + public Type getQName() + { + return qNameType; + } + + + private static InternalFactoryImpl instance = null; + public static InternalFactoryImpl init() + { + if (instance != null ) return instance; + instance = new InternalFactoryImpl(); + + // Initialize dependent packages + + // Create package meta-data objects + instance.createMetaData(); + + // Initialize created meta-data + instance.initializeMetaData(); + + // Mark meta-data to indicate it can't be changed + //theInternalFactoryImpl.freeze(); //FB do we need to freeze / should we freeze ???? + + return instance; + } + + private boolean isCreated = false; + + public void createMetaData() + { + if (isCreated) return; + isCreated = true; + + // Create data types + base64BytesType = createType(true, BASE64_BYTES ); + qNameType = createType(true, QNAME ); + } + + private boolean isInitialized = false; + + public void initializeMetaData() + { + if (isInitialized) return; + isInitialized = true; + Property property = null; + + // Add supertypes to types + + // Initialize types and properties + // Initialize data types + initializeType(base64BytesType, byte[].class, "Base64Bytes", true, false); + setInstanceProperty (base64BytesType, "commonj.sdo/java", "instanceClass", "byte[]"); + + initializeType(qNameType, String.class, "QName", true, false); + setInstanceProperty (qNameType, "commonj.sdo/java", "instanceClass", "java.lang.String"); + + createXSDMetaData(); + } + + protected void createXSDMetaData() + { + super.initXSD(); + + Property property = null; + + + addXSDMapping + (base64BytesType, + new String[] + { + "name", "Base64Bytes" + }); + + addXSDMapping + (qNameType, + new String[] + { + "name", "QName" + }); + + } + + /** + * + * + * @generated NOT + */ + public byte[] createBase64BytesFromString(String initialValue) + { + return XMLTypeFactory.eINSTANCE.createBase64Binary(initialValue); + } + + /** + * + * + * @generated NOT + */ + public String convertBase64BytesToString(Object instanceValue) + { + if (instanceValue instanceof byte[]) { + return XMLTypeFactory.eINSTANCE.convertBase64Binary((byte[])instanceValue); + } else { + return XMLTypeFactory.eINSTANCE.convertBase64Binary(instanceValue.toString().getBytes()); + } + } + + /** + * + * + * @generated + */ + public String createQNameFromString(String initialValue) + { + return (String)super.createFromString(QNAME, initialValue); + } + + /** + * + * + * @generated + */ + public String convertQNameToString(Object instanceValue) + { + return super.convertToString(QNAME, instanceValue); + } + +} //InternalFactoryImpl diff --git a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/xml/XMLFactory.java b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/xml/XMLFactory.java index 84a60cf849..39119a1c77 100644 --- a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/xml/XMLFactory.java +++ b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/xml/XMLFactory.java @@ -1,61 +1,61 @@ -/** - * - * 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.model.xml; - -import commonj.sdo.helper.HelperContext; - - -/** - * - * The Factory for the model. - * It provides a create method for each non-abstract class of the model. - * - * @generated - */ -public interface XMLFactory -{ - - /** - * The singleton instance of the factory. - * - * - * @generated - */ - XMLFactory INSTANCE = org.apache.tuscany.sdo.model.xml.impl.XMLFactoryImpl.init(); - - /** - * Returns a new object of class 'Info'. - * - * - * @return a new object of class 'Info'. - * @generated - */ - XMLInfo createXMLInfo(); - - /** - * Registers the types supported by this Factory within the supplied scope.argument - * - * - * @param scope an instance of HelperContext used to manage the scoping of types. - * @generated - */ - public void register(HelperContext scope); - -} //XMLFactory +/** + * + * 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.model.xml; + +import commonj.sdo.helper.HelperContext; + + +/** + * + * The Factory for the model. + * It provides a create method for each non-abstract class of the model. + * + * @generated + */ +public interface XMLFactory +{ + + /** + * The singleton instance of the factory. + * + * + * @generated + */ + XMLFactory INSTANCE = org.apache.tuscany.sdo.model.xml.impl.XMLFactoryImpl.init(); + + /** + * Returns a new object of class 'Info'. + * + * + * @return a new object of class 'Info'. + * @generated + */ + XMLInfo createXMLInfo(); + + /** + * Registers the types supported by this Factory within the supplied scope.argument + * + * + * @param scope an instance of HelperContext used to manage the scoping of types. + * @generated + */ + public void register(HelperContext scope); + +} //XMLFactory diff --git a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/xml/XMLInfo.java b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/xml/XMLInfo.java index 85cad641c9..6f438bc3e2 100644 --- a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/xml/XMLInfo.java +++ b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/xml/XMLInfo.java @@ -1,92 +1,92 @@ -/** - * - * 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.model.xml; - -import java.io.Serializable; - -/** - * - * A representation of the model object 'Info'. - * - * - *

- * The following features are supported: - *

    - *
  • {@link org.apache.tuscany.sdo.model.xml.XMLInfo#isXmlElement Xml Element}
  • - *
- *

- * - * @extends Serializable - * @generated - */ -public interface XMLInfo extends Serializable -{ - /** - * Returns the value of the 'Xml Element' attribute. - * - *

- * If the meaning of the 'Xml Element' attribute isn't clear, - * there really should be more of a description here... - *

- * - * @return the value of the 'Xml Element' attribute. - * @see #isSetXmlElement() - * @see #unsetXmlElement() - * @see #setXmlElement(boolean) - * @generated - */ - boolean isXmlElement(); - - /** - * Sets the value of the '{@link org.apache.tuscany.sdo.model.xml.XMLInfo#isXmlElement Xml Element}' attribute. - * - * - * @param value the new value of the 'Xml Element' attribute. - * @see #isSetXmlElement() - * @see #unsetXmlElement() - * @see #isXmlElement() - * @generated - */ - void setXmlElement(boolean value); - - /** - * Unsets the value of the '{@link org.apache.tuscany.sdo.model.xml.XMLInfo#isXmlElement Xml Element}' attribute. - * - * - * @see #isSetXmlElement() - * @see #isXmlElement() - * @see #setXmlElement(boolean) - * @generated - */ - void unsetXmlElement(); - - /** - * Returns whether the value of the '{@link org.apache.tuscany.sdo.model.xml.XMLInfo#isXmlElement Xml Element}' attribute is set. - * - * - * @return whether the value of the 'Xml Element' attribute is set. - * @see #unsetXmlElement() - * @see #isXmlElement() - * @see #setXmlElement(boolean) - * @generated - */ - boolean isSetXmlElement(); - -} // XMLInfo +/** + * + * 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.model.xml; + +import java.io.Serializable; + +/** + * + * A representation of the model object 'Info'. + * + * + *

+ * The following features are supported: + *

    + *
  • {@link org.apache.tuscany.sdo.model.xml.XMLInfo#isXmlElement Xml Element}
  • + *
+ *

+ * + * @extends Serializable + * @generated + */ +public interface XMLInfo extends Serializable +{ + /** + * Returns the value of the 'Xml Element' attribute. + * + *

+ * If the meaning of the 'Xml Element' attribute isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Xml Element' attribute. + * @see #isSetXmlElement() + * @see #unsetXmlElement() + * @see #setXmlElement(boolean) + * @generated + */ + boolean isXmlElement(); + + /** + * Sets the value of the '{@link org.apache.tuscany.sdo.model.xml.XMLInfo#isXmlElement Xml Element}' attribute. + * + * + * @param value the new value of the 'Xml Element' attribute. + * @see #isSetXmlElement() + * @see #unsetXmlElement() + * @see #isXmlElement() + * @generated + */ + void setXmlElement(boolean value); + + /** + * Unsets the value of the '{@link org.apache.tuscany.sdo.model.xml.XMLInfo#isXmlElement Xml Element}' attribute. + * + * + * @see #isSetXmlElement() + * @see #isXmlElement() + * @see #setXmlElement(boolean) + * @generated + */ + void unsetXmlElement(); + + /** + * Returns whether the value of the '{@link org.apache.tuscany.sdo.model.xml.XMLInfo#isXmlElement Xml Element}' attribute is set. + * + * + * @return whether the value of the 'Xml Element' attribute is set. + * @see #unsetXmlElement() + * @see #isXmlElement() + * @see #setXmlElement(boolean) + * @generated + */ + boolean isSetXmlElement(); + +} // XMLInfo diff --git a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/xml/impl/XMLFactoryImpl.java b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/xml/impl/XMLFactoryImpl.java index 293a7b0398..f07d8b7f3c 100644 --- a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/xml/impl/XMLFactoryImpl.java +++ b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/xml/impl/XMLFactoryImpl.java @@ -1,341 +1,341 @@ -/** - * - * 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.model.xml.impl; - -import commonj.sdo.helper.HelperContext; -import org.apache.tuscany.sdo.helper.TypeHelperImpl; - -import commonj.sdo.DataObject; -import commonj.sdo.Property; -import commonj.sdo.Type; - -import org.apache.tuscany.sdo.impl.FactoryBase; - -import org.apache.tuscany.sdo.model.ModelFactory; - -import org.apache.tuscany.sdo.model.impl.ModelFactoryImpl; - -import org.apache.tuscany.sdo.model.internal.InternalFactory; - -import org.apache.tuscany.sdo.model.internal.impl.InternalFactoryImpl; - -import org.apache.tuscany.sdo.model.xml.*; - -/** - * - * An implementation of the commonj.sdo/xml model factory. - * This model is generated from sdoXML.xsd, in the sdo-api project. - * Until the SDO code generator supports name conflicts and regen/merge, follow the following steps to regenerate this model: - * 1. Regenerate the model into a temporary directory: - * XSD2JavaGenerator -generateBuiltIn commonj.sdo/xml -prefix XML -targetDirectory -javaPackage org.apache.tuscany.sdo.model.xml /src/main/resources/xml/sdoXML.xsd - * 2. Make sure the top of each generated file contains the ASF License. - * 3. Move this JavaDoc comment into the newly generated XMLFactoryImpl class. - * - * @generated - */ -public class XMLFactoryImpl extends FactoryBase implements XMLFactory -{ - - /** - * The package namespace URI. - * - * - * @generated - */ - public static final String NAMESPACE_URI = "commonj.sdo/xml"; - - /** - * The package namespace name. - * - * - * @generated - */ - public static final String NAMESPACE_PREFIX = "sdoXML"; - - /** - * The version of the generator pattern used to generate this class. - * - * - * @generated - */ - public static final String PATTERN_VERSION = "1.2"; - - public static final int XML_INFO = 1; - - /** - * Creates an instance of the factory. - * - * - * @generated - */ - public XMLFactoryImpl() - { - super(NAMESPACE_URI, NAMESPACE_PREFIX, "org.apache.tuscany.sdo.model.xml"); - } - - /** - * Registers the Factory instance so that it is available within the supplied scope. - * @argument scope a HelperContext instance that will make the types supported by this Factory available. - * - * - * @generated - */ - public void register(HelperContext scope) - { - if(scope == null) { - throw new IllegalArgumentException("Scope can not be null"); - } - - //Register dependent packages with provided scope - ModelFactory.INSTANCE.register(scope); - InternalFactory.INSTANCE.register(scope); - - // Initialize this package - TypeHelperImpl th = (TypeHelperImpl)scope.getTypeHelper(); - th.getExtendedMetaData().putPackage(NAMESPACE_URI, this); - } - - /** - * - * - * @generated - */ - public DataObject create(int typeNumber) - { - switch (typeNumber) - { - case XML_INFO: return (DataObject)createXMLInfo(); - default: - return super.create(typeNumber); - } - } - - /** - * - * - * @generated - */ - public XMLInfo createXMLInfo() - { - XMLInfoImpl xmlInfo = new XMLInfoImpl(); - return xmlInfo; - } - - // Following creates and initializes SDO metadata for the supported types. - protected Type xmlInfoType = null; - - public Type getXMLInfo() - { - return xmlInfoType; - } - - - private static XMLFactoryImpl instance = null; - public static XMLFactoryImpl init() - { - if (instance != null ) return instance; - instance = new XMLFactoryImpl(); - - // Initialize dependent packages - ModelFactory ModelFactoryInstance = ModelFactory.INSTANCE; - InternalFactory InternalFactoryInstance = InternalFactory.INSTANCE; - - // Create package meta-data objects - instance.createMetaData(); - - // Initialize created meta-data - instance.initializeMetaData(); - - // Mark meta-data to indicate it can't be changed - //theXMLFactoryImpl.freeze(); //FB do we need to freeze / should we freeze ???? - - return instance; - } - - private boolean isCreated = false; - - public void createMetaData() - { - if (isCreated) return; - isCreated = true; - - // Create types and their properties - xmlInfoType = createType(false, XML_INFO); - createProperty(true, xmlInfoType,XMLInfoImpl.INTERNAL_XML_ELEMENT); - } - - private boolean isInitialized = false; - - public void initializeMetaData() - { - if (isInitialized) return; - isInitialized = true; - - // Obtain other dependent packages - ModelFactoryImpl theModelPackageImpl = (ModelFactoryImpl)ModelFactory.INSTANCE; - InternalFactoryImpl theInternalPackageImpl = (InternalFactoryImpl)InternalFactory.INSTANCE; - Property property = null; - - // Add supertypes to types - - // Initialize types and properties - initializeType(xmlInfoType, XMLInfo.class, "XMLInfo", false); - property = getLocalProperty(xmlInfoType, 0); - initializeProperty(property, theModelPackageImpl.getBoolean(), "xmlElement", null, 0, 1, XMLInfo.class, false, true, false); - - createXSDMetaData(theModelPackageImpl, theInternalPackageImpl); - } - - protected void createXSDMetaData(ModelFactoryImpl theModelPackageImpl, InternalFactoryImpl theInternalPackageImpl) - { - super.initXSD(); - - Property property = null; - - - property = createGlobalProperty - ("aliasName", - theModelPackageImpl.getString(), - new String[] - { - "kind", "attribute", - "name", "aliasName", - "namespace", "##targetNamespace" - }, - IS_ATTRIBUTE); - - property = createGlobalProperty - ("dataType", - theInternalPackageImpl.getQName(), - new String[] - { - "kind", "attribute", - "name", "dataType", - "namespace", "##targetNamespace" - }, - IS_ATTRIBUTE); - - property = createGlobalProperty - ("many", - theModelPackageImpl.getBoolean(), - new String[] - { - "kind", "attribute", - "name", "many", - "namespace", "##targetNamespace" - }, - IS_ATTRIBUTE); - - property = createGlobalProperty - ("name", - theModelPackageImpl.getString(), - new String[] - { - "kind", "attribute", - "name", "name", - "namespace", "##targetNamespace" - }, - IS_ATTRIBUTE); - - property = createGlobalProperty - ("oppositeProperty", - theModelPackageImpl.getString(), - new String[] - { - "kind", "attribute", - "name", "oppositeProperty", - "namespace", "##targetNamespace" - }, - IS_ATTRIBUTE); - - property = createGlobalProperty - ("propertyType", - theInternalPackageImpl.getQName(), - new String[] - { - "kind", "attribute", - "name", "propertyType", - "namespace", "##targetNamespace" - }, - IS_ATTRIBUTE); - - property = createGlobalProperty - ("readOnly", - theModelPackageImpl.getBoolean(), - new String[] - { - "kind", "attribute", - "name", "readOnly", - "namespace", "##targetNamespace" - }, - IS_ATTRIBUTE); - - property = createGlobalProperty - ("sequence", - theModelPackageImpl.getBoolean(), - new String[] - { - "kind", "attribute", - "name", "sequence", - "namespace", "##targetNamespace" - }, - IS_ATTRIBUTE); - - property = createGlobalProperty - ("string", - theModelPackageImpl.getBoolean(), - new String[] - { - "kind", "attribute", - "name", "string", - "namespace", "##targetNamespace" - }, - IS_ATTRIBUTE); - - property = createGlobalProperty - ("xmlElement", - theModelPackageImpl.getBoolean(), - new String[] - { - "kind", "attribute", - "name", "xmlElement", - "namespace", "##targetNamespace" - }, - IS_ATTRIBUTE); - - addXSDMapping - (xmlInfoType, - new String[] - { - "name", "XMLInfo", - "kind", "empty" - }); - - addXSDMapping - (getProperty(xmlInfoType, XMLInfoImpl.INTERNAL_XML_ELEMENT), - new String[] - { - "kind", "attribute", - "name", "xmlElement" - }); - - } - -} //XMLFactoryImpl +/** + * + * 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.model.xml.impl; + +import commonj.sdo.helper.HelperContext; +import org.apache.tuscany.sdo.helper.TypeHelperImpl; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Type; + +import org.apache.tuscany.sdo.impl.FactoryBase; + +import org.apache.tuscany.sdo.model.ModelFactory; + +import org.apache.tuscany.sdo.model.impl.ModelFactoryImpl; + +import org.apache.tuscany.sdo.model.internal.InternalFactory; + +import org.apache.tuscany.sdo.model.internal.impl.InternalFactoryImpl; + +import org.apache.tuscany.sdo.model.xml.*; + +/** + * + * An implementation of the commonj.sdo/xml model factory. + * This model is generated from sdoXML.xsd, in the sdo-api project. + * Until the SDO code generator supports name conflicts and regen/merge, follow the following steps to regenerate this model: + * 1. Regenerate the model into a temporary directory: + * XSD2JavaGenerator -generateBuiltIn commonj.sdo/xml -prefix XML -targetDirectory -javaPackage org.apache.tuscany.sdo.model.xml /src/main/resources/xml/sdoXML.xsd + * 2. Make sure the top of each generated file contains the ASF License. + * 3. Move this JavaDoc comment into the newly generated XMLFactoryImpl class. + * + * @generated + */ +public class XMLFactoryImpl extends FactoryBase implements XMLFactory +{ + + /** + * The package namespace URI. + * + * + * @generated + */ + public static final String NAMESPACE_URI = "commonj.sdo/xml"; + + /** + * The package namespace name. + * + * + * @generated + */ + public static final String NAMESPACE_PREFIX = "sdoXML"; + + /** + * The version of the generator pattern used to generate this class. + * + * + * @generated + */ + public static final String PATTERN_VERSION = "1.2"; + + public static final int XML_INFO = 1; + + /** + * Creates an instance of the factory. + * + * + * @generated + */ + public XMLFactoryImpl() + { + super(NAMESPACE_URI, NAMESPACE_PREFIX, "org.apache.tuscany.sdo.model.xml"); + } + + /** + * Registers the Factory instance so that it is available within the supplied scope. + * @argument scope a HelperContext instance that will make the types supported by this Factory available. + * + * + * @generated + */ + public void register(HelperContext scope) + { + if(scope == null) { + throw new IllegalArgumentException("Scope can not be null"); + } + + //Register dependent packages with provided scope + ModelFactory.INSTANCE.register(scope); + InternalFactory.INSTANCE.register(scope); + + // Initialize this package + TypeHelperImpl th = (TypeHelperImpl)scope.getTypeHelper(); + th.getExtendedMetaData().putPackage(NAMESPACE_URI, this); + } + + /** + * + * + * @generated + */ + public DataObject create(int typeNumber) + { + switch (typeNumber) + { + case XML_INFO: return (DataObject)createXMLInfo(); + default: + return super.create(typeNumber); + } + } + + /** + * + * + * @generated + */ + public XMLInfo createXMLInfo() + { + XMLInfoImpl xmlInfo = new XMLInfoImpl(); + return xmlInfo; + } + + // Following creates and initializes SDO metadata for the supported types. + protected Type xmlInfoType = null; + + public Type getXMLInfo() + { + return xmlInfoType; + } + + + private static XMLFactoryImpl instance = null; + public static XMLFactoryImpl init() + { + if (instance != null ) return instance; + instance = new XMLFactoryImpl(); + + // Initialize dependent packages + ModelFactory ModelFactoryInstance = ModelFactory.INSTANCE; + InternalFactory InternalFactoryInstance = InternalFactory.INSTANCE; + + // Create package meta-data objects + instance.createMetaData(); + + // Initialize created meta-data + instance.initializeMetaData(); + + // Mark meta-data to indicate it can't be changed + //theXMLFactoryImpl.freeze(); //FB do we need to freeze / should we freeze ???? + + return instance; + } + + private boolean isCreated = false; + + public void createMetaData() + { + if (isCreated) return; + isCreated = true; + + // Create types and their properties + xmlInfoType = createType(false, XML_INFO); + createProperty(true, xmlInfoType,XMLInfoImpl.INTERNAL_XML_ELEMENT); + } + + private boolean isInitialized = false; + + public void initializeMetaData() + { + if (isInitialized) return; + isInitialized = true; + + // Obtain other dependent packages + ModelFactoryImpl theModelPackageImpl = (ModelFactoryImpl)ModelFactory.INSTANCE; + InternalFactoryImpl theInternalPackageImpl = (InternalFactoryImpl)InternalFactory.INSTANCE; + Property property = null; + + // Add supertypes to types + + // Initialize types and properties + initializeType(xmlInfoType, XMLInfo.class, "XMLInfo", false); + property = getLocalProperty(xmlInfoType, 0); + initializeProperty(property, theModelPackageImpl.getBoolean(), "xmlElement", null, 0, 1, XMLInfo.class, false, true, false); + + createXSDMetaData(theModelPackageImpl, theInternalPackageImpl); + } + + protected void createXSDMetaData(ModelFactoryImpl theModelPackageImpl, InternalFactoryImpl theInternalPackageImpl) + { + super.initXSD(); + + Property property = null; + + + property = createGlobalProperty + ("aliasName", + theModelPackageImpl.getString(), + new String[] + { + "kind", "attribute", + "name", "aliasName", + "namespace", "##targetNamespace" + }, + IS_ATTRIBUTE); + + property = createGlobalProperty + ("dataType", + theInternalPackageImpl.getQName(), + new String[] + { + "kind", "attribute", + "name", "dataType", + "namespace", "##targetNamespace" + }, + IS_ATTRIBUTE); + + property = createGlobalProperty + ("many", + theModelPackageImpl.getBoolean(), + new String[] + { + "kind", "attribute", + "name", "many", + "namespace", "##targetNamespace" + }, + IS_ATTRIBUTE); + + property = createGlobalProperty + ("name", + theModelPackageImpl.getString(), + new String[] + { + "kind", "attribute", + "name", "name", + "namespace", "##targetNamespace" + }, + IS_ATTRIBUTE); + + property = createGlobalProperty + ("oppositeProperty", + theModelPackageImpl.getString(), + new String[] + { + "kind", "attribute", + "name", "oppositeProperty", + "namespace", "##targetNamespace" + }, + IS_ATTRIBUTE); + + property = createGlobalProperty + ("propertyType", + theInternalPackageImpl.getQName(), + new String[] + { + "kind", "attribute", + "name", "propertyType", + "namespace", "##targetNamespace" + }, + IS_ATTRIBUTE); + + property = createGlobalProperty + ("readOnly", + theModelPackageImpl.getBoolean(), + new String[] + { + "kind", "attribute", + "name", "readOnly", + "namespace", "##targetNamespace" + }, + IS_ATTRIBUTE); + + property = createGlobalProperty + ("sequence", + theModelPackageImpl.getBoolean(), + new String[] + { + "kind", "attribute", + "name", "sequence", + "namespace", "##targetNamespace" + }, + IS_ATTRIBUTE); + + property = createGlobalProperty + ("string", + theModelPackageImpl.getBoolean(), + new String[] + { + "kind", "attribute", + "name", "string", + "namespace", "##targetNamespace" + }, + IS_ATTRIBUTE); + + property = createGlobalProperty + ("xmlElement", + theModelPackageImpl.getBoolean(), + new String[] + { + "kind", "attribute", + "name", "xmlElement", + "namespace", "##targetNamespace" + }, + IS_ATTRIBUTE); + + addXSDMapping + (xmlInfoType, + new String[] + { + "name", "XMLInfo", + "kind", "empty" + }); + + addXSDMapping + (getProperty(xmlInfoType, XMLInfoImpl.INTERNAL_XML_ELEMENT), + new String[] + { + "kind", "attribute", + "name", "xmlElement" + }); + + } + +} //XMLFactoryImpl diff --git a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/xml/impl/XMLInfoImpl.java b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/xml/impl/XMLInfoImpl.java index a0906e32c1..83d8a6725a 100644 --- a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/xml/impl/XMLInfoImpl.java +++ b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/model/xml/impl/XMLInfoImpl.java @@ -1,256 +1,256 @@ -/** - * - * 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.model.xml.impl; - -import commonj.sdo.Type; - -import org.apache.tuscany.sdo.impl.DataObjectBase; - -import org.apache.tuscany.sdo.model.xml.XMLFactory; -import org.apache.tuscany.sdo.model.xml.XMLInfo; - -/** - * - * An implementation of the model object 'Info'. - * - *

- * The following features are implemented: - *

    - *
  • {@link org.apache.tuscany.sdo.model.xml.impl.XMLInfoImpl#isXmlElement Xml Element}
  • - *
- *

- * - * @generated - */ -public class XMLInfoImpl extends DataObjectBase implements XMLInfo -{ - - public final static int XML_ELEMENT = 0; - - public final static int SDO_PROPERTY_COUNT = 1; - - public final static int EXTENDED_PROPERTY_COUNT = 0; - - - /** - * The internal feature id for the 'Xml Element' attribute. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_XML_ELEMENT = 0; - - /** - * The number of properties for this type. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_PROPERTY_COUNT = 1; - - protected int internalConvertIndex(int internalIndex) - { - switch (internalIndex) - { - case INTERNAL_XML_ELEMENT: return XML_ELEMENT; - } - return super.internalConvertIndex(internalIndex); - } - - - /** - * The default value of the '{@link #isXmlElement() Xml Element}' attribute. - * - * - * @see #isXmlElement() - * @generated - * @ordered - */ - protected static final boolean XML_ELEMENT_DEFAULT_ = false; - - /** - * The cached value of the '{@link #isXmlElement() Xml Element}' attribute. - * - * - * @see #isXmlElement() - * @generated - * @ordered - */ - protected boolean xmlElement = XML_ELEMENT_DEFAULT_; - - /** - * This is true if the Xml Element attribute has been set. - * - * - * @generated - * @ordered - */ - protected boolean xmlElement_set_ = false; - - /** - * - * - * @generated - */ - public XMLInfoImpl() - { - super(); - } - - /** - * - * - * @generated - */ - public Type getStaticType() - { - return ((XMLFactoryImpl)XMLFactory.INSTANCE).getXMLInfo(); - } - - /** - * - * - * @generated - */ - public boolean isXmlElement() - { - return xmlElement; - } - /** - * - * - * @generated - */ - public void setXmlElement(boolean newXmlElement) - { - boolean oldXmlElement = xmlElement; - xmlElement = newXmlElement; - boolean oldXmlElement_set_ = xmlElement_set_; - xmlElement_set_ = true; - if (isNotifying()) - notify(ChangeKind.SET, INTERNAL_XML_ELEMENT, oldXmlElement, xmlElement, !oldXmlElement_set_); - } - - /** - * - * - * @generated - */ - public void unsetXmlElement() - { - boolean oldXmlElement = xmlElement; - boolean oldXmlElement_set_ = xmlElement_set_; - xmlElement = XML_ELEMENT_DEFAULT_; - xmlElement_set_ = false; - if (isNotifying()) - notify(ChangeKind.UNSET, INTERNAL_XML_ELEMENT, oldXmlElement, XML_ELEMENT_DEFAULT_, oldXmlElement_set_); - } - - /** - * - * - * @generated - */ - public boolean isSetXmlElement() - { - return xmlElement_set_; - } - - /** - * - * - * @generated - */ - public Object get(int propertyIndex, boolean resolve) - { - switch (propertyIndex) - { - case XML_ELEMENT: - return isXmlElement() ? Boolean.TRUE : Boolean.FALSE; - } - return super.get(propertyIndex, resolve); - } - - /** - * - * - * @generated - */ - public void set(int propertyIndex, Object newValue) - { - switch (propertyIndex) - { - case XML_ELEMENT: - setXmlElement(((Boolean)newValue).booleanValue()); - return; - } - super.set(propertyIndex, newValue); - } - - /** - * - * - * @generated - */ - public void unset(int propertyIndex) - { - switch (propertyIndex) - { - case XML_ELEMENT: - unsetXmlElement(); - return; - } - super.unset(propertyIndex); - } - - /** - * - * - * @generated - */ - public boolean isSet(int propertyIndex) - { - switch (propertyIndex) - { - case XML_ELEMENT: - return isSetXmlElement(); - } - return super.isSet(propertyIndex); - } - - /** - * - * - * @generated - */ - public String toString() - { - if (isProxy(this)) return super.toString(); - - StringBuffer result = new StringBuffer(super.toString()); - result.append(" (xmlElement: "); - if (xmlElement_set_) result.append(xmlElement); else result.append(""); - result.append(')'); - return result.toString(); - } - -} //XMLInfoImpl +/** + * + * 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.model.xml.impl; + +import commonj.sdo.Type; + +import org.apache.tuscany.sdo.impl.DataObjectBase; + +import org.apache.tuscany.sdo.model.xml.XMLFactory; +import org.apache.tuscany.sdo.model.xml.XMLInfo; + +/** + * + * An implementation of the model object 'Info'. + * + *

+ * The following features are implemented: + *

    + *
  • {@link org.apache.tuscany.sdo.model.xml.impl.XMLInfoImpl#isXmlElement Xml Element}
  • + *
+ *

+ * + * @generated + */ +public class XMLInfoImpl extends DataObjectBase implements XMLInfo +{ + + public final static int XML_ELEMENT = 0; + + public final static int SDO_PROPERTY_COUNT = 1; + + public final static int EXTENDED_PROPERTY_COUNT = 0; + + + /** + * The internal feature id for the 'Xml Element' attribute. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_XML_ELEMENT = 0; + + /** + * The number of properties for this type. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_PROPERTY_COUNT = 1; + + protected int internalConvertIndex(int internalIndex) + { + switch (internalIndex) + { + case INTERNAL_XML_ELEMENT: return XML_ELEMENT; + } + return super.internalConvertIndex(internalIndex); + } + + + /** + * The default value of the '{@link #isXmlElement() Xml Element}' attribute. + * + * + * @see #isXmlElement() + * @generated + * @ordered + */ + protected static final boolean XML_ELEMENT_DEFAULT_ = false; + + /** + * The cached value of the '{@link #isXmlElement() Xml Element}' attribute. + * + * + * @see #isXmlElement() + * @generated + * @ordered + */ + protected boolean xmlElement = XML_ELEMENT_DEFAULT_; + + /** + * This is true if the Xml Element attribute has been set. + * + * + * @generated + * @ordered + */ + protected boolean xmlElement_set_ = false; + + /** + * + * + * @generated + */ + public XMLInfoImpl() + { + super(); + } + + /** + * + * + * @generated + */ + public Type getStaticType() + { + return ((XMLFactoryImpl)XMLFactory.INSTANCE).getXMLInfo(); + } + + /** + * + * + * @generated + */ + public boolean isXmlElement() + { + return xmlElement; + } + /** + * + * + * @generated + */ + public void setXmlElement(boolean newXmlElement) + { + boolean oldXmlElement = xmlElement; + xmlElement = newXmlElement; + boolean oldXmlElement_set_ = xmlElement_set_; + xmlElement_set_ = true; + if (isNotifying()) + notify(ChangeKind.SET, INTERNAL_XML_ELEMENT, oldXmlElement, xmlElement, !oldXmlElement_set_); + } + + /** + * + * + * @generated + */ + public void unsetXmlElement() + { + boolean oldXmlElement = xmlElement; + boolean oldXmlElement_set_ = xmlElement_set_; + xmlElement = XML_ELEMENT_DEFAULT_; + xmlElement_set_ = false; + if (isNotifying()) + notify(ChangeKind.UNSET, INTERNAL_XML_ELEMENT, oldXmlElement, XML_ELEMENT_DEFAULT_, oldXmlElement_set_); + } + + /** + * + * + * @generated + */ + public boolean isSetXmlElement() + { + return xmlElement_set_; + } + + /** + * + * + * @generated + */ + public Object get(int propertyIndex, boolean resolve) + { + switch (propertyIndex) + { + case XML_ELEMENT: + return isXmlElement() ? Boolean.TRUE : Boolean.FALSE; + } + return super.get(propertyIndex, resolve); + } + + /** + * + * + * @generated + */ + public void set(int propertyIndex, Object newValue) + { + switch (propertyIndex) + { + case XML_ELEMENT: + setXmlElement(((Boolean)newValue).booleanValue()); + return; + } + super.set(propertyIndex, newValue); + } + + /** + * + * + * @generated + */ + public void unset(int propertyIndex) + { + switch (propertyIndex) + { + case XML_ELEMENT: + unsetXmlElement(); + return; + } + super.unset(propertyIndex); + } + + /** + * + * + * @generated + */ + public boolean isSet(int propertyIndex) + { + switch (propertyIndex) + { + case XML_ELEMENT: + return isSetXmlElement(); + } + return super.isSet(propertyIndex); + } + + /** + * + * + * @generated + */ + public String toString() + { + if (isProxy(this)) return super.toString(); + + StringBuffer result = new StringBuffer(super.toString()); + result.append(" (xmlElement: "); + if (xmlElement_set_) result.append(xmlElement); else result.append(""); + result.append(')'); + return result.toString(); + } + +} //XMLInfoImpl diff --git a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/StreamDeserializer.java b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/StreamDeserializer.java index 5d7bee9c3f..9e1492c9fd 100644 --- a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/StreamDeserializer.java +++ b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/StreamDeserializer.java @@ -1,92 +1,92 @@ -/** - * - * 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.util; - -import java.util.Comparator; - -import javax.xml.XMLConstants; -import javax.xml.namespace.NamespaceContext; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.sdo.util.resource.RecordedEventXMLStreamReader; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.emf.ecore.util.ExtendedMetaData; -import org.eclipse.emf.ecore.xmi.XMLResource; -import org.eclipse.emf.ecore.xml.type.internal.QName; - -/** - * StAX Deserializer. The instance isn't thread-safe, however it's safe to use the instance any times on the same thread. - */ -public class StreamDeserializer implements XMLStreamConstants { - protected XMLStreamReader reader; - - protected final XMLStreamReader play(RecordedEventXMLStreamReader.Tag tag) { - return tag.play(reader); - } - - protected String nameSpace, name; - - protected final boolean typedXSI() { - name = reader.getAttributeValue(ExtendedMetaData.XSI_URI, XMLResource.TYPE); - if (name == null) - return false; - int index = name.indexOf(':'); - if (index == -1) - nameSpace = reader.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX); // may be XMLConstants.NULL_NS_URI - else { - nameSpace = reader.getNamespaceURI(name.substring(0, index)); - name = name.substring(++index); - } - return true; - } - - static protected Object value(Object type, String literal, NamespaceContext nameSpaces) { - Object value = EcoreUtil.createFromString((EDataType) type, literal); - if (!(value instanceof QName)) - return value; - QName qName = (QName) value; - qName.setNamespaceURI(nameSpaces.getNamespaceURI(qName.getPrefix())); - return value; - } - - static public class Attribute { - public String name, value; - } - - static public final class QualifiedAttribute extends Attribute { - public String nameSpace; - } - - static protected final Comparator EQUAL_NULL = new Comparator() { - public int compare(Object v, Object NULL) { - return v == null || v.equals(null) ? 0 : 1; - } - }, EQUAL = new Comparator() { - public int compare(Object v, Object value) { - return value.equals(v) ? 0 : -1; - } - }, SAME = new Comparator() { - public int compare(Object v, Object value) { - return value == v ? 0 : -1; - } - }; -} +/** + * + * 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.util; + +import java.util.Comparator; + +import javax.xml.XMLConstants; +import javax.xml.namespace.NamespaceContext; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sdo.util.resource.RecordedEventXMLStreamReader; +import org.eclipse.emf.ecore.EDataType; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.ecore.util.ExtendedMetaData; +import org.eclipse.emf.ecore.xmi.XMLResource; +import org.eclipse.emf.ecore.xml.type.internal.QName; + +/** + * StAX Deserializer. The instance isn't thread-safe, however it's safe to use the instance any times on the same thread. + */ +public class StreamDeserializer implements XMLStreamConstants { + protected XMLStreamReader reader; + + protected final XMLStreamReader play(RecordedEventXMLStreamReader.Tag tag) { + return tag.play(reader); + } + + protected String nameSpace, name; + + protected final boolean typedXSI() { + name = reader.getAttributeValue(ExtendedMetaData.XSI_URI, XMLResource.TYPE); + if (name == null) + return false; + int index = name.indexOf(':'); + if (index == -1) + nameSpace = reader.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX); // may be XMLConstants.NULL_NS_URI + else { + nameSpace = reader.getNamespaceURI(name.substring(0, index)); + name = name.substring(++index); + } + return true; + } + + static protected Object value(Object type, String literal, NamespaceContext nameSpaces) { + Object value = EcoreUtil.createFromString((EDataType) type, literal); + if (!(value instanceof QName)) + return value; + QName qName = (QName) value; + qName.setNamespaceURI(nameSpaces.getNamespaceURI(qName.getPrefix())); + return value; + } + + static public class Attribute { + public String name, value; + } + + static public final class QualifiedAttribute extends Attribute { + public String nameSpace; + } + + static protected final Comparator EQUAL_NULL = new Comparator() { + public int compare(Object v, Object NULL) { + return v == null || v.equals(null) ? 0 : 1; + } + }, EQUAL = new Comparator() { + public int compare(Object v, Object value) { + return value.equals(v) ? 0 : -1; + } + }, SAME = new Comparator() { + public int compare(Object v, Object value) { + return value == v ? 0 : -1; + } + }; +} diff --git a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/VirtualSequence.java b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/VirtualSequence.java index 2f86fa9d12..a5982ceb35 100644 --- a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/VirtualSequence.java +++ b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/VirtualSequence.java @@ -1,780 +1,780 @@ -/** - * - * 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.util; - -import java.util.Iterator; -import java.util.List; - -import org.apache.tuscany.sdo.impl.ClassImpl; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecore.util.FeatureMapUtil; - -import commonj.sdo.DataObject; -import commonj.sdo.Property; -import commonj.sdo.Sequence; - -/** - * SDO Sequance implementation which delegates to a Collection of DataObject properties. - */ -public class VirtualSequence implements Sequence -{ - private final DataObject dataObject; - protected final List delegateProperties; // size > 1 - - public VirtualSequence(DataObject object) - { - dataObject = object; - delegateProperties = ((ClassImpl)dataObject.getType()).getVirtualSequenceProperties(); - } - - static protected boolean isSequenceProperty(Object property) - { - return FeatureMapUtil.isFeatureMap((EStructuralFeature)property); - } - - public int size() - { - int size = 0; - for (Iterator iterator = delegateProperties.iterator() ; iterator.hasNext() ;) - { - Property property = (Property)iterator.next(); - if (dataObject.isSet(property)) - if (isSequenceProperty(property)) - size += ((Sequence)dataObject.get(property)).size(); - else if (property.isMany()) - size += dataObject.getList(property).size(); - else - ++size; - } - return size; - } - - public Property getProperty(int index) - { - for (Iterator iterator = delegateProperties.iterator() ; iterator.hasNext() ;) - { - Property property = (Property)iterator.next(); - if (dataObject.isSet(property)) - if (isSequenceProperty(property)) - { - Sequence sequence = (Sequence)dataObject.get(property); - int size = sequence.size(); - if (index < size) - return sequence.getProperty(index); - index -= size; - } - else if (property.isMany()) - { - int size = dataObject.getList(property).size(); - if (index < size) - return property; - index -= size; - } - else if (index == 0) - return property; - else - --index; - } - throw new IndexOutOfBoundsException(); - } - - public Object getValue(int index) - { - for (Iterator iterator = delegateProperties.iterator() ; iterator.hasNext() ;) - { - Property property = (Property)iterator.next(); - if (dataObject.isSet(property)) - if (isSequenceProperty(property)) - { - Sequence sequence = (Sequence)dataObject.get(property); - int size = sequence.size(); - if (index < size) - return sequence.getValue(index); - index -= size; - } - else if (property.isMany()) - { - List values = dataObject.getList(property); - int size = values.size(); - if (index < size) - return values.get(index); - index -= size; - } - else if (index == 0) - return dataObject.get(property); - else - --index; - } - throw new IndexOutOfBoundsException(); - } - - public Object setValue(int index, Object value) - { - for (Iterator iterator = delegateProperties.iterator() ; iterator.hasNext() ;) - { - Property property = (Property)iterator.next(); - if (dataObject.isSet(property)) - if (isSequenceProperty(property)) - { - Sequence sequence = (Sequence)dataObject.get(property); - int size = sequence.size(); - if (index < size) - return sequence.setValue(index, value); - index -= size; - } - else if (property.isMany()) - { - List values = dataObject.getList(property); - int size = values.size(); - if (index < size) - return values.set(index, value); - index -= size; - } - else if (index == 0) - { - Object old = dataObject.get(property); - dataObject.set(property, value); - return old; - } - else - --index; - } - throw new IndexOutOfBoundsException(); - } - - boolean validate(EStructuralFeature feature, Object property) - { - return FeatureMapUtil.getValidator((EClass)dataObject.getType(), feature).isValid((EStructuralFeature)property); - } - - boolean append(Property delegateProperty, Property property, Object value) - { - return ((Sequence)dataObject.get(delegateProperty)).add(property, value); - } - - boolean append(Property property, Object value) - { - return dataObject.getList(property).add(value); - } - - boolean set(Property property, Object value) - { - if (property.isMany()) - return append(property, value); - dataObject.set(property, value); - return true; - } - - public final boolean add(Property p, Object value) - { - Property property; - int size = delegateProperties.size(), index = size; - do - { - property = (Property)delegateProperties.get(--index); - if (!dataObject.isSet(property)) - continue; - EStructuralFeature feature = (EStructuralFeature)property; - if (FeatureMapUtil.isFeatureMap(feature)) - { - if (validate(feature, p)) - return append(property, p, value); - } - else if (property == p && property.isMany()) - return append(property, value); - if (size == ++index) - return false; - property = (Property)delegateProperties.get(index); - break; - } - while (index != 0); - for (;;) - { - EStructuralFeature feature = (EStructuralFeature)property; - if (FeatureMapUtil.isFeatureMap(feature)) - { - if (validate(feature, p)) - return append(property, p, value); - } - else if (property == p) - return set(p, value); - if (size == ++index) - return false; - property = (Property)delegateProperties.get(index); - } - } - - protected final Property property(String name) - { - return dataObject.getType().getProperty(name); - } - - public boolean add(String propertyName, Object value) - { - return add(property(propertyName), value); - } - - protected final Property property(int index) - { - return (Property)dataObject.getType().getProperties().get(index); - } - - public boolean add(int propertyIndex, Object value) - { - return add(property(propertyIndex), value); - } - - void insert(Property property, Property p, Object value) - { - ((Sequence)dataObject.get(property)).add(0, p, value); - } - - void insert(Property property, Object value) - { - dataObject.getList(property).add(0, value); - } - - protected final int insert(Iterator iterator, Property p, Object value) - { - while (iterator.hasNext()) - { - Property property = (Property)iterator.next(); - EStructuralFeature feature = (EStructuralFeature)property; - if (dataObject.isSet(property)) - { - if (FeatureMapUtil.isFeatureMap(feature)) - { - if (!validate(feature, p)) - return 2; - insert(property, p, value); - return 0; - } - if (property != p || !property.isMany()) - return 2; - insert(property, value); - return 0; - } - if (FeatureMapUtil.isFeatureMap(feature)) - { - if (validate(feature, p)) - { - append(property, p, value); - return 0; - } - } - else if (property == p) - { - set(property, value); - return 0; - } - } // iterator.hasNext() - return 1; - } - - public final void add(int index, Property p, Object value) - { - Iterator iterator = delegateProperties.iterator(); - if (index == 0) - switch (insert(iterator, p, value)) - { - case 0: - return; - case 1: - throw new IndexOutOfBoundsException(); - default: // 2 - throw new IllegalArgumentException(); - } - while (iterator.hasNext()) - { - Property property = (Property)iterator.next(); - if (dataObject.isSet(property)) - if (isSequenceProperty(property)) - { - Sequence sequence = (Sequence)dataObject.get(property); - int size = sequence.size(); - if (index < size) - { - sequence.add(index, p, value); - return; - } - index -= size; - if (index != 0) - continue; - if (insert(iterator, p, value) != 0) - /*assert */sequence.add(p, value); - return; - } // sequence(property) - else if (property.isMany()) - { - List values = dataObject.getList(property); - int size = values.size(); - if (index < size) - { - values.add(index, value); - return; - } - index -= size; - if (index == 0 && property == p) - { - values.add(value); - return; - } - } - else if (index == 0) - throw new IllegalArgumentException(); - else - --index; - } - throw new IndexOutOfBoundsException(); - } - - public void add(int index, String propertyName, Object value) - { - add(index, property(propertyName), value); - } - - public void add(int index, int propertyIndex, Object value) - { - add(index, property(propertyIndex), value); - } - - public final void addText(String text) - { - throw new IllegalArgumentException(); - } - - /** - * @deprecated - */ - public void add(String text) - { - addText(text); - } - - public final void addText(int index, String text) - { - throw new IllegalArgumentException(); - } - - /** - * @deprecated - */ - public void add(int index, String text) - { - addText(index, text); - } - - public void remove(int index) - { - for (Iterator iterator = delegateProperties.iterator() ; iterator.hasNext() ;) - { - Property property = (Property)iterator.next(); - if (dataObject.isSet(property)) - if (isSequenceProperty(property)) - { - Sequence sequence = (Sequence)dataObject.get(property); - int size = sequence.size(); - if (index < size) - { - sequence.remove(index); - return; - } - index -= size; - } - else if (property.isMany()) - { - List values = dataObject.getList(property); - int size = values.size(); - if (index < size) - { - values.remove(index); - return; - } - index -= size; - } - else if (index == 0) - { - dataObject.unset(property); - return; - } - else - --index; - } - throw new IndexOutOfBoundsException(); - } - - static private Object remove(Sequence sequence, int index) - { - Object value = sequence.getValue(index); - sequence.remove(index); - return value; - } - - static void move(Sequence fromSequence, int fromIndex, Sequence toSequence, int toIndex, Property property) - { - toSequence.add(toIndex, property, remove(fromSequence, fromIndex)); // removes containment - } - - static protected void move(Sequence fromSequence, int fromIndex, Sequence toSequence, int toIndex) - { - move(fromSequence, fromIndex, toSequence, toIndex, fromSequence.getProperty(fromIndex)); - } - - static protected void add(Object value,List list,int index, int size) - { - if (++index == size) - /*assert */list.add(value); - else - list.add(index, value); // removes containment - } - - static protected void add(Property property, Object value, Sequence toSequence, int toIndex, int size) - { - if (++toIndex == size) - toSequence.add(property, value); // removes containment - else - toSequence.add(toIndex, property, value); // removes containment - } - - public void move(int toIndex, int fromIndex) - { - for (Iterator iterator = delegateProperties.iterator(); iterator.hasNext() ;) - { - Property property = (Property)iterator.next(); - if (dataObject.isSet(property)) - if (isSequenceProperty(property)) - { - Sequence sequence = (Sequence)dataObject.get(property); - int size = sequence.size(); - if (toIndex < size) - { - if (fromIndex < size) - { - sequence.move(toIndex, fromIndex); - return; - } - while (iterator.hasNext()) - { - property = (Property)iterator.next(); - if (!dataObject.isSet(property)) - continue; - fromIndex -= size; - if (isSequenceProperty(property)) - { - Sequence fromSequence = (Sequence)dataObject.get(property); - size = fromSequence.size(); - if (fromIndex >= size) - continue; - move(fromSequence, fromIndex, sequence, toIndex); - return; - } - if (property.isMany()) - { - List list = dataObject.getList(property); - size = list.size(); - if (fromIndex >= size) - continue; - sequence.add(toIndex, property, list.remove(fromIndex)); // removes containment - return; - } - if (fromIndex == 0) - { - sequence.add(toIndex, property, dataObject.get(property)); // removes containment - dataObject.unset(property); - return; - } - size = 1; - } // iterator.hasNext() - break; - } // toIndex < size - if (fromIndex < size) - { - while (iterator.hasNext()) - { - property = (Property)iterator.next(); - if (!dataObject.isSet(property)) - continue; - toIndex -= size; - if (isSequenceProperty(property)) - { - Sequence toSequence = (Sequence)dataObject.get(property); - size = toSequence.size(); - if (toIndex >= size) - continue; - if (++toIndex == size) - toSequence.add(sequence.getProperty(fromIndex), remove(sequence, fromIndex)); // Java pushes stack from left to right - // removes containment - else - move(sequence, fromIndex, toSequence, toIndex); - return; - } - if (property.isMany()) - { - List list = dataObject.getList(property); - size = list.size(); - if (toIndex >= size) - continue; - if (sequence.getProperty(fromIndex) != property) - throw new IllegalArgumentException(); - add(remove(sequence, fromIndex), list, toIndex, size); - return; - } - if (toIndex == 0) - { - while (iterator.hasNext()) - { - Property p = sequence.getProperty(fromIndex); - property = (Property)iterator.next(); - EStructuralFeature feature = (EStructuralFeature)property; - if (dataObject.isSet(property)) - { - if (FeatureMapUtil.isFeatureMap(feature)) - { - /*if (!validate(feature, p)) - throw new IllegalArgumentException(); */ - move(sequence, fromIndex, (Sequence)dataObject.get(property), 0, p); - return; - } - if (property != p || !property.isMany()) - throw new IllegalArgumentException(); - insert(property, remove(sequence, fromIndex)); // removes containment - return; - } - if (FeatureMapUtil.isFeatureMap(feature)) - { - if (validate(feature, p)) - { - append(property, p, remove(sequence, fromIndex)); // removes containment - return; - } - } - else if (property == p) - { - set(property, remove(sequence, fromIndex)); - return; - } - } // iterator.hasNext() - break; - } - size = 1; - } // iterator.hasNext() - break; - } // fromIndex < size - toIndex -= size; - fromIndex -= size; - } // sequence(property) - else if (property.isMany()) - { - List list = dataObject.getList(property); - int size = list.size(); - if (toIndex < size) - { - if (fromIndex < size) - { - ((EList)list).move(toIndex, fromIndex); - return; - } - while (iterator.hasNext()) - { - Property p = (Property)iterator.next(); - if (!dataObject.isSet(p)) - continue; - fromIndex -= size; - if (isSequenceProperty(p)) - { - Sequence fromSequence = (Sequence)dataObject.get(p); - size = fromSequence.size(); - if (fromIndex >= size) - continue; - if (fromSequence.getProperty(fromIndex) != property) - throw new IllegalArgumentException(); - list.add(toIndex, remove(fromSequence, fromIndex)); // removes containment - return; - } - if (p.isMany()) - { - List l = dataObject.getList(p); - size = l.size(); - if (fromIndex >= size) - continue; - /*if (p != property) - throw new IllegalArgumentException(); */ - list.add(toIndex, l.remove(fromIndex)); // removes containment - return; - } - if (fromIndex == 0) - { - /*if (p != property) - throw new IllegalArgumentException(); */ - list.add(toIndex, dataObject.get(p)); // removes containment - dataObject.unset(p); - return; - } - size = 1; - } // iterator.hasNext() - break; - } // toIndex < size - if (fromIndex < size) - { - while (iterator.hasNext()) - { - Property p = (Property)iterator.next(); - if (!dataObject.isSet(p)) - continue; - toIndex -= size; - if (isSequenceProperty(p)) - { - Sequence toSequence = (Sequence)dataObject.get(p); - size = toSequence.size(); - if (toIndex >= size) - continue; - add(property, list.remove(fromIndex), toSequence, toIndex, size); - return; - } - if (p.isMany()) - { - List l = dataObject.getList(p); - size = l.size(); - if (toIndex >= size) - continue; - /*if (property != p) - throw new IllegalArgumentException(); */ - add(list.remove(fromIndex), l, toIndex, size); - return; - } - if (toIndex == 0) - { - while (iterator.hasNext()) - { - p = (Property)iterator.next(); - EStructuralFeature feature = (EStructuralFeature)p; - if (dataObject.isSet(p)) - { - if (FeatureMapUtil.isFeatureMap(feature)) - { - /*if (!validate(feature, property)) - throw new IllegalArgumentException(); */ - insert(p, property, list.remove(fromIndex)); - return; - } - if (/*p != property || */!p.isMany()) - throw new IllegalArgumentException(); - insert(p, list.remove(fromIndex)); // removes containment - return; - } - if (FeatureMapUtil.isFeatureMap(feature)) - { - if (!validate(feature, property)) - continue; - append(p, property, list.remove(fromIndex)); // removes containment - return; - } - else if (p == property) - { - set(p, list.remove(fromIndex)); - return; - } - } // iterator.hasNext() - break; - } // toIndex == 0 - size = 1; - } // iterator.hasNext() - break; - } // fromIndex < size - toIndex -= size; - fromIndex -= size; - } // property.isMany() - else if (toIndex == 0) - throw new IllegalArgumentException(); - else if (fromIndex == 0) - { - for (int size = 1; iterator.hasNext() ;) - { - Property p = (Property)iterator.next(); - if (!dataObject.isSet(p)) - continue; - toIndex -= size; - if (isSequenceProperty(p)) - { - Sequence toSequence = (Sequence)dataObject.get(p); - size = toSequence.size(); - if (toIndex >= size) - continue; - add(property, dataObject.get(property), toSequence, toIndex, size); - dataObject.unset(property); - return; - } - if (p.isMany()) - { - List l = dataObject.getList(p); - size = l.size(); - if (toIndex >= size) - continue; - /*if (property != p) - throw new IllegalArgumentException(); */ - add(dataObject.get(property), l, toIndex, size); - dataObject.unset(property); - return; - } - if (toIndex == 0) - { - while (iterator.hasNext()) - { - p = (Property)iterator.next(); - EStructuralFeature feature = (EStructuralFeature)p; - if (dataObject.isSet(p)) - if (FeatureMapUtil.isFeatureMap(feature)) - /*if (!validate(feature, property)) - throw new IllegalArgumentException(); */ - insert(p, property, dataObject.get(property)); - else if (/*p == property && */p.isMany()) - insert(p, dataObject.get(property)); // removes containment - else - throw new IllegalArgumentException(); - else if (FeatureMapUtil.isFeatureMap(feature)) - { - if (!validate(feature, property)) - continue; - append(p, property, dataObject.get(property)); // removes containment - } - else if (p == property) - set(p, dataObject.get(property)); - else - continue; - dataObject.unset(property); - return; - } // iterator.hasNext() - break; - } // toIndex == 0 - size = 1; - } // iterator.hasNext() - break; - } // fromIndex == 0 - else - { - --toIndex; - --fromIndex; - } - } - throw new IndexOutOfBoundsException(); - } -} +/** + * + * 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.util; + +import java.util.Iterator; +import java.util.List; + +import org.apache.tuscany.sdo.impl.ClassImpl; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.util.FeatureMapUtil; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Sequence; + +/** + * SDO Sequance implementation which delegates to a Collection of DataObject properties. + */ +public class VirtualSequence implements Sequence +{ + private final DataObject dataObject; + protected final List delegateProperties; // size > 1 + + public VirtualSequence(DataObject object) + { + dataObject = object; + delegateProperties = ((ClassImpl)dataObject.getType()).getVirtualSequenceProperties(); + } + + static protected boolean isSequenceProperty(Object property) + { + return FeatureMapUtil.isFeatureMap((EStructuralFeature)property); + } + + public int size() + { + int size = 0; + for (Iterator iterator = delegateProperties.iterator() ; iterator.hasNext() ;) + { + Property property = (Property)iterator.next(); + if (dataObject.isSet(property)) + if (isSequenceProperty(property)) + size += ((Sequence)dataObject.get(property)).size(); + else if (property.isMany()) + size += dataObject.getList(property).size(); + else + ++size; + } + return size; + } + + public Property getProperty(int index) + { + for (Iterator iterator = delegateProperties.iterator() ; iterator.hasNext() ;) + { + Property property = (Property)iterator.next(); + if (dataObject.isSet(property)) + if (isSequenceProperty(property)) + { + Sequence sequence = (Sequence)dataObject.get(property); + int size = sequence.size(); + if (index < size) + return sequence.getProperty(index); + index -= size; + } + else if (property.isMany()) + { + int size = dataObject.getList(property).size(); + if (index < size) + return property; + index -= size; + } + else if (index == 0) + return property; + else + --index; + } + throw new IndexOutOfBoundsException(); + } + + public Object getValue(int index) + { + for (Iterator iterator = delegateProperties.iterator() ; iterator.hasNext() ;) + { + Property property = (Property)iterator.next(); + if (dataObject.isSet(property)) + if (isSequenceProperty(property)) + { + Sequence sequence = (Sequence)dataObject.get(property); + int size = sequence.size(); + if (index < size) + return sequence.getValue(index); + index -= size; + } + else if (property.isMany()) + { + List values = dataObject.getList(property); + int size = values.size(); + if (index < size) + return values.get(index); + index -= size; + } + else if (index == 0) + return dataObject.get(property); + else + --index; + } + throw new IndexOutOfBoundsException(); + } + + public Object setValue(int index, Object value) + { + for (Iterator iterator = delegateProperties.iterator() ; iterator.hasNext() ;) + { + Property property = (Property)iterator.next(); + if (dataObject.isSet(property)) + if (isSequenceProperty(property)) + { + Sequence sequence = (Sequence)dataObject.get(property); + int size = sequence.size(); + if (index < size) + return sequence.setValue(index, value); + index -= size; + } + else if (property.isMany()) + { + List values = dataObject.getList(property); + int size = values.size(); + if (index < size) + return values.set(index, value); + index -= size; + } + else if (index == 0) + { + Object old = dataObject.get(property); + dataObject.set(property, value); + return old; + } + else + --index; + } + throw new IndexOutOfBoundsException(); + } + + boolean validate(EStructuralFeature feature, Object property) + { + return FeatureMapUtil.getValidator((EClass)dataObject.getType(), feature).isValid((EStructuralFeature)property); + } + + boolean append(Property delegateProperty, Property property, Object value) + { + return ((Sequence)dataObject.get(delegateProperty)).add(property, value); + } + + boolean append(Property property, Object value) + { + return dataObject.getList(property).add(value); + } + + boolean set(Property property, Object value) + { + if (property.isMany()) + return append(property, value); + dataObject.set(property, value); + return true; + } + + public final boolean add(Property p, Object value) + { + Property property; + int size = delegateProperties.size(), index = size; + do + { + property = (Property)delegateProperties.get(--index); + if (!dataObject.isSet(property)) + continue; + EStructuralFeature feature = (EStructuralFeature)property; + if (FeatureMapUtil.isFeatureMap(feature)) + { + if (validate(feature, p)) + return append(property, p, value); + } + else if (property == p && property.isMany()) + return append(property, value); + if (size == ++index) + return false; + property = (Property)delegateProperties.get(index); + break; + } + while (index != 0); + for (;;) + { + EStructuralFeature feature = (EStructuralFeature)property; + if (FeatureMapUtil.isFeatureMap(feature)) + { + if (validate(feature, p)) + return append(property, p, value); + } + else if (property == p) + return set(p, value); + if (size == ++index) + return false; + property = (Property)delegateProperties.get(index); + } + } + + protected final Property property(String name) + { + return dataObject.getType().getProperty(name); + } + + public boolean add(String propertyName, Object value) + { + return add(property(propertyName), value); + } + + protected final Property property(int index) + { + return (Property)dataObject.getType().getProperties().get(index); + } + + public boolean add(int propertyIndex, Object value) + { + return add(property(propertyIndex), value); + } + + void insert(Property property, Property p, Object value) + { + ((Sequence)dataObject.get(property)).add(0, p, value); + } + + void insert(Property property, Object value) + { + dataObject.getList(property).add(0, value); + } + + protected final int insert(Iterator iterator, Property p, Object value) + { + while (iterator.hasNext()) + { + Property property = (Property)iterator.next(); + EStructuralFeature feature = (EStructuralFeature)property; + if (dataObject.isSet(property)) + { + if (FeatureMapUtil.isFeatureMap(feature)) + { + if (!validate(feature, p)) + return 2; + insert(property, p, value); + return 0; + } + if (property != p || !property.isMany()) + return 2; + insert(property, value); + return 0; + } + if (FeatureMapUtil.isFeatureMap(feature)) + { + if (validate(feature, p)) + { + append(property, p, value); + return 0; + } + } + else if (property == p) + { + set(property, value); + return 0; + } + } // iterator.hasNext() + return 1; + } + + public final void add(int index, Property p, Object value) + { + Iterator iterator = delegateProperties.iterator(); + if (index == 0) + switch (insert(iterator, p, value)) + { + case 0: + return; + case 1: + throw new IndexOutOfBoundsException(); + default: // 2 + throw new IllegalArgumentException(); + } + while (iterator.hasNext()) + { + Property property = (Property)iterator.next(); + if (dataObject.isSet(property)) + if (isSequenceProperty(property)) + { + Sequence sequence = (Sequence)dataObject.get(property); + int size = sequence.size(); + if (index < size) + { + sequence.add(index, p, value); + return; + } + index -= size; + if (index != 0) + continue; + if (insert(iterator, p, value) != 0) + /*assert */sequence.add(p, value); + return; + } // sequence(property) + else if (property.isMany()) + { + List values = dataObject.getList(property); + int size = values.size(); + if (index < size) + { + values.add(index, value); + return; + } + index -= size; + if (index == 0 && property == p) + { + values.add(value); + return; + } + } + else if (index == 0) + throw new IllegalArgumentException(); + else + --index; + } + throw new IndexOutOfBoundsException(); + } + + public void add(int index, String propertyName, Object value) + { + add(index, property(propertyName), value); + } + + public void add(int index, int propertyIndex, Object value) + { + add(index, property(propertyIndex), value); + } + + public final void addText(String text) + { + throw new IllegalArgumentException(); + } + + /** + * @deprecated + */ + public void add(String text) + { + addText(text); + } + + public final void addText(int index, String text) + { + throw new IllegalArgumentException(); + } + + /** + * @deprecated + */ + public void add(int index, String text) + { + addText(index, text); + } + + public void remove(int index) + { + for (Iterator iterator = delegateProperties.iterator() ; iterator.hasNext() ;) + { + Property property = (Property)iterator.next(); + if (dataObject.isSet(property)) + if (isSequenceProperty(property)) + { + Sequence sequence = (Sequence)dataObject.get(property); + int size = sequence.size(); + if (index < size) + { + sequence.remove(index); + return; + } + index -= size; + } + else if (property.isMany()) + { + List values = dataObject.getList(property); + int size = values.size(); + if (index < size) + { + values.remove(index); + return; + } + index -= size; + } + else if (index == 0) + { + dataObject.unset(property); + return; + } + else + --index; + } + throw new IndexOutOfBoundsException(); + } + + static private Object remove(Sequence sequence, int index) + { + Object value = sequence.getValue(index); + sequence.remove(index); + return value; + } + + static void move(Sequence fromSequence, int fromIndex, Sequence toSequence, int toIndex, Property property) + { + toSequence.add(toIndex, property, remove(fromSequence, fromIndex)); // removes containment + } + + static protected void move(Sequence fromSequence, int fromIndex, Sequence toSequence, int toIndex) + { + move(fromSequence, fromIndex, toSequence, toIndex, fromSequence.getProperty(fromIndex)); + } + + static protected void add(Object value,List list,int index, int size) + { + if (++index == size) + /*assert */list.add(value); + else + list.add(index, value); // removes containment + } + + static protected void add(Property property, Object value, Sequence toSequence, int toIndex, int size) + { + if (++toIndex == size) + toSequence.add(property, value); // removes containment + else + toSequence.add(toIndex, property, value); // removes containment + } + + public void move(int toIndex, int fromIndex) + { + for (Iterator iterator = delegateProperties.iterator(); iterator.hasNext() ;) + { + Property property = (Property)iterator.next(); + if (dataObject.isSet(property)) + if (isSequenceProperty(property)) + { + Sequence sequence = (Sequence)dataObject.get(property); + int size = sequence.size(); + if (toIndex < size) + { + if (fromIndex < size) + { + sequence.move(toIndex, fromIndex); + return; + } + while (iterator.hasNext()) + { + property = (Property)iterator.next(); + if (!dataObject.isSet(property)) + continue; + fromIndex -= size; + if (isSequenceProperty(property)) + { + Sequence fromSequence = (Sequence)dataObject.get(property); + size = fromSequence.size(); + if (fromIndex >= size) + continue; + move(fromSequence, fromIndex, sequence, toIndex); + return; + } + if (property.isMany()) + { + List list = dataObject.getList(property); + size = list.size(); + if (fromIndex >= size) + continue; + sequence.add(toIndex, property, list.remove(fromIndex)); // removes containment + return; + } + if (fromIndex == 0) + { + sequence.add(toIndex, property, dataObject.get(property)); // removes containment + dataObject.unset(property); + return; + } + size = 1; + } // iterator.hasNext() + break; + } // toIndex < size + if (fromIndex < size) + { + while (iterator.hasNext()) + { + property = (Property)iterator.next(); + if (!dataObject.isSet(property)) + continue; + toIndex -= size; + if (isSequenceProperty(property)) + { + Sequence toSequence = (Sequence)dataObject.get(property); + size = toSequence.size(); + if (toIndex >= size) + continue; + if (++toIndex == size) + toSequence.add(sequence.getProperty(fromIndex), remove(sequence, fromIndex)); // Java pushes stack from left to right + // removes containment + else + move(sequence, fromIndex, toSequence, toIndex); + return; + } + if (property.isMany()) + { + List list = dataObject.getList(property); + size = list.size(); + if (toIndex >= size) + continue; + if (sequence.getProperty(fromIndex) != property) + throw new IllegalArgumentException(); + add(remove(sequence, fromIndex), list, toIndex, size); + return; + } + if (toIndex == 0) + { + while (iterator.hasNext()) + { + Property p = sequence.getProperty(fromIndex); + property = (Property)iterator.next(); + EStructuralFeature feature = (EStructuralFeature)property; + if (dataObject.isSet(property)) + { + if (FeatureMapUtil.isFeatureMap(feature)) + { + /*if (!validate(feature, p)) + throw new IllegalArgumentException(); */ + move(sequence, fromIndex, (Sequence)dataObject.get(property), 0, p); + return; + } + if (property != p || !property.isMany()) + throw new IllegalArgumentException(); + insert(property, remove(sequence, fromIndex)); // removes containment + return; + } + if (FeatureMapUtil.isFeatureMap(feature)) + { + if (validate(feature, p)) + { + append(property, p, remove(sequence, fromIndex)); // removes containment + return; + } + } + else if (property == p) + { + set(property, remove(sequence, fromIndex)); + return; + } + } // iterator.hasNext() + break; + } + size = 1; + } // iterator.hasNext() + break; + } // fromIndex < size + toIndex -= size; + fromIndex -= size; + } // sequence(property) + else if (property.isMany()) + { + List list = dataObject.getList(property); + int size = list.size(); + if (toIndex < size) + { + if (fromIndex < size) + { + ((EList)list).move(toIndex, fromIndex); + return; + } + while (iterator.hasNext()) + { + Property p = (Property)iterator.next(); + if (!dataObject.isSet(p)) + continue; + fromIndex -= size; + if (isSequenceProperty(p)) + { + Sequence fromSequence = (Sequence)dataObject.get(p); + size = fromSequence.size(); + if (fromIndex >= size) + continue; + if (fromSequence.getProperty(fromIndex) != property) + throw new IllegalArgumentException(); + list.add(toIndex, remove(fromSequence, fromIndex)); // removes containment + return; + } + if (p.isMany()) + { + List l = dataObject.getList(p); + size = l.size(); + if (fromIndex >= size) + continue; + /*if (p != property) + throw new IllegalArgumentException(); */ + list.add(toIndex, l.remove(fromIndex)); // removes containment + return; + } + if (fromIndex == 0) + { + /*if (p != property) + throw new IllegalArgumentException(); */ + list.add(toIndex, dataObject.get(p)); // removes containment + dataObject.unset(p); + return; + } + size = 1; + } // iterator.hasNext() + break; + } // toIndex < size + if (fromIndex < size) + { + while (iterator.hasNext()) + { + Property p = (Property)iterator.next(); + if (!dataObject.isSet(p)) + continue; + toIndex -= size; + if (isSequenceProperty(p)) + { + Sequence toSequence = (Sequence)dataObject.get(p); + size = toSequence.size(); + if (toIndex >= size) + continue; + add(property, list.remove(fromIndex), toSequence, toIndex, size); + return; + } + if (p.isMany()) + { + List l = dataObject.getList(p); + size = l.size(); + if (toIndex >= size) + continue; + /*if (property != p) + throw new IllegalArgumentException(); */ + add(list.remove(fromIndex), l, toIndex, size); + return; + } + if (toIndex == 0) + { + while (iterator.hasNext()) + { + p = (Property)iterator.next(); + EStructuralFeature feature = (EStructuralFeature)p; + if (dataObject.isSet(p)) + { + if (FeatureMapUtil.isFeatureMap(feature)) + { + /*if (!validate(feature, property)) + throw new IllegalArgumentException(); */ + insert(p, property, list.remove(fromIndex)); + return; + } + if (/*p != property || */!p.isMany()) + throw new IllegalArgumentException(); + insert(p, list.remove(fromIndex)); // removes containment + return; + } + if (FeatureMapUtil.isFeatureMap(feature)) + { + if (!validate(feature, property)) + continue; + append(p, property, list.remove(fromIndex)); // removes containment + return; + } + else if (p == property) + { + set(p, list.remove(fromIndex)); + return; + } + } // iterator.hasNext() + break; + } // toIndex == 0 + size = 1; + } // iterator.hasNext() + break; + } // fromIndex < size + toIndex -= size; + fromIndex -= size; + } // property.isMany() + else if (toIndex == 0) + throw new IllegalArgumentException(); + else if (fromIndex == 0) + { + for (int size = 1; iterator.hasNext() ;) + { + Property p = (Property)iterator.next(); + if (!dataObject.isSet(p)) + continue; + toIndex -= size; + if (isSequenceProperty(p)) + { + Sequence toSequence = (Sequence)dataObject.get(p); + size = toSequence.size(); + if (toIndex >= size) + continue; + add(property, dataObject.get(property), toSequence, toIndex, size); + dataObject.unset(property); + return; + } + if (p.isMany()) + { + List l = dataObject.getList(p); + size = l.size(); + if (toIndex >= size) + continue; + /*if (property != p) + throw new IllegalArgumentException(); */ + add(dataObject.get(property), l, toIndex, size); + dataObject.unset(property); + return; + } + if (toIndex == 0) + { + while (iterator.hasNext()) + { + p = (Property)iterator.next(); + EStructuralFeature feature = (EStructuralFeature)p; + if (dataObject.isSet(p)) + if (FeatureMapUtil.isFeatureMap(feature)) + /*if (!validate(feature, property)) + throw new IllegalArgumentException(); */ + insert(p, property, dataObject.get(property)); + else if (/*p == property && */p.isMany()) + insert(p, dataObject.get(property)); // removes containment + else + throw new IllegalArgumentException(); + else if (FeatureMapUtil.isFeatureMap(feature)) + { + if (!validate(feature, property)) + continue; + append(p, property, dataObject.get(property)); // removes containment + } + else if (p == property) + set(p, dataObject.get(property)); + else + continue; + dataObject.unset(property); + return; + } // iterator.hasNext() + break; + } // toIndex == 0 + size = 1; + } // iterator.hasNext() + break; + } // fromIndex == 0 + else + { + --toIndex; + --fromIndex; + } + } + throw new IndexOutOfBoundsException(); + } +} diff --git a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/ChangeSummaryStreamDeserializer.java b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/ChangeSummaryStreamDeserializer.java index 6dc461a2fe..697de1c7ad 100644 --- a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/ChangeSummaryStreamDeserializer.java +++ b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/ChangeSummaryStreamDeserializer.java @@ -1,663 +1,663 @@ -/** - * - * 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.util.resource; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import javax.xml.namespace.NamespaceContext; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.sdo.SDOFactory; -import org.apache.tuscany.sdo.helper.SDOAnnotations; -import org.apache.tuscany.sdo.impl.ChangeSummaryImpl; -import org.apache.tuscany.sdo.impl.ClassImpl; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecore.ETypedElement; -import org.eclipse.emf.ecore.change.ChangeDescription; -import org.eclipse.emf.ecore.change.ChangeFactory; -import org.eclipse.emf.ecore.change.ChangeKind; -import org.eclipse.emf.ecore.change.FeatureChange; -import org.eclipse.emf.ecore.change.FeatureMapEntry; -import org.eclipse.emf.ecore.change.ListChange; -import org.eclipse.emf.ecore.util.FeatureMap; -import org.eclipse.emf.ecore.util.FeatureMapUtil; - -import commonj.sdo.ChangeSummary; -import commonj.sdo.DataObject; -import commonj.sdo.Property; -import commonj.sdo.Type; -import commonj.sdo.helper.HelperContext; - -/** - * ChangeSummary StAX Deserializer whose input conforms to the SDO Java/C++/PHP specifications. The instance isn't thread-safe, however it's safe to - * use the instance any times on the same thread. - */ -public class ChangeSummaryStreamDeserializer extends SDODeserializer { - static final class ForwardReference extends Ref { - final String unset; - - ForwardReference(String ref, NamespaceContext nameSpaces, String u) { - super(ref, nameSpaces); - unset = u; - } - - Collection attributes/* = null */, qualifiedAttributes/* = null */, tags/* = null */; // may be null, never empty - } - - protected Collection forwardReferences/* = null */; - - static private final class ElementChange extends Ref { - private final Object containing, containment; - private ElementChange(String ref, NamespaceContext nameSpaces, Object property, Object propertyInSequence) { - super(ref, nameSpaces); - containing = property; - containment = propertyInSequence; - } - } - - static private class PropertyMapChanges { - Map/* Property,List */lists/* = null */;// may be null - - Collection put(Object property) { - Collection list = new ArrayList(); - lists.put(property, list); - return list; - } - - protected final Collection get(Object property) { - Object list = lists.get(property); - return list == null ? put(property) : (Collection) list; - } - - protected final Collection newList(Object property) { - lists = new HashMap(); - return put(property); - } - } - - static final class ObjectChanges extends PropertyMapChanges { - Collection elementChanges/* = null */,// may be null, never empty - featureChanges; - - protected final void newElementChanges() { - elementChanges = new ArrayList(); - } - } - - Collection objectChangesCollection/* = null */, objectMapChanges, deletedDataObjects; - - protected final ObjectChanges newObjectChanges(Collection featureChanges) { - ObjectChanges objectChanges = new ObjectChanges(); - objectChanges.featureChanges = featureChanges; - if (objectChangesCollection == null) - objectChangesCollection = new ArrayList(); - objectChangesCollection.add(objectChanges); - return objectChanges; - } - - private ChangeFactory changeFactory; - - private SDOFactory changeSettingFactory; - - private void logPropertyChange(Collection featureChanges, EStructuralFeature feature, Object value, boolean set) { - if (changeSettingFactory == null) - featureChanges.add(changeFactory.createFeatureChange(feature, value, set)); - else - featureChanges.add(changeSettingFactory.createChangeSummarySetting(feature, value, set)); - } - - void unsetProperty(Collection featureChanges, String unset, int begin, int index, Type type) { - logPropertyChange(featureChanges, (EStructuralFeature) type.getProperty(unset.substring(begin, index)), null, false); - } - - static boolean isWhitespace(String unset, int index) { - return Character.isWhitespace(unset.charAt(index)); - } - - protected final Collection unsetProperties(EObject referent, String unset, Type type) { - Map.Entry entry = changeFactory.createEObjectToChangesMapEntry(referent); - objectMapChanges.add(entry); - Collection featureChanges = (Collection) entry.getValue(); - if (unset == null) - return featureChanges; - int end = unset.length(); - if (end != 0) - for (int begin = 0, index = 1;/* true */; ++index) { - if (index == end) { - unsetProperty(featureChanges, unset, begin, index, type); - break; - } - if (isWhitespace(unset, index)) { - unsetProperty(featureChanges, unset, begin, index, type); - while (true) { - if (++index != end) - return featureChanges; - if (!isWhitespace(unset, index)) { - begin = index; - break; - } - } - } - } - return featureChanges; - } - - private Object value(EStructuralFeature containing, Object containment, Object value) { - return FeatureMapUtil.isFeatureMap(containing) ? changeFactory.createFeatureMapEntry((EStructuralFeature) containment, value) : value; - } - - private void logPropertyChange(Collection featureChanges, Object containing, Object containment, Object value) { - EStructuralFeature feature = (EStructuralFeature) containing; - logPropertyChange(featureChanges, feature, value(feature, containment, value), true); - } - - private void logPropertyChange(Collection featureChanges, Object property, Object value) { - logPropertyChange(featureChanges, property, propertyInSequence, value); - } - - void logAttributeChange(Collection featureChanges, Property property, String literal, NamespaceContext nameSpaces) { - logPropertyChange(featureChanges, property, value(property.getType(), literal, nameSpaces)); - } - - protected final void logAttributeChange(Collection featureChanges, String property, Type type, String value, NamespaceContext nameSpaces) { - logAttributeChange(featureChanges, getProperty(type, property), value, nameSpaces); - } - - protected final void logAttributeChange(Collection featureChanges, String nameSpace, String name, Type type, String value, - NamespaceContext nameSpaces) { - logAttributeChange(featureChanges, getProperty(type, nameSpace, name, false), value, nameSpaces); - } - - protected final String ref() { - return reader.getAttributeValue(SDOAnnotations.COMMONJ_SDO_NS, ChangeSummaryStreamSerializer.REF_ATTRIBUTE); - } - - ChangeSummaryImpl changeSummary; - - protected Object load(XMLStreamReader reader, Map options) throws XMLStreamException { - Object value = super.load(reader, options); - deletedDataObjects.add(value); - return value; - } - - protected final void getChangeSummary(DataObject rootObject) { - changeSummary = (ChangeSummaryImpl) rootObject.getChangeSummary(); // DynamicDataObjectImpl(EClass) - } - - static protected final class Tag extends RecordedEventXMLStreamReader.Tag { - protected String ref; - - protected Object value; - - protected Tag(XMLStreamReader reader) { - super(reader); - } - } - - protected final void addPropertyChange(Collection list, Object value, Object containing) { - list.add(value((EStructuralFeature) containing, propertyInSequence, value)); - } - - protected boolean logging; - - /** - * Imports ChangeSummary 2-1. Forward references will be resolved by {@link #end()}. - * - * @param reader - * Never null - * @throws XMLStreamException - */ - public final void begin(DataObject rootObject, HelperContext scope, XMLStreamReader reader) throws XMLStreamException { - /* - * 3-1. Instantiate ChangeSummary input: reader (xsi:type), factory, rootObject output: changeSummary, changeDescription - */ - initialize(reader, scope, rootObject); - if (typedXSI()) { - changeSummary = (ChangeSummaryImpl) scope.getDataFactory().create(nameSpace, name); - if (changeSummary == null) - getChangeSummary(rootObject); - else { - Property csp = ((ClassImpl) rootObject.getType()).getChangeSummaryProperty(); - rootObject.set(csp, changeSummary); - changeSummary.setDataObject(rootObject); - } - } else - getChangeSummary(rootObject); - ChangeDescription changeDescription = (ChangeDescription) changeSummary; - - /* - * 3-2. "logging" attribute input: reader output: logging - */ - logging = Boolean.valueOf(reader.getAttributeValue(null, "logging")).booleanValue(); - - /* - * 3-3. Modified DataObjects input: changeDescription - */ - if (forwardReferences != null) - forwardReferences.clear(); - if (objectChangesCollection != null) - objectChangesCollection.clear(); - if (START_ELEMENT == reader.nextTag()) { - objectMapChanges = changeDescription.getObjectChanges(); - deletedDataObjects = changeDescription.getObjectsToAttach(); - Object factory = changeDescription.eClass().getEPackage().getEFactoryInstance(); - changeFactory = factory instanceof ChangeFactory ? (ChangeFactory) factory : ChangeFactory.eINSTANCE; - changeSettingFactory = factory instanceof SDOFactory ? (SDOFactory) factory : null; - do { - /* - * Modified DataObject - */ - String ref = ref(), unset = reader.getAttributeValue(SDOAnnotations.COMMONJ_SDO_NS, ChangeSummaryStreamSerializer.UNSET); - int attributes = reader.getAttributeCount(); - NamespaceContext nameSpaces = reader.getNamespaceContext(); - EObject referent = referent(ref, nameSpaces); - if (referent == null) { - /* - * Forward-referenced(unresolved) modified DataObject - */ - ForwardReference forwardReference = new ForwardReference(ref, nameSpaces, unset); - if (forwardReferences == null) - forwardReferences = new ArrayList(); - forwardReferences.add(forwardReference); - do // what about xmlns="NS1" a1="qName" xmlns="NS2" a2="qName" ? - { - /* - * Record property old value as attribute for end() - */ - String nameSpace = reader.getAttributeNamespace(--attributes), name = reader.getAttributeLocalName(attributes), value = reader - .getAttributeValue(attributes); - if (nameSpace == null) { - /* - * Local attribute - */ - Attribute attribute = new Attribute(); - attribute.name = name; - attribute.value = value; - if (forwardReference.attributes == null) - forwardReference.attributes = new ArrayList(); - forwardReference.attributes.add(attribute); - } else if (!SDOAnnotations.COMMONJ_SDO_NS.equals(nameSpace) || !ChangeSummaryStreamSerializer.REF_ATTRIBUTE.equals(name) - && !ChangeSummaryStreamSerializer.UNSET.equals(name)) { - /* - * Qualified(global) attribute - */ - QualifiedAttribute attribute = new QualifiedAttribute(); - attribute.name = name; - attribute.value = value; - attribute.nameSpace = nameSpace; - if (forwardReference.qualifiedAttributes == null) - forwardReference.qualifiedAttributes = new ArrayList(); - forwardReference.qualifiedAttributes.add(attribute); - } - } while (attributes != 0); - while (START_ELEMENT == reader.nextTag()) { - /* - * Record property old value as element for end() - */ - Tag tag = new Tag(reader); - if (forwardReference.tags == null) - forwardReference.tags = new ArrayList(); - forwardReference.tags.add(tag); - tag.ref = ref(); - if (tag.ref != null) - continue; - Type xsi = typeXSI(); - if (xsi == null) { - if (tag.nameSpace != null) - tag.value = value(globalElementType(tag.nameSpace, tag.name.getLocalPart())); // TODO substitutionGroup type if null - else if (tag.record(reader)) - break; - } else - tag.value = value(xsi); - } - } else { - /* - * Resolved(back-referenced) modified DataObject - */ - Type type = ((DataObject) referent).getType(); - Collection featureChanges = unsetProperties(referent, unset, type); - do // what about xmlns="NS1" a1="qName" xmlns="NS2" a2="qName" ? - { - /* - * Log property old value as attribute - */ - String nameSpace = reader.getAttributeNamespace(--attributes), name = reader.getAttributeLocalName(attributes), value = reader - .getAttributeValue(attributes); - if (nameSpace == null) - logAttributeChange(featureChanges, name, type, value, nameSpaces); - else if (!SDOAnnotations.COMMONJ_SDO_NS.equals(nameSpace) || !ChangeSummaryStreamSerializer.REF_ATTRIBUTE.equals(name) - && !ChangeSummaryStreamSerializer.UNSET.equals(name)) - logAttributeChange(featureChanges, nameSpace, name, type, value, nameSpaces); - } while (attributes != 0); - if (START_ELEMENT == reader.nextTag()) { - ObjectChanges objectChanges = null; - do { - /* - * Log property old value as element - */ - String nameSpace = reader.getNamespaceURI(), name = reader.getLocalName(); - Property property = getProperty(nameSpace, name, type); - boolean many = property.isMany(); - Object value; - ref = ref(); - if (ref == null) { - /* - * Contained property old value - */ - Type xsi = typeXSI(); - if (xsi != null) - value = value(xsi); - else if (nameSpace == null) - value = value(reader); - else { - xsi = globalElementType(nameSpace, name); - value = value(xsi == null ? propertyInSequence.getType() : xsi); - } - } else { - /* - * Referenced child DataObject - */ - nameSpaces = reader.getNamespaceContext(); - reader.nextTag()/* END_ELEMENT */; - value = referent(ref, nameSpaces); - if (value == null) { - /* - * Forward-referenced(unresolved) child DataObject - */ - if (!many) { - ElementChange elementChange = new ElementChange(ref, nameSpaces, property, propertyInSequence); - if (objectChanges == null) { - objectChanges = newObjectChanges(featureChanges); - objectChanges.newElementChanges(); - } else if (objectChanges.elementChanges == null) - objectChanges.newElementChanges(); - objectChanges.elementChanges.add(elementChange); - continue; - } - value = new Ref(ref, nameSpaces); - } - } - if (many) { - Collection list; - if (objectChanges == null) { - objectChanges = newObjectChanges(featureChanges); - list = objectChanges.newList(property); - } else if (objectChanges.lists == null) - list = objectChanges.newList(property); - else - list = objectChanges.get(property); - addPropertyChange(list, value, property); - } else - logPropertyChange(featureChanges, property, value); - } while (START_ELEMENT == reader.nextTag()); - } - } - } while (START_ELEMENT == reader.nextTag()); - } - } - - static private boolean sequence(Object listChanges) { - return FeatureMapUtil.isFeatureMap(((FeatureChange) ((EStructuralFeature.Setting) listChanges).getEObject()).getFeature()); - } - - private ListChange createListChange(ChangeKind changeKind, int index, Collection listChanges) { - ListChange listChange = changeFactory.createListChange(); - listChange.setKind(changeKind); - listChange.setIndex(index); - listChanges.add(listChange); - return listChange; - } - - Collection add(Collection adds, int change, Collection listChanges, Object value) { - if (adds == null) { - ListChange listChange = createListChange(ChangeKind.ADD_LITERAL, change, listChanges); - adds = sequence(listChanges) ? listChange.getFeatureMapEntryValues() : listChange.getValues(); - } - adds.add(value); - return adds; - } - - private int remove(int change, Collection listChanges, List list, int begin, int end) { - ListChange listChange = createListChange(ChangeKind.REMOVE_LITERAL, change, listChanges); - if (sequence(listChanges)) { - Collection removes = listChange.getFeatureMapEntryValues(); - do { - FeatureMap.Entry fme = (FeatureMap.Entry) list.get(begin); - removes.add(changeFactory.createFeatureMapEntry(fme.getEStructuralFeature(), fme.getValue())); - } while (++begin != end); - return begin; - } - Collection removes = listChange.getValues(); - do - removes.add(list.get(begin)); - while (++begin != end); - return begin; - } - - int remove(int begin, int end, int change, Collection listChanges, List list) { - return begin == end ? begin : remove(change, listChanges, list, begin, end); - } - - protected final void logManyChanges(PropertyMapChanges propertyMapChanges, EObject referent, Collection featureChanges) { - for (Iterator lists = propertyMapChanges.lists.entrySet().iterator(); lists.hasNext();) { - /* - * Compute ListChanges out of comparision of old and new list - */ - Map.Entry entry = (Map.Entry) lists.next(); - EStructuralFeature property = (EStructuralFeature) entry.getKey(); - Iterator values = ((Collection) entry.getValue()).iterator(); // old list - Object value = referent.eGet(property); - List list = value instanceof FeatureMap.Internal.Wrapper ? ((FeatureMap.Internal.Wrapper) value).featureMap() : (List) value; // new - int change = 0; - FeatureChange featureChange = changeSettingFactory == null ? changeFactory.createFeatureChange() : (FeatureChange) changeSettingFactory - .createChangeSummarySetting(); - featureChange.setFeature(property); - Collection listChanges = featureChange.getListChanges(), adds = null; - featureChanges.add(featureChange); - if (property.getEType() instanceof EClass) { - /* - * Log child DataObject changes - */ - int begin = 0, end = list.size(); - while (values.hasNext()) { - value = values.next(); - if (value.getClass() == Ref.class) { - value = referent((Ref) value); - if (value == null) - continue;// report error? - } - // values.remove(); - for (int index = begin;/* true */; ++index) - if (index == end) { - adds = add(adds, change, listChanges, value); - break; - } else if (list.get(index) == value) // List#indexOf uses equals - { - begin = remove(begin, index, change, listChanges, list); - ++begin; - adds = null; - break; - } - ++change; - } - remove(begin, end, change, listChanges, list); - } else if (FeatureMapUtil.isFeatureMap(property)) { - /* - * Log Sequence changes - */ - int begin = 0, end = list.size(); - while (values.hasNext()) { - FeatureMapEntry featureMapEntry = (FeatureMapEntry) values.next(); - value = featureMapEntry.getValue(); - if (value.getClass() == Ref.class) { - value = referent((Ref) value); - if (value == null) - continue;// report error? - } - // values.remove(); - Comparator equality; - ETypedElement feature = featureMapEntry.getFeature(); - if (((Type) feature.getEType()).isDataType()) - if (value == null) - equality = EQUAL_NULL; - else - equality = EQUAL; - else - equality = SAME; - for (int index = begin;/* true */; ++index) - if (index == end) { - adds = add(adds, change, listChanges, featureMapEntry); - break; - } else { - FeatureMap.Entry fme = (FeatureMap.Entry) list.get(index); - if (feature == fme.getEStructuralFeature() && equality.compare(fme.getValue(), value) == 0) { - begin = remove(begin, index, change, listChanges, list); - ++begin; - adds = null; - break; - } - } - ++change; - } - remove(begin, end, change, listChanges, list); - } else { - /* - * Log simple value changes - */ - while (values.hasNext()) { - value = values.next(); - // values.remove(); - int index = list.indexOf(value); - switch (index) { - case -1: - adds = add(adds, change, listChanges, value); - break; - default: - remove(change, listChanges, list, 0, index); - case 0: - list = list.subList(++index, list.size()); - adds = null; - } - ++change; - } - remove(0, list.size(), change, listChanges, list); - } - } - } - - protected PropertyMapChanges propertyMapChanges/* = null */; - - /** - * Imports ChangeSummary 2-2. Resolves forward references from {@link #begin} and resumes logging if necessary. If it's invoked from - * patching/resolving, try to make it last since logging may be turned on. - * - * @see #begin - */ - public final ChangeSummary end() throws XMLStreamException { - if (forwardReferences != null) - for (Iterator iterator = forwardReferences.iterator(); iterator.hasNext();) { - /* - * Forward-referenced(unresolved) modified DataObject from begin(...) - */ - ForwardReference forwardReference = (ForwardReference) iterator.next(); - EObject referent = referent(forwardReference); - if (referent == null) - continue; // report error? - // iterator.remove(); - Type type = ((DataObject) referent).getType(); - Collection featureChanges = unsetProperties(referent, forwardReference.unset, type); - if (forwardReference.attributes != null) - for (Iterator attributes = forwardReference.attributes.iterator(); attributes.hasNext();) { - /* - * Log property old value as local attribute from begin(...) - */ - Attribute attribute = (Attribute) attributes.next(); - logAttributeChange(featureChanges, attribute.name, type, attribute.value, forwardReference.nameSpaces); - } - if (forwardReference.qualifiedAttributes != null) - for (Iterator attributes = forwardReference.qualifiedAttributes.iterator(); attributes.hasNext();) { - /* - * Log property old value as qualified/global attribute from begin(...) - */ - QualifiedAttribute attribute = (QualifiedAttribute) attributes.next(); - logAttributeChange(featureChanges, attribute.nameSpace, attribute.name, type, attribute.value, forwardReference.nameSpaces); - } - if (forwardReference.tags != null) { - if (propertyMapChanges != null) - propertyMapChanges.lists.clear(); - for (Iterator tags = forwardReference.tags.iterator(); tags.hasNext();) { - /* - * Log property old value as element from begin(...) - */ - Tag tag = (Tag) tags.next(); - Property property = getProperty(tag.nameSpace, tag.name.getLocalPart(), type); - if (tag.ref != null) - tag.value = referent(tag.ref, tag.nameSpaceContext); - // if (tag.value == null) report error? - else if (tag.events != null) - tag.value = value(play(tag)); - if (property.isMany()) { - Collection list; - if (propertyMapChanges == null) { - propertyMapChanges = new PropertyMapChanges(); - list = propertyMapChanges.newList(property); - } else - list = propertyMapChanges.get(property); - addPropertyChange( list, tag.value, property); - } else - logPropertyChange(featureChanges, property, tag.value); - } - if (propertyMapChanges != null) - logManyChanges(propertyMapChanges, referent, featureChanges); - } - } - if (objectChangesCollection != null) - for (Iterator iterator = objectChangesCollection.iterator(); iterator.hasNext();) { - /* - * Forward-referenced(unresolved) child DataObject from begin(...) - */ - ObjectChanges objectChanges = (ObjectChanges) iterator.next(); - if (objectChanges.elementChanges != null) - for (Iterator elementChanges = objectChanges.elementChanges.iterator(); elementChanges.hasNext();) { - ElementChange elementChange = (ElementChange) elementChanges.next(); - Object value = referent(elementChange); - if (value == null) - continue; // report error? - // iterator.remove(); - logPropertyChange(objectChanges.featureChanges, elementChange.containing, elementChange.containment, value); - } - if (objectChanges.lists != null) - logManyChanges(objectChanges, (EObject) ((Map.Entry) ((EStructuralFeature.Setting) objectChanges.featureChanges).getEObject()) - .getKey(), objectChanges.featureChanges); - } - if (logging) - changeSummary.resumeLogging(); - return changeSummary; - } -} +/** + * + * 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.util.resource; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sdo.SDOFactory; +import org.apache.tuscany.sdo.helper.SDOAnnotations; +import org.apache.tuscany.sdo.impl.ChangeSummaryImpl; +import org.apache.tuscany.sdo.impl.ClassImpl; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.ETypedElement; +import org.eclipse.emf.ecore.change.ChangeDescription; +import org.eclipse.emf.ecore.change.ChangeFactory; +import org.eclipse.emf.ecore.change.ChangeKind; +import org.eclipse.emf.ecore.change.FeatureChange; +import org.eclipse.emf.ecore.change.FeatureMapEntry; +import org.eclipse.emf.ecore.change.ListChange; +import org.eclipse.emf.ecore.util.FeatureMap; +import org.eclipse.emf.ecore.util.FeatureMapUtil; + +import commonj.sdo.ChangeSummary; +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; + +/** + * ChangeSummary StAX Deserializer whose input conforms to the SDO Java/C++/PHP specifications. The instance isn't thread-safe, however it's safe to + * use the instance any times on the same thread. + */ +public class ChangeSummaryStreamDeserializer extends SDODeserializer { + static final class ForwardReference extends Ref { + final String unset; + + ForwardReference(String ref, NamespaceContext nameSpaces, String u) { + super(ref, nameSpaces); + unset = u; + } + + Collection attributes/* = null */, qualifiedAttributes/* = null */, tags/* = null */; // may be null, never empty + } + + protected Collection forwardReferences/* = null */; + + static private final class ElementChange extends Ref { + private final Object containing, containment; + private ElementChange(String ref, NamespaceContext nameSpaces, Object property, Object propertyInSequence) { + super(ref, nameSpaces); + containing = property; + containment = propertyInSequence; + } + } + + static private class PropertyMapChanges { + Map/* Property,List */lists/* = null */;// may be null + + Collection put(Object property) { + Collection list = new ArrayList(); + lists.put(property, list); + return list; + } + + protected final Collection get(Object property) { + Object list = lists.get(property); + return list == null ? put(property) : (Collection) list; + } + + protected final Collection newList(Object property) { + lists = new HashMap(); + return put(property); + } + } + + static final class ObjectChanges extends PropertyMapChanges { + Collection elementChanges/* = null */,// may be null, never empty + featureChanges; + + protected final void newElementChanges() { + elementChanges = new ArrayList(); + } + } + + Collection objectChangesCollection/* = null */, objectMapChanges, deletedDataObjects; + + protected final ObjectChanges newObjectChanges(Collection featureChanges) { + ObjectChanges objectChanges = new ObjectChanges(); + objectChanges.featureChanges = featureChanges; + if (objectChangesCollection == null) + objectChangesCollection = new ArrayList(); + objectChangesCollection.add(objectChanges); + return objectChanges; + } + + private ChangeFactory changeFactory; + + private SDOFactory changeSettingFactory; + + private void logPropertyChange(Collection featureChanges, EStructuralFeature feature, Object value, boolean set) { + if (changeSettingFactory == null) + featureChanges.add(changeFactory.createFeatureChange(feature, value, set)); + else + featureChanges.add(changeSettingFactory.createChangeSummarySetting(feature, value, set)); + } + + void unsetProperty(Collection featureChanges, String unset, int begin, int index, Type type) { + logPropertyChange(featureChanges, (EStructuralFeature) type.getProperty(unset.substring(begin, index)), null, false); + } + + static boolean isWhitespace(String unset, int index) { + return Character.isWhitespace(unset.charAt(index)); + } + + protected final Collection unsetProperties(EObject referent, String unset, Type type) { + Map.Entry entry = changeFactory.createEObjectToChangesMapEntry(referent); + objectMapChanges.add(entry); + Collection featureChanges = (Collection) entry.getValue(); + if (unset == null) + return featureChanges; + int end = unset.length(); + if (end != 0) + for (int begin = 0, index = 1;/* true */; ++index) { + if (index == end) { + unsetProperty(featureChanges, unset, begin, index, type); + break; + } + if (isWhitespace(unset, index)) { + unsetProperty(featureChanges, unset, begin, index, type); + while (true) { + if (++index != end) + return featureChanges; + if (!isWhitespace(unset, index)) { + begin = index; + break; + } + } + } + } + return featureChanges; + } + + private Object value(EStructuralFeature containing, Object containment, Object value) { + return FeatureMapUtil.isFeatureMap(containing) ? changeFactory.createFeatureMapEntry((EStructuralFeature) containment, value) : value; + } + + private void logPropertyChange(Collection featureChanges, Object containing, Object containment, Object value) { + EStructuralFeature feature = (EStructuralFeature) containing; + logPropertyChange(featureChanges, feature, value(feature, containment, value), true); + } + + private void logPropertyChange(Collection featureChanges, Object property, Object value) { + logPropertyChange(featureChanges, property, propertyInSequence, value); + } + + void logAttributeChange(Collection featureChanges, Property property, String literal, NamespaceContext nameSpaces) { + logPropertyChange(featureChanges, property, value(property.getType(), literal, nameSpaces)); + } + + protected final void logAttributeChange(Collection featureChanges, String property, Type type, String value, NamespaceContext nameSpaces) { + logAttributeChange(featureChanges, getProperty(type, property), value, nameSpaces); + } + + protected final void logAttributeChange(Collection featureChanges, String nameSpace, String name, Type type, String value, + NamespaceContext nameSpaces) { + logAttributeChange(featureChanges, getProperty(type, nameSpace, name, false), value, nameSpaces); + } + + protected final String ref() { + return reader.getAttributeValue(SDOAnnotations.COMMONJ_SDO_NS, ChangeSummaryStreamSerializer.REF_ATTRIBUTE); + } + + ChangeSummaryImpl changeSummary; + + protected Object load(XMLStreamReader reader, Map options) throws XMLStreamException { + Object value = super.load(reader, options); + deletedDataObjects.add(value); + return value; + } + + protected final void getChangeSummary(DataObject rootObject) { + changeSummary = (ChangeSummaryImpl) rootObject.getChangeSummary(); // DynamicDataObjectImpl(EClass) + } + + static protected final class Tag extends RecordedEventXMLStreamReader.Tag { + protected String ref; + + protected Object value; + + protected Tag(XMLStreamReader reader) { + super(reader); + } + } + + protected final void addPropertyChange(Collection list, Object value, Object containing) { + list.add(value((EStructuralFeature) containing, propertyInSequence, value)); + } + + protected boolean logging; + + /** + * Imports ChangeSummary 2-1. Forward references will be resolved by {@link #end()}. + * + * @param reader + * Never null + * @throws XMLStreamException + */ + public final void begin(DataObject rootObject, HelperContext scope, XMLStreamReader reader) throws XMLStreamException { + /* + * 3-1. Instantiate ChangeSummary input: reader (xsi:type), factory, rootObject output: changeSummary, changeDescription + */ + initialize(reader, scope, rootObject); + if (typedXSI()) { + changeSummary = (ChangeSummaryImpl) scope.getDataFactory().create(nameSpace, name); + if (changeSummary == null) + getChangeSummary(rootObject); + else { + Property csp = ((ClassImpl) rootObject.getType()).getChangeSummaryProperty(); + rootObject.set(csp, changeSummary); + changeSummary.setDataObject(rootObject); + } + } else + getChangeSummary(rootObject); + ChangeDescription changeDescription = (ChangeDescription) changeSummary; + + /* + * 3-2. "logging" attribute input: reader output: logging + */ + logging = Boolean.valueOf(reader.getAttributeValue(null, "logging")).booleanValue(); + + /* + * 3-3. Modified DataObjects input: changeDescription + */ + if (forwardReferences != null) + forwardReferences.clear(); + if (objectChangesCollection != null) + objectChangesCollection.clear(); + if (START_ELEMENT == reader.nextTag()) { + objectMapChanges = changeDescription.getObjectChanges(); + deletedDataObjects = changeDescription.getObjectsToAttach(); + Object factory = changeDescription.eClass().getEPackage().getEFactoryInstance(); + changeFactory = factory instanceof ChangeFactory ? (ChangeFactory) factory : ChangeFactory.eINSTANCE; + changeSettingFactory = factory instanceof SDOFactory ? (SDOFactory) factory : null; + do { + /* + * Modified DataObject + */ + String ref = ref(), unset = reader.getAttributeValue(SDOAnnotations.COMMONJ_SDO_NS, ChangeSummaryStreamSerializer.UNSET); + int attributes = reader.getAttributeCount(); + NamespaceContext nameSpaces = reader.getNamespaceContext(); + EObject referent = referent(ref, nameSpaces); + if (referent == null) { + /* + * Forward-referenced(unresolved) modified DataObject + */ + ForwardReference forwardReference = new ForwardReference(ref, nameSpaces, unset); + if (forwardReferences == null) + forwardReferences = new ArrayList(); + forwardReferences.add(forwardReference); + do // what about xmlns="NS1" a1="qName" xmlns="NS2" a2="qName" ? + { + /* + * Record property old value as attribute for end() + */ + String nameSpace = reader.getAttributeNamespace(--attributes), name = reader.getAttributeLocalName(attributes), value = reader + .getAttributeValue(attributes); + if (nameSpace == null) { + /* + * Local attribute + */ + Attribute attribute = new Attribute(); + attribute.name = name; + attribute.value = value; + if (forwardReference.attributes == null) + forwardReference.attributes = new ArrayList(); + forwardReference.attributes.add(attribute); + } else if (!SDOAnnotations.COMMONJ_SDO_NS.equals(nameSpace) || !ChangeSummaryStreamSerializer.REF_ATTRIBUTE.equals(name) + && !ChangeSummaryStreamSerializer.UNSET.equals(name)) { + /* + * Qualified(global) attribute + */ + QualifiedAttribute attribute = new QualifiedAttribute(); + attribute.name = name; + attribute.value = value; + attribute.nameSpace = nameSpace; + if (forwardReference.qualifiedAttributes == null) + forwardReference.qualifiedAttributes = new ArrayList(); + forwardReference.qualifiedAttributes.add(attribute); + } + } while (attributes != 0); + while (START_ELEMENT == reader.nextTag()) { + /* + * Record property old value as element for end() + */ + Tag tag = new Tag(reader); + if (forwardReference.tags == null) + forwardReference.tags = new ArrayList(); + forwardReference.tags.add(tag); + tag.ref = ref(); + if (tag.ref != null) + continue; + Type xsi = typeXSI(); + if (xsi == null) { + if (tag.nameSpace != null) + tag.value = value(globalElementType(tag.nameSpace, tag.name.getLocalPart())); // TODO substitutionGroup type if null + else if (tag.record(reader)) + break; + } else + tag.value = value(xsi); + } + } else { + /* + * Resolved(back-referenced) modified DataObject + */ + Type type = ((DataObject) referent).getType(); + Collection featureChanges = unsetProperties(referent, unset, type); + do // what about xmlns="NS1" a1="qName" xmlns="NS2" a2="qName" ? + { + /* + * Log property old value as attribute + */ + String nameSpace = reader.getAttributeNamespace(--attributes), name = reader.getAttributeLocalName(attributes), value = reader + .getAttributeValue(attributes); + if (nameSpace == null) + logAttributeChange(featureChanges, name, type, value, nameSpaces); + else if (!SDOAnnotations.COMMONJ_SDO_NS.equals(nameSpace) || !ChangeSummaryStreamSerializer.REF_ATTRIBUTE.equals(name) + && !ChangeSummaryStreamSerializer.UNSET.equals(name)) + logAttributeChange(featureChanges, nameSpace, name, type, value, nameSpaces); + } while (attributes != 0); + if (START_ELEMENT == reader.nextTag()) { + ObjectChanges objectChanges = null; + do { + /* + * Log property old value as element + */ + String nameSpace = reader.getNamespaceURI(), name = reader.getLocalName(); + Property property = getProperty(nameSpace, name, type); + boolean many = property.isMany(); + Object value; + ref = ref(); + if (ref == null) { + /* + * Contained property old value + */ + Type xsi = typeXSI(); + if (xsi != null) + value = value(xsi); + else if (nameSpace == null) + value = value(reader); + else { + xsi = globalElementType(nameSpace, name); + value = value(xsi == null ? propertyInSequence.getType() : xsi); + } + } else { + /* + * Referenced child DataObject + */ + nameSpaces = reader.getNamespaceContext(); + reader.nextTag()/* END_ELEMENT */; + value = referent(ref, nameSpaces); + if (value == null) { + /* + * Forward-referenced(unresolved) child DataObject + */ + if (!many) { + ElementChange elementChange = new ElementChange(ref, nameSpaces, property, propertyInSequence); + if (objectChanges == null) { + objectChanges = newObjectChanges(featureChanges); + objectChanges.newElementChanges(); + } else if (objectChanges.elementChanges == null) + objectChanges.newElementChanges(); + objectChanges.elementChanges.add(elementChange); + continue; + } + value = new Ref(ref, nameSpaces); + } + } + if (many) { + Collection list; + if (objectChanges == null) { + objectChanges = newObjectChanges(featureChanges); + list = objectChanges.newList(property); + } else if (objectChanges.lists == null) + list = objectChanges.newList(property); + else + list = objectChanges.get(property); + addPropertyChange(list, value, property); + } else + logPropertyChange(featureChanges, property, value); + } while (START_ELEMENT == reader.nextTag()); + } + } + } while (START_ELEMENT == reader.nextTag()); + } + } + + static private boolean sequence(Object listChanges) { + return FeatureMapUtil.isFeatureMap(((FeatureChange) ((EStructuralFeature.Setting) listChanges).getEObject()).getFeature()); + } + + private ListChange createListChange(ChangeKind changeKind, int index, Collection listChanges) { + ListChange listChange = changeFactory.createListChange(); + listChange.setKind(changeKind); + listChange.setIndex(index); + listChanges.add(listChange); + return listChange; + } + + Collection add(Collection adds, int change, Collection listChanges, Object value) { + if (adds == null) { + ListChange listChange = createListChange(ChangeKind.ADD_LITERAL, change, listChanges); + adds = sequence(listChanges) ? listChange.getFeatureMapEntryValues() : listChange.getValues(); + } + adds.add(value); + return adds; + } + + private int remove(int change, Collection listChanges, List list, int begin, int end) { + ListChange listChange = createListChange(ChangeKind.REMOVE_LITERAL, change, listChanges); + if (sequence(listChanges)) { + Collection removes = listChange.getFeatureMapEntryValues(); + do { + FeatureMap.Entry fme = (FeatureMap.Entry) list.get(begin); + removes.add(changeFactory.createFeatureMapEntry(fme.getEStructuralFeature(), fme.getValue())); + } while (++begin != end); + return begin; + } + Collection removes = listChange.getValues(); + do + removes.add(list.get(begin)); + while (++begin != end); + return begin; + } + + int remove(int begin, int end, int change, Collection listChanges, List list) { + return begin == end ? begin : remove(change, listChanges, list, begin, end); + } + + protected final void logManyChanges(PropertyMapChanges propertyMapChanges, EObject referent, Collection featureChanges) { + for (Iterator lists = propertyMapChanges.lists.entrySet().iterator(); lists.hasNext();) { + /* + * Compute ListChanges out of comparision of old and new list + */ + Map.Entry entry = (Map.Entry) lists.next(); + EStructuralFeature property = (EStructuralFeature) entry.getKey(); + Iterator values = ((Collection) entry.getValue()).iterator(); // old list + Object value = referent.eGet(property); + List list = value instanceof FeatureMap.Internal.Wrapper ? ((FeatureMap.Internal.Wrapper) value).featureMap() : (List) value; // new + int change = 0; + FeatureChange featureChange = changeSettingFactory == null ? changeFactory.createFeatureChange() : (FeatureChange) changeSettingFactory + .createChangeSummarySetting(); + featureChange.setFeature(property); + Collection listChanges = featureChange.getListChanges(), adds = null; + featureChanges.add(featureChange); + if (property.getEType() instanceof EClass) { + /* + * Log child DataObject changes + */ + int begin = 0, end = list.size(); + while (values.hasNext()) { + value = values.next(); + if (value.getClass() == Ref.class) { + value = referent((Ref) value); + if (value == null) + continue;// report error? + } + // values.remove(); + for (int index = begin;/* true */; ++index) + if (index == end) { + adds = add(adds, change, listChanges, value); + break; + } else if (list.get(index) == value) // List#indexOf uses equals + { + begin = remove(begin, index, change, listChanges, list); + ++begin; + adds = null; + break; + } + ++change; + } + remove(begin, end, change, listChanges, list); + } else if (FeatureMapUtil.isFeatureMap(property)) { + /* + * Log Sequence changes + */ + int begin = 0, end = list.size(); + while (values.hasNext()) { + FeatureMapEntry featureMapEntry = (FeatureMapEntry) values.next(); + value = featureMapEntry.getValue(); + if (value.getClass() == Ref.class) { + value = referent((Ref) value); + if (value == null) + continue;// report error? + } + // values.remove(); + Comparator equality; + ETypedElement feature = featureMapEntry.getFeature(); + if (((Type) feature.getEType()).isDataType()) + if (value == null) + equality = EQUAL_NULL; + else + equality = EQUAL; + else + equality = SAME; + for (int index = begin;/* true */; ++index) + if (index == end) { + adds = add(adds, change, listChanges, featureMapEntry); + break; + } else { + FeatureMap.Entry fme = (FeatureMap.Entry) list.get(index); + if (feature == fme.getEStructuralFeature() && equality.compare(fme.getValue(), value) == 0) { + begin = remove(begin, index, change, listChanges, list); + ++begin; + adds = null; + break; + } + } + ++change; + } + remove(begin, end, change, listChanges, list); + } else { + /* + * Log simple value changes + */ + while (values.hasNext()) { + value = values.next(); + // values.remove(); + int index = list.indexOf(value); + switch (index) { + case -1: + adds = add(adds, change, listChanges, value); + break; + default: + remove(change, listChanges, list, 0, index); + case 0: + list = list.subList(++index, list.size()); + adds = null; + } + ++change; + } + remove(0, list.size(), change, listChanges, list); + } + } + } + + protected PropertyMapChanges propertyMapChanges/* = null */; + + /** + * Imports ChangeSummary 2-2. Resolves forward references from {@link #begin} and resumes logging if necessary. If it's invoked from + * patching/resolving, try to make it last since logging may be turned on. + * + * @see #begin + */ + public final ChangeSummary end() throws XMLStreamException { + if (forwardReferences != null) + for (Iterator iterator = forwardReferences.iterator(); iterator.hasNext();) { + /* + * Forward-referenced(unresolved) modified DataObject from begin(...) + */ + ForwardReference forwardReference = (ForwardReference) iterator.next(); + EObject referent = referent(forwardReference); + if (referent == null) + continue; // report error? + // iterator.remove(); + Type type = ((DataObject) referent).getType(); + Collection featureChanges = unsetProperties(referent, forwardReference.unset, type); + if (forwardReference.attributes != null) + for (Iterator attributes = forwardReference.attributes.iterator(); attributes.hasNext();) { + /* + * Log property old value as local attribute from begin(...) + */ + Attribute attribute = (Attribute) attributes.next(); + logAttributeChange(featureChanges, attribute.name, type, attribute.value, forwardReference.nameSpaces); + } + if (forwardReference.qualifiedAttributes != null) + for (Iterator attributes = forwardReference.qualifiedAttributes.iterator(); attributes.hasNext();) { + /* + * Log property old value as qualified/global attribute from begin(...) + */ + QualifiedAttribute attribute = (QualifiedAttribute) attributes.next(); + logAttributeChange(featureChanges, attribute.nameSpace, attribute.name, type, attribute.value, forwardReference.nameSpaces); + } + if (forwardReference.tags != null) { + if (propertyMapChanges != null) + propertyMapChanges.lists.clear(); + for (Iterator tags = forwardReference.tags.iterator(); tags.hasNext();) { + /* + * Log property old value as element from begin(...) + */ + Tag tag = (Tag) tags.next(); + Property property = getProperty(tag.nameSpace, tag.name.getLocalPart(), type); + if (tag.ref != null) + tag.value = referent(tag.ref, tag.nameSpaceContext); + // if (tag.value == null) report error? + else if (tag.events != null) + tag.value = value(play(tag)); + if (property.isMany()) { + Collection list; + if (propertyMapChanges == null) { + propertyMapChanges = new PropertyMapChanges(); + list = propertyMapChanges.newList(property); + } else + list = propertyMapChanges.get(property); + addPropertyChange( list, tag.value, property); + } else + logPropertyChange(featureChanges, property, tag.value); + } + if (propertyMapChanges != null) + logManyChanges(propertyMapChanges, referent, featureChanges); + } + } + if (objectChangesCollection != null) + for (Iterator iterator = objectChangesCollection.iterator(); iterator.hasNext();) { + /* + * Forward-referenced(unresolved) child DataObject from begin(...) + */ + ObjectChanges objectChanges = (ObjectChanges) iterator.next(); + if (objectChanges.elementChanges != null) + for (Iterator elementChanges = objectChanges.elementChanges.iterator(); elementChanges.hasNext();) { + ElementChange elementChange = (ElementChange) elementChanges.next(); + Object value = referent(elementChange); + if (value == null) + continue; // report error? + // iterator.remove(); + logPropertyChange(objectChanges.featureChanges, elementChange.containing, elementChange.containment, value); + } + if (objectChanges.lists != null) + logManyChanges(objectChanges, (EObject) ((Map.Entry) ((EStructuralFeature.Setting) objectChanges.featureChanges).getEObject()) + .getKey(), objectChanges.featureChanges); + } + if (logging) + changeSummary.resumeLogging(); + return changeSummary; + } +} diff --git a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/ChangeSummaryStreamSerializer.java b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/ChangeSummaryStreamSerializer.java index bb598bea54..ef5af8ab57 100644 --- a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/ChangeSummaryStreamSerializer.java +++ b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/ChangeSummaryStreamSerializer.java @@ -1,690 +1,690 @@ -/** - * - * 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.util.resource; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import javax.xml.namespace.NamespaceContext; -import javax.xml.namespace.QName; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; - -import org.apache.tuscany.sdo.SDOPackage; -import org.apache.tuscany.sdo.helper.HelperContextImpl; -import org.apache.tuscany.sdo.helper.SDOAnnotations; -import org.apache.tuscany.sdo.helper.XSDHelperImpl; -import org.apache.tuscany.sdo.impl.ChangeSummaryImpl; -import org.apache.tuscany.sdo.model.ModelFactory; -import org.apache.tuscany.sdo.model.impl.ModelFactoryImpl; -import org.apache.tuscany.sdo.util.SDOUtil; -import org.eclipse.emf.common.util.EMap; -import org.eclipse.emf.ecore.EClassifier; -import org.eclipse.emf.ecore.EDataType; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecore.change.ChangeDescription; -import org.eclipse.emf.ecore.change.ChangeKind; -import org.eclipse.emf.ecore.change.FeatureChange; -import org.eclipse.emf.ecore.change.ListChange; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.emf.ecore.util.ExtendedMetaData; -import org.eclipse.emf.ecore.util.FeatureMap; -import org.eclipse.emf.ecore.util.FeatureMapUtil; -import org.eclipse.emf.ecore.xmi.XMLResource; - -import commonj.sdo.ChangeSummary; -import commonj.sdo.DataObject; -import commonj.sdo.Property; -import commonj.sdo.helper.XSDHelper; - -/** - * ChangeSummary StAX Serializer whose output conforms to the SDO Java/C++/PHP specifications. The instance isn't thread-safe, however it's safe to - * use the instance any times on the same thread. - */ -public class ChangeSummaryStreamSerializer { - private XMLStreamWriter writer; - - private String writeNamespace(String prefix, String nameSpace) throws XMLStreamException { - writer.writeNamespace(prefix, nameSpace); - writer.setPrefix(prefix, nameSpace); - return prefix; - } - - private int nsPrefixSuffix; - - private String prefix(String nameSpace, String preference) throws XMLStreamException { - if (preference != null) { - String bound = writer.getNamespaceContext().getNamespaceURI(preference); - if (bound == null) { - String prefix = writer.getPrefix(nameSpace); - return prefix == null ? writeNamespace(preference, nameSpace) : prefix/* or null */; - } - if (bound.equals(nameSpace)) - return preference; - } - Object automaticNsPrefix = writer.getProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES); - if (automaticNsPrefix != null && automaticNsPrefix.getClass() == Boolean.class // faster than instanceof since Boolean is final - && ((Boolean) automaticNsPrefix).booleanValue()) - return null; - String prefix = writer.getPrefix(nameSpace); - if (prefix != null) - return prefix; // or null - NamespaceContext nameSpaces = writer.getNamespaceContext(); - do - prefix = "CS" + nsPrefixSuffix++; - while (nameSpaces.getNamespaceURI(prefix) != null); - return writeNamespace(prefix, nameSpace); - } - - void writeGlobalAttribute(String prefix, String nameSpace, String name, String value) throws XMLStreamException { - prefix = prefix(nameSpace, prefix); - if (prefix == null) - writer.writeAttribute(nameSpace, name, value); - else - writer.writeAttribute(prefix, nameSpace, name, value); - } - - XSDHelper xsdHelper; - - protected final void writeAttribute(Property property, String value) throws XMLStreamException { - String name = xsdHelper.getLocalName(property), nameSpace = xsdHelper.getNamespaceURI(property); - // TODO "" for no-NameSpace global attribute - if (nameSpace == null) - writer.writeAttribute(name, value); - else - writeGlobalAttribute(null, nameSpace, name, value); - } - - private String lineBreak, indent, margin; - - private int nest; - - private void breakLine() throws XMLStreamException { - writer.writeCharacters(lineBreak); - - if (margin != null) - writer.writeCharacters(margin); - - if (indent != null) - for (int count = nest; count != 0; --count) - writer.writeCharacters(indent); - } - - private Map options; - - static private final String STRING_OPTION = "String option"; - - void startElement() throws XMLStreamException { - if (options == null) - return; - if (lineBreak == STRING_OPTION) - lineBreak = (String) options.get(SDOUtil.XML_SAVE_LineBreak); - if (lineBreak == null) - return; - if (margin == STRING_OPTION) - margin = (String) options.get(SDOUtil.XML_SAVE_MARGIN); - if (indent == STRING_OPTION) - indent = (String) options.get(SDOUtil.XML_SAVE_INDENT); - breakLine(); - } - - void writeStartElement(String prefix, String nameSpace, String name) throws XMLStreamException { - startElement(); - if (nameSpace == null) - writer.writeStartElement(name); - else { - prefix = prefix(nameSpace, prefix); - if (prefix == null) - writer.writeStartElement(nameSpace, name); - else - writer.writeStartElement(prefix, name, nameSpace); - } - } - - void writeStartElement(Property property) throws XMLStreamException { - ++nest; - writeStartElement(null, xsdHelper.getNamespaceURI(property),// TODO "" for no-NameSpace global element - xsdHelper.getLocalName(property)); - } - - static protected final String CREATE_ATTRIBUTE = "create", DELETE_ATTRIBUTE = "delete", LOGGING_ATTRIBUTE = "logging", REF_ATTRIBUTE = "ref", UNSET = "unset"; - - private StringBuffer step(String nameSpace, String name, StringBuffer path) throws XMLStreamException { - if (nameSpace != null) { - nameSpace = writer.getPrefix(nameSpace); - if (nameSpace != null && nameSpace.length() != 0) - return path.append(nameSpace).append(':').append(name); // *:name[namespace-uri()='nameSpace'] - } - return path.append(name); - } - - private StringBuffer step(Property containmentProperty, StringBuffer path) throws XMLStreamException { - return step(xsdHelper.getNamespaceURI(containmentProperty),// TODO "" for no-NameSpace global element - xsdHelper.getLocalName(containmentProperty), path); - } - - private StringBuffer step(Property containmentProperty) throws XMLStreamException { - return step(containmentProperty, new StringBuffer()); - } - - private DataObject dataObject; - - private StringBuffer step(Object container) throws XMLStreamException { - Property containmentProperty = dataObject.getContainmentProperty(); - StringBuffer step = step(containmentProperty); - if (containmentProperty.isMany() || ((EObject) dataObject).eContainingFeature() != containmentProperty) - step.append('[').append(((DataObject) container).getList(containmentProperty).indexOf(dataObject) + 1).append(']'); - return step; - } - - private String pathRootObject; - private DataObject rootObject; - - private EObject container(EObject object) { - final EObject container = object.eContainer(); - if (!(container instanceof DataObject)) - return null; - String name = extendedMetaData.getName(container.eClass()); - return name != null && name.length() == 0 // DocumentRoot - ? null : container; - } - - private String path() throws XMLStreamException { - if (pathRootObject == STRING_OPTION) - pathRootObject = options == null ? null : (String) options.get(OPTION_RootObject_PATH); - if (pathRootObject != null && dataObject == rootObject) - return null; - EObject container = container((EObject) dataObject); - if (container == null) - return null; - StringBuffer step = step(container); - while (true) { - String path = step.toString(); - dataObject = (DataObject) container; - if (pathRootObject != null && container == rootObject) - return path; - container = container(container); - if (container == null) - return path; - step = step(container).append('/').append(path); - } - } - - /* - * not to support DataGraph 3-1 private org.eclipse.emf.ecore.resource.Resource rootResource; - */ - - protected String rootElementNS; - - String rootElementName; - - ExtendedMetaData extendedMetaData; - - protected final String rootElementName() { - if (rootElementNS != null) - return rootElementName; - QName rootElement = (QName) options.get(OPTION_ROOT_ELEMENT); - if (rootElement != null) { - rootElementNS = rootElement.getNamespaceURI(); - return rootElementName = rootElement.getLocalPart(); - } - EStructuralFeature element = ((EObject) rootObject).eContainingFeature(); - if (element == null) { - rootElementNS = ""; - return rootElementName = "descendant-or-self::node()"; - } - rootElementNS = extendedMetaData.getNamespace(element); - if (rootElementNS == null) - rootElementNS = ""; - return rootElementName = extendedMetaData.getName(element); - } - - String ref() throws XMLStreamException { - /* - * not to support DataGraph 3-2 if (rootResource != null) return rootResource.getURIFragment((EObject) dataObject); - */ - String id = EcoreUtil.getID((EObject) dataObject); - if (id != null) - return id; - id = path(); - if (pathRootObject == null) - return id == null ? "#/" + rootElementName() // descendant-or-self::node() - : "#//" + id; - return id == null ? pathRootObject/* + "."*/ : pathRootObject + id; - } - - void writeRef(String ref) throws XMLStreamException { - writer.writeAttribute(SDOAnnotations.COMMONJ_SDO_NS, REF_ATTRIBUTE, ref); - } - - void writeRef() throws XMLStreamException { - writeRef(ref()); - } - - void writeEndElement(String lineBreak) throws XMLStreamException { - if (lineBreak != null) - breakLine(); - writer.writeEndElement(); - --nest; - } - - private StringBuffer pathDeleted/* = null */; - - private Collection modifiedDataObjects; - - private int lengthDeleted; - - private String changeSummaryElementNS, changeSummaryElementName; - - private ChangeSummary changeSummary; - - protected boolean skipDeletedModification(DataObject modifiedDataObject) { - return changeSummary.isDeleted(modifiedDataObject); - } - - String refDeleted() throws XMLStreamException { - String id = EcoreUtil.getID((EObject) dataObject); - if (id != null) - return id; - id = path(); // "dataObject" is updated too!! - DataObject deletedDataObject = dataObject; - - /* - * construct "#//...changeSummary/" - * output: pathDeleted - */ - if (lengthDeleted == -1) { - String path = pathRootObject == null ? "#//" : pathRootObject; - if (pathDeleted == null) - pathDeleted = new StringBuffer(path); - else - pathDeleted.replace(0, pathDeleted.length(), path); - dataObject = rootObject; - path = path(); - if (path != null) - pathDeleted.append(path).append('/'); - step(changeSummaryElementNS, changeSummaryElementName, pathDeleted).append('/'); - lengthDeleted = pathDeleted.length(); - } else - pathDeleted.delete(lengthDeleted, pathDeleted.length()); - - dataObject = changeSummary.getOldContainer(deletedDataObject); - Property containmentProperty = dataObject.getContainmentProperty(); - String name = containmentProperty == null ? rootElementName() : xsdHelper.getLocalName(containmentProperty); - int index = 1; - for (Iterator iterator = modifiedDataObjects.iterator(); iterator.hasNext();) { - DataObject modifiedDataObject = (DataObject) iterator.next(); - if (skipDeletedModification(modifiedDataObject)) - continue; - if (modifiedDataObject == dataObject) - break; - Property property = modifiedDataObject.getContainmentProperty(); - if (property == containmentProperty || name.equals(property == null ? rootElementName() : xsdHelper.getLocalName(property))) - ++index; - } - pathDeleted/*.append("*:")*/.append(name).append('[').append(index).append("]/"); - containmentProperty = changeSummary.getOldContainmentProperty(deletedDataObject); - // assert containmentProperty != null; - step(containmentProperty, pathDeleted); - Object f; - if (containmentProperty.isMany() - || (f = extendedMetaData.getAffiliation(((EObject) dataObject).eClass(), (EStructuralFeature) containmentProperty)) != null - && f != containmentProperty) - pathDeleted.append('[').append( - ((List) changeSummary.getOldValue(dataObject, containmentProperty).getValue()).indexOf(deletedDataObject) + 1).append(']'); - if (id != null) - pathDeleted.append('/').append(id); - return pathDeleted.toString(); - } - - static String convertToString(Property property, Object value) { - return EcoreUtil.convertToString((EDataType) property.getType(), value); - } - - void writeRefDeleted() throws XMLStreamException { - writeRef(refDeleted()); - } - - protected final void writeDeletedObject(Property property) throws XMLStreamException { - ++nest; - startElement(); - --nest; - DataObject oldDataObject = ((ChangeSummaryImpl)changeSummary).getOldDataObject(dataObject); - XMLStreamReader reader = new DataObjectXMLStreamReader(property, oldDataObject, null, xsdHelper); - new XMLStreamSerializer().serialize(new XMLDocumentStreamReader(reader), writer); - } - - static public final Object ChangeSummary_TYPE = ((ModelFactoryImpl) ModelFactory.INSTANCE).getChangeSummaryType(); - - Collection deletedDataObjects; - - protected final void writeElement(Object value, Property property) throws XMLStreamException { - if (value == null) { - writeStartElement(property); - writeGlobalAttribute(ExtendedMetaData.XSI_PREFIX, ExtendedMetaData.XSI_URI, XMLResource.NIL, "true"); - writeEndElement(null); - } else if (value instanceof DataObject) { - dataObject = (DataObject) value; - if (!changeSummary.isDeleted(dataObject)) { - writeStartElement(property); - writeRef(); - writeEndElement(null); - } else if (property.isContainment() && deletedDataObjects.contains(dataObject)) { - writeDeletedObject(property); - } else { - writeStartElement(property); - writeRefDeleted(); - writeEndElement(null); - } - } else { - Object type = property.getType(); - if (type == ChangeSummary_TYPE) - return; - writeStartElement(property); - writer.writeCharacters(EcoreUtil.convertToString((EDataType) type, value)); - writeEndElement(null); - } - } - - protected final void writeElement(Object value) throws XMLStreamException { - FeatureMap.Entry entry = (FeatureMap.Entry) value; - writeElement(entry.getValue(), (Property)entry.getEStructuralFeature()); - } - - static protected List optimize(List values, Object featureChange, int size) { - int fromIndex = size, toIndex = 0; - for (Iterator changes = ((FeatureChange) featureChange).getListChanges().iterator(); changes.hasNext();) { - ListChange change = (ListChange) changes.next(); - Object kind = change.getKind(); - if (kind == ChangeKind.MOVE_LITERAL) - return values; - int index = change.getIndex(); - if (kind == ChangeKind.ADD_LITERAL) { - if (index == 0) { - fromIndex = 0; - if (toIndex == 0) - toIndex = 1; - } else { - int to = index; - if (--index < fromIndex) - fromIndex = index; - if (++to > toIndex) - toIndex = to; - else if (to < toIndex) - ++toIndex; - } - ++size; - } else { - --size; - if (index < fromIndex) - fromIndex = index; - if (index < toIndex) - --toIndex; - else if (index > toIndex && index != size) - toIndex = index; - } - } - return values.subList(fromIndex, toIndex); - } - - static protected final Object CHANGE_SUMMARY = SDOPackage.eINSTANCE.getChangeSummary(); - - /** - * Root Object path String such as "#", etc. Absent/null is the default (automatic computation) - */ - static public final String OPTION_RootObject_PATH = "RootObject path", - /** - * Boolean to optimize sequence/list/array. Absent/null/Boolean.FALSE is the default (no optimization) - */ - OPTION_OPTIMIZE_LIST = "optimize sequence/list/array", - /** - * Element QName if the changeSummary Root Object is a XML root; the NameSpace can be empty, never null; the prefix is ignored. - * Absent/null is the default (automatic computation from DocumentRoot if any) - */ - OPTION_ROOT_ELEMENT = "Root Element"; - - /** - * Exports ChangeSummary - * - * @param changeSummary - * Never null - * @param changeSummaryElement - * changeSummary element; the NameSpace can be empty if no NameSpace, or null if local element; the prefix can be null(no preference) - * @param writer - * Never null - * @param options - * {@link SDOUtil#XML_SAVE_LineBreak} (absence/null is the default i.e. no Line Breaking), {@link SDOUtil#XML_SAVE_INDENT} (absence/null is the default i.e. no indentation), {@link SDOUtil#XML_SAVE_MARGIN}, {@link #OPTION_RootObject_PATH}, {@link #OPTION_OPTIMIZE_LIST} and XMLResource.OPTION_EXTENDED_META_DATA; can be null or empty - */ - public final void saveChangeSummary(ChangeSummary changeSummary, QName changeSummaryElement, XMLStreamWriter writer, Map options) - throws XMLStreamException { - /* - * 6-1. Group created, deleted and modified DataObjects - * input: changeSummary output: createdDataObjects, deletedDataObjects & modifiedDataObjects - * implement: careful if compute from changeSummary.getChangedDataObjects() since it also includes children of deleted objects (thank Frank) - */ - if (changeSummary.isLogging()) - ((ChangeSummaryImpl) changeSummary).summarize(); - ChangeDescription changeDescription = (ChangeDescription) changeSummary; - Iterator createdDataObjects = changeDescription.getObjectsToDetach().iterator(); - deletedDataObjects = changeDescription.getObjectsToAttach(); - EMap objectChanges = changeDescription.getObjectChanges(); - modifiedDataObjects = objectChanges.keySet(); // may contain DO(s) from createdDataObjects and/or deletedDataObjects - - /* - * 6-2. Prepare to compute (X)Path - * input: changeSummary - * output: rootResource - */ - /*not to support DataGraph 3-3 - Object dataGraph = changeSummary.getDataGraph(); - if (dataGraph == null) { - DataObject rootObject = changeSummary.getRootObject(); - // assert rootObject != null; - rootResource = rootObject.getContainer() == null ? ((EObject) rootObject).eResource() // Can be null since this *StAX* writer does NOT - // require rootObject contained by an *EMF* Resource - : null; // eResource() direct content may not necessarily always be the XML document - } else - // assert dataGraph instanceof DataGraphImpl; - rootResource = ((org.apache.tuscany.sdo.impl.DataGraphImpl) dataGraph).getRootResource(); */ - - /* - * 6-2. Start ChangeSummary element - * input: writer, options, elementCS, changeSummary & changeDescription (6-1) - */ - nsPrefixSuffix = 0; - this.writer = writer; - this.options = options; - lineBreak = ""; - indent = margin = pathRootObject = STRING_OPTION; - nest = 0; - changeSummaryElementNS = changeSummaryElement.getNamespaceURI(); - changeSummaryElementName = changeSummaryElement.getLocalPart(); - writeStartElement(changeSummaryElement.getPrefix(), changeSummaryElementNS, changeSummaryElementName); - lineBreak = STRING_OPTION; - rootObject = changeSummary.getRootObject(); - extendedMetaData = (ExtendedMetaData) options.get(XMLResource.OPTION_EXTENDED_META_DATA); - if (extendedMetaData == null) - { - extendedMetaData = ExtendedMetaData.INSTANCE; - xsdHelper = XSDHelper.INSTANCE; - } - else{ - xsdHelper = (new HelperContextImpl(extendedMetaData, false)).getXSDHelper(); - } - Property declaration = changeSummaryElementNS == null - ? rootObject.getType().getProperty(changeSummaryElementName) - : xsdHelper.getGlobalProperty(changeSummaryElementNS, changeSummaryElementName, true); - if (declaration != null) - { - EClassifier type = changeDescription.eClass(); - if (type != declaration.getType() && type != CHANGE_SUMMARY) - writeGlobalAttribute(ExtendedMetaData.XSI_PREFIX, ExtendedMetaData.XSI_URI, XMLResource.TYPE, new StringBuffer(prefix(extendedMetaData.getNamespace(type), null)) - .append(':').append(extendedMetaData.getName(type)).toString()); - } - - /* - * 6-3. "create" attribute - * input: createdDataObjects (6-1), rootResource (6-2), changeSummary & writer - */ - rootElementNS = null; - this.changeSummary = changeSummary; - if (createdDataObjects.hasNext()) { - StringBuffer buffer = new StringBuffer(); - while (true) { - dataObject = (DataObject) createdDataObjects.next(); - buffer.append(ref()); - if (!createdDataObjects.hasNext()) - break; - buffer.append(' '); - } - writer.writeAttribute(CREATE_ATTRIBUTE, buffer.toString()); - } - - /* - * 6-4. "delete" attribute - * input: deletedDataObjects (6-1), modifiedDataObjects (6-1) & writer - */ - Iterator iterator = deletedDataObjects.iterator(); - if (iterator.hasNext()) { - lengthDeleted = -1; - StringBuffer buffer = null; - do { - dataObject = (DataObject) iterator.next(); - if (skipDeletedModification(changeSummary.getOldContainer(dataObject))) - continue; - if (buffer == null) - buffer = new StringBuffer(); - else - buffer.append(' '); - buffer.append(refDeleted()); - } while (iterator.hasNext()); - writer.writeAttribute(DELETE_ATTRIBUTE, buffer.toString()); - } - - /* - * 6-5. "logging" attribute - * input: changeSummary & writer - */ - writer.writeAttribute(LOGGING_ATTRIBUTE, changeSummary.isLogging() ? "true" : "false"); - - /* - * 6-6. Modified DataObjects - * input: modifiedDataObjects (6-1), rootResource (6-2), changeSummary & writer - */ - iterator = modifiedDataObjects.iterator(); - if (iterator.hasNext()) { - boolean optimizeList; - if (options == null) - optimizeList = false; - else - { - Object option = options.get(OPTION_OPTIMIZE_LIST); - optimizeList = option == null ? false : ((Boolean)option).booleanValue(); - } - prefix(SDOAnnotations.COMMONJ_SDO_NS, SDOPackage.eNS_PREFIX); - do { - DataObject dataObject = (DataObject) iterator.next(); - if (skipDeletedModification(dataObject)) - continue; - Property containmentProperty = dataObject.getContainmentProperty(); - if (containmentProperty == null) { - ++nest; - startElement(); - rootElementName(); - writer.writeStartElement(rootElementNS, rootElementName); - } else - writeStartElement(containmentProperty); - this.dataObject = dataObject; - writeRef(); - - String lineBreak = null; - Collection oldValues = (Collection) objectChanges.get(dataObject); // changeSummary.getOldValues repeats Sequence changes - Iterator settings = oldValues.iterator(); - if (settings.hasNext()) { - do { - ChangeSummary.Setting oldValue = (ChangeSummary.Setting) settings.next(); - if (oldValue.isSet()) - continue; - StringBuffer unset = step(oldValue.getProperty()); - while (settings.hasNext()) { - oldValue = (ChangeSummary.Setting) settings.next(); - if (!oldValue.isSet()) - step(oldValue.getProperty(), unset.append(' ')); - } - writer.writeAttribute(SDOAnnotations.COMMONJ_SDO_NS, UNSET, unset.toString()); - break; - } while (settings.hasNext()); - for (settings = oldValues.iterator(); settings.hasNext();) { - ChangeSummary.Setting oldValue = (ChangeSummary.Setting) settings.next(); - Property property = oldValue.getProperty(); - if (oldValue.isSet() && xsdHelper.isAttribute(property)) - // assert ! property.isMany(); - writeAttribute(property, convertToString(property, oldValue.getValue())); - } - for (settings = oldValues.iterator(); settings.hasNext();) { - ChangeSummary.Setting oldValue = (ChangeSummary.Setting) settings.next(); - Property property = oldValue.getProperty(); - if (!xsdHelper.isAttribute(property)) - if (property.isMany()) { - Object value = oldValue.getValue(); - List list = (List) value; - if (FeatureMapUtil.isFeatureMap((EStructuralFeature) property)) { - if (optimizeList) - list = optimize(list, oldValue, dataObject.getSequence(property).size()); - Iterator values = list.iterator(); - if (!values.hasNext()) - continue; - do - writeElement(values.next()); - while (values.hasNext()); - } else { - if (optimizeList) - list = optimize(list, oldValue, dataObject.getList(property).size()); - Iterator values = list.iterator(); - if (!values.hasNext()) - continue; - do - writeElement(values.next(), property); - while (values.hasNext()); - } - lineBreak = this.lineBreak; - } else if (oldValue.isSet()) { - Object value = oldValue.getValue(); - if (value instanceof FeatureMap.Entry) - writeElement(value); - else - writeElement(value, property); - lineBreak = this.lineBreak; - } - } - } - writeEndElement(lineBreak); - } while (iterator.hasNext()); - writeEndElement(lineBreak); - } else - writeEndElement(null); - writer.flush(); - } -} +/** + * + * 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.util.resource; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sdo.SDOPackage; +import org.apache.tuscany.sdo.helper.HelperContextImpl; +import org.apache.tuscany.sdo.helper.SDOAnnotations; +import org.apache.tuscany.sdo.helper.XSDHelperImpl; +import org.apache.tuscany.sdo.impl.ChangeSummaryImpl; +import org.apache.tuscany.sdo.model.ModelFactory; +import org.apache.tuscany.sdo.model.impl.ModelFactoryImpl; +import org.apache.tuscany.sdo.util.SDOUtil; +import org.eclipse.emf.common.util.EMap; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EDataType; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.change.ChangeDescription; +import org.eclipse.emf.ecore.change.ChangeKind; +import org.eclipse.emf.ecore.change.FeatureChange; +import org.eclipse.emf.ecore.change.ListChange; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.ecore.util.ExtendedMetaData; +import org.eclipse.emf.ecore.util.FeatureMap; +import org.eclipse.emf.ecore.util.FeatureMapUtil; +import org.eclipse.emf.ecore.xmi.XMLResource; + +import commonj.sdo.ChangeSummary; +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.helper.XSDHelper; + +/** + * ChangeSummary StAX Serializer whose output conforms to the SDO Java/C++/PHP specifications. The instance isn't thread-safe, however it's safe to + * use the instance any times on the same thread. + */ +public class ChangeSummaryStreamSerializer { + private XMLStreamWriter writer; + + private String writeNamespace(String prefix, String nameSpace) throws XMLStreamException { + writer.writeNamespace(prefix, nameSpace); + writer.setPrefix(prefix, nameSpace); + return prefix; + } + + private int nsPrefixSuffix; + + private String prefix(String nameSpace, String preference) throws XMLStreamException { + if (preference != null) { + String bound = writer.getNamespaceContext().getNamespaceURI(preference); + if (bound == null) { + String prefix = writer.getPrefix(nameSpace); + return prefix == null ? writeNamespace(preference, nameSpace) : prefix/* or null */; + } + if (bound.equals(nameSpace)) + return preference; + } + Object automaticNsPrefix = writer.getProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES); + if (automaticNsPrefix != null && automaticNsPrefix.getClass() == Boolean.class // faster than instanceof since Boolean is final + && ((Boolean) automaticNsPrefix).booleanValue()) + return null; + String prefix = writer.getPrefix(nameSpace); + if (prefix != null) + return prefix; // or null + NamespaceContext nameSpaces = writer.getNamespaceContext(); + do + prefix = "CS" + nsPrefixSuffix++; + while (nameSpaces.getNamespaceURI(prefix) != null); + return writeNamespace(prefix, nameSpace); + } + + void writeGlobalAttribute(String prefix, String nameSpace, String name, String value) throws XMLStreamException { + prefix = prefix(nameSpace, prefix); + if (prefix == null) + writer.writeAttribute(nameSpace, name, value); + else + writer.writeAttribute(prefix, nameSpace, name, value); + } + + XSDHelper xsdHelper; + + protected final void writeAttribute(Property property, String value) throws XMLStreamException { + String name = xsdHelper.getLocalName(property), nameSpace = xsdHelper.getNamespaceURI(property); + // TODO "" for no-NameSpace global attribute + if (nameSpace == null) + writer.writeAttribute(name, value); + else + writeGlobalAttribute(null, nameSpace, name, value); + } + + private String lineBreak, indent, margin; + + private int nest; + + private void breakLine() throws XMLStreamException { + writer.writeCharacters(lineBreak); + + if (margin != null) + writer.writeCharacters(margin); + + if (indent != null) + for (int count = nest; count != 0; --count) + writer.writeCharacters(indent); + } + + private Map options; + + static private final String STRING_OPTION = "String option"; + + void startElement() throws XMLStreamException { + if (options == null) + return; + if (lineBreak == STRING_OPTION) + lineBreak = (String) options.get(SDOUtil.XML_SAVE_LineBreak); + if (lineBreak == null) + return; + if (margin == STRING_OPTION) + margin = (String) options.get(SDOUtil.XML_SAVE_MARGIN); + if (indent == STRING_OPTION) + indent = (String) options.get(SDOUtil.XML_SAVE_INDENT); + breakLine(); + } + + void writeStartElement(String prefix, String nameSpace, String name) throws XMLStreamException { + startElement(); + if (nameSpace == null) + writer.writeStartElement(name); + else { + prefix = prefix(nameSpace, prefix); + if (prefix == null) + writer.writeStartElement(nameSpace, name); + else + writer.writeStartElement(prefix, name, nameSpace); + } + } + + void writeStartElement(Property property) throws XMLStreamException { + ++nest; + writeStartElement(null, xsdHelper.getNamespaceURI(property),// TODO "" for no-NameSpace global element + xsdHelper.getLocalName(property)); + } + + static protected final String CREATE_ATTRIBUTE = "create", DELETE_ATTRIBUTE = "delete", LOGGING_ATTRIBUTE = "logging", REF_ATTRIBUTE = "ref", UNSET = "unset"; + + private StringBuffer step(String nameSpace, String name, StringBuffer path) throws XMLStreamException { + if (nameSpace != null) { + nameSpace = writer.getPrefix(nameSpace); + if (nameSpace != null && nameSpace.length() != 0) + return path.append(nameSpace).append(':').append(name); // *:name[namespace-uri()='nameSpace'] + } + return path.append(name); + } + + private StringBuffer step(Property containmentProperty, StringBuffer path) throws XMLStreamException { + return step(xsdHelper.getNamespaceURI(containmentProperty),// TODO "" for no-NameSpace global element + xsdHelper.getLocalName(containmentProperty), path); + } + + private StringBuffer step(Property containmentProperty) throws XMLStreamException { + return step(containmentProperty, new StringBuffer()); + } + + private DataObject dataObject; + + private StringBuffer step(Object container) throws XMLStreamException { + Property containmentProperty = dataObject.getContainmentProperty(); + StringBuffer step = step(containmentProperty); + if (containmentProperty.isMany() || ((EObject) dataObject).eContainingFeature() != containmentProperty) + step.append('[').append(((DataObject) container).getList(containmentProperty).indexOf(dataObject) + 1).append(']'); + return step; + } + + private String pathRootObject; + private DataObject rootObject; + + private EObject container(EObject object) { + final EObject container = object.eContainer(); + if (!(container instanceof DataObject)) + return null; + String name = extendedMetaData.getName(container.eClass()); + return name != null && name.length() == 0 // DocumentRoot + ? null : container; + } + + private String path() throws XMLStreamException { + if (pathRootObject == STRING_OPTION) + pathRootObject = options == null ? null : (String) options.get(OPTION_RootObject_PATH); + if (pathRootObject != null && dataObject == rootObject) + return null; + EObject container = container((EObject) dataObject); + if (container == null) + return null; + StringBuffer step = step(container); + while (true) { + String path = step.toString(); + dataObject = (DataObject) container; + if (pathRootObject != null && container == rootObject) + return path; + container = container(container); + if (container == null) + return path; + step = step(container).append('/').append(path); + } + } + + /* + * not to support DataGraph 3-1 private org.eclipse.emf.ecore.resource.Resource rootResource; + */ + + protected String rootElementNS; + + String rootElementName; + + ExtendedMetaData extendedMetaData; + + protected final String rootElementName() { + if (rootElementNS != null) + return rootElementName; + QName rootElement = (QName) options.get(OPTION_ROOT_ELEMENT); + if (rootElement != null) { + rootElementNS = rootElement.getNamespaceURI(); + return rootElementName = rootElement.getLocalPart(); + } + EStructuralFeature element = ((EObject) rootObject).eContainingFeature(); + if (element == null) { + rootElementNS = ""; + return rootElementName = "descendant-or-self::node()"; + } + rootElementNS = extendedMetaData.getNamespace(element); + if (rootElementNS == null) + rootElementNS = ""; + return rootElementName = extendedMetaData.getName(element); + } + + String ref() throws XMLStreamException { + /* + * not to support DataGraph 3-2 if (rootResource != null) return rootResource.getURIFragment((EObject) dataObject); + */ + String id = EcoreUtil.getID((EObject) dataObject); + if (id != null) + return id; + id = path(); + if (pathRootObject == null) + return id == null ? "#/" + rootElementName() // descendant-or-self::node() + : "#//" + id; + return id == null ? pathRootObject/* + "."*/ : pathRootObject + id; + } + + void writeRef(String ref) throws XMLStreamException { + writer.writeAttribute(SDOAnnotations.COMMONJ_SDO_NS, REF_ATTRIBUTE, ref); + } + + void writeRef() throws XMLStreamException { + writeRef(ref()); + } + + void writeEndElement(String lineBreak) throws XMLStreamException { + if (lineBreak != null) + breakLine(); + writer.writeEndElement(); + --nest; + } + + private StringBuffer pathDeleted/* = null */; + + private Collection modifiedDataObjects; + + private int lengthDeleted; + + private String changeSummaryElementNS, changeSummaryElementName; + + private ChangeSummary changeSummary; + + protected boolean skipDeletedModification(DataObject modifiedDataObject) { + return changeSummary.isDeleted(modifiedDataObject); + } + + String refDeleted() throws XMLStreamException { + String id = EcoreUtil.getID((EObject) dataObject); + if (id != null) + return id; + id = path(); // "dataObject" is updated too!! + DataObject deletedDataObject = dataObject; + + /* + * construct "#//...changeSummary/" + * output: pathDeleted + */ + if (lengthDeleted == -1) { + String path = pathRootObject == null ? "#//" : pathRootObject; + if (pathDeleted == null) + pathDeleted = new StringBuffer(path); + else + pathDeleted.replace(0, pathDeleted.length(), path); + dataObject = rootObject; + path = path(); + if (path != null) + pathDeleted.append(path).append('/'); + step(changeSummaryElementNS, changeSummaryElementName, pathDeleted).append('/'); + lengthDeleted = pathDeleted.length(); + } else + pathDeleted.delete(lengthDeleted, pathDeleted.length()); + + dataObject = changeSummary.getOldContainer(deletedDataObject); + Property containmentProperty = dataObject.getContainmentProperty(); + String name = containmentProperty == null ? rootElementName() : xsdHelper.getLocalName(containmentProperty); + int index = 1; + for (Iterator iterator = modifiedDataObjects.iterator(); iterator.hasNext();) { + DataObject modifiedDataObject = (DataObject) iterator.next(); + if (skipDeletedModification(modifiedDataObject)) + continue; + if (modifiedDataObject == dataObject) + break; + Property property = modifiedDataObject.getContainmentProperty(); + if (property == containmentProperty || name.equals(property == null ? rootElementName() : xsdHelper.getLocalName(property))) + ++index; + } + pathDeleted/*.append("*:")*/.append(name).append('[').append(index).append("]/"); + containmentProperty = changeSummary.getOldContainmentProperty(deletedDataObject); + // assert containmentProperty != null; + step(containmentProperty, pathDeleted); + Object f; + if (containmentProperty.isMany() + || (f = extendedMetaData.getAffiliation(((EObject) dataObject).eClass(), (EStructuralFeature) containmentProperty)) != null + && f != containmentProperty) + pathDeleted.append('[').append( + ((List) changeSummary.getOldValue(dataObject, containmentProperty).getValue()).indexOf(deletedDataObject) + 1).append(']'); + if (id != null) + pathDeleted.append('/').append(id); + return pathDeleted.toString(); + } + + static String convertToString(Property property, Object value) { + return EcoreUtil.convertToString((EDataType) property.getType(), value); + } + + void writeRefDeleted() throws XMLStreamException { + writeRef(refDeleted()); + } + + protected final void writeDeletedObject(Property property) throws XMLStreamException { + ++nest; + startElement(); + --nest; + DataObject oldDataObject = ((ChangeSummaryImpl)changeSummary).getOldDataObject(dataObject); + XMLStreamReader reader = new DataObjectXMLStreamReader(property, oldDataObject, null, xsdHelper); + new XMLStreamSerializer().serialize(new XMLDocumentStreamReader(reader), writer); + } + + static public final Object ChangeSummary_TYPE = ((ModelFactoryImpl) ModelFactory.INSTANCE).getChangeSummaryType(); + + Collection deletedDataObjects; + + protected final void writeElement(Object value, Property property) throws XMLStreamException { + if (value == null) { + writeStartElement(property); + writeGlobalAttribute(ExtendedMetaData.XSI_PREFIX, ExtendedMetaData.XSI_URI, XMLResource.NIL, "true"); + writeEndElement(null); + } else if (value instanceof DataObject) { + dataObject = (DataObject) value; + if (!changeSummary.isDeleted(dataObject)) { + writeStartElement(property); + writeRef(); + writeEndElement(null); + } else if (property.isContainment() && deletedDataObjects.contains(dataObject)) { + writeDeletedObject(property); + } else { + writeStartElement(property); + writeRefDeleted(); + writeEndElement(null); + } + } else { + Object type = property.getType(); + if (type == ChangeSummary_TYPE) + return; + writeStartElement(property); + writer.writeCharacters(EcoreUtil.convertToString((EDataType) type, value)); + writeEndElement(null); + } + } + + protected final void writeElement(Object value) throws XMLStreamException { + FeatureMap.Entry entry = (FeatureMap.Entry) value; + writeElement(entry.getValue(), (Property)entry.getEStructuralFeature()); + } + + static protected List optimize(List values, Object featureChange, int size) { + int fromIndex = size, toIndex = 0; + for (Iterator changes = ((FeatureChange) featureChange).getListChanges().iterator(); changes.hasNext();) { + ListChange change = (ListChange) changes.next(); + Object kind = change.getKind(); + if (kind == ChangeKind.MOVE_LITERAL) + return values; + int index = change.getIndex(); + if (kind == ChangeKind.ADD_LITERAL) { + if (index == 0) { + fromIndex = 0; + if (toIndex == 0) + toIndex = 1; + } else { + int to = index; + if (--index < fromIndex) + fromIndex = index; + if (++to > toIndex) + toIndex = to; + else if (to < toIndex) + ++toIndex; + } + ++size; + } else { + --size; + if (index < fromIndex) + fromIndex = index; + if (index < toIndex) + --toIndex; + else if (index > toIndex && index != size) + toIndex = index; + } + } + return values.subList(fromIndex, toIndex); + } + + static protected final Object CHANGE_SUMMARY = SDOPackage.eINSTANCE.getChangeSummary(); + + /** + * Root Object path String such as "#", etc. Absent/null is the default (automatic computation) + */ + static public final String OPTION_RootObject_PATH = "RootObject path", + /** + * Boolean to optimize sequence/list/array. Absent/null/Boolean.FALSE is the default (no optimization) + */ + OPTION_OPTIMIZE_LIST = "optimize sequence/list/array", + /** + * Element QName if the changeSummary Root Object is a XML root; the NameSpace can be empty, never null; the prefix is ignored. + * Absent/null is the default (automatic computation from DocumentRoot if any) + */ + OPTION_ROOT_ELEMENT = "Root Element"; + + /** + * Exports ChangeSummary + * + * @param changeSummary + * Never null + * @param changeSummaryElement + * changeSummary element; the NameSpace can be empty if no NameSpace, or null if local element; the prefix can be null(no preference) + * @param writer + * Never null + * @param options + * {@link SDOUtil#XML_SAVE_LineBreak} (absence/null is the default i.e. no Line Breaking), {@link SDOUtil#XML_SAVE_INDENT} (absence/null is the default i.e. no indentation), {@link SDOUtil#XML_SAVE_MARGIN}, {@link #OPTION_RootObject_PATH}, {@link #OPTION_OPTIMIZE_LIST} and XMLResource.OPTION_EXTENDED_META_DATA; can be null or empty + */ + public final void saveChangeSummary(ChangeSummary changeSummary, QName changeSummaryElement, XMLStreamWriter writer, Map options) + throws XMLStreamException { + /* + * 6-1. Group created, deleted and modified DataObjects + * input: changeSummary output: createdDataObjects, deletedDataObjects & modifiedDataObjects + * implement: careful if compute from changeSummary.getChangedDataObjects() since it also includes children of deleted objects (thank Frank) + */ + if (changeSummary.isLogging()) + ((ChangeSummaryImpl) changeSummary).summarize(); + ChangeDescription changeDescription = (ChangeDescription) changeSummary; + Iterator createdDataObjects = changeDescription.getObjectsToDetach().iterator(); + deletedDataObjects = changeDescription.getObjectsToAttach(); + EMap objectChanges = changeDescription.getObjectChanges(); + modifiedDataObjects = objectChanges.keySet(); // may contain DO(s) from createdDataObjects and/or deletedDataObjects + + /* + * 6-2. Prepare to compute (X)Path + * input: changeSummary + * output: rootResource + */ + /*not to support DataGraph 3-3 + Object dataGraph = changeSummary.getDataGraph(); + if (dataGraph == null) { + DataObject rootObject = changeSummary.getRootObject(); + // assert rootObject != null; + rootResource = rootObject.getContainer() == null ? ((EObject) rootObject).eResource() // Can be null since this *StAX* writer does NOT + // require rootObject contained by an *EMF* Resource + : null; // eResource() direct content may not necessarily always be the XML document + } else + // assert dataGraph instanceof DataGraphImpl; + rootResource = ((org.apache.tuscany.sdo.impl.DataGraphImpl) dataGraph).getRootResource(); */ + + /* + * 6-2. Start ChangeSummary element + * input: writer, options, elementCS, changeSummary & changeDescription (6-1) + */ + nsPrefixSuffix = 0; + this.writer = writer; + this.options = options; + lineBreak = ""; + indent = margin = pathRootObject = STRING_OPTION; + nest = 0; + changeSummaryElementNS = changeSummaryElement.getNamespaceURI(); + changeSummaryElementName = changeSummaryElement.getLocalPart(); + writeStartElement(changeSummaryElement.getPrefix(), changeSummaryElementNS, changeSummaryElementName); + lineBreak = STRING_OPTION; + rootObject = changeSummary.getRootObject(); + extendedMetaData = (ExtendedMetaData) options.get(XMLResource.OPTION_EXTENDED_META_DATA); + if (extendedMetaData == null) + { + extendedMetaData = ExtendedMetaData.INSTANCE; + xsdHelper = XSDHelper.INSTANCE; + } + else{ + xsdHelper = (new HelperContextImpl(extendedMetaData, false)).getXSDHelper(); + } + Property declaration = changeSummaryElementNS == null + ? rootObject.getType().getProperty(changeSummaryElementName) + : xsdHelper.getGlobalProperty(changeSummaryElementNS, changeSummaryElementName, true); + if (declaration != null) + { + EClassifier type = changeDescription.eClass(); + if (type != declaration.getType() && type != CHANGE_SUMMARY) + writeGlobalAttribute(ExtendedMetaData.XSI_PREFIX, ExtendedMetaData.XSI_URI, XMLResource.TYPE, new StringBuffer(prefix(extendedMetaData.getNamespace(type), null)) + .append(':').append(extendedMetaData.getName(type)).toString()); + } + + /* + * 6-3. "create" attribute + * input: createdDataObjects (6-1), rootResource (6-2), changeSummary & writer + */ + rootElementNS = null; + this.changeSummary = changeSummary; + if (createdDataObjects.hasNext()) { + StringBuffer buffer = new StringBuffer(); + while (true) { + dataObject = (DataObject) createdDataObjects.next(); + buffer.append(ref()); + if (!createdDataObjects.hasNext()) + break; + buffer.append(' '); + } + writer.writeAttribute(CREATE_ATTRIBUTE, buffer.toString()); + } + + /* + * 6-4. "delete" attribute + * input: deletedDataObjects (6-1), modifiedDataObjects (6-1) & writer + */ + Iterator iterator = deletedDataObjects.iterator(); + if (iterator.hasNext()) { + lengthDeleted = -1; + StringBuffer buffer = null; + do { + dataObject = (DataObject) iterator.next(); + if (skipDeletedModification(changeSummary.getOldContainer(dataObject))) + continue; + if (buffer == null) + buffer = new StringBuffer(); + else + buffer.append(' '); + buffer.append(refDeleted()); + } while (iterator.hasNext()); + writer.writeAttribute(DELETE_ATTRIBUTE, buffer.toString()); + } + + /* + * 6-5. "logging" attribute + * input: changeSummary & writer + */ + writer.writeAttribute(LOGGING_ATTRIBUTE, changeSummary.isLogging() ? "true" : "false"); + + /* + * 6-6. Modified DataObjects + * input: modifiedDataObjects (6-1), rootResource (6-2), changeSummary & writer + */ + iterator = modifiedDataObjects.iterator(); + if (iterator.hasNext()) { + boolean optimizeList; + if (options == null) + optimizeList = false; + else + { + Object option = options.get(OPTION_OPTIMIZE_LIST); + optimizeList = option == null ? false : ((Boolean)option).booleanValue(); + } + prefix(SDOAnnotations.COMMONJ_SDO_NS, SDOPackage.eNS_PREFIX); + do { + DataObject dataObject = (DataObject) iterator.next(); + if (skipDeletedModification(dataObject)) + continue; + Property containmentProperty = dataObject.getContainmentProperty(); + if (containmentProperty == null) { + ++nest; + startElement(); + rootElementName(); + writer.writeStartElement(rootElementNS, rootElementName); + } else + writeStartElement(containmentProperty); + this.dataObject = dataObject; + writeRef(); + + String lineBreak = null; + Collection oldValues = (Collection) objectChanges.get(dataObject); // changeSummary.getOldValues repeats Sequence changes + Iterator settings = oldValues.iterator(); + if (settings.hasNext()) { + do { + ChangeSummary.Setting oldValue = (ChangeSummary.Setting) settings.next(); + if (oldValue.isSet()) + continue; + StringBuffer unset = step(oldValue.getProperty()); + while (settings.hasNext()) { + oldValue = (ChangeSummary.Setting) settings.next(); + if (!oldValue.isSet()) + step(oldValue.getProperty(), unset.append(' ')); + } + writer.writeAttribute(SDOAnnotations.COMMONJ_SDO_NS, UNSET, unset.toString()); + break; + } while (settings.hasNext()); + for (settings = oldValues.iterator(); settings.hasNext();) { + ChangeSummary.Setting oldValue = (ChangeSummary.Setting) settings.next(); + Property property = oldValue.getProperty(); + if (oldValue.isSet() && xsdHelper.isAttribute(property)) + // assert ! property.isMany(); + writeAttribute(property, convertToString(property, oldValue.getValue())); + } + for (settings = oldValues.iterator(); settings.hasNext();) { + ChangeSummary.Setting oldValue = (ChangeSummary.Setting) settings.next(); + Property property = oldValue.getProperty(); + if (!xsdHelper.isAttribute(property)) + if (property.isMany()) { + Object value = oldValue.getValue(); + List list = (List) value; + if (FeatureMapUtil.isFeatureMap((EStructuralFeature) property)) { + if (optimizeList) + list = optimize(list, oldValue, dataObject.getSequence(property).size()); + Iterator values = list.iterator(); + if (!values.hasNext()) + continue; + do + writeElement(values.next()); + while (values.hasNext()); + } else { + if (optimizeList) + list = optimize(list, oldValue, dataObject.getList(property).size()); + Iterator values = list.iterator(); + if (!values.hasNext()) + continue; + do + writeElement(values.next(), property); + while (values.hasNext()); + } + lineBreak = this.lineBreak; + } else if (oldValue.isSet()) { + Object value = oldValue.getValue(); + if (value instanceof FeatureMap.Entry) + writeElement(value); + else + writeElement(value, property); + lineBreak = this.lineBreak; + } + } + } + writeEndElement(lineBreak); + } while (iterator.hasNext()); + writeEndElement(lineBreak); + } else + writeEndElement(null); + writer.flush(); + } +} diff --git a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/RecordedEventXMLStreamReader.java b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/RecordedEventXMLStreamReader.java index b2b3036692..a0da5d2609 100644 --- a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/RecordedEventXMLStreamReader.java +++ b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/RecordedEventXMLStreamReader.java @@ -1,868 +1,868 @@ -/** - * - * 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.util.resource; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.NoSuchElementException; - -import javax.xml.XMLConstants; -import javax.xml.namespace.NamespaceContext; -import javax.xml.namespace.QName; -import javax.xml.stream.Location; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.eclipse.emf.ecore.xmi.XMLResource; -import org.xml.sax.Attributes; -import org.xml.sax.Locator; - -/** - * This special purpose XMLStreamReader is used to produce a StAX event stream corresponding to a list of events - * recorded earlier. The recorded events are generated by the inner class RecordedEventXMLStreamReader.Tag, - * which records the events in either of 2 ways: - * - * 1) in conjunction with class SDOXMLLoadImpl, it records events corresponding to the SAX events being - * handled by the SDOXMLLoadImpl when loading XML using SDOXMLResourceImpl. - * 2) when Tag.record() is called (see class ChangeSummaryStreamDeserializer), it walks through and records - * the StAX events produced by another XMLStreamReader. - * - * This class is used by the SDO StAX-based ChangeSummaryType-property loader, class - * ChangeSummaryStreamDeserializer, which is inoked by and uses (for loading deleted object XML fragments) - * the SAX-based loader class XMLResourceImpl. - */ -public abstract class RecordedEventXMLStreamReader implements XMLStreamReader { - - static private class Event { - int type; - - public NamespaceContext nameSpaceContext; - - Location location; - - protected final void initialize(XMLStreamReader reader) { - nameSpaceContext = reader.getNamespaceContext(); - location = reader.getLocation(); - } - - protected final void location(final Locator locator) { - location = new Location() { - public int getCharacterOffset() { - return -1; - } - - public int getColumnNumber() { - return locator.getColumnNumber(); - } - - public int getLineNumber() { - return locator.getLineNumber(); - } - - public String getPublicId() { - return locator.getPublicId(); - } - - public String getSystemId() { - return locator.getSystemId(); - } - }; - } - } - - static class ValueEvent extends Event { - final String value; - - protected ValueEvent(String v) { - value = v; - } - } - - static protected class Reference extends ValueEvent { - final String target; - - protected Reference(String name, String data) { - super(data); - target = name; - } - } - - static protected final class AttributeEvent extends Reference { - final QName name; - - final String nameSpace, prefix; - - int attributes; - - final boolean specified; - - protected AttributeEvent(XMLStreamReader reader) { - super(reader.getAttributeType(0), reader.getAttributeValue(0)); - attributes = reader.getAttributeCount(); - name = reader.getAttributeName(0); - nameSpace = reader.getAttributeNamespace(0); - prefix = reader.getAttributePrefix(0); - specified = reader.isAttributeSpecified(0); - } - } - - static protected final class NameSpaceEvent extends Reference { - int nameSpaces; - - protected NameSpaceEvent(XMLStreamReader reader) { - super(reader.getNamespacePrefix(0), reader.getNamespaceURI(0)); - nameSpaces = reader.getNamespaceCount(); - } - } - - static protected String prefix(String qName, String nameSpace) { - int delimiter = qName.indexOf(':'); - if (delimiter != -1) - return qName.substring(0, delimiter); - if (nameSpace.length() != 0) - return XMLConstants.DEFAULT_NS_PREFIX; - // if (nameSpaceContext.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX) != null || xsdHelper.getGlobalProperty(null, name, element) == null) - return null; - } - - static class EndElement extends Event { - List nameSpaces/* = null */; - - public final QName name; - - public final String nameSpace; - - final String prefix; - - protected EndElement(XMLStreamReader reader) { - name = reader.getName(); - nameSpace = reader.getNamespaceURI(); - prefix = reader.getPrefix(); - int count = reader.getNamespaceCount(); - if (count == 0) - return; - nameSpaces = new ArrayList(count); - int index = 0; - do - Tag.bind(reader.getNamespacePrefix(index), reader.getNamespaceURI(index), nameSpaces); - while (++index != count); - } - - protected EndElement(String uri, String local, String p, Locator locator) { - if (p == null) { - name = new QName(uri, local, XMLConstants.DEFAULT_NS_PREFIX); - nameSpace = null; - } else { - name = new QName(uri, local, p); - nameSpace = uri; - } - prefix = p; - location(locator); - } - } - - static class NameSpace { - final String prefix, uri; - - protected NameSpace(String p, String nameSpace) { - prefix = p; - uri = nameSpace; - } - } - - static final class Attribute extends NameSpace { - final String type, value; - - final QName qName; - - boolean specified/* = false */; - - protected Attribute(String t, String v, QName name, String prefix, String nameSpace) { - super(prefix, nameSpace); - type = t; - value = v; - qName = name; - } - } - - static final class AttributeList /* implements Attributes */{// TODO exclude XMLConstants.XMLNS_ATTRIBUTE - final List attributes; - - protected AttributeList(int size) { - attributes = new ArrayList(size); - } - - /* - * @param uri Never null - */ - public final int getIndex(String uri, String localName) { - for (int index = getLength(); index != 0;) - if (getLocalName(--index).equals(localName) && uri.equals(getURI(index))) - return index; - return -1; - } - - public final int getLength() { - return attributes.size(); - } - - protected final Attribute attribute(int index) { - return (Attribute) attributes.get(index); - } - - public final String getLocalName(int index) { - return attribute(index).qName.getLocalPart(); - } - - public final String getType(int index) { - return attribute(index).type; - } - - /*public String getType(String uri, String localName) { - int index = getIndex(uri, localName); - return index == -1 ? null: getType(index); - } */ - - public final String getURI(int index) { - return attribute(index).uri; - } - - public final String getValue(int index) { - return attribute(index).value; - } - - /* - * @param uri Never null - */ - public final String getValue(String uri, String localName) { - int index = getIndex(uri, localName); - return index == -1 ? null : getValue(index); - } - } - - static protected class StartElement extends EndElement { - final AttributeList attributes; - - protected StartElement(XMLStreamReader reader) { - super(reader); - int count = reader.getAttributeCount(); - if (count == 0) - attributes = null; - else { - attributes = new AttributeList(count); - int index = 0; - do { - Attribute attribute = new Attribute(reader.getAttributeType(index), reader.getAttributeValue(index), reader - .getAttributeName(index), reader.getAttributePrefix(index), reader.getAttributeNamespace(index)); - attribute.specified = reader.isAttributeSpecified(index); - attributes.attributes.add(attribute); - } while (++index != count); - } - } - - protected StartElement(String nameSpace, String local, String prefix, Attributes attributeArray, Locator locator, List bindings, - final NamespaceContext context) { - super(nameSpace, local, prefix, locator); - nameSpaces = bindings; - nameSpaceContext = bindings == null || bindings.isEmpty() ? context : new NamespaceContext() { - public String getNamespaceURI(String prefix) { - for (int index = nameSpaces.size(); index != 0;) { - NameSpace binding = (NameSpace) nameSpaces.get(--index); - if (binding.prefix.equals(prefix)) - return binding.uri; - } - return context.getNamespaceURI(prefix); - } - - public String getPrefix(String namespaceURI) { - for (int index = nameSpaces.size(); index != 0;) { - NameSpace binding = (NameSpace) nameSpaces.get(--index); - if (binding.uri.equals(namespaceURI)) - return binding.prefix; - } - return context.getPrefix(namespaceURI); - } - - public Iterator getPrefixes(final String namespaceURI) { - final Iterator iterator = context.getPrefixes(namespaceURI); - return new Iterator() { - Iterator bindings = nameSpaces.iterator(); - - NameSpace binding/* = null */; - - protected final boolean prefix() { - while (bindings.hasNext()) { - binding = (NameSpace) bindings.next(); - if (binding.uri.equals(namespaceURI)) - return true; - } - bindings = null; - return false; - } - - public boolean hasNext() { - return bindings != null && prefix() || iterator.hasNext(); - } - - protected NameSpace nameSpace; - - public Object next() { - if (bindings == null || binding == null && !prefix()) - return iterator.next(); - nameSpace = binding; - binding = null; - return nameSpace.prefix; - } - - public void remove() { - if (bindings == null) - iterator.remove(); - else - nameSpaces.remove(nameSpace); - } - }; - } - }; - int count = attributeArray.getLength(); - if (count == 0) - attributes = null; - else { - attributes = new AttributeList(count); - int index = 0; - do { - QName name; - nameSpace = attributeArray.getURI(index); - local = attributeArray.getLocalName(index); - prefix = prefix(attributeArray.getQName(index), nameSpace); - if (prefix == null) { - name = new QName(nameSpace, local, XMLConstants.DEFAULT_NS_PREFIX); - nameSpace = null; - } else - name = new QName(nameSpace, local, prefix); - attributes.attributes.add(new Attribute(attributeArray.getType(index), attributeArray.getValue(index), name, prefix, nameSpace)); - } while (++index != count); - } - } - } - - static public class Tag extends StartElement { - public Tag(XMLStreamReader reader) { - super(reader); - initialize(reader); - } - - public List events/* = null */; // may be empty - - protected final void events() { - events = new ArrayList(); - } - - public Tag(String nameSpace, String local, String prefix, Attributes attributes, Locator locator, NamespaceContext context, List bindings) { - super(nameSpace, local, prefix, attributes, locator, bindings, context); - events(); - } - - static public void bind(String prefix, String nameSpace, Collection nameSpaces) { - nameSpaces.add(new NameSpace(prefix, nameSpace)); - } - - protected int nest/* = 0 */; - - public final void start(String nameSpace, String local, String qName, Attributes attributes, Locator locator, List bindings) { - Event event; - for (int index = events.size();/* true */;) { - if (index == 0) { - event = this; - break; - } - event = (Event) events.get(--index); - if (event.type != END_ELEMENT) - break; - siblings: for (int nest = 0;/* true */;) - switch (((Event) events.get(--index)).type) { - case START_ELEMENT: - if (nest == 0) - break siblings; - --nest; - break; - case END_ELEMENT: - ++nest; - } - } - Event start = new StartElement(nameSpace, local, prefix(qName, nameSpace), attributes, locator, bindings, event.nameSpaceContext); - start.type = START_ELEMENT; - events.add(start); - ++nest; - } - - protected final void add (Event event) - { - int index = events.size(); - event.nameSpaceContext = index == 0 ? nameSpaceContext : ((Event) events.get(--index)).nameSpaceContext; - events.add(event); - } - - public final void text(int type, String value, Locator locator) { - Event event = new ValueEvent(value); - event.type = type; - event.location(locator); - //int index = events.size(); - add(event); - } - - public final boolean end(String nameSpace, String local, String qName, Locator locator) { - Event end = new EndElement(nameSpace, local, prefix(qName, nameSpace), locator); - end.type = END_ELEMENT; - add(end); - if (nest == 0) - return true; - --nest; - return false; - } - - public final XMLStreamReader play(final XMLResource resource) { - return new RecordedEventXMLStreamReader(this) { - public void close() { - } - - public String getCharacterEncodingScheme() { - return null; // TODO - } - - public String getEncoding() { - return resource.getEncoding(); - } - - public Object getProperty(String property) { - return null; // TODO javax.xml.stream.notations & javax.xml.stream.entities for DTD - } - - public String getVersion() { - return resource.getXMLVersion(); - } - - public boolean isStandalone() { - return false; // TODO - } - - public boolean standaloneSet() { - return false; // TODO - } - }; - } - - protected final void add(Event event, int type, XMLStreamReader reader) { - event.type = type; - event.initialize(reader); - events.add(event); - } - - public final boolean record(XMLStreamReader reader) throws XMLStreamException { - events(); - for (int nest = 0; reader.hasNext();) { - Event event; - int type = reader.next(); - switch (type) { - case CHARACTERS: - case CDATA: - case COMMENT: - case SPACE: - case DTD: - event = new ValueEvent(reader.getText()); - break; - case ENTITY_REFERENCE: - event = new Reference(reader.getLocalName(), reader.getText()); - break; - case PROCESSING_INSTRUCTION: - event = new Reference(reader.getPITarget(), reader.getPIData()); - break; - case ATTRIBUTE: - event = new AttributeEvent(reader); - break; - case NAMESPACE: - event = new NameSpaceEvent(reader); - break; - case START_ELEMENT: - ++nest; - event = new StartElement(reader); - break; - case END_ELEMENT: - add(new EndElement(reader), type, reader); - if (nest == 0) - return false; - --nest; - continue; - case END_DOCUMENT: - return true; // report error? - default: // new type - event = new Event(); - } - add(event, type, reader); - } - return true; // report error? - } - - public final XMLStreamReader play(final XMLStreamReader reader) { - return new RecordedEventXMLStreamReader(this) { - public void close() throws XMLStreamException { - reader.close(); - } - - public String getCharacterEncodingScheme() { - return reader.getCharacterEncodingScheme(); - } - - public String getEncoding() { - return reader.getEncoding(); - } - - public Object getProperty(String property) { - return reader.getProperty(property); // TODO javax.xml.stream.notations & javax.xml.stream.entities for DTD - } - - public String getVersion() { - return reader.getVersion(); - } - - public boolean isStandalone() { - return reader.isStandalone(); - } - - public boolean standaloneSet() { - return reader.standaloneSet(); - } - }; - } - } - - Event event; - - final List events; - - final int size; - - protected RecordedEventXMLStreamReader(Tag tag) { - event = tag; - tag.type = START_ELEMENT; - events = tag.events; - size = events.size(); - } - - public int getAttributeCount() { - switch (getEventType()) { - case START_ELEMENT: - AttributeList attributes = ((StartElement) event).attributes; - return attributes == null ? 0 : attributes.getLength(); - case ATTRIBUTE: - return ((AttributeEvent) event).attributes; - } - throw new IllegalStateException("Neither START_ELEMENT nor ATTRIBUTE"); - } - - protected final AttributeList attributes() { - if (getEventType() == START_ELEMENT) - return ((StartElement) event).attributes; - throw new IllegalStateException("Neither START_ELEMENT nor ATTRIBUTE"); - } - - public String getAttributeLocalName(int index) { - return attributes().getLocalName(index); - } - - static Attribute attribute(AttributeList attributes, int index) { - return (Attribute) attributes.attributes.get(index); - } - - public QName getAttributeName(int index) { - return getEventType() == ATTRIBUTE ? ((AttributeEvent) event).name : attribute(attributes(), index).qName; - } - - public String getAttributeNamespace(int index) { - return getEventType() == ATTRIBUTE ? ((AttributeEvent) event).nameSpace : attributes().getURI(index); - } - - public String getAttributePrefix(int index) { - return getEventType() == ATTRIBUTE ? ((AttributeEvent) event).prefix : attribute(attributes(), index).prefix; - } - - public String getAttributeType(int index) { - return getEventType() == ATTRIBUTE ? ((Reference) event).target : attributes().getType(index); - } - - public String getAttributeValue(int index) { - return getEventType() == ATTRIBUTE ? ((ValueEvent) event).value : attributes().getValue(index); - } - - public boolean isAttributeSpecified(int index) { - if (getEventType() == ATTRIBUTE) - return ((AttributeEvent) event).specified; - AttributeList attributes = attributes(); - return attribute(attributes, index).specified; - } - - public String getAttributeValue(String nameSpace, String name) { - if (getEventType() == ATTRIBUTE) { - AttributeEvent attribute = (AttributeEvent) event; - return !attribute.name.getLocalPart().equals(name) ? null : nameSpace == null ? (attribute.nameSpace == null ? attribute.value : null) - : nameSpace.equals(attribute.nameSpace) ? attribute.value : null; - } - AttributeList attributes = attributes(); - return attributes == null ? null : attributes.getValue(nameSpace == null ? "" : nameSpace, name); - } - - protected StringBuffer buffer/* = null */; - - public String getElementText() { - if (buffer != null) - buffer.delete(0, buffer.length()); - for (;;) - switch (next()) { - case END_ELEMENT: - return buffer == null ? null : buffer.toString(); - default: - if (buffer == null) - buffer = new StringBuffer(); - buffer.append(getText()); - case PROCESSING_INSTRUCTION: - case COMMENT: - } - } - - public final int getEventType() { - return event.type; - } - - public String getLocalName() { - if (getEventType() == ENTITY_REFERENCE) - return ((Reference) event).target; - if (event instanceof EndElement) - return ((EndElement) event).name.getLocalPart(); - throw new IllegalStateException("Neither START_ELEMENT, END_ELEMENT nor ENTITY_REFERENCE"); - } - - public final Location getLocation() { - return event.location; - } - - public QName getName() { - if (hasName()) - return ((EndElement) event).name; - throw new IllegalStateException("Neither START_ELEMENT nor END_ELEMENT"); - } - - public final NamespaceContext getNamespaceContext() { - return event.nameSpaceContext; - } - - public int getNamespaceCount() { - if (getEventType() == NAMESPACE) - return ((NameSpaceEvent) event).nameSpaces; - if (!(event instanceof EndElement)) - throw new IllegalStateException("Neither START_ELEMENT, END_ELEMENT nor NAMESPACE"); - Collection nameSpaces = ((EndElement) event).nameSpaces; - return nameSpaces == null ? 0 : nameSpaces.size(); - } - - protected final NameSpace getNameSpace(int index) { - if (event instanceof EndElement) - return (NameSpace) ((EndElement) event).nameSpaces.get(index); - throw new IllegalStateException("Neither START_ELEMENT, END_ELEMENT nor NAMESPACE"); - } - - public String getNamespacePrefix(int index) { - return getEventType() == NAMESPACE ? ((Reference) event).target : getNameSpace(index).prefix; - } - - public final String getNamespaceURI() { - switch (getEventType()) { - case ATTRIBUTE: - return ((AttributeEvent) event).nameSpace; - case NAMESPACE: - return ((ValueEvent) event).value; - } - return event instanceof EndElement ? ((EndElement) event).nameSpace : null; - } - - public String getNamespaceURI(String prefix) { - return getNamespaceContext().getNamespaceURI(prefix); - } - - public String getNamespaceURI(int index) { - return getEventType() == NAMESPACE ? ((ValueEvent) event).value : getNameSpace(index).uri; - } - - public String getPIData() { - return getEventType() == PROCESSING_INSTRUCTION ? ((ValueEvent) event).value : null; - } - - public String getPITarget() { - return getEventType() == PROCESSING_INSTRUCTION ? ((Reference) event).target : null; - } - - public String getPrefix() { - switch (getEventType()) { - case ATTRIBUTE: - return ((AttributeEvent) event).prefix; - case NAMESPACE: - return ((Reference) event).target; - } - return event instanceof EndElement ? ((EndElement) event).prefix : null; - } - - public final String getText() { - if (hasText()) - return ((ValueEvent) event).value; - throw new IllegalStateException("Neither CHARACTERS, CDATA, COMMENT, SPACE, ENTITY_REFERENCE nor DTD"); - } - - public final char[] getTextCharacters() { - switch (getEventType()) { - case CHARACTERS: - case CDATA: - case COMMENT: - case SPACE: - return ((ValueEvent) event).value.toCharArray(); - } - throw new IllegalStateException("Neither CHARACTERS, CDATA, COMMENT nor SPACE"); - } - - public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length) { - char[] source = getTextCharacters(); - if (sourceStart > source.length) - throw new IndexOutOfBoundsException("source start > source length"); - int sourceLen = source.length - sourceStart; - if (length > sourceLen) - length = sourceLen; - System.arraycopy(source, sourceStart, target, targetStart, length); - return sourceLen; - } - - public int getTextLength() { - return getTextCharacters().length; - } - - public int getTextStart() { - return 0; - } - - public final boolean hasName() { - return event instanceof EndElement; - } - - protected int next/* = 0 */; - - public final boolean hasNext() { - return next != size; - } - - public final boolean hasText() { - switch (getEventType()) { - case CHARACTERS: - case CDATA: - case COMMENT: - case SPACE: - case ENTITY_REFERENCE: - case DTD: - return true; - } - return false; - } - - public boolean isCharacters() { - switch (getEventType()) { - case CHARACTERS: - case CDATA: - case SPACE: - return true; - } - return false; - } - - public boolean isEndElement() { - return getEventType() == END_ELEMENT; - } - - public boolean isStartElement() { - return getEventType() == START_ELEMENT; - } - - protected final boolean areWhiteSpace() { - String text = getText(); - for (int index = text.length(); index != 0;) - if (!Character.isWhitespace(text.charAt(--index))) - return false; - return true; - } - - public boolean isWhiteSpace() { - switch (getEventType()) { - case CHARACTERS: - case CDATA: - return areWhiteSpace(); - case SPACE: - return true; - } - return false; - } - - public final int next() { - if (!hasNext()) - throw new NoSuchElementException(); - event = (Event) events.get(next++); - return event.type; - } - - protected final void throwXMLStreamException(String message) throws XMLStreamException { - throw new XMLStreamException(message, getLocation()); - } - - public int nextTag() throws XMLStreamException { - for (;;) { - int type = next(); - switch (type) { - case CHARACTERS: - case CDATA: - if (!areWhiteSpace()) - break; - case SPACE: - case PROCESSING_INSTRUCTION: - case COMMENT: - continue; - case START_ELEMENT: - case END_ELEMENT: - return type; - } - throwXMLStreamException("expected start or end tag"); - } - } - - public void require(int type, String nameSpace, String name) throws XMLStreamException { - if (getEventType() != type) - throwXMLStreamException("type not matched"); - if (nameSpace != null && !nameSpace.equals(getNamespaceURI())) - throwXMLStreamException("Name Space not matched"); - if (name != null - && !(getEventType() == ATTRIBUTE ? name.equals(((AttributeEvent) event).name.getLocalPart()) : event instanceof EndElement - && name.equals(((EndElement) event).name.getLocalPart()))) - throwXMLStreamException("name not matched"); - } -} +/** + * + * 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.util.resource; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; + +import javax.xml.XMLConstants; +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; +import javax.xml.stream.Location; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.eclipse.emf.ecore.xmi.XMLResource; +import org.xml.sax.Attributes; +import org.xml.sax.Locator; + +/** + * This special purpose XMLStreamReader is used to produce a StAX event stream corresponding to a list of events + * recorded earlier. The recorded events are generated by the inner class RecordedEventXMLStreamReader.Tag, + * which records the events in either of 2 ways: + * + * 1) in conjunction with class SDOXMLLoadImpl, it records events corresponding to the SAX events being + * handled by the SDOXMLLoadImpl when loading XML using SDOXMLResourceImpl. + * 2) when Tag.record() is called (see class ChangeSummaryStreamDeserializer), it walks through and records + * the StAX events produced by another XMLStreamReader. + * + * This class is used by the SDO StAX-based ChangeSummaryType-property loader, class + * ChangeSummaryStreamDeserializer, which is inoked by and uses (for loading deleted object XML fragments) + * the SAX-based loader class XMLResourceImpl. + */ +public abstract class RecordedEventXMLStreamReader implements XMLStreamReader { + + static private class Event { + int type; + + public NamespaceContext nameSpaceContext; + + Location location; + + protected final void initialize(XMLStreamReader reader) { + nameSpaceContext = reader.getNamespaceContext(); + location = reader.getLocation(); + } + + protected final void location(final Locator locator) { + location = new Location() { + public int getCharacterOffset() { + return -1; + } + + public int getColumnNumber() { + return locator.getColumnNumber(); + } + + public int getLineNumber() { + return locator.getLineNumber(); + } + + public String getPublicId() { + return locator.getPublicId(); + } + + public String getSystemId() { + return locator.getSystemId(); + } + }; + } + } + + static class ValueEvent extends Event { + final String value; + + protected ValueEvent(String v) { + value = v; + } + } + + static protected class Reference extends ValueEvent { + final String target; + + protected Reference(String name, String data) { + super(data); + target = name; + } + } + + static protected final class AttributeEvent extends Reference { + final QName name; + + final String nameSpace, prefix; + + int attributes; + + final boolean specified; + + protected AttributeEvent(XMLStreamReader reader) { + super(reader.getAttributeType(0), reader.getAttributeValue(0)); + attributes = reader.getAttributeCount(); + name = reader.getAttributeName(0); + nameSpace = reader.getAttributeNamespace(0); + prefix = reader.getAttributePrefix(0); + specified = reader.isAttributeSpecified(0); + } + } + + static protected final class NameSpaceEvent extends Reference { + int nameSpaces; + + protected NameSpaceEvent(XMLStreamReader reader) { + super(reader.getNamespacePrefix(0), reader.getNamespaceURI(0)); + nameSpaces = reader.getNamespaceCount(); + } + } + + static protected String prefix(String qName, String nameSpace) { + int delimiter = qName.indexOf(':'); + if (delimiter != -1) + return qName.substring(0, delimiter); + if (nameSpace.length() != 0) + return XMLConstants.DEFAULT_NS_PREFIX; + // if (nameSpaceContext.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX) != null || xsdHelper.getGlobalProperty(null, name, element) == null) + return null; + } + + static class EndElement extends Event { + List nameSpaces/* = null */; + + public final QName name; + + public final String nameSpace; + + final String prefix; + + protected EndElement(XMLStreamReader reader) { + name = reader.getName(); + nameSpace = reader.getNamespaceURI(); + prefix = reader.getPrefix(); + int count = reader.getNamespaceCount(); + if (count == 0) + return; + nameSpaces = new ArrayList(count); + int index = 0; + do + Tag.bind(reader.getNamespacePrefix(index), reader.getNamespaceURI(index), nameSpaces); + while (++index != count); + } + + protected EndElement(String uri, String local, String p, Locator locator) { + if (p == null) { + name = new QName(uri, local, XMLConstants.DEFAULT_NS_PREFIX); + nameSpace = null; + } else { + name = new QName(uri, local, p); + nameSpace = uri; + } + prefix = p; + location(locator); + } + } + + static class NameSpace { + final String prefix, uri; + + protected NameSpace(String p, String nameSpace) { + prefix = p; + uri = nameSpace; + } + } + + static final class Attribute extends NameSpace { + final String type, value; + + final QName qName; + + boolean specified/* = false */; + + protected Attribute(String t, String v, QName name, String prefix, String nameSpace) { + super(prefix, nameSpace); + type = t; + value = v; + qName = name; + } + } + + static final class AttributeList /* implements Attributes */{// TODO exclude XMLConstants.XMLNS_ATTRIBUTE + final List attributes; + + protected AttributeList(int size) { + attributes = new ArrayList(size); + } + + /* + * @param uri Never null + */ + public final int getIndex(String uri, String localName) { + for (int index = getLength(); index != 0;) + if (getLocalName(--index).equals(localName) && uri.equals(getURI(index))) + return index; + return -1; + } + + public final int getLength() { + return attributes.size(); + } + + protected final Attribute attribute(int index) { + return (Attribute) attributes.get(index); + } + + public final String getLocalName(int index) { + return attribute(index).qName.getLocalPart(); + } + + public final String getType(int index) { + return attribute(index).type; + } + + /*public String getType(String uri, String localName) { + int index = getIndex(uri, localName); + return index == -1 ? null: getType(index); + } */ + + public final String getURI(int index) { + return attribute(index).uri; + } + + public final String getValue(int index) { + return attribute(index).value; + } + + /* + * @param uri Never null + */ + public final String getValue(String uri, String localName) { + int index = getIndex(uri, localName); + return index == -1 ? null : getValue(index); + } + } + + static protected class StartElement extends EndElement { + final AttributeList attributes; + + protected StartElement(XMLStreamReader reader) { + super(reader); + int count = reader.getAttributeCount(); + if (count == 0) + attributes = null; + else { + attributes = new AttributeList(count); + int index = 0; + do { + Attribute attribute = new Attribute(reader.getAttributeType(index), reader.getAttributeValue(index), reader + .getAttributeName(index), reader.getAttributePrefix(index), reader.getAttributeNamespace(index)); + attribute.specified = reader.isAttributeSpecified(index); + attributes.attributes.add(attribute); + } while (++index != count); + } + } + + protected StartElement(String nameSpace, String local, String prefix, Attributes attributeArray, Locator locator, List bindings, + final NamespaceContext context) { + super(nameSpace, local, prefix, locator); + nameSpaces = bindings; + nameSpaceContext = bindings == null || bindings.isEmpty() ? context : new NamespaceContext() { + public String getNamespaceURI(String prefix) { + for (int index = nameSpaces.size(); index != 0;) { + NameSpace binding = (NameSpace) nameSpaces.get(--index); + if (binding.prefix.equals(prefix)) + return binding.uri; + } + return context.getNamespaceURI(prefix); + } + + public String getPrefix(String namespaceURI) { + for (int index = nameSpaces.size(); index != 0;) { + NameSpace binding = (NameSpace) nameSpaces.get(--index); + if (binding.uri.equals(namespaceURI)) + return binding.prefix; + } + return context.getPrefix(namespaceURI); + } + + public Iterator getPrefixes(final String namespaceURI) { + final Iterator iterator = context.getPrefixes(namespaceURI); + return new Iterator() { + Iterator bindings = nameSpaces.iterator(); + + NameSpace binding/* = null */; + + protected final boolean prefix() { + while (bindings.hasNext()) { + binding = (NameSpace) bindings.next(); + if (binding.uri.equals(namespaceURI)) + return true; + } + bindings = null; + return false; + } + + public boolean hasNext() { + return bindings != null && prefix() || iterator.hasNext(); + } + + protected NameSpace nameSpace; + + public Object next() { + if (bindings == null || binding == null && !prefix()) + return iterator.next(); + nameSpace = binding; + binding = null; + return nameSpace.prefix; + } + + public void remove() { + if (bindings == null) + iterator.remove(); + else + nameSpaces.remove(nameSpace); + } + }; + } + }; + int count = attributeArray.getLength(); + if (count == 0) + attributes = null; + else { + attributes = new AttributeList(count); + int index = 0; + do { + QName name; + nameSpace = attributeArray.getURI(index); + local = attributeArray.getLocalName(index); + prefix = prefix(attributeArray.getQName(index), nameSpace); + if (prefix == null) { + name = new QName(nameSpace, local, XMLConstants.DEFAULT_NS_PREFIX); + nameSpace = null; + } else + name = new QName(nameSpace, local, prefix); + attributes.attributes.add(new Attribute(attributeArray.getType(index), attributeArray.getValue(index), name, prefix, nameSpace)); + } while (++index != count); + } + } + } + + static public class Tag extends StartElement { + public Tag(XMLStreamReader reader) { + super(reader); + initialize(reader); + } + + public List events/* = null */; // may be empty + + protected final void events() { + events = new ArrayList(); + } + + public Tag(String nameSpace, String local, String prefix, Attributes attributes, Locator locator, NamespaceContext context, List bindings) { + super(nameSpace, local, prefix, attributes, locator, bindings, context); + events(); + } + + static public void bind(String prefix, String nameSpace, Collection nameSpaces) { + nameSpaces.add(new NameSpace(prefix, nameSpace)); + } + + protected int nest/* = 0 */; + + public final void start(String nameSpace, String local, String qName, Attributes attributes, Locator locator, List bindings) { + Event event; + for (int index = events.size();/* true */;) { + if (index == 0) { + event = this; + break; + } + event = (Event) events.get(--index); + if (event.type != END_ELEMENT) + break; + siblings: for (int nest = 0;/* true */;) + switch (((Event) events.get(--index)).type) { + case START_ELEMENT: + if (nest == 0) + break siblings; + --nest; + break; + case END_ELEMENT: + ++nest; + } + } + Event start = new StartElement(nameSpace, local, prefix(qName, nameSpace), attributes, locator, bindings, event.nameSpaceContext); + start.type = START_ELEMENT; + events.add(start); + ++nest; + } + + protected final void add (Event event) + { + int index = events.size(); + event.nameSpaceContext = index == 0 ? nameSpaceContext : ((Event) events.get(--index)).nameSpaceContext; + events.add(event); + } + + public final void text(int type, String value, Locator locator) { + Event event = new ValueEvent(value); + event.type = type; + event.location(locator); + //int index = events.size(); + add(event); + } + + public final boolean end(String nameSpace, String local, String qName, Locator locator) { + Event end = new EndElement(nameSpace, local, prefix(qName, nameSpace), locator); + end.type = END_ELEMENT; + add(end); + if (nest == 0) + return true; + --nest; + return false; + } + + public final XMLStreamReader play(final XMLResource resource) { + return new RecordedEventXMLStreamReader(this) { + public void close() { + } + + public String getCharacterEncodingScheme() { + return null; // TODO + } + + public String getEncoding() { + return resource.getEncoding(); + } + + public Object getProperty(String property) { + return null; // TODO javax.xml.stream.notations & javax.xml.stream.entities for DTD + } + + public String getVersion() { + return resource.getXMLVersion(); + } + + public boolean isStandalone() { + return false; // TODO + } + + public boolean standaloneSet() { + return false; // TODO + } + }; + } + + protected final void add(Event event, int type, XMLStreamReader reader) { + event.type = type; + event.initialize(reader); + events.add(event); + } + + public final boolean record(XMLStreamReader reader) throws XMLStreamException { + events(); + for (int nest = 0; reader.hasNext();) { + Event event; + int type = reader.next(); + switch (type) { + case CHARACTERS: + case CDATA: + case COMMENT: + case SPACE: + case DTD: + event = new ValueEvent(reader.getText()); + break; + case ENTITY_REFERENCE: + event = new Reference(reader.getLocalName(), reader.getText()); + break; + case PROCESSING_INSTRUCTION: + event = new Reference(reader.getPITarget(), reader.getPIData()); + break; + case ATTRIBUTE: + event = new AttributeEvent(reader); + break; + case NAMESPACE: + event = new NameSpaceEvent(reader); + break; + case START_ELEMENT: + ++nest; + event = new StartElement(reader); + break; + case END_ELEMENT: + add(new EndElement(reader), type, reader); + if (nest == 0) + return false; + --nest; + continue; + case END_DOCUMENT: + return true; // report error? + default: // new type + event = new Event(); + } + add(event, type, reader); + } + return true; // report error? + } + + public final XMLStreamReader play(final XMLStreamReader reader) { + return new RecordedEventXMLStreamReader(this) { + public void close() throws XMLStreamException { + reader.close(); + } + + public String getCharacterEncodingScheme() { + return reader.getCharacterEncodingScheme(); + } + + public String getEncoding() { + return reader.getEncoding(); + } + + public Object getProperty(String property) { + return reader.getProperty(property); // TODO javax.xml.stream.notations & javax.xml.stream.entities for DTD + } + + public String getVersion() { + return reader.getVersion(); + } + + public boolean isStandalone() { + return reader.isStandalone(); + } + + public boolean standaloneSet() { + return reader.standaloneSet(); + } + }; + } + } + + Event event; + + final List events; + + final int size; + + protected RecordedEventXMLStreamReader(Tag tag) { + event = tag; + tag.type = START_ELEMENT; + events = tag.events; + size = events.size(); + } + + public int getAttributeCount() { + switch (getEventType()) { + case START_ELEMENT: + AttributeList attributes = ((StartElement) event).attributes; + return attributes == null ? 0 : attributes.getLength(); + case ATTRIBUTE: + return ((AttributeEvent) event).attributes; + } + throw new IllegalStateException("Neither START_ELEMENT nor ATTRIBUTE"); + } + + protected final AttributeList attributes() { + if (getEventType() == START_ELEMENT) + return ((StartElement) event).attributes; + throw new IllegalStateException("Neither START_ELEMENT nor ATTRIBUTE"); + } + + public String getAttributeLocalName(int index) { + return attributes().getLocalName(index); + } + + static Attribute attribute(AttributeList attributes, int index) { + return (Attribute) attributes.attributes.get(index); + } + + public QName getAttributeName(int index) { + return getEventType() == ATTRIBUTE ? ((AttributeEvent) event).name : attribute(attributes(), index).qName; + } + + public String getAttributeNamespace(int index) { + return getEventType() == ATTRIBUTE ? ((AttributeEvent) event).nameSpace : attributes().getURI(index); + } + + public String getAttributePrefix(int index) { + return getEventType() == ATTRIBUTE ? ((AttributeEvent) event).prefix : attribute(attributes(), index).prefix; + } + + public String getAttributeType(int index) { + return getEventType() == ATTRIBUTE ? ((Reference) event).target : attributes().getType(index); + } + + public String getAttributeValue(int index) { + return getEventType() == ATTRIBUTE ? ((ValueEvent) event).value : attributes().getValue(index); + } + + public boolean isAttributeSpecified(int index) { + if (getEventType() == ATTRIBUTE) + return ((AttributeEvent) event).specified; + AttributeList attributes = attributes(); + return attribute(attributes, index).specified; + } + + public String getAttributeValue(String nameSpace, String name) { + if (getEventType() == ATTRIBUTE) { + AttributeEvent attribute = (AttributeEvent) event; + return !attribute.name.getLocalPart().equals(name) ? null : nameSpace == null ? (attribute.nameSpace == null ? attribute.value : null) + : nameSpace.equals(attribute.nameSpace) ? attribute.value : null; + } + AttributeList attributes = attributes(); + return attributes == null ? null : attributes.getValue(nameSpace == null ? "" : nameSpace, name); + } + + protected StringBuffer buffer/* = null */; + + public String getElementText() { + if (buffer != null) + buffer.delete(0, buffer.length()); + for (;;) + switch (next()) { + case END_ELEMENT: + return buffer == null ? null : buffer.toString(); + default: + if (buffer == null) + buffer = new StringBuffer(); + buffer.append(getText()); + case PROCESSING_INSTRUCTION: + case COMMENT: + } + } + + public final int getEventType() { + return event.type; + } + + public String getLocalName() { + if (getEventType() == ENTITY_REFERENCE) + return ((Reference) event).target; + if (event instanceof EndElement) + return ((EndElement) event).name.getLocalPart(); + throw new IllegalStateException("Neither START_ELEMENT, END_ELEMENT nor ENTITY_REFERENCE"); + } + + public final Location getLocation() { + return event.location; + } + + public QName getName() { + if (hasName()) + return ((EndElement) event).name; + throw new IllegalStateException("Neither START_ELEMENT nor END_ELEMENT"); + } + + public final NamespaceContext getNamespaceContext() { + return event.nameSpaceContext; + } + + public int getNamespaceCount() { + if (getEventType() == NAMESPACE) + return ((NameSpaceEvent) event).nameSpaces; + if (!(event instanceof EndElement)) + throw new IllegalStateException("Neither START_ELEMENT, END_ELEMENT nor NAMESPACE"); + Collection nameSpaces = ((EndElement) event).nameSpaces; + return nameSpaces == null ? 0 : nameSpaces.size(); + } + + protected final NameSpace getNameSpace(int index) { + if (event instanceof EndElement) + return (NameSpace) ((EndElement) event).nameSpaces.get(index); + throw new IllegalStateException("Neither START_ELEMENT, END_ELEMENT nor NAMESPACE"); + } + + public String getNamespacePrefix(int index) { + return getEventType() == NAMESPACE ? ((Reference) event).target : getNameSpace(index).prefix; + } + + public final String getNamespaceURI() { + switch (getEventType()) { + case ATTRIBUTE: + return ((AttributeEvent) event).nameSpace; + case NAMESPACE: + return ((ValueEvent) event).value; + } + return event instanceof EndElement ? ((EndElement) event).nameSpace : null; + } + + public String getNamespaceURI(String prefix) { + return getNamespaceContext().getNamespaceURI(prefix); + } + + public String getNamespaceURI(int index) { + return getEventType() == NAMESPACE ? ((ValueEvent) event).value : getNameSpace(index).uri; + } + + public String getPIData() { + return getEventType() == PROCESSING_INSTRUCTION ? ((ValueEvent) event).value : null; + } + + public String getPITarget() { + return getEventType() == PROCESSING_INSTRUCTION ? ((Reference) event).target : null; + } + + public String getPrefix() { + switch (getEventType()) { + case ATTRIBUTE: + return ((AttributeEvent) event).prefix; + case NAMESPACE: + return ((Reference) event).target; + } + return event instanceof EndElement ? ((EndElement) event).prefix : null; + } + + public final String getText() { + if (hasText()) + return ((ValueEvent) event).value; + throw new IllegalStateException("Neither CHARACTERS, CDATA, COMMENT, SPACE, ENTITY_REFERENCE nor DTD"); + } + + public final char[] getTextCharacters() { + switch (getEventType()) { + case CHARACTERS: + case CDATA: + case COMMENT: + case SPACE: + return ((ValueEvent) event).value.toCharArray(); + } + throw new IllegalStateException("Neither CHARACTERS, CDATA, COMMENT nor SPACE"); + } + + public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length) { + char[] source = getTextCharacters(); + if (sourceStart > source.length) + throw new IndexOutOfBoundsException("source start > source length"); + int sourceLen = source.length - sourceStart; + if (length > sourceLen) + length = sourceLen; + System.arraycopy(source, sourceStart, target, targetStart, length); + return sourceLen; + } + + public int getTextLength() { + return getTextCharacters().length; + } + + public int getTextStart() { + return 0; + } + + public final boolean hasName() { + return event instanceof EndElement; + } + + protected int next/* = 0 */; + + public final boolean hasNext() { + return next != size; + } + + public final boolean hasText() { + switch (getEventType()) { + case CHARACTERS: + case CDATA: + case COMMENT: + case SPACE: + case ENTITY_REFERENCE: + case DTD: + return true; + } + return false; + } + + public boolean isCharacters() { + switch (getEventType()) { + case CHARACTERS: + case CDATA: + case SPACE: + return true; + } + return false; + } + + public boolean isEndElement() { + return getEventType() == END_ELEMENT; + } + + public boolean isStartElement() { + return getEventType() == START_ELEMENT; + } + + protected final boolean areWhiteSpace() { + String text = getText(); + for (int index = text.length(); index != 0;) + if (!Character.isWhitespace(text.charAt(--index))) + return false; + return true; + } + + public boolean isWhiteSpace() { + switch (getEventType()) { + case CHARACTERS: + case CDATA: + return areWhiteSpace(); + case SPACE: + return true; + } + return false; + } + + public final int next() { + if (!hasNext()) + throw new NoSuchElementException(); + event = (Event) events.get(next++); + return event.type; + } + + protected final void throwXMLStreamException(String message) throws XMLStreamException { + throw new XMLStreamException(message, getLocation()); + } + + public int nextTag() throws XMLStreamException { + for (;;) { + int type = next(); + switch (type) { + case CHARACTERS: + case CDATA: + if (!areWhiteSpace()) + break; + case SPACE: + case PROCESSING_INSTRUCTION: + case COMMENT: + continue; + case START_ELEMENT: + case END_ELEMENT: + return type; + } + throwXMLStreamException("expected start or end tag"); + } + } + + public void require(int type, String nameSpace, String name) throws XMLStreamException { + if (getEventType() != type) + throwXMLStreamException("type not matched"); + if (nameSpace != null && !nameSpace.equals(getNamespaceURI())) + throwXMLStreamException("Name Space not matched"); + if (name != null + && !(getEventType() == ATTRIBUTE ? name.equals(((AttributeEvent) event).name.getLocalPart()) : event instanceof EndElement + && name.equals(((EndElement) event).name.getLocalPart()))) + throwXMLStreamException("name not matched"); + } +} diff --git a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/SDODeserializer.java b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/SDODeserializer.java index af14f13319..01c043b074 100644 --- a/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/SDODeserializer.java +++ b/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/resource/SDODeserializer.java @@ -1,340 +1,340 @@ -/** - * - * 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.util.resource; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import javax.xml.namespace.NamespaceContext; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.sdo.helper.HelperContextImpl; -import org.apache.tuscany.sdo.helper.TypeHelperImpl; -import org.apache.tuscany.sdo.helper.XMLStreamHelper; -import org.apache.tuscany.sdo.helper.XMLStreamHelperImpl; -import org.apache.tuscany.sdo.util.StreamDeserializer; -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.common.util.TreeIterator; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EReference; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.emf.ecore.util.ExtendedMetaData; -import org.eclipse.emf.ecore.xmi.XMLResource; - -import commonj.sdo.Property; -import commonj.sdo.Type; -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.TypeHelper; -import commonj.sdo.helper.XSDHelper; - -/** - * SDO StAX Deserializer. The instance isn't thread-safe, however it's safe to use the instance any times on the same thread. - */ -public class SDODeserializer extends StreamDeserializer { - private HelperContext hc; - protected final void initialize(XMLStreamReader stream, HelperContext scope, Object rootObject) { - hc = scope; - reader = stream; - xsdHelper = scope.getXSDHelper(); - typeHelper = scope.getTypeHelper(); - extendedMetaData = ((TypeHelperImpl) typeHelper).getExtendedMetaData(); - deserializer = (XMLStreamHelperImpl)((HelperContextImpl)scope).getXMLStreamHelper();; - root = (EObject) rootObject; - } - - XSDHelper xsdHelper; - - protected Property propertyInSequence; - - Property getProperty(Object type) { - EClass c = (EClass) type; - EStructuralFeature containment = (EStructuralFeature) propertyInSequence; - Object containing = extendedMetaData.getAffiliation(c, containment); - // if (containing == null) report error? - if (containment == containing && containment.isDerived()) { - containing = extendedMetaData.getMixedFeature(c); - if (containing == null) { - containing = extendedMetaData.getGroup(containment); - if (containing == null) - return propertyInSequence; - } - } - return (Property) containing; - } - - protected final Property getProperty(Type type, String nameSpace, String name, boolean element) { - for (Iterator iterator = type.getProperties().iterator(); iterator.hasNext();) { - propertyInSequence = (Property) iterator.next(); - if (name.equals(xsdHelper.getLocalName(propertyInSequence)) - && nameSpace.equals(xsdHelper.getNamespaceURI(propertyInSequence))) - return getProperty(type); - } - propertyInSequence = xsdHelper.getGlobalProperty(nameSpace, name, element); - // if (propertyInSequence == null) report error? - return getProperty(type); - } - - protected final Property getProperty(Type type, String name) { - propertyInSequence = type.getProperty(name); - // if (propertyInSequence == null) report error? - return getProperty(type); - } - - protected final Property getProperty(String nameSpace, String name, Type type) { - return null == nameSpace ? getProperty(type, name) : getProperty(type, nameSpace, name, true); - } - - XMLStreamHelperImpl deserializer; - - TypeHelper typeHelper; - - protected Object load(XMLStreamReader reader, Map options) throws XMLStreamException { - return deserializer.loadObject(reader, options); - } - - static Object value(Type type, XMLStreamReader reader) throws XMLStreamException { - return value(type, reader.getElementText(), reader.getNamespaceContext()); - } - - protected final Object value(Type type) throws XMLStreamException { - return "true".equals(reader.getAttributeValue(ExtendedMetaData.XSI_URI, XMLResource.NIL)) ? null : type.isDataType() ? value(type, reader) - : load(reader, null); - } - - Map options/* = null */; - - protected final Object value(XMLStreamReader reader) throws XMLStreamException { - Type propertyType = propertyInSequence.getType(); - if (propertyType.isDataType()) - return value(propertyType, reader); - if (options == null) - options = new HashMap(); - options.put(XMLStreamHelper.OPTION_DEFAULT_ROOT_TYPE, propertyType); - return load(reader, options); - } - - private boolean match(String name, String space, EStructuralFeature feature) { - return name.equals(extendedMetaData.getName(feature)) && space.equals(extendedMetaData.getNamespace(feature)); - } - - EObject step(String ref, int step, int index, EObject container, String prefix, NamespaceContext nameSpaces) { - String name = ref.substring(step, index); - Iterator iterator = container.eContents().iterator(); - if (iterator.hasNext()) - if (prefix == null) - do { - container = (EObject) iterator.next(); - // if( container == null )continue; - if (name.equals(extendedMetaData.getName(container.eContainmentFeature()))) - return container; - } while (iterator.hasNext()); - else { - prefix = nameSpaces.getNamespaceURI(prefix); - do { - container = (EObject) iterator.next(); - // if( container == null )continue; - if (match(name, prefix, container.eContainmentFeature())) - return container; - } while (iterator.hasNext()); - } - return null; - } - - EObject root; - - ExtendedMetaData extendedMetaData; - - protected final EObject referent(String ref, NamespaceContext nameSpaces) { - int length = ref.length(); - switch (length) { - case 0: - return null; - case 1: // # - return root; - } - EObject container; - int step; - if (ref.charAt(1) == '/') { - container = EcoreUtil.getRootContainer(root); - if (length == 2) - return container; - if (ref.charAt(2) == '/') { - for (Iterator iterator = container.eContents().iterator();/* true */;) { - if (!iterator.hasNext()) - return null; - container = (EObject) iterator.next(); - // if( container != null ) - break; - } - /*#// is invalid - if (length == 3) - return container; */ - step = 3; - } else - step = 2; - } else { - container = root; - step = 1; - } - String prefix = null; - for (int index = step; ++index != length;) { - switch (ref.charAt(index)) { - case '/': - container = step(ref, step, index, container, prefix, nameSpaces); - if (container == null) - return null; - break; - case ':': - prefix = ref.substring(step, index); - if (++index == length) - return container; // report error? - step = index; - default: - continue; - case '[': - name = ref.substring(step, index); - step = ref.indexOf(']', index + 2); - if (step == -1) - return container; // report error? - index = Integer.parseInt(ref.substring(++index, step)); - EStructuralFeature feature; - Iterator iterator = container.eContents().iterator(); - if (prefix == null) - do { - if (!iterator.hasNext()) - return null; - EObject content = (EObject) iterator.next(); - // if( content == null )continue; - feature = content.eContainmentFeature(); - } while (!name.equals(extendedMetaData.getName(feature))); - else { - prefix = nameSpaces.getNamespaceURI(prefix); - do { - if (!iterator.hasNext()) - return null; - EObject content = (EObject) iterator.next(); - // if( content == null )continue; - feature = content.eContainmentFeature(); - } while (!match(name, prefix, feature)); - } - Object value = container.eGet(feature); - if (value instanceof List) { - List values = (List) value; - if (index > values.size()) - return null; - container = (EObject) values.get(--index); - } else if (index == 1) - container = (EObject) value; - else - return null; - index = ref.indexOf('/', ++step); - if (index == -1) - return container; - } - if (++index == length) - return container; - step = index; - prefix = null; - } - return step(ref, step, length, container, prefix, nameSpaces); - } - - static protected class Ref implements EObject // FeatureMapEntry value - { - protected Ref(String path, NamespaceContext context) { - ref = path; - nameSpaces = context; - } - - final String ref; - - final NamespaceContext nameSpaces; - - public TreeIterator eAllContents() { - return null; - } - public EClass eClass() { - return null; - } - public EObject eContainer() { - return null; - } - public EStructuralFeature eContainingFeature() { - return null; - } - public EReference eContainmentFeature() { - return null; - } - public EList eContents() { - return null; - } - public EList eCrossReferences() { - return null; - } - public Object eGet(EStructuralFeature feature) { - return null; - } - public Object eGet(EStructuralFeature feature, boolean resolve) { - return null; - } - public boolean eIsProxy() { - return false; - } - public boolean eIsSet(EStructuralFeature feature) { - return false; - } - public Resource eResource() { - return null; - } - public void eSet(EStructuralFeature feature, Object newValue) { - } - public void eUnset(EStructuralFeature feature) { - } - public EList eAdapters() { - return null; - } - public boolean eDeliver() { - return false; - } - public void eNotify(Notification notification) { - } - public void eSetDeliver(boolean deliver) { - } - } - - protected final EObject referent(Ref path) { - return referent(path.ref, path.nameSpaces); - } - - protected final Type typeXSI() { - return typedXSI() ? typeHelper.getType(nameSpace, name) : null; - } - - protected final Type globalElementType(String nameSpace, String name) { - return xsdHelper.getGlobalProperty(nameSpace, name, true).getType(); - } -} +/** + * + * 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.util.resource; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sdo.helper.HelperContextImpl; +import org.apache.tuscany.sdo.helper.TypeHelperImpl; +import org.apache.tuscany.sdo.helper.XMLStreamHelper; +import org.apache.tuscany.sdo.helper.XMLStreamHelperImpl; +import org.apache.tuscany.sdo.util.StreamDeserializer; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.TreeIterator; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.ecore.util.ExtendedMetaData; +import org.eclipse.emf.ecore.xmi.XMLResource; + +import commonj.sdo.Property; +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XSDHelper; + +/** + * SDO StAX Deserializer. The instance isn't thread-safe, however it's safe to use the instance any times on the same thread. + */ +public class SDODeserializer extends StreamDeserializer { + private HelperContext hc; + protected final void initialize(XMLStreamReader stream, HelperContext scope, Object rootObject) { + hc = scope; + reader = stream; + xsdHelper = scope.getXSDHelper(); + typeHelper = scope.getTypeHelper(); + extendedMetaData = ((TypeHelperImpl) typeHelper).getExtendedMetaData(); + deserializer = (XMLStreamHelperImpl)((HelperContextImpl)scope).getXMLStreamHelper();; + root = (EObject) rootObject; + } + + XSDHelper xsdHelper; + + protected Property propertyInSequence; + + Property getProperty(Object type) { + EClass c = (EClass) type; + EStructuralFeature containment = (EStructuralFeature) propertyInSequence; + Object containing = extendedMetaData.getAffiliation(c, containment); + // if (containing == null) report error? + if (containment == containing && containment.isDerived()) { + containing = extendedMetaData.getMixedFeature(c); + if (containing == null) { + containing = extendedMetaData.getGroup(containment); + if (containing == null) + return propertyInSequence; + } + } + return (Property) containing; + } + + protected final Property getProperty(Type type, String nameSpace, String name, boolean element) { + for (Iterator iterator = type.getProperties().iterator(); iterator.hasNext();) { + propertyInSequence = (Property) iterator.next(); + if (name.equals(xsdHelper.getLocalName(propertyInSequence)) + && nameSpace.equals(xsdHelper.getNamespaceURI(propertyInSequence))) + return getProperty(type); + } + propertyInSequence = xsdHelper.getGlobalProperty(nameSpace, name, element); + // if (propertyInSequence == null) report error? + return getProperty(type); + } + + protected final Property getProperty(Type type, String name) { + propertyInSequence = type.getProperty(name); + // if (propertyInSequence == null) report error? + return getProperty(type); + } + + protected final Property getProperty(String nameSpace, String name, Type type) { + return null == nameSpace ? getProperty(type, name) : getProperty(type, nameSpace, name, true); + } + + XMLStreamHelperImpl deserializer; + + TypeHelper typeHelper; + + protected Object load(XMLStreamReader reader, Map options) throws XMLStreamException { + return deserializer.loadObject(reader, options); + } + + static Object value(Type type, XMLStreamReader reader) throws XMLStreamException { + return value(type, reader.getElementText(), reader.getNamespaceContext()); + } + + protected final Object value(Type type) throws XMLStreamException { + return "true".equals(reader.getAttributeValue(ExtendedMetaData.XSI_URI, XMLResource.NIL)) ? null : type.isDataType() ? value(type, reader) + : load(reader, null); + } + + Map options/* = null */; + + protected final Object value(XMLStreamReader reader) throws XMLStreamException { + Type propertyType = propertyInSequence.getType(); + if (propertyType.isDataType()) + return value(propertyType, reader); + if (options == null) + options = new HashMap(); + options.put(XMLStreamHelper.OPTION_DEFAULT_ROOT_TYPE, propertyType); + return load(reader, options); + } + + private boolean match(String name, String space, EStructuralFeature feature) { + return name.equals(extendedMetaData.getName(feature)) && space.equals(extendedMetaData.getNamespace(feature)); + } + + EObject step(String ref, int step, int index, EObject container, String prefix, NamespaceContext nameSpaces) { + String name = ref.substring(step, index); + Iterator iterator = container.eContents().iterator(); + if (iterator.hasNext()) + if (prefix == null) + do { + container = (EObject) iterator.next(); + // if( container == null )continue; + if (name.equals(extendedMetaData.getName(container.eContainmentFeature()))) + return container; + } while (iterator.hasNext()); + else { + prefix = nameSpaces.getNamespaceURI(prefix); + do { + container = (EObject) iterator.next(); + // if( container == null )continue; + if (match(name, prefix, container.eContainmentFeature())) + return container; + } while (iterator.hasNext()); + } + return null; + } + + EObject root; + + ExtendedMetaData extendedMetaData; + + protected final EObject referent(String ref, NamespaceContext nameSpaces) { + int length = ref.length(); + switch (length) { + case 0: + return null; + case 1: // # + return root; + } + EObject container; + int step; + if (ref.charAt(1) == '/') { + container = EcoreUtil.getRootContainer(root); + if (length == 2) + return container; + if (ref.charAt(2) == '/') { + for (Iterator iterator = container.eContents().iterator();/* true */;) { + if (!iterator.hasNext()) + return null; + container = (EObject) iterator.next(); + // if( container != null ) + break; + } + /*#// is invalid + if (length == 3) + return container; */ + step = 3; + } else + step = 2; + } else { + container = root; + step = 1; + } + String prefix = null; + for (int index = step; ++index != length;) { + switch (ref.charAt(index)) { + case '/': + container = step(ref, step, index, container, prefix, nameSpaces); + if (container == null) + return null; + break; + case ':': + prefix = ref.substring(step, index); + if (++index == length) + return container; // report error? + step = index; + default: + continue; + case '[': + name = ref.substring(step, index); + step = ref.indexOf(']', index + 2); + if (step == -1) + return container; // report error? + index = Integer.parseInt(ref.substring(++index, step)); + EStructuralFeature feature; + Iterator iterator = container.eContents().iterator(); + if (prefix == null) + do { + if (!iterator.hasNext()) + return null; + EObject content = (EObject) iterator.next(); + // if( content == null )continue; + feature = content.eContainmentFeature(); + } while (!name.equals(extendedMetaData.getName(feature))); + else { + prefix = nameSpaces.getNamespaceURI(prefix); + do { + if (!iterator.hasNext()) + return null; + EObject content = (EObject) iterator.next(); + // if( content == null )continue; + feature = content.eContainmentFeature(); + } while (!match(name, prefix, feature)); + } + Object value = container.eGet(feature); + if (value instanceof List) { + List values = (List) value; + if (index > values.size()) + return null; + container = (EObject) values.get(--index); + } else if (index == 1) + container = (EObject) value; + else + return null; + index = ref.indexOf('/', ++step); + if (index == -1) + return container; + } + if (++index == length) + return container; + step = index; + prefix = null; + } + return step(ref, step, length, container, prefix, nameSpaces); + } + + static protected class Ref implements EObject // FeatureMapEntry value + { + protected Ref(String path, NamespaceContext context) { + ref = path; + nameSpaces = context; + } + + final String ref; + + final NamespaceContext nameSpaces; + + public TreeIterator eAllContents() { + return null; + } + public EClass eClass() { + return null; + } + public EObject eContainer() { + return null; + } + public EStructuralFeature eContainingFeature() { + return null; + } + public EReference eContainmentFeature() { + return null; + } + public EList eContents() { + return null; + } + public EList eCrossReferences() { + return null; + } + public Object eGet(EStructuralFeature feature) { + return null; + } + public Object eGet(EStructuralFeature feature, boolean resolve) { + return null; + } + public boolean eIsProxy() { + return false; + } + public boolean eIsSet(EStructuralFeature feature) { + return false; + } + public Resource eResource() { + return null; + } + public void eSet(EStructuralFeature feature, Object newValue) { + } + public void eUnset(EStructuralFeature feature) { + } + public EList eAdapters() { + return null; + } + public boolean eDeliver() { + return false; + } + public void eNotify(Notification notification) { + } + public void eSetDeliver(boolean deliver) { + } + } + + protected final EObject referent(Ref path) { + return referent(path.ref, path.nameSpaces); + } + + protected final Type typeXSI() { + return typedXSI() ? typeHelper.getType(nameSpace, name) : null; + } + + protected final Type globalElementType(String nameSpace, String name) { + return xsdHelper.getGlobalProperty(nameSpace, name, true).getType(); + } +} diff --git a/java/sdo/impl/src/main/resources/META-INF/NOTICE b/java/sdo/impl/src/main/resources/META-INF/NOTICE index 6901a96038..9f9572a167 100644 --- a/java/sdo/impl/src/main/resources/META-INF/NOTICE +++ b/java/sdo/impl/src/main/resources/META-INF/NOTICE @@ -4,5 +4,4 @@ Copyright (c) 2005 - 2008 The Apache Software Foundation This product includes software developed at The Apache Software Foundation (http://www.apache.org/). -Please see the LICENSE file present in the META-INF directory of this archive. diff --git a/java/sdo/impl/src/main/resources/META-INF/README.txt b/java/sdo/impl/src/main/resources/META-INF/README.txt index b6d11e9008..c658fee5d5 100644 --- a/java/sdo/impl/src/main/resources/META-INF/README.txt +++ b/java/sdo/impl/src/main/resources/META-INF/README.txt @@ -1,5 +1,5 @@ -Apache Tuscany 1.1-incubating build February 2008) -=============================================== +Apache Tuscany 1.1-incubating build April 2008 +============================================== http://incubator.apache.org/tuscany/ diff --git a/java/sdo/impl/src/main/resources/xml/sdoInternal.xsd b/java/sdo/impl/src/main/resources/xml/sdoInternal.xsd index c1616ad7fe..b606caf424 100644 --- a/java/sdo/impl/src/main/resources/xml/sdoInternal.xsd +++ b/java/sdo/impl/src/main/resources/xml/sdoInternal.xsd @@ -1,33 +1,33 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/java/sdo/impl/src/main/resources/xml/sdoModelChangeSummary.xsd b/java/sdo/impl/src/main/resources/xml/sdoModelChangeSummary.xsd index 645b7b700a..6b596c5b36 100644 --- a/java/sdo/impl/src/main/resources/xml/sdoModelChangeSummary.xsd +++ b/java/sdo/impl/src/main/resources/xml/sdoModelChangeSummary.xsd @@ -1,28 +1,28 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/java/sdo/impl/src/test/java/com/example/ExpectedException/ExpectedExceptionFactory.java b/java/sdo/impl/src/test/java/com/example/ExpectedException/ExpectedExceptionFactory.java index 0ba0d7037e..938c4b25d2 100644 --- a/java/sdo/impl/src/test/java/com/example/ExpectedException/ExpectedExceptionFactory.java +++ b/java/sdo/impl/src/test/java/com/example/ExpectedException/ExpectedExceptionFactory.java @@ -1,70 +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 com.example.ExpectedException; - -import commonj.sdo.helper.HelperContext; - - -/** - * - * The Factory for the model. - * It provides a create method for each non-abstract class of the model. - * - * @generated - */ -public interface ExpectedExceptionFactory -{ - - /** - * The singleton instance of the factory. - * - * - * @generated - */ - ExpectedExceptionFactory INSTANCE = com.example.ExpectedException.impl.ExpectedExceptionFactoryImpl.init(); - - /** - * Returns a new object of class 'Type'. - * - * - * @return a new object of class 'Type'. - * @generated - */ - ExpectedExceptionType createExpectedExceptionType(); - - /** - * Returns a new object of class 'Sequence Read Only Type'. - * - * - * @return a new object of class 'Sequence Read Only Type'. - * @generated - */ - SequenceReadOnlyType createSequenceReadOnlyType(); - - /** - * Registers the types supported by this Factory within the supplied scope.argument - * - * - * @param scope an instance of HelperContext used to manage the scoping of types. - * @generated - */ - public void register(HelperContext scope); - -} //ExpectedExceptionFactory +/** + * + * 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 com.example.ExpectedException; + +import commonj.sdo.helper.HelperContext; + + +/** + * + * The Factory for the model. + * It provides a create method for each non-abstract class of the model. + * + * @generated + */ +public interface ExpectedExceptionFactory +{ + + /** + * The singleton instance of the factory. + * + * + * @generated + */ + ExpectedExceptionFactory INSTANCE = com.example.ExpectedException.impl.ExpectedExceptionFactoryImpl.init(); + + /** + * Returns a new object of class 'Type'. + * + * + * @return a new object of class 'Type'. + * @generated + */ + ExpectedExceptionType createExpectedExceptionType(); + + /** + * Returns a new object of class 'Sequence Read Only Type'. + * + * + * @return a new object of class 'Sequence Read Only Type'. + * @generated + */ + SequenceReadOnlyType createSequenceReadOnlyType(); + + /** + * Registers the types supported by this Factory within the supplied scope.argument + * + * + * @param scope an instance of HelperContext used to manage the scoping of types. + * @generated + */ + public void register(HelperContext scope); + +} //ExpectedExceptionFactory diff --git a/java/sdo/impl/src/test/java/com/example/ExpectedException/ExpectedExceptionType.java b/java/sdo/impl/src/test/java/com/example/ExpectedException/ExpectedExceptionType.java index 2f3e1ba63a..80159443dc 100644 --- a/java/sdo/impl/src/test/java/com/example/ExpectedException/ExpectedExceptionType.java +++ b/java/sdo/impl/src/test/java/com/example/ExpectedException/ExpectedExceptionType.java @@ -1,786 +1,786 @@ -/** - * - * 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 com.example.ExpectedException; - -import java.io.Serializable; - -import java.math.BigDecimal; -import java.math.BigInteger; - -import java.util.List; - -/** - * - * A representation of the model object 'Type'. - * - * - *

- * The following features are supported: - *

    - *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getStringVal String Val}
  • - *
  • {@link com.example.ExpectedException.ExpectedExceptionType#isBooleanVal Boolean Val}
  • - *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getByteVal Byte Val}
  • - *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getDecimalVal Decimal Val}
  • - *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getIntVal Int Val}
  • - *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getFloatVal Float Val}
  • - *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getDoubleVal Double Val}
  • - *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getDateVal Date Val}
  • - *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getShortVal Short Val}
  • - *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getLongVal Long Val}
  • - *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getListVal List Val}
  • - *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getBytesVal Bytes Val}
  • - *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getIntegerVal Integer Val}
  • - *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getCharVal Char Val}
  • - *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getReadOnlyVal Read Only Val}
  • - *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getReadOnlyListVal Read Only List Val}
  • - *
- *

- * - * @extends Serializable - * @generated - */ -public interface ExpectedExceptionType extends Serializable -{ - /** - * Returns the value of the 'String Val' attribute. - * - *

- * If the meaning of the 'String Val' attribute isn't clear, - * there really should be more of a description here... - *

- * - * @return the value of the 'String Val' attribute. - * @see #isSetStringVal() - * @see #unsetStringVal() - * @see #setStringVal(String) - * @generated - */ - String getStringVal(); - - /** - * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getStringVal String Val}' attribute. - * - * - * @param value the new value of the 'String Val' attribute. - * @see #isSetStringVal() - * @see #unsetStringVal() - * @see #getStringVal() - * @generated - */ - void setStringVal(String value); - - /** - * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getStringVal String Val}' attribute. - * - * - * @see #isSetStringVal() - * @see #getStringVal() - * @see #setStringVal(String) - * @generated - */ - void unsetStringVal(); - - /** - * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getStringVal String Val}' attribute is set. - * - * - * @return whether the value of the 'String Val' attribute is set. - * @see #unsetStringVal() - * @see #getStringVal() - * @see #setStringVal(String) - * @generated - */ - boolean isSetStringVal(); - - /** - * Returns the value of the 'Boolean Val' attribute. - * - *

- * If the meaning of the 'Boolean Val' attribute isn't clear, - * there really should be more of a description here... - *

- * - * @return the value of the 'Boolean Val' attribute. - * @see #isSetBooleanVal() - * @see #unsetBooleanVal() - * @see #setBooleanVal(boolean) - * @generated - */ - boolean isBooleanVal(); - - /** - * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#isBooleanVal Boolean Val}' attribute. - * - * - * @param value the new value of the 'Boolean Val' attribute. - * @see #isSetBooleanVal() - * @see #unsetBooleanVal() - * @see #isBooleanVal() - * @generated - */ - void setBooleanVal(boolean value); - - /** - * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#isBooleanVal Boolean Val}' attribute. - * - * - * @see #isSetBooleanVal() - * @see #isBooleanVal() - * @see #setBooleanVal(boolean) - * @generated - */ - void unsetBooleanVal(); - - /** - * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#isBooleanVal Boolean Val}' attribute is set. - * - * - * @return whether the value of the 'Boolean Val' attribute is set. - * @see #unsetBooleanVal() - * @see #isBooleanVal() - * @see #setBooleanVal(boolean) - * @generated - */ - boolean isSetBooleanVal(); - - /** - * Returns the value of the 'Byte Val' attribute. - * - *

- * If the meaning of the 'Byte Val' attribute isn't clear, - * there really should be more of a description here... - *

- * - * @return the value of the 'Byte Val' attribute. - * @see #isSetByteVal() - * @see #unsetByteVal() - * @see #setByteVal(byte) - * @generated - */ - byte getByteVal(); - - /** - * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getByteVal Byte Val}' attribute. - * - * - * @param value the new value of the 'Byte Val' attribute. - * @see #isSetByteVal() - * @see #unsetByteVal() - * @see #getByteVal() - * @generated - */ - void setByteVal(byte value); - - /** - * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getByteVal Byte Val}' attribute. - * - * - * @see #isSetByteVal() - * @see #getByteVal() - * @see #setByteVal(byte) - * @generated - */ - void unsetByteVal(); - - /** - * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getByteVal Byte Val}' attribute is set. - * - * - * @return whether the value of the 'Byte Val' attribute is set. - * @see #unsetByteVal() - * @see #getByteVal() - * @see #setByteVal(byte) - * @generated - */ - boolean isSetByteVal(); - - /** - * Returns the value of the 'Decimal Val' attribute. - * - *

- * If the meaning of the 'Decimal Val' attribute isn't clear, - * there really should be more of a description here... - *

- * - * @return the value of the 'Decimal Val' attribute. - * @see #isSetDecimalVal() - * @see #unsetDecimalVal() - * @see #setDecimalVal(BigDecimal) - * @generated - */ - BigDecimal getDecimalVal(); - - /** - * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getDecimalVal Decimal Val}' attribute. - * - * - * @param value the new value of the 'Decimal Val' attribute. - * @see #isSetDecimalVal() - * @see #unsetDecimalVal() - * @see #getDecimalVal() - * @generated - */ - void setDecimalVal(BigDecimal value); - - /** - * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getDecimalVal Decimal Val}' attribute. - * - * - * @see #isSetDecimalVal() - * @see #getDecimalVal() - * @see #setDecimalVal(BigDecimal) - * @generated - */ - void unsetDecimalVal(); - - /** - * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getDecimalVal Decimal Val}' attribute is set. - * - * - * @return whether the value of the 'Decimal Val' attribute is set. - * @see #unsetDecimalVal() - * @see #getDecimalVal() - * @see #setDecimalVal(BigDecimal) - * @generated - */ - boolean isSetDecimalVal(); - - /** - * Returns the value of the 'Int Val' attribute. - * - *

- * If the meaning of the 'Int Val' attribute isn't clear, - * there really should be more of a description here... - *

- * - * @return the value of the 'Int Val' attribute. - * @see #isSetIntVal() - * @see #unsetIntVal() - * @see #setIntVal(int) - * @generated - */ - int getIntVal(); - - /** - * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getIntVal Int Val}' attribute. - * - * - * @param value the new value of the 'Int Val' attribute. - * @see #isSetIntVal() - * @see #unsetIntVal() - * @see #getIntVal() - * @generated - */ - void setIntVal(int value); - - /** - * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getIntVal Int Val}' attribute. - * - * - * @see #isSetIntVal() - * @see #getIntVal() - * @see #setIntVal(int) - * @generated - */ - void unsetIntVal(); - - /** - * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getIntVal Int Val}' attribute is set. - * - * - * @return whether the value of the 'Int Val' attribute is set. - * @see #unsetIntVal() - * @see #getIntVal() - * @see #setIntVal(int) - * @generated - */ - boolean isSetIntVal(); - - /** - * Returns the value of the 'Float Val' attribute. - * - *

- * If the meaning of the 'Float Val' attribute isn't clear, - * there really should be more of a description here... - *

- * - * @return the value of the 'Float Val' attribute. - * @see #isSetFloatVal() - * @see #unsetFloatVal() - * @see #setFloatVal(float) - * @generated - */ - float getFloatVal(); - - /** - * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getFloatVal Float Val}' attribute. - * - * - * @param value the new value of the 'Float Val' attribute. - * @see #isSetFloatVal() - * @see #unsetFloatVal() - * @see #getFloatVal() - * @generated - */ - void setFloatVal(float value); - - /** - * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getFloatVal Float Val}' attribute. - * - * - * @see #isSetFloatVal() - * @see #getFloatVal() - * @see #setFloatVal(float) - * @generated - */ - void unsetFloatVal(); - - /** - * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getFloatVal Float Val}' attribute is set. - * - * - * @return whether the value of the 'Float Val' attribute is set. - * @see #unsetFloatVal() - * @see #getFloatVal() - * @see #setFloatVal(float) - * @generated - */ - boolean isSetFloatVal(); - - /** - * Returns the value of the 'Double Val' attribute. - * - *

- * If the meaning of the 'Double Val' attribute isn't clear, - * there really should be more of a description here... - *

- * - * @return the value of the 'Double Val' attribute. - * @see #isSetDoubleVal() - * @see #unsetDoubleVal() - * @see #setDoubleVal(double) - * @generated - */ - double getDoubleVal(); - - /** - * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getDoubleVal Double Val}' attribute. - * - * - * @param value the new value of the 'Double Val' attribute. - * @see #isSetDoubleVal() - * @see #unsetDoubleVal() - * @see #getDoubleVal() - * @generated - */ - void setDoubleVal(double value); - - /** - * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getDoubleVal Double Val}' attribute. - * - * - * @see #isSetDoubleVal() - * @see #getDoubleVal() - * @see #setDoubleVal(double) - * @generated - */ - void unsetDoubleVal(); - - /** - * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getDoubleVal Double Val}' attribute is set. - * - * - * @return whether the value of the 'Double Val' attribute is set. - * @see #unsetDoubleVal() - * @see #getDoubleVal() - * @see #setDoubleVal(double) - * @generated - */ - boolean isSetDoubleVal(); - - /** - * Returns the value of the 'Date Val' attribute. - * - *

- * If the meaning of the 'Date Val' attribute isn't clear, - * there really should be more of a description here... - *

- * - * @return the value of the 'Date Val' attribute. - * @see #isSetDateVal() - * @see #unsetDateVal() - * @see #setDateVal(String) - * @generated - */ - String getDateVal(); - - /** - * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getDateVal Date Val}' attribute. - * - * - * @param value the new value of the 'Date Val' attribute. - * @see #isSetDateVal() - * @see #unsetDateVal() - * @see #getDateVal() - * @generated - */ - void setDateVal(String value); - - /** - * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getDateVal Date Val}' attribute. - * - * - * @see #isSetDateVal() - * @see #getDateVal() - * @see #setDateVal(String) - * @generated - */ - void unsetDateVal(); - - /** - * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getDateVal Date Val}' attribute is set. - * - * - * @return whether the value of the 'Date Val' attribute is set. - * @see #unsetDateVal() - * @see #getDateVal() - * @see #setDateVal(String) - * @generated - */ - boolean isSetDateVal(); - - /** - * Returns the value of the 'Short Val' attribute. - * - *

- * If the meaning of the 'Short Val' attribute isn't clear, - * there really should be more of a description here... - *

- * - * @return the value of the 'Short Val' attribute. - * @see #isSetShortVal() - * @see #unsetShortVal() - * @see #setShortVal(short) - * @generated - */ - short getShortVal(); - - /** - * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getShortVal Short Val}' attribute. - * - * - * @param value the new value of the 'Short Val' attribute. - * @see #isSetShortVal() - * @see #unsetShortVal() - * @see #getShortVal() - * @generated - */ - void setShortVal(short value); - - /** - * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getShortVal Short Val}' attribute. - * - * - * @see #isSetShortVal() - * @see #getShortVal() - * @see #setShortVal(short) - * @generated - */ - void unsetShortVal(); - - /** - * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getShortVal Short Val}' attribute is set. - * - * - * @return whether the value of the 'Short Val' attribute is set. - * @see #unsetShortVal() - * @see #getShortVal() - * @see #setShortVal(short) - * @generated - */ - boolean isSetShortVal(); - - /** - * Returns the value of the 'Long Val' attribute. - * - *

- * If the meaning of the 'Long Val' attribute isn't clear, - * there really should be more of a description here... - *

- * - * @return the value of the 'Long Val' attribute. - * @see #isSetLongVal() - * @see #unsetLongVal() - * @see #setLongVal(long) - * @generated - */ - long getLongVal(); - - /** - * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getLongVal Long Val}' attribute. - * - * - * @param value the new value of the 'Long Val' attribute. - * @see #isSetLongVal() - * @see #unsetLongVal() - * @see #getLongVal() - * @generated - */ - void setLongVal(long value); - - /** - * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getLongVal Long Val}' attribute. - * - * - * @see #isSetLongVal() - * @see #getLongVal() - * @see #setLongVal(long) - * @generated - */ - void unsetLongVal(); - - /** - * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getLongVal Long Val}' attribute is set. - * - * - * @return whether the value of the 'Long Val' attribute is set. - * @see #unsetLongVal() - * @see #getLongVal() - * @see #setLongVal(long) - * @generated - */ - boolean isSetLongVal(); - - /** - * Returns the value of the 'List Val' attribute list. - * The list contents are of type {@link java.lang.String}. - * - *

- * If the meaning of the 'List Val' attribute list isn't clear, - * there really should be more of a description here... - *

- * - * @return the value of the 'List Val' attribute list. - * @generated - */ - List getListVal(); - - /** - * Returns the value of the 'Bytes Val' attribute. - * - *

- * If the meaning of the 'Bytes Val' attribute isn't clear, - * there really should be more of a description here... - *

- * - * @return the value of the 'Bytes Val' attribute. - * @see #isSetBytesVal() - * @see #unsetBytesVal() - * @see #setBytesVal(byte[]) - * @generated - */ - byte[] getBytesVal(); - - /** - * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getBytesVal Bytes Val}' attribute. - * - * - * @param value the new value of the 'Bytes Val' attribute. - * @see #isSetBytesVal() - * @see #unsetBytesVal() - * @see #getBytesVal() - * @generated - */ - void setBytesVal(byte[] value); - - /** - * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getBytesVal Bytes Val}' attribute. - * - * - * @see #isSetBytesVal() - * @see #getBytesVal() - * @see #setBytesVal(byte[]) - * @generated - */ - void unsetBytesVal(); - - /** - * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getBytesVal Bytes Val}' attribute is set. - * - * - * @return whether the value of the 'Bytes Val' attribute is set. - * @see #unsetBytesVal() - * @see #getBytesVal() - * @see #setBytesVal(byte[]) - * @generated - */ - boolean isSetBytesVal(); - - /** - * Returns the value of the 'Integer Val' attribute. - * - *

- * If the meaning of the 'Integer Val' attribute isn't clear, - * there really should be more of a description here... - *

- * - * @return the value of the 'Integer Val' attribute. - * @see #isSetIntegerVal() - * @see #unsetIntegerVal() - * @see #setIntegerVal(BigInteger) - * @generated - */ - BigInteger getIntegerVal(); - - /** - * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getIntegerVal Integer Val}' attribute. - * - * - * @param value the new value of the 'Integer Val' attribute. - * @see #isSetIntegerVal() - * @see #unsetIntegerVal() - * @see #getIntegerVal() - * @generated - */ - void setIntegerVal(BigInteger value); - - /** - * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getIntegerVal Integer Val}' attribute. - * - * - * @see #isSetIntegerVal() - * @see #getIntegerVal() - * @see #setIntegerVal(BigInteger) - * @generated - */ - void unsetIntegerVal(); - - /** - * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getIntegerVal Integer Val}' attribute is set. - * - * - * @return whether the value of the 'Integer Val' attribute is set. - * @see #unsetIntegerVal() - * @see #getIntegerVal() - * @see #setIntegerVal(BigInteger) - * @generated - */ - boolean isSetIntegerVal(); - - /** - * Returns the value of the 'Char Val' attribute. - * - *

- * If the meaning of the 'Char Val' attribute isn't clear, - * there really should be more of a description here... - *

- * - * @return the value of the 'Char Val' attribute. - * @see #isSetCharVal() - * @see #unsetCharVal() - * @see #setCharVal(String) - * @generated - */ - String getCharVal(); - - /** - * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getCharVal Char Val}' attribute. - * - * - * @param value the new value of the 'Char Val' attribute. - * @see #isSetCharVal() - * @see #unsetCharVal() - * @see #getCharVal() - * @generated - */ - void setCharVal(String value); - - /** - * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getCharVal Char Val}' attribute. - * - * - * @see #isSetCharVal() - * @see #getCharVal() - * @see #setCharVal(String) - * @generated - */ - void unsetCharVal(); - - /** - * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getCharVal Char Val}' attribute is set. - * - * - * @return whether the value of the 'Char Val' attribute is set. - * @see #unsetCharVal() - * @see #getCharVal() - * @see #setCharVal(String) - * @generated - */ - boolean isSetCharVal(); - - /** - * Returns the value of the 'Read Only Val' attribute. - * - *

- * If the meaning of the 'Read Only Val' attribute isn't clear, - * there really should be more of a description here... - *

- * - * @return the value of the 'Read Only Val' attribute. - * @see #isSetReadOnlyVal() - * @generated - */ - String getReadOnlyVal(); - - /** - * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getReadOnlyVal Read Only Val}' attribute is set. - * - * - * @return whether the value of the 'Read Only Val' attribute is set. - * @see #getReadOnlyVal() - * @generated - */ - boolean isSetReadOnlyVal(); - - /** - * Returns the value of the 'Read Only List Val' attribute. - * - *

- * If the meaning of the 'Read Only List Val' attribute isn't clear, - * there really should be more of a description here... - *

- * - * @return the value of the 'Read Only List Val' attribute. - * @see #isSetReadOnlyListVal() - * @generated - */ - String getReadOnlyListVal(); - - /** - * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getReadOnlyListVal Read Only List Val}' attribute is set. - * - * - * @return whether the value of the 'Read Only List Val' attribute is set. - * @see #getReadOnlyListVal() - * @generated - */ - boolean isSetReadOnlyListVal(); - -} // ExpectedExceptionType +/** + * + * 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 com.example.ExpectedException; + +import java.io.Serializable; + +import java.math.BigDecimal; +import java.math.BigInteger; + +import java.util.List; + +/** + * + * A representation of the model object 'Type'. + * + * + *

+ * The following features are supported: + *

    + *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getStringVal String Val}
  • + *
  • {@link com.example.ExpectedException.ExpectedExceptionType#isBooleanVal Boolean Val}
  • + *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getByteVal Byte Val}
  • + *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getDecimalVal Decimal Val}
  • + *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getIntVal Int Val}
  • + *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getFloatVal Float Val}
  • + *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getDoubleVal Double Val}
  • + *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getDateVal Date Val}
  • + *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getShortVal Short Val}
  • + *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getLongVal Long Val}
  • + *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getListVal List Val}
  • + *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getBytesVal Bytes Val}
  • + *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getIntegerVal Integer Val}
  • + *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getCharVal Char Val}
  • + *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getReadOnlyVal Read Only Val}
  • + *
  • {@link com.example.ExpectedException.ExpectedExceptionType#getReadOnlyListVal Read Only List Val}
  • + *
+ *

+ * + * @extends Serializable + * @generated + */ +public interface ExpectedExceptionType extends Serializable +{ + /** + * Returns the value of the 'String Val' attribute. + * + *

+ * If the meaning of the 'String Val' attribute isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'String Val' attribute. + * @see #isSetStringVal() + * @see #unsetStringVal() + * @see #setStringVal(String) + * @generated + */ + String getStringVal(); + + /** + * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getStringVal String Val}' attribute. + * + * + * @param value the new value of the 'String Val' attribute. + * @see #isSetStringVal() + * @see #unsetStringVal() + * @see #getStringVal() + * @generated + */ + void setStringVal(String value); + + /** + * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getStringVal String Val}' attribute. + * + * + * @see #isSetStringVal() + * @see #getStringVal() + * @see #setStringVal(String) + * @generated + */ + void unsetStringVal(); + + /** + * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getStringVal String Val}' attribute is set. + * + * + * @return whether the value of the 'String Val' attribute is set. + * @see #unsetStringVal() + * @see #getStringVal() + * @see #setStringVal(String) + * @generated + */ + boolean isSetStringVal(); + + /** + * Returns the value of the 'Boolean Val' attribute. + * + *

+ * If the meaning of the 'Boolean Val' attribute isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Boolean Val' attribute. + * @see #isSetBooleanVal() + * @see #unsetBooleanVal() + * @see #setBooleanVal(boolean) + * @generated + */ + boolean isBooleanVal(); + + /** + * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#isBooleanVal Boolean Val}' attribute. + * + * + * @param value the new value of the 'Boolean Val' attribute. + * @see #isSetBooleanVal() + * @see #unsetBooleanVal() + * @see #isBooleanVal() + * @generated + */ + void setBooleanVal(boolean value); + + /** + * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#isBooleanVal Boolean Val}' attribute. + * + * + * @see #isSetBooleanVal() + * @see #isBooleanVal() + * @see #setBooleanVal(boolean) + * @generated + */ + void unsetBooleanVal(); + + /** + * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#isBooleanVal Boolean Val}' attribute is set. + * + * + * @return whether the value of the 'Boolean Val' attribute is set. + * @see #unsetBooleanVal() + * @see #isBooleanVal() + * @see #setBooleanVal(boolean) + * @generated + */ + boolean isSetBooleanVal(); + + /** + * Returns the value of the 'Byte Val' attribute. + * + *

+ * If the meaning of the 'Byte Val' attribute isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Byte Val' attribute. + * @see #isSetByteVal() + * @see #unsetByteVal() + * @see #setByteVal(byte) + * @generated + */ + byte getByteVal(); + + /** + * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getByteVal Byte Val}' attribute. + * + * + * @param value the new value of the 'Byte Val' attribute. + * @see #isSetByteVal() + * @see #unsetByteVal() + * @see #getByteVal() + * @generated + */ + void setByteVal(byte value); + + /** + * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getByteVal Byte Val}' attribute. + * + * + * @see #isSetByteVal() + * @see #getByteVal() + * @see #setByteVal(byte) + * @generated + */ + void unsetByteVal(); + + /** + * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getByteVal Byte Val}' attribute is set. + * + * + * @return whether the value of the 'Byte Val' attribute is set. + * @see #unsetByteVal() + * @see #getByteVal() + * @see #setByteVal(byte) + * @generated + */ + boolean isSetByteVal(); + + /** + * Returns the value of the 'Decimal Val' attribute. + * + *

+ * If the meaning of the 'Decimal Val' attribute isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Decimal Val' attribute. + * @see #isSetDecimalVal() + * @see #unsetDecimalVal() + * @see #setDecimalVal(BigDecimal) + * @generated + */ + BigDecimal getDecimalVal(); + + /** + * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getDecimalVal Decimal Val}' attribute. + * + * + * @param value the new value of the 'Decimal Val' attribute. + * @see #isSetDecimalVal() + * @see #unsetDecimalVal() + * @see #getDecimalVal() + * @generated + */ + void setDecimalVal(BigDecimal value); + + /** + * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getDecimalVal Decimal Val}' attribute. + * + * + * @see #isSetDecimalVal() + * @see #getDecimalVal() + * @see #setDecimalVal(BigDecimal) + * @generated + */ + void unsetDecimalVal(); + + /** + * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getDecimalVal Decimal Val}' attribute is set. + * + * + * @return whether the value of the 'Decimal Val' attribute is set. + * @see #unsetDecimalVal() + * @see #getDecimalVal() + * @see #setDecimalVal(BigDecimal) + * @generated + */ + boolean isSetDecimalVal(); + + /** + * Returns the value of the 'Int Val' attribute. + * + *

+ * If the meaning of the 'Int Val' attribute isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Int Val' attribute. + * @see #isSetIntVal() + * @see #unsetIntVal() + * @see #setIntVal(int) + * @generated + */ + int getIntVal(); + + /** + * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getIntVal Int Val}' attribute. + * + * + * @param value the new value of the 'Int Val' attribute. + * @see #isSetIntVal() + * @see #unsetIntVal() + * @see #getIntVal() + * @generated + */ + void setIntVal(int value); + + /** + * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getIntVal Int Val}' attribute. + * + * + * @see #isSetIntVal() + * @see #getIntVal() + * @see #setIntVal(int) + * @generated + */ + void unsetIntVal(); + + /** + * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getIntVal Int Val}' attribute is set. + * + * + * @return whether the value of the 'Int Val' attribute is set. + * @see #unsetIntVal() + * @see #getIntVal() + * @see #setIntVal(int) + * @generated + */ + boolean isSetIntVal(); + + /** + * Returns the value of the 'Float Val' attribute. + * + *

+ * If the meaning of the 'Float Val' attribute isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Float Val' attribute. + * @see #isSetFloatVal() + * @see #unsetFloatVal() + * @see #setFloatVal(float) + * @generated + */ + float getFloatVal(); + + /** + * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getFloatVal Float Val}' attribute. + * + * + * @param value the new value of the 'Float Val' attribute. + * @see #isSetFloatVal() + * @see #unsetFloatVal() + * @see #getFloatVal() + * @generated + */ + void setFloatVal(float value); + + /** + * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getFloatVal Float Val}' attribute. + * + * + * @see #isSetFloatVal() + * @see #getFloatVal() + * @see #setFloatVal(float) + * @generated + */ + void unsetFloatVal(); + + /** + * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getFloatVal Float Val}' attribute is set. + * + * + * @return whether the value of the 'Float Val' attribute is set. + * @see #unsetFloatVal() + * @see #getFloatVal() + * @see #setFloatVal(float) + * @generated + */ + boolean isSetFloatVal(); + + /** + * Returns the value of the 'Double Val' attribute. + * + *

+ * If the meaning of the 'Double Val' attribute isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Double Val' attribute. + * @see #isSetDoubleVal() + * @see #unsetDoubleVal() + * @see #setDoubleVal(double) + * @generated + */ + double getDoubleVal(); + + /** + * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getDoubleVal Double Val}' attribute. + * + * + * @param value the new value of the 'Double Val' attribute. + * @see #isSetDoubleVal() + * @see #unsetDoubleVal() + * @see #getDoubleVal() + * @generated + */ + void setDoubleVal(double value); + + /** + * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getDoubleVal Double Val}' attribute. + * + * + * @see #isSetDoubleVal() + * @see #getDoubleVal() + * @see #setDoubleVal(double) + * @generated + */ + void unsetDoubleVal(); + + /** + * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getDoubleVal Double Val}' attribute is set. + * + * + * @return whether the value of the 'Double Val' attribute is set. + * @see #unsetDoubleVal() + * @see #getDoubleVal() + * @see #setDoubleVal(double) + * @generated + */ + boolean isSetDoubleVal(); + + /** + * Returns the value of the 'Date Val' attribute. + * + *

+ * If the meaning of the 'Date Val' attribute isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Date Val' attribute. + * @see #isSetDateVal() + * @see #unsetDateVal() + * @see #setDateVal(String) + * @generated + */ + String getDateVal(); + + /** + * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getDateVal Date Val}' attribute. + * + * + * @param value the new value of the 'Date Val' attribute. + * @see #isSetDateVal() + * @see #unsetDateVal() + * @see #getDateVal() + * @generated + */ + void setDateVal(String value); + + /** + * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getDateVal Date Val}' attribute. + * + * + * @see #isSetDateVal() + * @see #getDateVal() + * @see #setDateVal(String) + * @generated + */ + void unsetDateVal(); + + /** + * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getDateVal Date Val}' attribute is set. + * + * + * @return whether the value of the 'Date Val' attribute is set. + * @see #unsetDateVal() + * @see #getDateVal() + * @see #setDateVal(String) + * @generated + */ + boolean isSetDateVal(); + + /** + * Returns the value of the 'Short Val' attribute. + * + *

+ * If the meaning of the 'Short Val' attribute isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Short Val' attribute. + * @see #isSetShortVal() + * @see #unsetShortVal() + * @see #setShortVal(short) + * @generated + */ + short getShortVal(); + + /** + * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getShortVal Short Val}' attribute. + * + * + * @param value the new value of the 'Short Val' attribute. + * @see #isSetShortVal() + * @see #unsetShortVal() + * @see #getShortVal() + * @generated + */ + void setShortVal(short value); + + /** + * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getShortVal Short Val}' attribute. + * + * + * @see #isSetShortVal() + * @see #getShortVal() + * @see #setShortVal(short) + * @generated + */ + void unsetShortVal(); + + /** + * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getShortVal Short Val}' attribute is set. + * + * + * @return whether the value of the 'Short Val' attribute is set. + * @see #unsetShortVal() + * @see #getShortVal() + * @see #setShortVal(short) + * @generated + */ + boolean isSetShortVal(); + + /** + * Returns the value of the 'Long Val' attribute. + * + *

+ * If the meaning of the 'Long Val' attribute isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Long Val' attribute. + * @see #isSetLongVal() + * @see #unsetLongVal() + * @see #setLongVal(long) + * @generated + */ + long getLongVal(); + + /** + * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getLongVal Long Val}' attribute. + * + * + * @param value the new value of the 'Long Val' attribute. + * @see #isSetLongVal() + * @see #unsetLongVal() + * @see #getLongVal() + * @generated + */ + void setLongVal(long value); + + /** + * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getLongVal Long Val}' attribute. + * + * + * @see #isSetLongVal() + * @see #getLongVal() + * @see #setLongVal(long) + * @generated + */ + void unsetLongVal(); + + /** + * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getLongVal Long Val}' attribute is set. + * + * + * @return whether the value of the 'Long Val' attribute is set. + * @see #unsetLongVal() + * @see #getLongVal() + * @see #setLongVal(long) + * @generated + */ + boolean isSetLongVal(); + + /** + * Returns the value of the 'List Val' attribute list. + * The list contents are of type {@link java.lang.String}. + * + *

+ * If the meaning of the 'List Val' attribute list isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'List Val' attribute list. + * @generated + */ + List getListVal(); + + /** + * Returns the value of the 'Bytes Val' attribute. + * + *

+ * If the meaning of the 'Bytes Val' attribute isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Bytes Val' attribute. + * @see #isSetBytesVal() + * @see #unsetBytesVal() + * @see #setBytesVal(byte[]) + * @generated + */ + byte[] getBytesVal(); + + /** + * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getBytesVal Bytes Val}' attribute. + * + * + * @param value the new value of the 'Bytes Val' attribute. + * @see #isSetBytesVal() + * @see #unsetBytesVal() + * @see #getBytesVal() + * @generated + */ + void setBytesVal(byte[] value); + + /** + * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getBytesVal Bytes Val}' attribute. + * + * + * @see #isSetBytesVal() + * @see #getBytesVal() + * @see #setBytesVal(byte[]) + * @generated + */ + void unsetBytesVal(); + + /** + * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getBytesVal Bytes Val}' attribute is set. + * + * + * @return whether the value of the 'Bytes Val' attribute is set. + * @see #unsetBytesVal() + * @see #getBytesVal() + * @see #setBytesVal(byte[]) + * @generated + */ + boolean isSetBytesVal(); + + /** + * Returns the value of the 'Integer Val' attribute. + * + *

+ * If the meaning of the 'Integer Val' attribute isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Integer Val' attribute. + * @see #isSetIntegerVal() + * @see #unsetIntegerVal() + * @see #setIntegerVal(BigInteger) + * @generated + */ + BigInteger getIntegerVal(); + + /** + * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getIntegerVal Integer Val}' attribute. + * + * + * @param value the new value of the 'Integer Val' attribute. + * @see #isSetIntegerVal() + * @see #unsetIntegerVal() + * @see #getIntegerVal() + * @generated + */ + void setIntegerVal(BigInteger value); + + /** + * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getIntegerVal Integer Val}' attribute. + * + * + * @see #isSetIntegerVal() + * @see #getIntegerVal() + * @see #setIntegerVal(BigInteger) + * @generated + */ + void unsetIntegerVal(); + + /** + * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getIntegerVal Integer Val}' attribute is set. + * + * + * @return whether the value of the 'Integer Val' attribute is set. + * @see #unsetIntegerVal() + * @see #getIntegerVal() + * @see #setIntegerVal(BigInteger) + * @generated + */ + boolean isSetIntegerVal(); + + /** + * Returns the value of the 'Char Val' attribute. + * + *

+ * If the meaning of the 'Char Val' attribute isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Char Val' attribute. + * @see #isSetCharVal() + * @see #unsetCharVal() + * @see #setCharVal(String) + * @generated + */ + String getCharVal(); + + /** + * Sets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getCharVal Char Val}' attribute. + * + * + * @param value the new value of the 'Char Val' attribute. + * @see #isSetCharVal() + * @see #unsetCharVal() + * @see #getCharVal() + * @generated + */ + void setCharVal(String value); + + /** + * Unsets the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getCharVal Char Val}' attribute. + * + * + * @see #isSetCharVal() + * @see #getCharVal() + * @see #setCharVal(String) + * @generated + */ + void unsetCharVal(); + + /** + * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getCharVal Char Val}' attribute is set. + * + * + * @return whether the value of the 'Char Val' attribute is set. + * @see #unsetCharVal() + * @see #getCharVal() + * @see #setCharVal(String) + * @generated + */ + boolean isSetCharVal(); + + /** + * Returns the value of the 'Read Only Val' attribute. + * + *

+ * If the meaning of the 'Read Only Val' attribute isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Read Only Val' attribute. + * @see #isSetReadOnlyVal() + * @generated + */ + String getReadOnlyVal(); + + /** + * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getReadOnlyVal Read Only Val}' attribute is set. + * + * + * @return whether the value of the 'Read Only Val' attribute is set. + * @see #getReadOnlyVal() + * @generated + */ + boolean isSetReadOnlyVal(); + + /** + * Returns the value of the 'Read Only List Val' attribute. + * + *

+ * If the meaning of the 'Read Only List Val' attribute isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Read Only List Val' attribute. + * @see #isSetReadOnlyListVal() + * @generated + */ + String getReadOnlyListVal(); + + /** + * Returns whether the value of the '{@link com.example.ExpectedException.ExpectedExceptionType#getReadOnlyListVal Read Only List Val}' attribute is set. + * + * + * @return whether the value of the 'Read Only List Val' attribute is set. + * @see #getReadOnlyListVal() + * @generated + */ + boolean isSetReadOnlyListVal(); + +} // ExpectedExceptionType diff --git a/java/sdo/impl/src/test/java/com/example/ExpectedException/SequenceReadOnlyType.java b/java/sdo/impl/src/test/java/com/example/ExpectedException/SequenceReadOnlyType.java index 2a2ae0db02..a87511df28 100644 --- a/java/sdo/impl/src/test/java/com/example/ExpectedException/SequenceReadOnlyType.java +++ b/java/sdo/impl/src/test/java/com/example/ExpectedException/SequenceReadOnlyType.java @@ -1,158 +1,158 @@ -/** - * - * 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 com.example.ExpectedException; - -import commonj.sdo.Sequence; - -import java.io.Serializable; - -/** - * - * A representation of the model object 'Sequence Read Only Type'. - * - * - *

- * The following features are supported: - *

    - *
  • {@link com.example.ExpectedException.SequenceReadOnlyType#getMixed Mixed}
  • - *
  • {@link com.example.ExpectedException.SequenceReadOnlyType#getReadOnlyVal Read Only Val}
  • - *
  • {@link com.example.ExpectedException.SequenceReadOnlyType#getReadOnlyListVal Read Only List Val}
  • - *
  • {@link com.example.ExpectedException.SequenceReadOnlyType#getUniqueName Unique Name}
  • - *
- *

- * - * @extends Serializable - * @generated - */ -public interface SequenceReadOnlyType extends Serializable -{ - /** - * Returns the value of the 'Mixed' attribute list. - * - *

- * If the meaning of the 'Mixed' attribute list isn't clear, - * there really should be more of a description here... - *

- * - * @return the value of the 'Mixed' attribute list. - * @generated - */ - Sequence getMixed(); - - /** - * Returns the value of the 'Read Only Val' attribute. - * - *

- * If the meaning of the 'Read Only Val' attribute isn't clear, - * there really should be more of a description here... - *

- * - * @return the value of the 'Read Only Val' attribute. - * @see #isSetReadOnlyVal() - * @generated - */ - String getReadOnlyVal(); - - /** - * Returns whether the value of the '{@link com.example.ExpectedException.SequenceReadOnlyType#getReadOnlyVal Read Only Val}' attribute is set. - * - * - * @return whether the value of the 'Read Only Val' attribute is set. - * @see #getReadOnlyVal() - * @generated - */ - boolean isSetReadOnlyVal(); - - /** - * Returns the value of the 'Read Only List Val' attribute. - * - *

- * If the meaning of the 'Read Only List Val' attribute isn't clear, - * there really should be more of a description here... - *

- * - * @return the value of the 'Read Only List Val' attribute. - * @see #isSetReadOnlyListVal() - * @generated - */ - String getReadOnlyListVal(); - - /** - * Returns whether the value of the '{@link com.example.ExpectedException.SequenceReadOnlyType#getReadOnlyListVal Read Only List Val}' attribute is set. - * - * - * @return whether the value of the 'Read Only List Val' attribute is set. - * @see #getReadOnlyListVal() - * @generated - */ - boolean isSetReadOnlyListVal(); - - /** - * Returns the value of the 'Unique Name' attribute. - * - *

- * If the meaning of the 'Unique Name' attribute isn't clear, - * there really should be more of a description here... - *

- * - * @return the value of the 'Unique Name' attribute. - * @see #isSetUniqueName() - * @see #unsetUniqueName() - * @see #setUniqueName(String) - * @generated - */ - String getUniqueName(); - - /** - * Sets the value of the '{@link com.example.ExpectedException.SequenceReadOnlyType#getUniqueName Unique Name}' attribute. - * - * - * @param value the new value of the 'Unique Name' attribute. - * @see #isSetUniqueName() - * @see #unsetUniqueName() - * @see #getUniqueName() - * @generated - */ - void setUniqueName(String value); - - /** - * Unsets the value of the '{@link com.example.ExpectedException.SequenceReadOnlyType#getUniqueName Unique Name}' attribute. - * - * - * @see #isSetUniqueName() - * @see #getUniqueName() - * @see #setUniqueName(String) - * @generated - */ - void unsetUniqueName(); - - /** - * Returns whether the value of the '{@link com.example.ExpectedException.SequenceReadOnlyType#getUniqueName Unique Name}' attribute is set. - * - * - * @return whether the value of the 'Unique Name' attribute is set. - * @see #unsetUniqueName() - * @see #getUniqueName() - * @see #setUniqueName(String) - * @generated - */ - boolean isSetUniqueName(); - -} // SequenceReadOnlyType +/** + * + * 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 com.example.ExpectedException; + +import commonj.sdo.Sequence; + +import java.io.Serializable; + +/** + * + * A representation of the model object 'Sequence Read Only Type'. + * + * + *

+ * The following features are supported: + *

    + *
  • {@link com.example.ExpectedException.SequenceReadOnlyType#getMixed Mixed}
  • + *
  • {@link com.example.ExpectedException.SequenceReadOnlyType#getReadOnlyVal Read Only Val}
  • + *
  • {@link com.example.ExpectedException.SequenceReadOnlyType#getReadOnlyListVal Read Only List Val}
  • + *
  • {@link com.example.ExpectedException.SequenceReadOnlyType#getUniqueName Unique Name}
  • + *
+ *

+ * + * @extends Serializable + * @generated + */ +public interface SequenceReadOnlyType extends Serializable +{ + /** + * Returns the value of the 'Mixed' attribute list. + * + *

+ * If the meaning of the 'Mixed' attribute list isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Mixed' attribute list. + * @generated + */ + Sequence getMixed(); + + /** + * Returns the value of the 'Read Only Val' attribute. + * + *

+ * If the meaning of the 'Read Only Val' attribute isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Read Only Val' attribute. + * @see #isSetReadOnlyVal() + * @generated + */ + String getReadOnlyVal(); + + /** + * Returns whether the value of the '{@link com.example.ExpectedException.SequenceReadOnlyType#getReadOnlyVal Read Only Val}' attribute is set. + * + * + * @return whether the value of the 'Read Only Val' attribute is set. + * @see #getReadOnlyVal() + * @generated + */ + boolean isSetReadOnlyVal(); + + /** + * Returns the value of the 'Read Only List Val' attribute. + * + *

+ * If the meaning of the 'Read Only List Val' attribute isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Read Only List Val' attribute. + * @see #isSetReadOnlyListVal() + * @generated + */ + String getReadOnlyListVal(); + + /** + * Returns whether the value of the '{@link com.example.ExpectedException.SequenceReadOnlyType#getReadOnlyListVal Read Only List Val}' attribute is set. + * + * + * @return whether the value of the 'Read Only List Val' attribute is set. + * @see #getReadOnlyListVal() + * @generated + */ + boolean isSetReadOnlyListVal(); + + /** + * Returns the value of the 'Unique Name' attribute. + * + *

+ * If the meaning of the 'Unique Name' attribute isn't clear, + * there really should be more of a description here... + *

+ * + * @return the value of the 'Unique Name' attribute. + * @see #isSetUniqueName() + * @see #unsetUniqueName() + * @see #setUniqueName(String) + * @generated + */ + String getUniqueName(); + + /** + * Sets the value of the '{@link com.example.ExpectedException.SequenceReadOnlyType#getUniqueName Unique Name}' attribute. + * + * + * @param value the new value of the 'Unique Name' attribute. + * @see #isSetUniqueName() + * @see #unsetUniqueName() + * @see #getUniqueName() + * @generated + */ + void setUniqueName(String value); + + /** + * Unsets the value of the '{@link com.example.ExpectedException.SequenceReadOnlyType#getUniqueName Unique Name}' attribute. + * + * + * @see #isSetUniqueName() + * @see #getUniqueName() + * @see #setUniqueName(String) + * @generated + */ + void unsetUniqueName(); + + /** + * Returns whether the value of the '{@link com.example.ExpectedException.SequenceReadOnlyType#getUniqueName Unique Name}' attribute is set. + * + * + * @return whether the value of the 'Unique Name' attribute is set. + * @see #unsetUniqueName() + * @see #getUniqueName() + * @see #setUniqueName(String) + * @generated + */ + boolean isSetUniqueName(); + +} // SequenceReadOnlyType diff --git a/java/sdo/impl/src/test/java/com/example/ExpectedException/impl/ExpectedExceptionFactoryImpl.java b/java/sdo/impl/src/test/java/com/example/ExpectedException/impl/ExpectedExceptionFactoryImpl.java index 791c5a4604..68280749c4 100644 --- a/java/sdo/impl/src/test/java/com/example/ExpectedException/impl/ExpectedExceptionFactoryImpl.java +++ b/java/sdo/impl/src/test/java/com/example/ExpectedException/impl/ExpectedExceptionFactoryImpl.java @@ -1,579 +1,579 @@ -/** - * - * 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 com.example.ExpectedException.impl; - -import commonj.sdo.helper.HelperContext; -import org.apache.tuscany.sdo.helper.TypeHelperImpl; - -import com.example.ExpectedException.*; - -import commonj.sdo.DataObject; -import commonj.sdo.Property; -import commonj.sdo.Type; - -import org.apache.tuscany.sdo.SDOFactory; - -import org.apache.tuscany.sdo.impl.FactoryBase; - -import org.apache.tuscany.sdo.model.ModelFactory; - -import org.apache.tuscany.sdo.model.impl.ModelFactoryImpl; - -import org.apache.tuscany.sdo.model.internal.InternalFactory; - -import org.apache.tuscany.sdo.util.SDOUtil; - -/** - * - * An implementation of the model Factory. - * Generator information: - * patternVersion=1.2; -prefix ExpectedException - * - * @generated - */ -public class ExpectedExceptionFactoryImpl extends FactoryBase implements ExpectedExceptionFactory -{ - - /** - * The package namespace URI. - * - * - * @generated - */ - public static final String NAMESPACE_URI = "http://example.com/ExpectedException"; - - /** - * The package namespace name. - * - * - * @generated - */ - public static final String NAMESPACE_PREFIX = "expect"; - - /** - * The version of the generator pattern used to generate this class. - * - * - * @generated - */ - public static final String PATTERN_VERSION = "1.2"; - - public static final int EXPECTED_EXCEPTION_TYPE = 1; - public static final int SEQUENCE_READ_ONLY_TYPE = 2; - public static final int CHAR = 3; - - /** - * Creates an instance of the factory. - * - * - * @generated - */ - public ExpectedExceptionFactoryImpl() - { - super(NAMESPACE_URI, NAMESPACE_PREFIX, "com.sdo.test.ExpectedException"); - } - - /** - * Registers the Factory instance so that it is available within the supplied scope. - * @argument scope a HelperContext instance that will make the types supported by this Factory available. - * - * - * @generated - */ - public void register(HelperContext scope) { - if(scope == null) { - throw new IllegalArgumentException("Scope can not be null"); - } - TypeHelperImpl th = (TypeHelperImpl)scope.getTypeHelper(); - th.getExtendedMetaData().putPackage(NAMESPACE_URI, this); - } - - /** - * - * - * @generated - */ - public DataObject create(int typeNumber) - { - switch (typeNumber) - { - case EXPECTED_EXCEPTION_TYPE: return (DataObject)createExpectedExceptionType(); - case SEQUENCE_READ_ONLY_TYPE: return (DataObject)createSequenceReadOnlyType(); - default: - return super.create(typeNumber); - } - } - - /** - * - * - * @generated - */ - public Object createFromString(int typeNumber, String initialValue) - { - switch (typeNumber) - { - case CHAR: - return createcharFromString(initialValue); - default: - throw new IllegalArgumentException("The type number '" + typeNumber + "' is not a valid datatype"); - } - } - - /** - * - * - * @generated - */ - public String convertToString(int typeNumber, Object instanceValue) - { - switch (typeNumber) - { - case CHAR: - return convertcharToString(instanceValue); - default: - throw new IllegalArgumentException("The type number '" + typeNumber + "' is not a valid datatype"); - } - } - /** - * - * - * @generated - */ - public ExpectedExceptionType createExpectedExceptionType() - { - ExpectedExceptionTypeImpl expectedExceptionType = new ExpectedExceptionTypeImpl(); - return expectedExceptionType; - } - /** - * - * - * @generated - */ - public SequenceReadOnlyType createSequenceReadOnlyType() - { - SequenceReadOnlyTypeImpl sequenceReadOnlyType = new SequenceReadOnlyTypeImpl(); - return sequenceReadOnlyType; - } - - // Following creates and initializes SDO metadata for the supported types. - protected Type expectedExceptionTypeType = null; - - public Type getExpectedExceptionType() - { - return expectedExceptionTypeType; - } - - protected Type sequenceReadOnlyTypeType = null; - - public Type getSequenceReadOnlyType() - { - return sequenceReadOnlyTypeType; - } - - protected Type char_Type = null; - - public Type getchar() - { - return char_Type; - } - - - private static boolean isInited = false; - - public static ExpectedExceptionFactoryImpl init() - { - if (isInited) return (ExpectedExceptionFactoryImpl)FactoryBase.getStaticFactory(ExpectedExceptionFactoryImpl.NAMESPACE_URI); - ExpectedExceptionFactoryImpl theExpectedExceptionFactoryImpl = new ExpectedExceptionFactoryImpl(); - isInited = true; - - // Initialize dependencies - SDOUtil.registerStaticTypes(SDOFactory.class); - SDOUtil.registerStaticTypes(ModelFactory.class); - SDOUtil.registerStaticTypes(InternalFactory.class); - - // Create package meta-data objects - theExpectedExceptionFactoryImpl.createMetaData(); - - // Initialize created meta-data - theExpectedExceptionFactoryImpl.initializeMetaData(); - - // Mark meta-data to indicate it can't be changed - //theExpectedExceptionFactoryImpl.freeze(); //FB do we need to freeze / should we freeze ???? - - return theExpectedExceptionFactoryImpl; - } - - private boolean isCreated = false; - - public void createMetaData() - { - if (isCreated) return; - isCreated = true; - - // Create types and their properties - expectedExceptionTypeType = createType(false, EXPECTED_EXCEPTION_TYPE); - createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_STRING_VAL); - createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_BOOLEAN_VAL); - createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_BYTE_VAL); - createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_DECIMAL_VAL); - createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_INT_VAL); - createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_FLOAT_VAL); - createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_DOUBLE_VAL); - createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_DATE_VAL); - createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_SHORT_VAL); - createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_LONG_VAL); - createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_LIST_VAL); - createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_BYTES_VAL); - createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_INTEGER_VAL); - createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_CHAR_VAL); - createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_READ_ONLY_VAL); - createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_READ_ONLY_LIST_VAL); - sequenceReadOnlyTypeType = createType(false, SEQUENCE_READ_ONLY_TYPE); - createProperty(true, sequenceReadOnlyTypeType,SequenceReadOnlyTypeImpl.INTERNAL_MIXED); - createProperty(true, sequenceReadOnlyTypeType,SequenceReadOnlyTypeImpl.INTERNAL_READ_ONLY_VAL); - createProperty(true, sequenceReadOnlyTypeType,SequenceReadOnlyTypeImpl.INTERNAL_READ_ONLY_LIST_VAL); - createProperty(true, sequenceReadOnlyTypeType,SequenceReadOnlyTypeImpl.INTERNAL_UNIQUE_NAME); - - // Create data types - char_Type = createType(true, CHAR ); - } - - private boolean isInitialized = false; - - public void initializeMetaData() - { - if (isInitialized) return; - isInitialized = true; - - // Obtain other dependent packages - ModelFactoryImpl theModelPackageImpl = (ModelFactoryImpl)FactoryBase.getStaticFactory(ModelFactoryImpl.NAMESPACE_URI); - Property property = null; - - // Add supertypes to types - - // Initialize types and properties - initializeType(expectedExceptionTypeType, ExpectedExceptionType.class, "ExpectedExceptionType", false); - property = getLocalProperty(expectedExceptionTypeType, 0); - initializeProperty(property, theModelPackageImpl.getString(), "stringVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); - - property = getLocalProperty(expectedExceptionTypeType, 1); - initializeProperty(property, theModelPackageImpl.getBoolean(), "booleanVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); - - property = getLocalProperty(expectedExceptionTypeType, 2); - initializeProperty(property, theModelPackageImpl.getByte(), "byteVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); - - property = getLocalProperty(expectedExceptionTypeType, 3); - initializeProperty(property, theModelPackageImpl.getDecimal(), "decimalVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); - - property = getLocalProperty(expectedExceptionTypeType, 4); - initializeProperty(property, theModelPackageImpl.getInt(), "intVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); - - property = getLocalProperty(expectedExceptionTypeType, 5); - initializeProperty(property, theModelPackageImpl.getFloat(), "floatVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); - - property = getLocalProperty(expectedExceptionTypeType, 6); - initializeProperty(property, theModelPackageImpl.getDouble(), "doubleVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); - - property = getLocalProperty(expectedExceptionTypeType, 7); - initializeProperty(property, theModelPackageImpl.getDateTime(), "dateVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); - - property = getLocalProperty(expectedExceptionTypeType, 8); - initializeProperty(property, theModelPackageImpl.getShort(), "shortVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); - - property = getLocalProperty(expectedExceptionTypeType, 9); - initializeProperty(property, theModelPackageImpl.getLong(), "longVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); - - property = getLocalProperty(expectedExceptionTypeType, 10); - initializeProperty(property, theModelPackageImpl.getString(), "listVal", null, 0, -1, ExpectedExceptionType.class, false, false, false); - - property = getLocalProperty(expectedExceptionTypeType, 11); - initializeProperty(property, theModelPackageImpl.getBytes(), "bytesVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); - - property = getLocalProperty(expectedExceptionTypeType, 12); - initializeProperty(property, theModelPackageImpl.getInteger(), "integerVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); - - property = getLocalProperty(expectedExceptionTypeType, 13); - initializeProperty(property, this.getchar(), "charVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); - - property = getLocalProperty(expectedExceptionTypeType, 14); - initializeProperty(property, theModelPackageImpl.getString(), "readOnlyVal", null, 1, 1, ExpectedExceptionType.class, true, true, false); - setInstanceProperty (property, "commonj.sdo/xml", "readOnly", "true"); - - property = getLocalProperty(expectedExceptionTypeType, 15); - initializeProperty(property, theModelPackageImpl.getString(), "readOnlyListVal", null, 1, 1, ExpectedExceptionType.class, true, true, false); - setInstanceProperty (property, "commonj.sdo/xml", "readOnly", "true"); - - initializeType(sequenceReadOnlyTypeType, SequenceReadOnlyType.class, "SequenceReadOnlyType", false); - property = getLocalProperty(sequenceReadOnlyTypeType, 0); - initializeProperty(property, getSequence(), "mixed", null, 0, -1, SequenceReadOnlyType.class, false, false, false); - - property = getLocalProperty(sequenceReadOnlyTypeType, 1); - initializeProperty(property, theModelPackageImpl.getString(), "readOnlyVal", null, 1, 1, SequenceReadOnlyType.class, true, true, true); - setInstanceProperty (property, "commonj.sdo/xml", "readOnly", "true"); - - property = getLocalProperty(sequenceReadOnlyTypeType, 2); - initializeProperty(property, theModelPackageImpl.getString(), "readOnlyListVal", null, 1, 1, SequenceReadOnlyType.class, true, true, true); - setInstanceProperty (property, "commonj.sdo/xml", "readOnly", "true"); - - property = getLocalProperty(sequenceReadOnlyTypeType, 3); - initializeProperty(property, theModelPackageImpl.getString(), "uniqueName", null, 1, 1, SequenceReadOnlyType.class, false, true, true); - - // Initialize data types - initializeType(char_Type, String.class, "char", true, false); - - createXSDMetaData(theModelPackageImpl); - } - - protected void createXSDMetaData(ModelFactoryImpl theModelPackageImpl) - { - super.initXSD(); - - Property property = null; - - - property = createGlobalProperty - ("expectedExceptionsElem", - this.getExpectedExceptionType(), - new String[] - { - "kind", "element", - "name", "expectedExceptionsElem", - "namespace", "##targetNamespace" - }); - - property = createGlobalProperty - ("sequencedReadOnlyElem", - this.getSequenceReadOnlyType(), - new String[] - { - "kind", "element", - "name", "sequencedReadOnlyElem", - "namespace", "##targetNamespace" - }); - - addXSDMapping - (expectedExceptionTypeType, - new String[] - { - "name", "ExpectedExceptionType", - "kind", "elementOnly" - }); - - addXSDMapping - (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_STRING_VAL), - new String[] - { - "kind", "element", - "name", "stringVal" - }); - - addXSDMapping - (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_BOOLEAN_VAL), - new String[] - { - "kind", "element", - "name", "booleanVal" - }); - - addXSDMapping - (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_BYTE_VAL), - new String[] - { - "kind", "element", - "name", "byteVal" - }); - - addXSDMapping - (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_DECIMAL_VAL), - new String[] - { - "kind", "element", - "name", "decimalVal" - }); - - addXSDMapping - (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_INT_VAL), - new String[] - { - "kind", "element", - "name", "intVal" - }); - - addXSDMapping - (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_FLOAT_VAL), - new String[] - { - "kind", "element", - "name", "floatVal" - }); - - addXSDMapping - (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_DOUBLE_VAL), - new String[] - { - "kind", "element", - "name", "doubleVal" - }); - - addXSDMapping - (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_DATE_VAL), - new String[] - { - "kind", "element", - "name", "dateVal" - }); - - addXSDMapping - (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_SHORT_VAL), - new String[] - { - "kind", "element", - "name", "shortVal" - }); - - addXSDMapping - (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_LONG_VAL), - new String[] - { - "kind", "element", - "name", "longVal" - }); - - addXSDMapping - (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_LIST_VAL), - new String[] - { - "kind", "element", - "name", "listVal" - }); - - addXSDMapping - (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_BYTES_VAL), - new String[] - { - "kind", "element", - "name", "bytesVal" - }); - - addXSDMapping - (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_INTEGER_VAL), - new String[] - { - "kind", "element", - "name", "integerVal" - }); - - addXSDMapping - (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_CHAR_VAL), - new String[] - { - "kind", "element", - "name", "charVal" - }); - - addXSDMapping - (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_READ_ONLY_VAL), - new String[] - { - "kind", "element", - "name", "readOnlyVal" - }); - - addXSDMapping - (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_READ_ONLY_LIST_VAL), - new String[] - { - "kind", "element", - "name", "readOnlyListVal" - }); - - addXSDMapping - (sequenceReadOnlyTypeType, - new String[] - { - "name", "SequenceReadOnlyType", - "kind", "mixed" - }); - - addXSDMapping - (getProperty(sequenceReadOnlyTypeType, SequenceReadOnlyTypeImpl.INTERNAL_MIXED), - new String[] - { - "kind", "elementWildcard", - "name", ":mixed" - }); - - addXSDMapping - (getProperty(sequenceReadOnlyTypeType, SequenceReadOnlyTypeImpl.INTERNAL_READ_ONLY_VAL), - new String[] - { - "kind", "element", - "name", "readOnlyVal" - }); - - addXSDMapping - (getProperty(sequenceReadOnlyTypeType, SequenceReadOnlyTypeImpl.INTERNAL_READ_ONLY_LIST_VAL), - new String[] - { - "kind", "element", - "name", "readOnlyListVal" - }); - - addXSDMapping - (getProperty(sequenceReadOnlyTypeType, SequenceReadOnlyTypeImpl.INTERNAL_UNIQUE_NAME), - new String[] - { - "kind", "element", - "name", "uniqueName" - }); - - addXSDMapping - (char_Type, - new String[] - { - "name", "char", - "baseType", "commonj.sdo#String", - "length", "1" - }); - - } - - /** - * - * - * @generated - */ - public String createcharFromString(String initialValue) - { - return (String)((ModelFactoryImpl)ModelFactory.INSTANCE).createStringFromString(initialValue); - } - - /** - * - * - * @generated - */ - public String convertcharToString(Object instanceValue) - { - return ((ModelFactoryImpl)ModelFactory.INSTANCE).convertStringToString(instanceValue); - } - -} //ExpectedExceptionFactoryImpl +/** + * + * 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 com.example.ExpectedException.impl; + +import commonj.sdo.helper.HelperContext; +import org.apache.tuscany.sdo.helper.TypeHelperImpl; + +import com.example.ExpectedException.*; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Type; + +import org.apache.tuscany.sdo.SDOFactory; + +import org.apache.tuscany.sdo.impl.FactoryBase; + +import org.apache.tuscany.sdo.model.ModelFactory; + +import org.apache.tuscany.sdo.model.impl.ModelFactoryImpl; + +import org.apache.tuscany.sdo.model.internal.InternalFactory; + +import org.apache.tuscany.sdo.util.SDOUtil; + +/** + * + * An implementation of the model Factory. + * Generator information: + * patternVersion=1.2; -prefix ExpectedException + * + * @generated + */ +public class ExpectedExceptionFactoryImpl extends FactoryBase implements ExpectedExceptionFactory +{ + + /** + * The package namespace URI. + * + * + * @generated + */ + public static final String NAMESPACE_URI = "http://example.com/ExpectedException"; + + /** + * The package namespace name. + * + * + * @generated + */ + public static final String NAMESPACE_PREFIX = "expect"; + + /** + * The version of the generator pattern used to generate this class. + * + * + * @generated + */ + public static final String PATTERN_VERSION = "1.2"; + + public static final int EXPECTED_EXCEPTION_TYPE = 1; + public static final int SEQUENCE_READ_ONLY_TYPE = 2; + public static final int CHAR = 3; + + /** + * Creates an instance of the factory. + * + * + * @generated + */ + public ExpectedExceptionFactoryImpl() + { + super(NAMESPACE_URI, NAMESPACE_PREFIX, "com.sdo.test.ExpectedException"); + } + + /** + * Registers the Factory instance so that it is available within the supplied scope. + * @argument scope a HelperContext instance that will make the types supported by this Factory available. + * + * + * @generated + */ + public void register(HelperContext scope) { + if(scope == null) { + throw new IllegalArgumentException("Scope can not be null"); + } + TypeHelperImpl th = (TypeHelperImpl)scope.getTypeHelper(); + th.getExtendedMetaData().putPackage(NAMESPACE_URI, this); + } + + /** + * + * + * @generated + */ + public DataObject create(int typeNumber) + { + switch (typeNumber) + { + case EXPECTED_EXCEPTION_TYPE: return (DataObject)createExpectedExceptionType(); + case SEQUENCE_READ_ONLY_TYPE: return (DataObject)createSequenceReadOnlyType(); + default: + return super.create(typeNumber); + } + } + + /** + * + * + * @generated + */ + public Object createFromString(int typeNumber, String initialValue) + { + switch (typeNumber) + { + case CHAR: + return createcharFromString(initialValue); + default: + throw new IllegalArgumentException("The type number '" + typeNumber + "' is not a valid datatype"); + } + } + + /** + * + * + * @generated + */ + public String convertToString(int typeNumber, Object instanceValue) + { + switch (typeNumber) + { + case CHAR: + return convertcharToString(instanceValue); + default: + throw new IllegalArgumentException("The type number '" + typeNumber + "' is not a valid datatype"); + } + } + /** + * + * + * @generated + */ + public ExpectedExceptionType createExpectedExceptionType() + { + ExpectedExceptionTypeImpl expectedExceptionType = new ExpectedExceptionTypeImpl(); + return expectedExceptionType; + } + /** + * + * + * @generated + */ + public SequenceReadOnlyType createSequenceReadOnlyType() + { + SequenceReadOnlyTypeImpl sequenceReadOnlyType = new SequenceReadOnlyTypeImpl(); + return sequenceReadOnlyType; + } + + // Following creates and initializes SDO metadata for the supported types. + protected Type expectedExceptionTypeType = null; + + public Type getExpectedExceptionType() + { + return expectedExceptionTypeType; + } + + protected Type sequenceReadOnlyTypeType = null; + + public Type getSequenceReadOnlyType() + { + return sequenceReadOnlyTypeType; + } + + protected Type char_Type = null; + + public Type getchar() + { + return char_Type; + } + + + private static boolean isInited = false; + + public static ExpectedExceptionFactoryImpl init() + { + if (isInited) return (ExpectedExceptionFactoryImpl)FactoryBase.getStaticFactory(ExpectedExceptionFactoryImpl.NAMESPACE_URI); + ExpectedExceptionFactoryImpl theExpectedExceptionFactoryImpl = new ExpectedExceptionFactoryImpl(); + isInited = true; + + // Initialize dependencies + SDOUtil.registerStaticTypes(SDOFactory.class); + SDOUtil.registerStaticTypes(ModelFactory.class); + SDOUtil.registerStaticTypes(InternalFactory.class); + + // Create package meta-data objects + theExpectedExceptionFactoryImpl.createMetaData(); + + // Initialize created meta-data + theExpectedExceptionFactoryImpl.initializeMetaData(); + + // Mark meta-data to indicate it can't be changed + //theExpectedExceptionFactoryImpl.freeze(); //FB do we need to freeze / should we freeze ???? + + return theExpectedExceptionFactoryImpl; + } + + private boolean isCreated = false; + + public void createMetaData() + { + if (isCreated) return; + isCreated = true; + + // Create types and their properties + expectedExceptionTypeType = createType(false, EXPECTED_EXCEPTION_TYPE); + createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_STRING_VAL); + createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_BOOLEAN_VAL); + createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_BYTE_VAL); + createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_DECIMAL_VAL); + createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_INT_VAL); + createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_FLOAT_VAL); + createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_DOUBLE_VAL); + createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_DATE_VAL); + createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_SHORT_VAL); + createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_LONG_VAL); + createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_LIST_VAL); + createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_BYTES_VAL); + createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_INTEGER_VAL); + createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_CHAR_VAL); + createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_READ_ONLY_VAL); + createProperty(true, expectedExceptionTypeType,ExpectedExceptionTypeImpl.INTERNAL_READ_ONLY_LIST_VAL); + sequenceReadOnlyTypeType = createType(false, SEQUENCE_READ_ONLY_TYPE); + createProperty(true, sequenceReadOnlyTypeType,SequenceReadOnlyTypeImpl.INTERNAL_MIXED); + createProperty(true, sequenceReadOnlyTypeType,SequenceReadOnlyTypeImpl.INTERNAL_READ_ONLY_VAL); + createProperty(true, sequenceReadOnlyTypeType,SequenceReadOnlyTypeImpl.INTERNAL_READ_ONLY_LIST_VAL); + createProperty(true, sequenceReadOnlyTypeType,SequenceReadOnlyTypeImpl.INTERNAL_UNIQUE_NAME); + + // Create data types + char_Type = createType(true, CHAR ); + } + + private boolean isInitialized = false; + + public void initializeMetaData() + { + if (isInitialized) return; + isInitialized = true; + + // Obtain other dependent packages + ModelFactoryImpl theModelPackageImpl = (ModelFactoryImpl)FactoryBase.getStaticFactory(ModelFactoryImpl.NAMESPACE_URI); + Property property = null; + + // Add supertypes to types + + // Initialize types and properties + initializeType(expectedExceptionTypeType, ExpectedExceptionType.class, "ExpectedExceptionType", false); + property = getLocalProperty(expectedExceptionTypeType, 0); + initializeProperty(property, theModelPackageImpl.getString(), "stringVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); + + property = getLocalProperty(expectedExceptionTypeType, 1); + initializeProperty(property, theModelPackageImpl.getBoolean(), "booleanVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); + + property = getLocalProperty(expectedExceptionTypeType, 2); + initializeProperty(property, theModelPackageImpl.getByte(), "byteVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); + + property = getLocalProperty(expectedExceptionTypeType, 3); + initializeProperty(property, theModelPackageImpl.getDecimal(), "decimalVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); + + property = getLocalProperty(expectedExceptionTypeType, 4); + initializeProperty(property, theModelPackageImpl.getInt(), "intVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); + + property = getLocalProperty(expectedExceptionTypeType, 5); + initializeProperty(property, theModelPackageImpl.getFloat(), "floatVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); + + property = getLocalProperty(expectedExceptionTypeType, 6); + initializeProperty(property, theModelPackageImpl.getDouble(), "doubleVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); + + property = getLocalProperty(expectedExceptionTypeType, 7); + initializeProperty(property, theModelPackageImpl.getDateTime(), "dateVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); + + property = getLocalProperty(expectedExceptionTypeType, 8); + initializeProperty(property, theModelPackageImpl.getShort(), "shortVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); + + property = getLocalProperty(expectedExceptionTypeType, 9); + initializeProperty(property, theModelPackageImpl.getLong(), "longVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); + + property = getLocalProperty(expectedExceptionTypeType, 10); + initializeProperty(property, theModelPackageImpl.getString(), "listVal", null, 0, -1, ExpectedExceptionType.class, false, false, false); + + property = getLocalProperty(expectedExceptionTypeType, 11); + initializeProperty(property, theModelPackageImpl.getBytes(), "bytesVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); + + property = getLocalProperty(expectedExceptionTypeType, 12); + initializeProperty(property, theModelPackageImpl.getInteger(), "integerVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); + + property = getLocalProperty(expectedExceptionTypeType, 13); + initializeProperty(property, this.getchar(), "charVal", null, 1, 1, ExpectedExceptionType.class, false, true, false); + + property = getLocalProperty(expectedExceptionTypeType, 14); + initializeProperty(property, theModelPackageImpl.getString(), "readOnlyVal", null, 1, 1, ExpectedExceptionType.class, true, true, false); + setInstanceProperty (property, "commonj.sdo/xml", "readOnly", "true"); + + property = getLocalProperty(expectedExceptionTypeType, 15); + initializeProperty(property, theModelPackageImpl.getString(), "readOnlyListVal", null, 1, 1, ExpectedExceptionType.class, true, true, false); + setInstanceProperty (property, "commonj.sdo/xml", "readOnly", "true"); + + initializeType(sequenceReadOnlyTypeType, SequenceReadOnlyType.class, "SequenceReadOnlyType", false); + property = getLocalProperty(sequenceReadOnlyTypeType, 0); + initializeProperty(property, getSequence(), "mixed", null, 0, -1, SequenceReadOnlyType.class, false, false, false); + + property = getLocalProperty(sequenceReadOnlyTypeType, 1); + initializeProperty(property, theModelPackageImpl.getString(), "readOnlyVal", null, 1, 1, SequenceReadOnlyType.class, true, true, true); + setInstanceProperty (property, "commonj.sdo/xml", "readOnly", "true"); + + property = getLocalProperty(sequenceReadOnlyTypeType, 2); + initializeProperty(property, theModelPackageImpl.getString(), "readOnlyListVal", null, 1, 1, SequenceReadOnlyType.class, true, true, true); + setInstanceProperty (property, "commonj.sdo/xml", "readOnly", "true"); + + property = getLocalProperty(sequenceReadOnlyTypeType, 3); + initializeProperty(property, theModelPackageImpl.getString(), "uniqueName", null, 1, 1, SequenceReadOnlyType.class, false, true, true); + + // Initialize data types + initializeType(char_Type, String.class, "char", true, false); + + createXSDMetaData(theModelPackageImpl); + } + + protected void createXSDMetaData(ModelFactoryImpl theModelPackageImpl) + { + super.initXSD(); + + Property property = null; + + + property = createGlobalProperty + ("expectedExceptionsElem", + this.getExpectedExceptionType(), + new String[] + { + "kind", "element", + "name", "expectedExceptionsElem", + "namespace", "##targetNamespace" + }); + + property = createGlobalProperty + ("sequencedReadOnlyElem", + this.getSequenceReadOnlyType(), + new String[] + { + "kind", "element", + "name", "sequencedReadOnlyElem", + "namespace", "##targetNamespace" + }); + + addXSDMapping + (expectedExceptionTypeType, + new String[] + { + "name", "ExpectedExceptionType", + "kind", "elementOnly" + }); + + addXSDMapping + (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_STRING_VAL), + new String[] + { + "kind", "element", + "name", "stringVal" + }); + + addXSDMapping + (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_BOOLEAN_VAL), + new String[] + { + "kind", "element", + "name", "booleanVal" + }); + + addXSDMapping + (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_BYTE_VAL), + new String[] + { + "kind", "element", + "name", "byteVal" + }); + + addXSDMapping + (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_DECIMAL_VAL), + new String[] + { + "kind", "element", + "name", "decimalVal" + }); + + addXSDMapping + (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_INT_VAL), + new String[] + { + "kind", "element", + "name", "intVal" + }); + + addXSDMapping + (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_FLOAT_VAL), + new String[] + { + "kind", "element", + "name", "floatVal" + }); + + addXSDMapping + (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_DOUBLE_VAL), + new String[] + { + "kind", "element", + "name", "doubleVal" + }); + + addXSDMapping + (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_DATE_VAL), + new String[] + { + "kind", "element", + "name", "dateVal" + }); + + addXSDMapping + (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_SHORT_VAL), + new String[] + { + "kind", "element", + "name", "shortVal" + }); + + addXSDMapping + (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_LONG_VAL), + new String[] + { + "kind", "element", + "name", "longVal" + }); + + addXSDMapping + (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_LIST_VAL), + new String[] + { + "kind", "element", + "name", "listVal" + }); + + addXSDMapping + (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_BYTES_VAL), + new String[] + { + "kind", "element", + "name", "bytesVal" + }); + + addXSDMapping + (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_INTEGER_VAL), + new String[] + { + "kind", "element", + "name", "integerVal" + }); + + addXSDMapping + (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_CHAR_VAL), + new String[] + { + "kind", "element", + "name", "charVal" + }); + + addXSDMapping + (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_READ_ONLY_VAL), + new String[] + { + "kind", "element", + "name", "readOnlyVal" + }); + + addXSDMapping + (getProperty(expectedExceptionTypeType, ExpectedExceptionTypeImpl.INTERNAL_READ_ONLY_LIST_VAL), + new String[] + { + "kind", "element", + "name", "readOnlyListVal" + }); + + addXSDMapping + (sequenceReadOnlyTypeType, + new String[] + { + "name", "SequenceReadOnlyType", + "kind", "mixed" + }); + + addXSDMapping + (getProperty(sequenceReadOnlyTypeType, SequenceReadOnlyTypeImpl.INTERNAL_MIXED), + new String[] + { + "kind", "elementWildcard", + "name", ":mixed" + }); + + addXSDMapping + (getProperty(sequenceReadOnlyTypeType, SequenceReadOnlyTypeImpl.INTERNAL_READ_ONLY_VAL), + new String[] + { + "kind", "element", + "name", "readOnlyVal" + }); + + addXSDMapping + (getProperty(sequenceReadOnlyTypeType, SequenceReadOnlyTypeImpl.INTERNAL_READ_ONLY_LIST_VAL), + new String[] + { + "kind", "element", + "name", "readOnlyListVal" + }); + + addXSDMapping + (getProperty(sequenceReadOnlyTypeType, SequenceReadOnlyTypeImpl.INTERNAL_UNIQUE_NAME), + new String[] + { + "kind", "element", + "name", "uniqueName" + }); + + addXSDMapping + (char_Type, + new String[] + { + "name", "char", + "baseType", "commonj.sdo#String", + "length", "1" + }); + + } + + /** + * + * + * @generated + */ + public String createcharFromString(String initialValue) + { + return (String)((ModelFactoryImpl)ModelFactory.INSTANCE).createStringFromString(initialValue); + } + + /** + * + * + * @generated + */ + public String convertcharToString(Object instanceValue) + { + return ((ModelFactoryImpl)ModelFactory.INSTANCE).convertStringToString(instanceValue); + } + +} //ExpectedExceptionFactoryImpl diff --git a/java/sdo/impl/src/test/java/com/example/ExpectedException/impl/ExpectedExceptionTypeImpl.java b/java/sdo/impl/src/test/java/com/example/ExpectedException/impl/ExpectedExceptionTypeImpl.java index 9021e52c18..df7bdbd66e 100644 --- a/java/sdo/impl/src/test/java/com/example/ExpectedException/impl/ExpectedExceptionTypeImpl.java +++ b/java/sdo/impl/src/test/java/com/example/ExpectedException/impl/ExpectedExceptionTypeImpl.java @@ -1,1682 +1,1682 @@ -/** - * - * 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 com.example.ExpectedException.impl; - -import com.example.ExpectedException.ExpectedExceptionFactory; -import com.example.ExpectedException.ExpectedExceptionType; - -import commonj.sdo.Type; - -import java.math.BigDecimal; -import java.math.BigInteger; - -import java.util.Collection; -import java.util.List; - -import org.apache.tuscany.sdo.impl.DataObjectBase; - -/** - * - * An implementation of the model object 'Type'. - * - *

- * The following features are implemented: - *

    - *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getStringVal String Val}
  • - *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#isBooleanVal Boolean Val}
  • - *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getByteVal Byte Val}
  • - *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getDecimalVal Decimal Val}
  • - *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getIntVal Int Val}
  • - *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getFloatVal Float Val}
  • - *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getDoubleVal Double Val}
  • - *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getDateVal Date Val}
  • - *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getShortVal Short Val}
  • - *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getLongVal Long Val}
  • - *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getListVal List Val}
  • - *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getBytesVal Bytes Val}
  • - *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getIntegerVal Integer Val}
  • - *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getCharVal Char Val}
  • - *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getReadOnlyVal Read Only Val}
  • - *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getReadOnlyListVal Read Only List Val}
  • - *
- *

- * - * @generated - */ -public class ExpectedExceptionTypeImpl extends DataObjectBase implements ExpectedExceptionType -{ - - public final static int STRING_VAL = 0; - - public final static int BOOLEAN_VAL = 1; - - public final static int BYTE_VAL = 2; - - public final static int DECIMAL_VAL = 3; - - public final static int INT_VAL = 4; - - public final static int FLOAT_VAL = 5; - - public final static int DOUBLE_VAL = 6; - - public final static int DATE_VAL = 7; - - public final static int SHORT_VAL = 8; - - public final static int LONG_VAL = 9; - - public final static int LIST_VAL = 10; - - public final static int BYTES_VAL = 11; - - public final static int INTEGER_VAL = 12; - - public final static int CHAR_VAL = 13; - - public final static int READ_ONLY_VAL = 14; - - public final static int READ_ONLY_LIST_VAL = 15; - - public final static int SDO_PROPERTY_COUNT = 16; - - public final static int EXTENDED_PROPERTY_COUNT = 0; - - - /** - * The internal feature id for the 'String Val' attribute. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_STRING_VAL = 0; - - /** - * The internal feature id for the 'Boolean Val' attribute. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_BOOLEAN_VAL = 1; - - /** - * The internal feature id for the 'Byte Val' attribute. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_BYTE_VAL = 2; - - /** - * The internal feature id for the 'Decimal Val' attribute. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_DECIMAL_VAL = 3; - - /** - * The internal feature id for the 'Int Val' attribute. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_INT_VAL = 4; - - /** - * The internal feature id for the 'Float Val' attribute. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_FLOAT_VAL = 5; - - /** - * The internal feature id for the 'Double Val' attribute. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_DOUBLE_VAL = 6; - - /** - * The internal feature id for the 'Date Val' attribute. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_DATE_VAL = 7; - - /** - * The internal feature id for the 'Short Val' attribute. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_SHORT_VAL = 8; - - /** - * The internal feature id for the 'Long Val' attribute. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_LONG_VAL = 9; - - /** - * The internal feature id for the 'List Val' attribute list. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_LIST_VAL = 10; - - /** - * The internal feature id for the 'Bytes Val' attribute. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_BYTES_VAL = 11; - - /** - * The internal feature id for the 'Integer Val' attribute. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_INTEGER_VAL = 12; - - /** - * The internal feature id for the 'Char Val' attribute. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_CHAR_VAL = 13; - - /** - * The internal feature id for the 'Read Only Val' attribute. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_READ_ONLY_VAL = 14; - - /** - * The internal feature id for the 'Read Only List Val' attribute. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_READ_ONLY_LIST_VAL = 15; - - /** - * The number of properties for this type. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_PROPERTY_COUNT = 16; - - protected int internalConvertIndex(int internalIndex) - { - switch (internalIndex) - { - case INTERNAL_STRING_VAL: return STRING_VAL; - case INTERNAL_BOOLEAN_VAL: return BOOLEAN_VAL; - case INTERNAL_BYTE_VAL: return BYTE_VAL; - case INTERNAL_DECIMAL_VAL: return DECIMAL_VAL; - case INTERNAL_INT_VAL: return INT_VAL; - case INTERNAL_FLOAT_VAL: return FLOAT_VAL; - case INTERNAL_DOUBLE_VAL: return DOUBLE_VAL; - case INTERNAL_DATE_VAL: return DATE_VAL; - case INTERNAL_SHORT_VAL: return SHORT_VAL; - case INTERNAL_LONG_VAL: return LONG_VAL; - case INTERNAL_LIST_VAL: return LIST_VAL; - case INTERNAL_BYTES_VAL: return BYTES_VAL; - case INTERNAL_INTEGER_VAL: return INTEGER_VAL; - case INTERNAL_CHAR_VAL: return CHAR_VAL; - case INTERNAL_READ_ONLY_VAL: return READ_ONLY_VAL; - case INTERNAL_READ_ONLY_LIST_VAL: return READ_ONLY_LIST_VAL; - } - return super.internalConvertIndex(internalIndex); - } - - - /** - * The default value of the '{@link #getStringVal() String Val}' attribute. - * - * - * @see #getStringVal() - * @generated - * @ordered - */ - protected static final String STRING_VAL_DEFAULT_ = null; - - /** - * The cached value of the '{@link #getStringVal() String Val}' attribute. - * - * - * @see #getStringVal() - * @generated - * @ordered - */ - protected String stringVal = STRING_VAL_DEFAULT_; - - /** - * This is true if the String Val attribute has been set. - * - * - * @generated - * @ordered - */ - protected boolean stringVal_set_ = false; - - /** - * The default value of the '{@link #isBooleanVal() Boolean Val}' attribute. - * - * - * @see #isBooleanVal() - * @generated - * @ordered - */ - protected static final boolean BOOLEAN_VAL_DEFAULT_ = false; - - /** - * The cached value of the '{@link #isBooleanVal() Boolean Val}' attribute. - * - * - * @see #isBooleanVal() - * @generated - * @ordered - */ - protected boolean booleanVal = BOOLEAN_VAL_DEFAULT_; - - /** - * This is true if the Boolean Val attribute has been set. - * - * - * @generated - * @ordered - */ - protected boolean booleanVal_set_ = false; - - /** - * The default value of the '{@link #getByteVal() Byte Val}' attribute. - * - * - * @see #getByteVal() - * @generated - * @ordered - */ - protected static final byte BYTE_VAL_DEFAULT_ = 0; - - /** - * The cached value of the '{@link #getByteVal() Byte Val}' attribute. - * - * - * @see #getByteVal() - * @generated - * @ordered - */ - protected byte byteVal = BYTE_VAL_DEFAULT_; - - /** - * This is true if the Byte Val attribute has been set. - * - * - * @generated - * @ordered - */ - protected boolean byteVal_set_ = false; - - /** - * The default value of the '{@link #getDecimalVal() Decimal Val}' attribute. - * - * - * @see #getDecimalVal() - * @generated - * @ordered - */ - protected static final BigDecimal DECIMAL_VAL_DEFAULT_ = null; - - /** - * The cached value of the '{@link #getDecimalVal() Decimal Val}' attribute. - * - * - * @see #getDecimalVal() - * @generated - * @ordered - */ - protected BigDecimal decimalVal = DECIMAL_VAL_DEFAULT_; - - /** - * This is true if the Decimal Val attribute has been set. - * - * - * @generated - * @ordered - */ - protected boolean decimalVal_set_ = false; - - /** - * The default value of the '{@link #getIntVal() Int Val}' attribute. - * - * - * @see #getIntVal() - * @generated - * @ordered - */ - protected static final int INT_VAL_DEFAULT_ = 0; - - /** - * The cached value of the '{@link #getIntVal() Int Val}' attribute. - * - * - * @see #getIntVal() - * @generated - * @ordered - */ - protected int intVal = INT_VAL_DEFAULT_; - - /** - * This is true if the Int Val attribute has been set. - * - * - * @generated - * @ordered - */ - protected boolean intVal_set_ = false; - - /** - * The default value of the '{@link #getFloatVal() Float Val}' attribute. - * - * - * @see #getFloatVal() - * @generated - * @ordered - */ - protected static final float FLOAT_VAL_DEFAULT_ = 0.0F; - - /** - * The cached value of the '{@link #getFloatVal() Float Val}' attribute. - * - * - * @see #getFloatVal() - * @generated - * @ordered - */ - protected float floatVal = FLOAT_VAL_DEFAULT_; - - /** - * This is true if the Float Val attribute has been set. - * - * - * @generated - * @ordered - */ - protected boolean floatVal_set_ = false; - - /** - * The default value of the '{@link #getDoubleVal() Double Val}' attribute. - * - * - * @see #getDoubleVal() - * @generated - * @ordered - */ - protected static final double DOUBLE_VAL_DEFAULT_ = 0.0; - - /** - * The cached value of the '{@link #getDoubleVal() Double Val}' attribute. - * - * - * @see #getDoubleVal() - * @generated - * @ordered - */ - protected double doubleVal = DOUBLE_VAL_DEFAULT_; - - /** - * This is true if the Double Val attribute has been set. - * - * - * @generated - * @ordered - */ - protected boolean doubleVal_set_ = false; - - /** - * The default value of the '{@link #getDateVal() Date Val}' attribute. - * - * - * @see #getDateVal() - * @generated - * @ordered - */ - protected static final String DATE_VAL_DEFAULT_ = null; - - /** - * The cached value of the '{@link #getDateVal() Date Val}' attribute. - * - * - * @see #getDateVal() - * @generated - * @ordered - */ - protected String dateVal = DATE_VAL_DEFAULT_; - - /** - * This is true if the Date Val attribute has been set. - * - * - * @generated - * @ordered - */ - protected boolean dateVal_set_ = false; - - /** - * The default value of the '{@link #getShortVal() Short Val}' attribute. - * - * - * @see #getShortVal() - * @generated - * @ordered - */ - protected static final short SHORT_VAL_DEFAULT_ = 0; - - /** - * The cached value of the '{@link #getShortVal() Short Val}' attribute. - * - * - * @see #getShortVal() - * @generated - * @ordered - */ - protected short shortVal = SHORT_VAL_DEFAULT_; - - /** - * This is true if the Short Val attribute has been set. - * - * - * @generated - * @ordered - */ - protected boolean shortVal_set_ = false; - - /** - * The default value of the '{@link #getLongVal() Long Val}' attribute. - * - * - * @see #getLongVal() - * @generated - * @ordered - */ - protected static final long LONG_VAL_DEFAULT_ = 0L; - - /** - * The cached value of the '{@link #getLongVal() Long Val}' attribute. - * - * - * @see #getLongVal() - * @generated - * @ordered - */ - protected long longVal = LONG_VAL_DEFAULT_; - - /** - * This is true if the Long Val attribute has been set. - * - * - * @generated - * @ordered - */ - protected boolean longVal_set_ = false; - - /** - * The cached value of the '{@link #getListVal() List Val}' attribute list. - * - * - * @see #getListVal() - * @generated - * @ordered - */ - - protected List listVal = null; - - /** - * The default value of the '{@link #getBytesVal() Bytes Val}' attribute. - * - * - * @see #getBytesVal() - * @generated - * @ordered - */ - protected static final byte[] BYTES_VAL_DEFAULT_ = null; - - /** - * The cached value of the '{@link #getBytesVal() Bytes Val}' attribute. - * - * - * @see #getBytesVal() - * @generated - * @ordered - */ - protected byte[] bytesVal = BYTES_VAL_DEFAULT_; - - /** - * This is true if the Bytes Val attribute has been set. - * - * - * @generated - * @ordered - */ - protected boolean bytesVal_set_ = false; - - /** - * The default value of the '{@link #getIntegerVal() Integer Val}' attribute. - * - * - * @see #getIntegerVal() - * @generated - * @ordered - */ - protected static final BigInteger INTEGER_VAL_DEFAULT_ = null; - - /** - * The cached value of the '{@link #getIntegerVal() Integer Val}' attribute. - * - * - * @see #getIntegerVal() - * @generated - * @ordered - */ - protected BigInteger integerVal = INTEGER_VAL_DEFAULT_; - - /** - * This is true if the Integer Val attribute has been set. - * - * - * @generated - * @ordered - */ - protected boolean integerVal_set_ = false; - - /** - * The default value of the '{@link #getCharVal() Char Val}' attribute. - * - * - * @see #getCharVal() - * @generated - * @ordered - */ - protected static final String CHAR_VAL_DEFAULT_ = null; - - /** - * The cached value of the '{@link #getCharVal() Char Val}' attribute. - * - * - * @see #getCharVal() - * @generated - * @ordered - */ - protected String charVal = CHAR_VAL_DEFAULT_; - - /** - * This is true if the Char Val attribute has been set. - * - * - * @generated - * @ordered - */ - protected boolean charVal_set_ = false; - - /** - * The default value of the '{@link #getReadOnlyVal() Read Only Val}' attribute. - * - * - * @see #getReadOnlyVal() - * @generated - * @ordered - */ - protected static final String READ_ONLY_VAL_DEFAULT_ = null; - - /** - * The cached value of the '{@link #getReadOnlyVal() Read Only Val}' attribute. - * - * - * @see #getReadOnlyVal() - * @generated - * @ordered - */ - protected String readOnlyVal = READ_ONLY_VAL_DEFAULT_; - - /** - * This is true if the Read Only Val attribute has been set. - * - * - * @generated - * @ordered - */ - protected boolean readOnlyVal_set_ = false; - - /** - * The default value of the '{@link #getReadOnlyListVal() Read Only List Val}' attribute. - * - * - * @see #getReadOnlyListVal() - * @generated - * @ordered - */ - protected static final String READ_ONLY_LIST_VAL_DEFAULT_ = null; - - /** - * The cached value of the '{@link #getReadOnlyListVal() Read Only List Val}' attribute. - * - * - * @see #getReadOnlyListVal() - * @generated - * @ordered - */ - protected String readOnlyListVal = READ_ONLY_LIST_VAL_DEFAULT_; - - /** - * This is true if the Read Only List Val attribute has been set. - * - * - * @generated - * @ordered - */ - protected boolean readOnlyListVal_set_ = false; - - /** - * - * - * @generated - */ - public ExpectedExceptionTypeImpl() - { - super(); - } - - /** - * - * - * @generated - */ - public Type getStaticType() - { - return ((ExpectedExceptionFactoryImpl)ExpectedExceptionFactory.INSTANCE).getExpectedExceptionType(); - } - - /** - * - * - * @generated - */ - public String getStringVal() - { - return stringVal; - } - /** - * - * - * @generated - */ - public void setStringVal(String newStringVal) - { - String oldStringVal = stringVal; - stringVal = newStringVal; - boolean oldStringVal_set_ = stringVal_set_; - stringVal_set_ = true; - if (isNotifying()) - notify(ChangeKind.SET, STRING_VAL, oldStringVal, stringVal, !oldStringVal_set_); - } - - /** - * - * - * @generated - */ - public void unsetStringVal() - { - String oldStringVal = stringVal; - boolean oldStringVal_set_ = stringVal_set_; - stringVal = STRING_VAL_DEFAULT_; - stringVal_set_ = false; - if (isNotifying()) - notify(ChangeKind.UNSET, STRING_VAL, oldStringVal, STRING_VAL_DEFAULT_, oldStringVal_set_); - } - - /** - * - * - * @generated - */ - public boolean isSetStringVal() - { - return stringVal_set_; - } - - /** - * - * - * @generated - */ - public boolean isBooleanVal() - { - return booleanVal; - } - /** - * - * - * @generated - */ - public void setBooleanVal(boolean newBooleanVal) - { - boolean oldBooleanVal = booleanVal; - booleanVal = newBooleanVal; - boolean oldBooleanVal_set_ = booleanVal_set_; - booleanVal_set_ = true; - if (isNotifying()) - notify(ChangeKind.SET, BOOLEAN_VAL, oldBooleanVal, booleanVal, !oldBooleanVal_set_); - } - - /** - * - * - * @generated - */ - public void unsetBooleanVal() - { - boolean oldBooleanVal = booleanVal; - boolean oldBooleanVal_set_ = booleanVal_set_; - booleanVal = BOOLEAN_VAL_DEFAULT_; - booleanVal_set_ = false; - if (isNotifying()) - notify(ChangeKind.UNSET, BOOLEAN_VAL, oldBooleanVal, BOOLEAN_VAL_DEFAULT_, oldBooleanVal_set_); - } - - /** - * - * - * @generated - */ - public boolean isSetBooleanVal() - { - return booleanVal_set_; - } - - /** - * - * - * @generated - */ - public byte getByteVal() - { - return byteVal; - } - /** - * - * - * @generated - */ - public void setByteVal(byte newByteVal) - { - byte oldByteVal = byteVal; - byteVal = newByteVal; - boolean oldByteVal_set_ = byteVal_set_; - byteVal_set_ = true; - if (isNotifying()) - notify(ChangeKind.SET, BYTE_VAL, oldByteVal, byteVal, !oldByteVal_set_); - } - - /** - * - * - * @generated - */ - public void unsetByteVal() - { - byte oldByteVal = byteVal; - boolean oldByteVal_set_ = byteVal_set_; - byteVal = BYTE_VAL_DEFAULT_; - byteVal_set_ = false; - if (isNotifying()) - notify(ChangeKind.UNSET, BYTE_VAL, oldByteVal, BYTE_VAL_DEFAULT_, oldByteVal_set_); - } - - /** - * - * - * @generated - */ - public boolean isSetByteVal() - { - return byteVal_set_; - } - - /** - * - * - * @generated - */ - public BigDecimal getDecimalVal() - { - return decimalVal; - } - /** - * - * - * @generated - */ - public void setDecimalVal(BigDecimal newDecimalVal) - { - BigDecimal oldDecimalVal = decimalVal; - decimalVal = newDecimalVal; - boolean oldDecimalVal_set_ = decimalVal_set_; - decimalVal_set_ = true; - if (isNotifying()) - notify(ChangeKind.SET, DECIMAL_VAL, oldDecimalVal, decimalVal, !oldDecimalVal_set_); - } - - /** - * - * - * @generated - */ - public void unsetDecimalVal() - { - BigDecimal oldDecimalVal = decimalVal; - boolean oldDecimalVal_set_ = decimalVal_set_; - decimalVal = DECIMAL_VAL_DEFAULT_; - decimalVal_set_ = false; - if (isNotifying()) - notify(ChangeKind.UNSET, DECIMAL_VAL, oldDecimalVal, DECIMAL_VAL_DEFAULT_, oldDecimalVal_set_); - } - - /** - * - * - * @generated - */ - public boolean isSetDecimalVal() - { - return decimalVal_set_; - } - - /** - * - * - * @generated - */ - public int getIntVal() - { - return intVal; - } - /** - * - * - * @generated - */ - public void setIntVal(int newIntVal) - { - int oldIntVal = intVal; - intVal = newIntVal; - boolean oldIntVal_set_ = intVal_set_; - intVal_set_ = true; - if (isNotifying()) - notify(ChangeKind.SET, INT_VAL, oldIntVal, intVal, !oldIntVal_set_); - } - - /** - * - * - * @generated - */ - public void unsetIntVal() - { - int oldIntVal = intVal; - boolean oldIntVal_set_ = intVal_set_; - intVal = INT_VAL_DEFAULT_; - intVal_set_ = false; - if (isNotifying()) - notify(ChangeKind.UNSET, INT_VAL, oldIntVal, INT_VAL_DEFAULT_, oldIntVal_set_); - } - - /** - * - * - * @generated - */ - public boolean isSetIntVal() - { - return intVal_set_; - } - - /** - * - * - * @generated - */ - public float getFloatVal() - { - return floatVal; - } - /** - * - * - * @generated - */ - public void setFloatVal(float newFloatVal) - { - float oldFloatVal = floatVal; - floatVal = newFloatVal; - boolean oldFloatVal_set_ = floatVal_set_; - floatVal_set_ = true; - if (isNotifying()) - notify(ChangeKind.SET, FLOAT_VAL, oldFloatVal, floatVal, !oldFloatVal_set_); - } - - /** - * - * - * @generated - */ - public void unsetFloatVal() - { - float oldFloatVal = floatVal; - boolean oldFloatVal_set_ = floatVal_set_; - floatVal = FLOAT_VAL_DEFAULT_; - floatVal_set_ = false; - if (isNotifying()) - notify(ChangeKind.UNSET, FLOAT_VAL, oldFloatVal, FLOAT_VAL_DEFAULT_, oldFloatVal_set_); - } - - /** - * - * - * @generated - */ - public boolean isSetFloatVal() - { - return floatVal_set_; - } - - /** - * - * - * @generated - */ - public double getDoubleVal() - { - return doubleVal; - } - /** - * - * - * @generated - */ - public void setDoubleVal(double newDoubleVal) - { - double oldDoubleVal = doubleVal; - doubleVal = newDoubleVal; - boolean oldDoubleVal_set_ = doubleVal_set_; - doubleVal_set_ = true; - if (isNotifying()) - notify(ChangeKind.SET, DOUBLE_VAL, oldDoubleVal, doubleVal, !oldDoubleVal_set_); - } - - /** - * - * - * @generated - */ - public void unsetDoubleVal() - { - double oldDoubleVal = doubleVal; - boolean oldDoubleVal_set_ = doubleVal_set_; - doubleVal = DOUBLE_VAL_DEFAULT_; - doubleVal_set_ = false; - if (isNotifying()) - notify(ChangeKind.UNSET, DOUBLE_VAL, oldDoubleVal, DOUBLE_VAL_DEFAULT_, oldDoubleVal_set_); - } - - /** - * - * - * @generated - */ - public boolean isSetDoubleVal() - { - return doubleVal_set_; - } - - /** - * - * - * @generated - */ - public String getDateVal() - { - return dateVal; - } - /** - * - * - * @generated - */ - public void setDateVal(String newDateVal) - { - String oldDateVal = dateVal; - dateVal = newDateVal; - boolean oldDateVal_set_ = dateVal_set_; - dateVal_set_ = true; - if (isNotifying()) - notify(ChangeKind.SET, DATE_VAL, oldDateVal, dateVal, !oldDateVal_set_); - } - - /** - * - * - * @generated - */ - public void unsetDateVal() - { - String oldDateVal = dateVal; - boolean oldDateVal_set_ = dateVal_set_; - dateVal = DATE_VAL_DEFAULT_; - dateVal_set_ = false; - if (isNotifying()) - notify(ChangeKind.UNSET, DATE_VAL, oldDateVal, DATE_VAL_DEFAULT_, oldDateVal_set_); - } - - /** - * - * - * @generated - */ - public boolean isSetDateVal() - { - return dateVal_set_; - } - - /** - * - * - * @generated - */ - public short getShortVal() - { - return shortVal; - } - /** - * - * - * @generated - */ - public void setShortVal(short newShortVal) - { - short oldShortVal = shortVal; - shortVal = newShortVal; - boolean oldShortVal_set_ = shortVal_set_; - shortVal_set_ = true; - if (isNotifying()) - notify(ChangeKind.SET, SHORT_VAL, oldShortVal, shortVal, !oldShortVal_set_); - } - - /** - * - * - * @generated - */ - public void unsetShortVal() - { - short oldShortVal = shortVal; - boolean oldShortVal_set_ = shortVal_set_; - shortVal = SHORT_VAL_DEFAULT_; - shortVal_set_ = false; - if (isNotifying()) - notify(ChangeKind.UNSET, SHORT_VAL, oldShortVal, SHORT_VAL_DEFAULT_, oldShortVal_set_); - } - - /** - * - * - * @generated - */ - public boolean isSetShortVal() - { - return shortVal_set_; - } - - /** - * - * - * @generated - */ - public long getLongVal() - { - return longVal; - } - /** - * - * - * @generated - */ - public void setLongVal(long newLongVal) - { - long oldLongVal = longVal; - longVal = newLongVal; - boolean oldLongVal_set_ = longVal_set_; - longVal_set_ = true; - if (isNotifying()) - notify(ChangeKind.SET, LONG_VAL, oldLongVal, longVal, !oldLongVal_set_); - } - - /** - * - * - * @generated - */ - public void unsetLongVal() - { - long oldLongVal = longVal; - boolean oldLongVal_set_ = longVal_set_; - longVal = LONG_VAL_DEFAULT_; - longVal_set_ = false; - if (isNotifying()) - notify(ChangeKind.UNSET, LONG_VAL, oldLongVal, LONG_VAL_DEFAULT_, oldLongVal_set_); - } - - /** - * - * - * @generated - */ - public boolean isSetLongVal() - { - return longVal_set_; - } - - /** - * - * - * @generated - */ - public List getListVal() - { - if (listVal == null) - { - listVal = createPropertyList(ListKind.DATATYPE, String.class, LIST_VAL, 0); - } - return listVal; - } - /** - * - * - * @generated - */ - public byte[] getBytesVal() - { - return bytesVal; - } - /** - * - * - * @generated - */ - public void setBytesVal(byte[] newBytesVal) - { - byte[] oldBytesVal = bytesVal; - bytesVal = newBytesVal; - boolean oldBytesVal_set_ = bytesVal_set_; - bytesVal_set_ = true; - if (isNotifying()) - notify(ChangeKind.SET, BYTES_VAL, oldBytesVal, bytesVal, !oldBytesVal_set_); - } - - /** - * - * - * @generated - */ - public void unsetBytesVal() - { - byte[] oldBytesVal = bytesVal; - boolean oldBytesVal_set_ = bytesVal_set_; - bytesVal = BYTES_VAL_DEFAULT_; - bytesVal_set_ = false; - if (isNotifying()) - notify(ChangeKind.UNSET, BYTES_VAL, oldBytesVal, BYTES_VAL_DEFAULT_, oldBytesVal_set_); - } - - /** - * - * - * @generated - */ - public boolean isSetBytesVal() - { - return bytesVal_set_; - } - - /** - * - * - * @generated - */ - public BigInteger getIntegerVal() - { - return integerVal; - } - /** - * - * - * @generated - */ - public void setIntegerVal(BigInteger newIntegerVal) - { - BigInteger oldIntegerVal = integerVal; - integerVal = newIntegerVal; - boolean oldIntegerVal_set_ = integerVal_set_; - integerVal_set_ = true; - if (isNotifying()) - notify(ChangeKind.SET, INTEGER_VAL, oldIntegerVal, integerVal, !oldIntegerVal_set_); - } - - /** - * - * - * @generated - */ - public void unsetIntegerVal() - { - BigInteger oldIntegerVal = integerVal; - boolean oldIntegerVal_set_ = integerVal_set_; - integerVal = INTEGER_VAL_DEFAULT_; - integerVal_set_ = false; - if (isNotifying()) - notify(ChangeKind.UNSET, INTEGER_VAL, oldIntegerVal, INTEGER_VAL_DEFAULT_, oldIntegerVal_set_); - } - - /** - * - * - * @generated - */ - public boolean isSetIntegerVal() - { - return integerVal_set_; - } - - /** - * - * - * @generated - */ - public String getCharVal() - { - return charVal; - } - /** - * - * - * @generated - */ - public void setCharVal(String newCharVal) - { - String oldCharVal = charVal; - charVal = newCharVal; - boolean oldCharVal_set_ = charVal_set_; - charVal_set_ = true; - if (isNotifying()) - notify(ChangeKind.SET, CHAR_VAL, oldCharVal, charVal, !oldCharVal_set_); - } - - /** - * - * - * @generated - */ - public void unsetCharVal() - { - String oldCharVal = charVal; - boolean oldCharVal_set_ = charVal_set_; - charVal = CHAR_VAL_DEFAULT_; - charVal_set_ = false; - if (isNotifying()) - notify(ChangeKind.UNSET, CHAR_VAL, oldCharVal, CHAR_VAL_DEFAULT_, oldCharVal_set_); - } - - /** - * - * - * @generated - */ - public boolean isSetCharVal() - { - return charVal_set_; - } - - /** - * - * - * @generated - */ - public String getReadOnlyVal() - { - return readOnlyVal; - } - /** - * - * - * @generated - */ - public boolean isSetReadOnlyVal() - { - return readOnlyVal_set_; - } - - /** - * - * - * @generated - */ - public String getReadOnlyListVal() - { - return readOnlyListVal; - } - /** - * - * - * @generated - */ - public boolean isSetReadOnlyListVal() - { - return readOnlyListVal_set_; - } - - /** - * - * - * @generated - */ - public Object get(int propertyIndex, boolean resolve) - { - switch (propertyIndex) - { - case STRING_VAL: - return getStringVal(); - case BOOLEAN_VAL: - return isBooleanVal() ? Boolean.TRUE : Boolean.FALSE; - case BYTE_VAL: - return new Byte(getByteVal()); - case DECIMAL_VAL: - return getDecimalVal(); - case INT_VAL: - return new Integer(getIntVal()); - case FLOAT_VAL: - return new Float(getFloatVal()); - case DOUBLE_VAL: - return new Double(getDoubleVal()); - case DATE_VAL: - return getDateVal(); - case SHORT_VAL: - return new Short(getShortVal()); - case LONG_VAL: - return new Long(getLongVal()); - case LIST_VAL: - return getListVal(); - case BYTES_VAL: - return getBytesVal(); - case INTEGER_VAL: - return getIntegerVal(); - case CHAR_VAL: - return getCharVal(); - case READ_ONLY_VAL: - return getReadOnlyVal(); - case READ_ONLY_LIST_VAL: - return getReadOnlyListVal(); - } - return super.get(propertyIndex, resolve); - } - - /** - * - * - * @generated - */ - public void set(int propertyIndex, Object newValue) - { - switch (propertyIndex) - { - case STRING_VAL: - setStringVal((String)newValue); - return; - case BOOLEAN_VAL: - setBooleanVal(((Boolean)newValue).booleanValue()); - return; - case BYTE_VAL: - setByteVal(((Byte)newValue).byteValue()); - return; - case DECIMAL_VAL: - setDecimalVal((BigDecimal)newValue); - return; - case INT_VAL: - setIntVal(((Integer)newValue).intValue()); - return; - case FLOAT_VAL: - setFloatVal(((Float)newValue).floatValue()); - return; - case DOUBLE_VAL: - setDoubleVal(((Double)newValue).doubleValue()); - return; - case DATE_VAL: - setDateVal((String)newValue); - return; - case SHORT_VAL: - setShortVal(((Short)newValue).shortValue()); - return; - case LONG_VAL: - setLongVal(((Long)newValue).longValue()); - return; - case LIST_VAL: - getListVal().clear(); - getListVal().addAll((Collection)newValue); - return; - case BYTES_VAL: - setBytesVal((byte[])newValue); - return; - case INTEGER_VAL: - setIntegerVal((BigInteger)newValue); - return; - case CHAR_VAL: - setCharVal((String)newValue); - return; - } - super.set(propertyIndex, newValue); - } - - /** - * - * - * @generated - */ - public void unset(int propertyIndex) - { - switch (propertyIndex) - { - case STRING_VAL: - unsetStringVal(); - return; - case BOOLEAN_VAL: - unsetBooleanVal(); - return; - case BYTE_VAL: - unsetByteVal(); - return; - case DECIMAL_VAL: - unsetDecimalVal(); - return; - case INT_VAL: - unsetIntVal(); - return; - case FLOAT_VAL: - unsetFloatVal(); - return; - case DOUBLE_VAL: - unsetDoubleVal(); - return; - case DATE_VAL: - unsetDateVal(); - return; - case SHORT_VAL: - unsetShortVal(); - return; - case LONG_VAL: - unsetLongVal(); - return; - case LIST_VAL: - getListVal().clear(); - return; - case BYTES_VAL: - unsetBytesVal(); - return; - case INTEGER_VAL: - unsetIntegerVal(); - return; - case CHAR_VAL: - unsetCharVal(); - return; - } - super.unset(propertyIndex); - } - - /** - * - * - * @generated - */ - public boolean isSet(int propertyIndex) - { - switch (propertyIndex) - { - case STRING_VAL: - return isSetStringVal(); - case BOOLEAN_VAL: - return isSetBooleanVal(); - case BYTE_VAL: - return isSetByteVal(); - case DECIMAL_VAL: - return isSetDecimalVal(); - case INT_VAL: - return isSetIntVal(); - case FLOAT_VAL: - return isSetFloatVal(); - case DOUBLE_VAL: - return isSetDoubleVal(); - case DATE_VAL: - return isSetDateVal(); - case SHORT_VAL: - return isSetShortVal(); - case LONG_VAL: - return isSetLongVal(); - case LIST_VAL: - return listVal != null && !listVal.isEmpty(); - case BYTES_VAL: - return isSetBytesVal(); - case INTEGER_VAL: - return isSetIntegerVal(); - case CHAR_VAL: - return isSetCharVal(); - case READ_ONLY_VAL: - return isSetReadOnlyVal(); - case READ_ONLY_LIST_VAL: - return isSetReadOnlyListVal(); - } - return super.isSet(propertyIndex); - } - - /** - * - * - * @generated - */ - public String toString() - { - if (isProxy(this)) return super.toString(); - - StringBuffer result = new StringBuffer(super.toString()); - result.append(" (stringVal: "); - if (stringVal_set_) result.append(stringVal); else result.append(""); - result.append(", booleanVal: "); - if (booleanVal_set_) result.append(booleanVal); else result.append(""); - result.append(", byteVal: "); - if (byteVal_set_) result.append(byteVal); else result.append(""); - result.append(", decimalVal: "); - if (decimalVal_set_) result.append(decimalVal); else result.append(""); - result.append(", intVal: "); - if (intVal_set_) result.append(intVal); else result.append(""); - result.append(", floatVal: "); - if (floatVal_set_) result.append(floatVal); else result.append(""); - result.append(", doubleVal: "); - if (doubleVal_set_) result.append(doubleVal); else result.append(""); - result.append(", dateVal: "); - if (dateVal_set_) result.append(dateVal); else result.append(""); - result.append(", shortVal: "); - if (shortVal_set_) result.append(shortVal); else result.append(""); - result.append(", longVal: "); - if (longVal_set_) result.append(longVal); else result.append(""); - result.append(", listVal: "); - result.append(listVal); - result.append(", bytesVal: "); - if (bytesVal_set_) result.append(bytesVal); else result.append(""); - result.append(", integerVal: "); - if (integerVal_set_) result.append(integerVal); else result.append(""); - result.append(", charVal: "); - if (charVal_set_) result.append(charVal); else result.append(""); - result.append(", readOnlyVal: "); - if (readOnlyVal_set_) result.append(readOnlyVal); else result.append(""); - result.append(", readOnlyListVal: "); - if (readOnlyListVal_set_) result.append(readOnlyListVal); else result.append(""); - result.append(')'); - return result.toString(); - } - -} //ExpectedExceptionTypeImpl +/** + * + * 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 com.example.ExpectedException.impl; + +import com.example.ExpectedException.ExpectedExceptionFactory; +import com.example.ExpectedException.ExpectedExceptionType; + +import commonj.sdo.Type; + +import java.math.BigDecimal; +import java.math.BigInteger; + +import java.util.Collection; +import java.util.List; + +import org.apache.tuscany.sdo.impl.DataObjectBase; + +/** + * + * An implementation of the model object 'Type'. + * + *

+ * The following features are implemented: + *

    + *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getStringVal String Val}
  • + *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#isBooleanVal Boolean Val}
  • + *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getByteVal Byte Val}
  • + *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getDecimalVal Decimal Val}
  • + *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getIntVal Int Val}
  • + *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getFloatVal Float Val}
  • + *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getDoubleVal Double Val}
  • + *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getDateVal Date Val}
  • + *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getShortVal Short Val}
  • + *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getLongVal Long Val}
  • + *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getListVal List Val}
  • + *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getBytesVal Bytes Val}
  • + *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getIntegerVal Integer Val}
  • + *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getCharVal Char Val}
  • + *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getReadOnlyVal Read Only Val}
  • + *
  • {@link com.example.ExpectedException.impl.ExpectedExceptionTypeImpl#getReadOnlyListVal Read Only List Val}
  • + *
+ *

+ * + * @generated + */ +public class ExpectedExceptionTypeImpl extends DataObjectBase implements ExpectedExceptionType +{ + + public final static int STRING_VAL = 0; + + public final static int BOOLEAN_VAL = 1; + + public final static int BYTE_VAL = 2; + + public final static int DECIMAL_VAL = 3; + + public final static int INT_VAL = 4; + + public final static int FLOAT_VAL = 5; + + public final static int DOUBLE_VAL = 6; + + public final static int DATE_VAL = 7; + + public final static int SHORT_VAL = 8; + + public final static int LONG_VAL = 9; + + public final static int LIST_VAL = 10; + + public final static int BYTES_VAL = 11; + + public final static int INTEGER_VAL = 12; + + public final static int CHAR_VAL = 13; + + public final static int READ_ONLY_VAL = 14; + + public final static int READ_ONLY_LIST_VAL = 15; + + public final static int SDO_PROPERTY_COUNT = 16; + + public final static int EXTENDED_PROPERTY_COUNT = 0; + + + /** + * The internal feature id for the 'String Val' attribute. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_STRING_VAL = 0; + + /** + * The internal feature id for the 'Boolean Val' attribute. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_BOOLEAN_VAL = 1; + + /** + * The internal feature id for the 'Byte Val' attribute. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_BYTE_VAL = 2; + + /** + * The internal feature id for the 'Decimal Val' attribute. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_DECIMAL_VAL = 3; + + /** + * The internal feature id for the 'Int Val' attribute. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_INT_VAL = 4; + + /** + * The internal feature id for the 'Float Val' attribute. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_FLOAT_VAL = 5; + + /** + * The internal feature id for the 'Double Val' attribute. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_DOUBLE_VAL = 6; + + /** + * The internal feature id for the 'Date Val' attribute. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_DATE_VAL = 7; + + /** + * The internal feature id for the 'Short Val' attribute. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_SHORT_VAL = 8; + + /** + * The internal feature id for the 'Long Val' attribute. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_LONG_VAL = 9; + + /** + * The internal feature id for the 'List Val' attribute list. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_LIST_VAL = 10; + + /** + * The internal feature id for the 'Bytes Val' attribute. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_BYTES_VAL = 11; + + /** + * The internal feature id for the 'Integer Val' attribute. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_INTEGER_VAL = 12; + + /** + * The internal feature id for the 'Char Val' attribute. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_CHAR_VAL = 13; + + /** + * The internal feature id for the 'Read Only Val' attribute. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_READ_ONLY_VAL = 14; + + /** + * The internal feature id for the 'Read Only List Val' attribute. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_READ_ONLY_LIST_VAL = 15; + + /** + * The number of properties for this type. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_PROPERTY_COUNT = 16; + + protected int internalConvertIndex(int internalIndex) + { + switch (internalIndex) + { + case INTERNAL_STRING_VAL: return STRING_VAL; + case INTERNAL_BOOLEAN_VAL: return BOOLEAN_VAL; + case INTERNAL_BYTE_VAL: return BYTE_VAL; + case INTERNAL_DECIMAL_VAL: return DECIMAL_VAL; + case INTERNAL_INT_VAL: return INT_VAL; + case INTERNAL_FLOAT_VAL: return FLOAT_VAL; + case INTERNAL_DOUBLE_VAL: return DOUBLE_VAL; + case INTERNAL_DATE_VAL: return DATE_VAL; + case INTERNAL_SHORT_VAL: return SHORT_VAL; + case INTERNAL_LONG_VAL: return LONG_VAL; + case INTERNAL_LIST_VAL: return LIST_VAL; + case INTERNAL_BYTES_VAL: return BYTES_VAL; + case INTERNAL_INTEGER_VAL: return INTEGER_VAL; + case INTERNAL_CHAR_VAL: return CHAR_VAL; + case INTERNAL_READ_ONLY_VAL: return READ_ONLY_VAL; + case INTERNAL_READ_ONLY_LIST_VAL: return READ_ONLY_LIST_VAL; + } + return super.internalConvertIndex(internalIndex); + } + + + /** + * The default value of the '{@link #getStringVal() String Val}' attribute. + * + * + * @see #getStringVal() + * @generated + * @ordered + */ + protected static final String STRING_VAL_DEFAULT_ = null; + + /** + * The cached value of the '{@link #getStringVal() String Val}' attribute. + * + * + * @see #getStringVal() + * @generated + * @ordered + */ + protected String stringVal = STRING_VAL_DEFAULT_; + + /** + * This is true if the String Val attribute has been set. + * + * + * @generated + * @ordered + */ + protected boolean stringVal_set_ = false; + + /** + * The default value of the '{@link #isBooleanVal() Boolean Val}' attribute. + * + * + * @see #isBooleanVal() + * @generated + * @ordered + */ + protected static final boolean BOOLEAN_VAL_DEFAULT_ = false; + + /** + * The cached value of the '{@link #isBooleanVal() Boolean Val}' attribute. + * + * + * @see #isBooleanVal() + * @generated + * @ordered + */ + protected boolean booleanVal = BOOLEAN_VAL_DEFAULT_; + + /** + * This is true if the Boolean Val attribute has been set. + * + * + * @generated + * @ordered + */ + protected boolean booleanVal_set_ = false; + + /** + * The default value of the '{@link #getByteVal() Byte Val}' attribute. + * + * + * @see #getByteVal() + * @generated + * @ordered + */ + protected static final byte BYTE_VAL_DEFAULT_ = 0; + + /** + * The cached value of the '{@link #getByteVal() Byte Val}' attribute. + * + * + * @see #getByteVal() + * @generated + * @ordered + */ + protected byte byteVal = BYTE_VAL_DEFAULT_; + + /** + * This is true if the Byte Val attribute has been set. + * + * + * @generated + * @ordered + */ + protected boolean byteVal_set_ = false; + + /** + * The default value of the '{@link #getDecimalVal() Decimal Val}' attribute. + * + * + * @see #getDecimalVal() + * @generated + * @ordered + */ + protected static final BigDecimal DECIMAL_VAL_DEFAULT_ = null; + + /** + * The cached value of the '{@link #getDecimalVal() Decimal Val}' attribute. + * + * + * @see #getDecimalVal() + * @generated + * @ordered + */ + protected BigDecimal decimalVal = DECIMAL_VAL_DEFAULT_; + + /** + * This is true if the Decimal Val attribute has been set. + * + * + * @generated + * @ordered + */ + protected boolean decimalVal_set_ = false; + + /** + * The default value of the '{@link #getIntVal() Int Val}' attribute. + * + * + * @see #getIntVal() + * @generated + * @ordered + */ + protected static final int INT_VAL_DEFAULT_ = 0; + + /** + * The cached value of the '{@link #getIntVal() Int Val}' attribute. + * + * + * @see #getIntVal() + * @generated + * @ordered + */ + protected int intVal = INT_VAL_DEFAULT_; + + /** + * This is true if the Int Val attribute has been set. + * + * + * @generated + * @ordered + */ + protected boolean intVal_set_ = false; + + /** + * The default value of the '{@link #getFloatVal() Float Val}' attribute. + * + * + * @see #getFloatVal() + * @generated + * @ordered + */ + protected static final float FLOAT_VAL_DEFAULT_ = 0.0F; + + /** + * The cached value of the '{@link #getFloatVal() Float Val}' attribute. + * + * + * @see #getFloatVal() + * @generated + * @ordered + */ + protected float floatVal = FLOAT_VAL_DEFAULT_; + + /** + * This is true if the Float Val attribute has been set. + * + * + * @generated + * @ordered + */ + protected boolean floatVal_set_ = false; + + /** + * The default value of the '{@link #getDoubleVal() Double Val}' attribute. + * + * + * @see #getDoubleVal() + * @generated + * @ordered + */ + protected static final double DOUBLE_VAL_DEFAULT_ = 0.0; + + /** + * The cached value of the '{@link #getDoubleVal() Double Val}' attribute. + * + * + * @see #getDoubleVal() + * @generated + * @ordered + */ + protected double doubleVal = DOUBLE_VAL_DEFAULT_; + + /** + * This is true if the Double Val attribute has been set. + * + * + * @generated + * @ordered + */ + protected boolean doubleVal_set_ = false; + + /** + * The default value of the '{@link #getDateVal() Date Val}' attribute. + * + * + * @see #getDateVal() + * @generated + * @ordered + */ + protected static final String DATE_VAL_DEFAULT_ = null; + + /** + * The cached value of the '{@link #getDateVal() Date Val}' attribute. + * + * + * @see #getDateVal() + * @generated + * @ordered + */ + protected String dateVal = DATE_VAL_DEFAULT_; + + /** + * This is true if the Date Val attribute has been set. + * + * + * @generated + * @ordered + */ + protected boolean dateVal_set_ = false; + + /** + * The default value of the '{@link #getShortVal() Short Val}' attribute. + * + * + * @see #getShortVal() + * @generated + * @ordered + */ + protected static final short SHORT_VAL_DEFAULT_ = 0; + + /** + * The cached value of the '{@link #getShortVal() Short Val}' attribute. + * + * + * @see #getShortVal() + * @generated + * @ordered + */ + protected short shortVal = SHORT_VAL_DEFAULT_; + + /** + * This is true if the Short Val attribute has been set. + * + * + * @generated + * @ordered + */ + protected boolean shortVal_set_ = false; + + /** + * The default value of the '{@link #getLongVal() Long Val}' attribute. + * + * + * @see #getLongVal() + * @generated + * @ordered + */ + protected static final long LONG_VAL_DEFAULT_ = 0L; + + /** + * The cached value of the '{@link #getLongVal() Long Val}' attribute. + * + * + * @see #getLongVal() + * @generated + * @ordered + */ + protected long longVal = LONG_VAL_DEFAULT_; + + /** + * This is true if the Long Val attribute has been set. + * + * + * @generated + * @ordered + */ + protected boolean longVal_set_ = false; + + /** + * The cached value of the '{@link #getListVal() List Val}' attribute list. + * + * + * @see #getListVal() + * @generated + * @ordered + */ + + protected List listVal = null; + + /** + * The default value of the '{@link #getBytesVal() Bytes Val}' attribute. + * + * + * @see #getBytesVal() + * @generated + * @ordered + */ + protected static final byte[] BYTES_VAL_DEFAULT_ = null; + + /** + * The cached value of the '{@link #getBytesVal() Bytes Val}' attribute. + * + * + * @see #getBytesVal() + * @generated + * @ordered + */ + protected byte[] bytesVal = BYTES_VAL_DEFAULT_; + + /** + * This is true if the Bytes Val attribute has been set. + * + * + * @generated + * @ordered + */ + protected boolean bytesVal_set_ = false; + + /** + * The default value of the '{@link #getIntegerVal() Integer Val}' attribute. + * + * + * @see #getIntegerVal() + * @generated + * @ordered + */ + protected static final BigInteger INTEGER_VAL_DEFAULT_ = null; + + /** + * The cached value of the '{@link #getIntegerVal() Integer Val}' attribute. + * + * + * @see #getIntegerVal() + * @generated + * @ordered + */ + protected BigInteger integerVal = INTEGER_VAL_DEFAULT_; + + /** + * This is true if the Integer Val attribute has been set. + * + * + * @generated + * @ordered + */ + protected boolean integerVal_set_ = false; + + /** + * The default value of the '{@link #getCharVal() Char Val}' attribute. + * + * + * @see #getCharVal() + * @generated + * @ordered + */ + protected static final String CHAR_VAL_DEFAULT_ = null; + + /** + * The cached value of the '{@link #getCharVal() Char Val}' attribute. + * + * + * @see #getCharVal() + * @generated + * @ordered + */ + protected String charVal = CHAR_VAL_DEFAULT_; + + /** + * This is true if the Char Val attribute has been set. + * + * + * @generated + * @ordered + */ + protected boolean charVal_set_ = false; + + /** + * The default value of the '{@link #getReadOnlyVal() Read Only Val}' attribute. + * + * + * @see #getReadOnlyVal() + * @generated + * @ordered + */ + protected static final String READ_ONLY_VAL_DEFAULT_ = null; + + /** + * The cached value of the '{@link #getReadOnlyVal() Read Only Val}' attribute. + * + * + * @see #getReadOnlyVal() + * @generated + * @ordered + */ + protected String readOnlyVal = READ_ONLY_VAL_DEFAULT_; + + /** + * This is true if the Read Only Val attribute has been set. + * + * + * @generated + * @ordered + */ + protected boolean readOnlyVal_set_ = false; + + /** + * The default value of the '{@link #getReadOnlyListVal() Read Only List Val}' attribute. + * + * + * @see #getReadOnlyListVal() + * @generated + * @ordered + */ + protected static final String READ_ONLY_LIST_VAL_DEFAULT_ = null; + + /** + * The cached value of the '{@link #getReadOnlyListVal() Read Only List Val}' attribute. + * + * + * @see #getReadOnlyListVal() + * @generated + * @ordered + */ + protected String readOnlyListVal = READ_ONLY_LIST_VAL_DEFAULT_; + + /** + * This is true if the Read Only List Val attribute has been set. + * + * + * @generated + * @ordered + */ + protected boolean readOnlyListVal_set_ = false; + + /** + * + * + * @generated + */ + public ExpectedExceptionTypeImpl() + { + super(); + } + + /** + * + * + * @generated + */ + public Type getStaticType() + { + return ((ExpectedExceptionFactoryImpl)ExpectedExceptionFactory.INSTANCE).getExpectedExceptionType(); + } + + /** + * + * + * @generated + */ + public String getStringVal() + { + return stringVal; + } + /** + * + * + * @generated + */ + public void setStringVal(String newStringVal) + { + String oldStringVal = stringVal; + stringVal = newStringVal; + boolean oldStringVal_set_ = stringVal_set_; + stringVal_set_ = true; + if (isNotifying()) + notify(ChangeKind.SET, STRING_VAL, oldStringVal, stringVal, !oldStringVal_set_); + } + + /** + * + * + * @generated + */ + public void unsetStringVal() + { + String oldStringVal = stringVal; + boolean oldStringVal_set_ = stringVal_set_; + stringVal = STRING_VAL_DEFAULT_; + stringVal_set_ = false; + if (isNotifying()) + notify(ChangeKind.UNSET, STRING_VAL, oldStringVal, STRING_VAL_DEFAULT_, oldStringVal_set_); + } + + /** + * + * + * @generated + */ + public boolean isSetStringVal() + { + return stringVal_set_; + } + + /** + * + * + * @generated + */ + public boolean isBooleanVal() + { + return booleanVal; + } + /** + * + * + * @generated + */ + public void setBooleanVal(boolean newBooleanVal) + { + boolean oldBooleanVal = booleanVal; + booleanVal = newBooleanVal; + boolean oldBooleanVal_set_ = booleanVal_set_; + booleanVal_set_ = true; + if (isNotifying()) + notify(ChangeKind.SET, BOOLEAN_VAL, oldBooleanVal, booleanVal, !oldBooleanVal_set_); + } + + /** + * + * + * @generated + */ + public void unsetBooleanVal() + { + boolean oldBooleanVal = booleanVal; + boolean oldBooleanVal_set_ = booleanVal_set_; + booleanVal = BOOLEAN_VAL_DEFAULT_; + booleanVal_set_ = false; + if (isNotifying()) + notify(ChangeKind.UNSET, BOOLEAN_VAL, oldBooleanVal, BOOLEAN_VAL_DEFAULT_, oldBooleanVal_set_); + } + + /** + * + * + * @generated + */ + public boolean isSetBooleanVal() + { + return booleanVal_set_; + } + + /** + * + * + * @generated + */ + public byte getByteVal() + { + return byteVal; + } + /** + * + * + * @generated + */ + public void setByteVal(byte newByteVal) + { + byte oldByteVal = byteVal; + byteVal = newByteVal; + boolean oldByteVal_set_ = byteVal_set_; + byteVal_set_ = true; + if (isNotifying()) + notify(ChangeKind.SET, BYTE_VAL, oldByteVal, byteVal, !oldByteVal_set_); + } + + /** + * + * + * @generated + */ + public void unsetByteVal() + { + byte oldByteVal = byteVal; + boolean oldByteVal_set_ = byteVal_set_; + byteVal = BYTE_VAL_DEFAULT_; + byteVal_set_ = false; + if (isNotifying()) + notify(ChangeKind.UNSET, BYTE_VAL, oldByteVal, BYTE_VAL_DEFAULT_, oldByteVal_set_); + } + + /** + * + * + * @generated + */ + public boolean isSetByteVal() + { + return byteVal_set_; + } + + /** + * + * + * @generated + */ + public BigDecimal getDecimalVal() + { + return decimalVal; + } + /** + * + * + * @generated + */ + public void setDecimalVal(BigDecimal newDecimalVal) + { + BigDecimal oldDecimalVal = decimalVal; + decimalVal = newDecimalVal; + boolean oldDecimalVal_set_ = decimalVal_set_; + decimalVal_set_ = true; + if (isNotifying()) + notify(ChangeKind.SET, DECIMAL_VAL, oldDecimalVal, decimalVal, !oldDecimalVal_set_); + } + + /** + * + * + * @generated + */ + public void unsetDecimalVal() + { + BigDecimal oldDecimalVal = decimalVal; + boolean oldDecimalVal_set_ = decimalVal_set_; + decimalVal = DECIMAL_VAL_DEFAULT_; + decimalVal_set_ = false; + if (isNotifying()) + notify(ChangeKind.UNSET, DECIMAL_VAL, oldDecimalVal, DECIMAL_VAL_DEFAULT_, oldDecimalVal_set_); + } + + /** + * + * + * @generated + */ + public boolean isSetDecimalVal() + { + return decimalVal_set_; + } + + /** + * + * + * @generated + */ + public int getIntVal() + { + return intVal; + } + /** + * + * + * @generated + */ + public void setIntVal(int newIntVal) + { + int oldIntVal = intVal; + intVal = newIntVal; + boolean oldIntVal_set_ = intVal_set_; + intVal_set_ = true; + if (isNotifying()) + notify(ChangeKind.SET, INT_VAL, oldIntVal, intVal, !oldIntVal_set_); + } + + /** + * + * + * @generated + */ + public void unsetIntVal() + { + int oldIntVal = intVal; + boolean oldIntVal_set_ = intVal_set_; + intVal = INT_VAL_DEFAULT_; + intVal_set_ = false; + if (isNotifying()) + notify(ChangeKind.UNSET, INT_VAL, oldIntVal, INT_VAL_DEFAULT_, oldIntVal_set_); + } + + /** + * + * + * @generated + */ + public boolean isSetIntVal() + { + return intVal_set_; + } + + /** + * + * + * @generated + */ + public float getFloatVal() + { + return floatVal; + } + /** + * + * + * @generated + */ + public void setFloatVal(float newFloatVal) + { + float oldFloatVal = floatVal; + floatVal = newFloatVal; + boolean oldFloatVal_set_ = floatVal_set_; + floatVal_set_ = true; + if (isNotifying()) + notify(ChangeKind.SET, FLOAT_VAL, oldFloatVal, floatVal, !oldFloatVal_set_); + } + + /** + * + * + * @generated + */ + public void unsetFloatVal() + { + float oldFloatVal = floatVal; + boolean oldFloatVal_set_ = floatVal_set_; + floatVal = FLOAT_VAL_DEFAULT_; + floatVal_set_ = false; + if (isNotifying()) + notify(ChangeKind.UNSET, FLOAT_VAL, oldFloatVal, FLOAT_VAL_DEFAULT_, oldFloatVal_set_); + } + + /** + * + * + * @generated + */ + public boolean isSetFloatVal() + { + return floatVal_set_; + } + + /** + * + * + * @generated + */ + public double getDoubleVal() + { + return doubleVal; + } + /** + * + * + * @generated + */ + public void setDoubleVal(double newDoubleVal) + { + double oldDoubleVal = doubleVal; + doubleVal = newDoubleVal; + boolean oldDoubleVal_set_ = doubleVal_set_; + doubleVal_set_ = true; + if (isNotifying()) + notify(ChangeKind.SET, DOUBLE_VAL, oldDoubleVal, doubleVal, !oldDoubleVal_set_); + } + + /** + * + * + * @generated + */ + public void unsetDoubleVal() + { + double oldDoubleVal = doubleVal; + boolean oldDoubleVal_set_ = doubleVal_set_; + doubleVal = DOUBLE_VAL_DEFAULT_; + doubleVal_set_ = false; + if (isNotifying()) + notify(ChangeKind.UNSET, DOUBLE_VAL, oldDoubleVal, DOUBLE_VAL_DEFAULT_, oldDoubleVal_set_); + } + + /** + * + * + * @generated + */ + public boolean isSetDoubleVal() + { + return doubleVal_set_; + } + + /** + * + * + * @generated + */ + public String getDateVal() + { + return dateVal; + } + /** + * + * + * @generated + */ + public void setDateVal(String newDateVal) + { + String oldDateVal = dateVal; + dateVal = newDateVal; + boolean oldDateVal_set_ = dateVal_set_; + dateVal_set_ = true; + if (isNotifying()) + notify(ChangeKind.SET, DATE_VAL, oldDateVal, dateVal, !oldDateVal_set_); + } + + /** + * + * + * @generated + */ + public void unsetDateVal() + { + String oldDateVal = dateVal; + boolean oldDateVal_set_ = dateVal_set_; + dateVal = DATE_VAL_DEFAULT_; + dateVal_set_ = false; + if (isNotifying()) + notify(ChangeKind.UNSET, DATE_VAL, oldDateVal, DATE_VAL_DEFAULT_, oldDateVal_set_); + } + + /** + * + * + * @generated + */ + public boolean isSetDateVal() + { + return dateVal_set_; + } + + /** + * + * + * @generated + */ + public short getShortVal() + { + return shortVal; + } + /** + * + * + * @generated + */ + public void setShortVal(short newShortVal) + { + short oldShortVal = shortVal; + shortVal = newShortVal; + boolean oldShortVal_set_ = shortVal_set_; + shortVal_set_ = true; + if (isNotifying()) + notify(ChangeKind.SET, SHORT_VAL, oldShortVal, shortVal, !oldShortVal_set_); + } + + /** + * + * + * @generated + */ + public void unsetShortVal() + { + short oldShortVal = shortVal; + boolean oldShortVal_set_ = shortVal_set_; + shortVal = SHORT_VAL_DEFAULT_; + shortVal_set_ = false; + if (isNotifying()) + notify(ChangeKind.UNSET, SHORT_VAL, oldShortVal, SHORT_VAL_DEFAULT_, oldShortVal_set_); + } + + /** + * + * + * @generated + */ + public boolean isSetShortVal() + { + return shortVal_set_; + } + + /** + * + * + * @generated + */ + public long getLongVal() + { + return longVal; + } + /** + * + * + * @generated + */ + public void setLongVal(long newLongVal) + { + long oldLongVal = longVal; + longVal = newLongVal; + boolean oldLongVal_set_ = longVal_set_; + longVal_set_ = true; + if (isNotifying()) + notify(ChangeKind.SET, LONG_VAL, oldLongVal, longVal, !oldLongVal_set_); + } + + /** + * + * + * @generated + */ + public void unsetLongVal() + { + long oldLongVal = longVal; + boolean oldLongVal_set_ = longVal_set_; + longVal = LONG_VAL_DEFAULT_; + longVal_set_ = false; + if (isNotifying()) + notify(ChangeKind.UNSET, LONG_VAL, oldLongVal, LONG_VAL_DEFAULT_, oldLongVal_set_); + } + + /** + * + * + * @generated + */ + public boolean isSetLongVal() + { + return longVal_set_; + } + + /** + * + * + * @generated + */ + public List getListVal() + { + if (listVal == null) + { + listVal = createPropertyList(ListKind.DATATYPE, String.class, LIST_VAL, 0); + } + return listVal; + } + /** + * + * + * @generated + */ + public byte[] getBytesVal() + { + return bytesVal; + } + /** + * + * + * @generated + */ + public void setBytesVal(byte[] newBytesVal) + { + byte[] oldBytesVal = bytesVal; + bytesVal = newBytesVal; + boolean oldBytesVal_set_ = bytesVal_set_; + bytesVal_set_ = true; + if (isNotifying()) + notify(ChangeKind.SET, BYTES_VAL, oldBytesVal, bytesVal, !oldBytesVal_set_); + } + + /** + * + * + * @generated + */ + public void unsetBytesVal() + { + byte[] oldBytesVal = bytesVal; + boolean oldBytesVal_set_ = bytesVal_set_; + bytesVal = BYTES_VAL_DEFAULT_; + bytesVal_set_ = false; + if (isNotifying()) + notify(ChangeKind.UNSET, BYTES_VAL, oldBytesVal, BYTES_VAL_DEFAULT_, oldBytesVal_set_); + } + + /** + * + * + * @generated + */ + public boolean isSetBytesVal() + { + return bytesVal_set_; + } + + /** + * + * + * @generated + */ + public BigInteger getIntegerVal() + { + return integerVal; + } + /** + * + * + * @generated + */ + public void setIntegerVal(BigInteger newIntegerVal) + { + BigInteger oldIntegerVal = integerVal; + integerVal = newIntegerVal; + boolean oldIntegerVal_set_ = integerVal_set_; + integerVal_set_ = true; + if (isNotifying()) + notify(ChangeKind.SET, INTEGER_VAL, oldIntegerVal, integerVal, !oldIntegerVal_set_); + } + + /** + * + * + * @generated + */ + public void unsetIntegerVal() + { + BigInteger oldIntegerVal = integerVal; + boolean oldIntegerVal_set_ = integerVal_set_; + integerVal = INTEGER_VAL_DEFAULT_; + integerVal_set_ = false; + if (isNotifying()) + notify(ChangeKind.UNSET, INTEGER_VAL, oldIntegerVal, INTEGER_VAL_DEFAULT_, oldIntegerVal_set_); + } + + /** + * + * + * @generated + */ + public boolean isSetIntegerVal() + { + return integerVal_set_; + } + + /** + * + * + * @generated + */ + public String getCharVal() + { + return charVal; + } + /** + * + * + * @generated + */ + public void setCharVal(String newCharVal) + { + String oldCharVal = charVal; + charVal = newCharVal; + boolean oldCharVal_set_ = charVal_set_; + charVal_set_ = true; + if (isNotifying()) + notify(ChangeKind.SET, CHAR_VAL, oldCharVal, charVal, !oldCharVal_set_); + } + + /** + * + * + * @generated + */ + public void unsetCharVal() + { + String oldCharVal = charVal; + boolean oldCharVal_set_ = charVal_set_; + charVal = CHAR_VAL_DEFAULT_; + charVal_set_ = false; + if (isNotifying()) + notify(ChangeKind.UNSET, CHAR_VAL, oldCharVal, CHAR_VAL_DEFAULT_, oldCharVal_set_); + } + + /** + * + * + * @generated + */ + public boolean isSetCharVal() + { + return charVal_set_; + } + + /** + * + * + * @generated + */ + public String getReadOnlyVal() + { + return readOnlyVal; + } + /** + * + * + * @generated + */ + public boolean isSetReadOnlyVal() + { + return readOnlyVal_set_; + } + + /** + * + * + * @generated + */ + public String getReadOnlyListVal() + { + return readOnlyListVal; + } + /** + * + * + * @generated + */ + public boolean isSetReadOnlyListVal() + { + return readOnlyListVal_set_; + } + + /** + * + * + * @generated + */ + public Object get(int propertyIndex, boolean resolve) + { + switch (propertyIndex) + { + case STRING_VAL: + return getStringVal(); + case BOOLEAN_VAL: + return isBooleanVal() ? Boolean.TRUE : Boolean.FALSE; + case BYTE_VAL: + return new Byte(getByteVal()); + case DECIMAL_VAL: + return getDecimalVal(); + case INT_VAL: + return new Integer(getIntVal()); + case FLOAT_VAL: + return new Float(getFloatVal()); + case DOUBLE_VAL: + return new Double(getDoubleVal()); + case DATE_VAL: + return getDateVal(); + case SHORT_VAL: + return new Short(getShortVal()); + case LONG_VAL: + return new Long(getLongVal()); + case LIST_VAL: + return getListVal(); + case BYTES_VAL: + return getBytesVal(); + case INTEGER_VAL: + return getIntegerVal(); + case CHAR_VAL: + return getCharVal(); + case READ_ONLY_VAL: + return getReadOnlyVal(); + case READ_ONLY_LIST_VAL: + return getReadOnlyListVal(); + } + return super.get(propertyIndex, resolve); + } + + /** + * + * + * @generated + */ + public void set(int propertyIndex, Object newValue) + { + switch (propertyIndex) + { + case STRING_VAL: + setStringVal((String)newValue); + return; + case BOOLEAN_VAL: + setBooleanVal(((Boolean)newValue).booleanValue()); + return; + case BYTE_VAL: + setByteVal(((Byte)newValue).byteValue()); + return; + case DECIMAL_VAL: + setDecimalVal((BigDecimal)newValue); + return; + case INT_VAL: + setIntVal(((Integer)newValue).intValue()); + return; + case FLOAT_VAL: + setFloatVal(((Float)newValue).floatValue()); + return; + case DOUBLE_VAL: + setDoubleVal(((Double)newValue).doubleValue()); + return; + case DATE_VAL: + setDateVal((String)newValue); + return; + case SHORT_VAL: + setShortVal(((Short)newValue).shortValue()); + return; + case LONG_VAL: + setLongVal(((Long)newValue).longValue()); + return; + case LIST_VAL: + getListVal().clear(); + getListVal().addAll((Collection)newValue); + return; + case BYTES_VAL: + setBytesVal((byte[])newValue); + return; + case INTEGER_VAL: + setIntegerVal((BigInteger)newValue); + return; + case CHAR_VAL: + setCharVal((String)newValue); + return; + } + super.set(propertyIndex, newValue); + } + + /** + * + * + * @generated + */ + public void unset(int propertyIndex) + { + switch (propertyIndex) + { + case STRING_VAL: + unsetStringVal(); + return; + case BOOLEAN_VAL: + unsetBooleanVal(); + return; + case BYTE_VAL: + unsetByteVal(); + return; + case DECIMAL_VAL: + unsetDecimalVal(); + return; + case INT_VAL: + unsetIntVal(); + return; + case FLOAT_VAL: + unsetFloatVal(); + return; + case DOUBLE_VAL: + unsetDoubleVal(); + return; + case DATE_VAL: + unsetDateVal(); + return; + case SHORT_VAL: + unsetShortVal(); + return; + case LONG_VAL: + unsetLongVal(); + return; + case LIST_VAL: + getListVal().clear(); + return; + case BYTES_VAL: + unsetBytesVal(); + return; + case INTEGER_VAL: + unsetIntegerVal(); + return; + case CHAR_VAL: + unsetCharVal(); + return; + } + super.unset(propertyIndex); + } + + /** + * + * + * @generated + */ + public boolean isSet(int propertyIndex) + { + switch (propertyIndex) + { + case STRING_VAL: + return isSetStringVal(); + case BOOLEAN_VAL: + return isSetBooleanVal(); + case BYTE_VAL: + return isSetByteVal(); + case DECIMAL_VAL: + return isSetDecimalVal(); + case INT_VAL: + return isSetIntVal(); + case FLOAT_VAL: + return isSetFloatVal(); + case DOUBLE_VAL: + return isSetDoubleVal(); + case DATE_VAL: + return isSetDateVal(); + case SHORT_VAL: + return isSetShortVal(); + case LONG_VAL: + return isSetLongVal(); + case LIST_VAL: + return listVal != null && !listVal.isEmpty(); + case BYTES_VAL: + return isSetBytesVal(); + case INTEGER_VAL: + return isSetIntegerVal(); + case CHAR_VAL: + return isSetCharVal(); + case READ_ONLY_VAL: + return isSetReadOnlyVal(); + case READ_ONLY_LIST_VAL: + return isSetReadOnlyListVal(); + } + return super.isSet(propertyIndex); + } + + /** + * + * + * @generated + */ + public String toString() + { + if (isProxy(this)) return super.toString(); + + StringBuffer result = new StringBuffer(super.toString()); + result.append(" (stringVal: "); + if (stringVal_set_) result.append(stringVal); else result.append(""); + result.append(", booleanVal: "); + if (booleanVal_set_) result.append(booleanVal); else result.append(""); + result.append(", byteVal: "); + if (byteVal_set_) result.append(byteVal); else result.append(""); + result.append(", decimalVal: "); + if (decimalVal_set_) result.append(decimalVal); else result.append(""); + result.append(", intVal: "); + if (intVal_set_) result.append(intVal); else result.append(""); + result.append(", floatVal: "); + if (floatVal_set_) result.append(floatVal); else result.append(""); + result.append(", doubleVal: "); + if (doubleVal_set_) result.append(doubleVal); else result.append(""); + result.append(", dateVal: "); + if (dateVal_set_) result.append(dateVal); else result.append(""); + result.append(", shortVal: "); + if (shortVal_set_) result.append(shortVal); else result.append(""); + result.append(", longVal: "); + if (longVal_set_) result.append(longVal); else result.append(""); + result.append(", listVal: "); + result.append(listVal); + result.append(", bytesVal: "); + if (bytesVal_set_) result.append(bytesVal); else result.append(""); + result.append(", integerVal: "); + if (integerVal_set_) result.append(integerVal); else result.append(""); + result.append(", charVal: "); + if (charVal_set_) result.append(charVal); else result.append(""); + result.append(", readOnlyVal: "); + if (readOnlyVal_set_) result.append(readOnlyVal); else result.append(""); + result.append(", readOnlyListVal: "); + if (readOnlyListVal_set_) result.append(readOnlyListVal); else result.append(""); + result.append(')'); + return result.toString(); + } + +} //ExpectedExceptionTypeImpl diff --git a/java/sdo/impl/src/test/java/com/example/ExpectedException/impl/SequenceReadOnlyTypeImpl.java b/java/sdo/impl/src/test/java/com/example/ExpectedException/impl/SequenceReadOnlyTypeImpl.java index 4ac8a19807..048cb439db 100644 --- a/java/sdo/impl/src/test/java/com/example/ExpectedException/impl/SequenceReadOnlyTypeImpl.java +++ b/java/sdo/impl/src/test/java/com/example/ExpectedException/impl/SequenceReadOnlyTypeImpl.java @@ -1,354 +1,354 @@ -/** - * - * 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 com.example.ExpectedException.impl; - -import com.example.ExpectedException.ExpectedExceptionFactory; -import com.example.ExpectedException.SequenceReadOnlyType; - -import commonj.sdo.Sequence; -import commonj.sdo.Type; - -import org.apache.tuscany.sdo.impl.DataObjectBase; - -/** - * - * An implementation of the model object 'Sequence Read Only Type'. - * - *

- * The following features are implemented: - *

    - *
  • {@link com.example.ExpectedException.impl.SequenceReadOnlyTypeImpl#getMixed Mixed}
  • - *
  • {@link com.example.ExpectedException.impl.SequenceReadOnlyTypeImpl#getReadOnlyVal Read Only Val}
  • - *
  • {@link com.example.ExpectedException.impl.SequenceReadOnlyTypeImpl#getReadOnlyListVal Read Only List Val}
  • - *
  • {@link com.example.ExpectedException.impl.SequenceReadOnlyTypeImpl#getUniqueName Unique Name}
  • - *
- *

- * - * @generated - */ -public class SequenceReadOnlyTypeImpl extends DataObjectBase implements SequenceReadOnlyType -{ - - public final static int MIXED = -1; - - public final static int READ_ONLY_VAL = 0; - - public final static int READ_ONLY_LIST_VAL = 1; - - public final static int UNIQUE_NAME = 2; - - public final static int SDO_PROPERTY_COUNT = 3; - - public final static int EXTENDED_PROPERTY_COUNT = -1; - - - /** - * The internal feature id for the 'Mixed' attribute list. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_MIXED = 0; - - /** - * The internal feature id for the 'Read Only Val' attribute. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_READ_ONLY_VAL = 1; - - /** - * The internal feature id for the 'Read Only List Val' attribute. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_READ_ONLY_LIST_VAL = 2; - - /** - * The internal feature id for the 'Unique Name' attribute. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_UNIQUE_NAME = 3; - - /** - * The number of properties for this type. - * - * - * @generated - * @ordered - */ - public final static int INTERNAL_PROPERTY_COUNT = 4; - - protected int internalConvertIndex(int internalIndex) - { - switch (internalIndex) - { - case INTERNAL_MIXED: return MIXED; - case INTERNAL_READ_ONLY_VAL: return READ_ONLY_VAL; - case INTERNAL_READ_ONLY_LIST_VAL: return READ_ONLY_LIST_VAL; - case INTERNAL_UNIQUE_NAME: return UNIQUE_NAME; - } - return super.internalConvertIndex(internalIndex); - } - - - /** - * The cached value of the '{@link #getMixed() Mixed}' attribute list. - * - * - * @see #getMixed() - * @generated - * @ordered - */ - - protected Sequence mixed = null; - - /** - * - * - * @generated - */ - public SequenceReadOnlyTypeImpl() - { - super(); - } - - /** - * - * - * @generated - */ - public Type getStaticType() - { - return ((ExpectedExceptionFactoryImpl)ExpectedExceptionFactory.INSTANCE).getSequenceReadOnlyType(); - } - - /** - * - * - * @generated - */ - public Sequence getMixed() - { - if (mixed == null) - { - mixed = createSequence(INTERNAL_MIXED); - } - return mixed; - } - /** - * - * - * @generated - */ - public String getReadOnlyVal() - { - return (String)get(getMixed(), getType(), INTERNAL_READ_ONLY_VAL); - } - /** - * - * - * @generated - */ - public boolean isSetReadOnlyVal() - { - return isSet(getMixed(), getType(), INTERNAL_READ_ONLY_VAL); - } - - /** - * - * - * @generated - */ - public String getReadOnlyListVal() - { - return (String)get(getMixed(), getType(), INTERNAL_READ_ONLY_LIST_VAL); - } - /** - * - * - * @generated - */ - public boolean isSetReadOnlyListVal() - { - return isSet(getMixed(), getType(), INTERNAL_READ_ONLY_LIST_VAL); - } - - /** - * - * - * @generated - */ - public String getUniqueName() - { - return (String)get(getMixed(), getType(), INTERNAL_UNIQUE_NAME); - } - /** - * - * - * @generated - */ - public void setUniqueName(String newUniqueName) - { - set(getMixed(), getType(), INTERNAL_UNIQUE_NAME, newUniqueName); - } - - /** - * - * - * @generated - */ - public void unsetUniqueName() - { - unset(getMixed(), getType(), INTERNAL_UNIQUE_NAME); - } - - /** - * - * - * @generated - */ - public boolean isSetUniqueName() - { - return isSet(getMixed(), getType(), INTERNAL_UNIQUE_NAME); - } - - /** - * - * - * @generated - */ - public ChangeContext inverseRemove(Object otherEnd, int propertyIndex, ChangeContext changeContext) - { - switch (propertyIndex) - { - case MIXED: - return removeFromSequence(getMixed(), otherEnd, changeContext); - } - return super.inverseRemove(otherEnd, propertyIndex, changeContext); - } - - /** - * - * - * @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 READ_ONLY_VAL: - return getReadOnlyVal(); - case READ_ONLY_LIST_VAL: - return getReadOnlyListVal(); - case UNIQUE_NAME: - return getUniqueName(); - } - return super.get(propertyIndex, resolve); - } - - /** - * - * - * @generated - */ - public void set(int propertyIndex, Object newValue) - { - switch (propertyIndex) - { - case MIXED: - setSequence(getMixed(), newValue); - return; - case UNIQUE_NAME: - setUniqueName((String)newValue); - return; - } - super.set(propertyIndex, newValue); - } - - /** - * - * - * @generated - */ - public void unset(int propertyIndex) - { - switch (propertyIndex) - { - case MIXED: - unsetSequence(getMixed()); - return; - case UNIQUE_NAME: - unsetUniqueName(); - return; - } - super.unset(propertyIndex); - } - - /** - * - * - * @generated - */ - public boolean isSet(int propertyIndex) - { - switch (propertyIndex) - { - case MIXED: - return mixed != null && !isSequenceEmpty(getMixed()); - case READ_ONLY_VAL: - return isSetReadOnlyVal(); - case READ_ONLY_LIST_VAL: - return isSetReadOnlyListVal(); - case UNIQUE_NAME: - return isSetUniqueName(); - } - return super.isSet(propertyIndex); - } - - /** - * - * - * @generated - */ - public String toString() - { - if (isProxy(this)) return super.toString(); - - StringBuffer result = new StringBuffer(super.toString()); - result.append(" (mixed: "); - result.append(mixed); - result.append(')'); - return result.toString(); - } - -} //SequenceReadOnlyTypeImpl +/** + * + * 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 com.example.ExpectedException.impl; + +import com.example.ExpectedException.ExpectedExceptionFactory; +import com.example.ExpectedException.SequenceReadOnlyType; + +import commonj.sdo.Sequence; +import commonj.sdo.Type; + +import org.apache.tuscany.sdo.impl.DataObjectBase; + +/** + * + * An implementation of the model object 'Sequence Read Only Type'. + * + *

+ * The following features are implemented: + *

    + *
  • {@link com.example.ExpectedException.impl.SequenceReadOnlyTypeImpl#getMixed Mixed}
  • + *
  • {@link com.example.ExpectedException.impl.SequenceReadOnlyTypeImpl#getReadOnlyVal Read Only Val}
  • + *
  • {@link com.example.ExpectedException.impl.SequenceReadOnlyTypeImpl#getReadOnlyListVal Read Only List Val}
  • + *
  • {@link com.example.ExpectedException.impl.SequenceReadOnlyTypeImpl#getUniqueName Unique Name}
  • + *
+ *

+ * + * @generated + */ +public class SequenceReadOnlyTypeImpl extends DataObjectBase implements SequenceReadOnlyType +{ + + public final static int MIXED = -1; + + public final static int READ_ONLY_VAL = 0; + + public final static int READ_ONLY_LIST_VAL = 1; + + public final static int UNIQUE_NAME = 2; + + public final static int SDO_PROPERTY_COUNT = 3; + + public final static int EXTENDED_PROPERTY_COUNT = -1; + + + /** + * The internal feature id for the 'Mixed' attribute list. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_MIXED = 0; + + /** + * The internal feature id for the 'Read Only Val' attribute. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_READ_ONLY_VAL = 1; + + /** + * The internal feature id for the 'Read Only List Val' attribute. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_READ_ONLY_LIST_VAL = 2; + + /** + * The internal feature id for the 'Unique Name' attribute. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_UNIQUE_NAME = 3; + + /** + * The number of properties for this type. + * + * + * @generated + * @ordered + */ + public final static int INTERNAL_PROPERTY_COUNT = 4; + + protected int internalConvertIndex(int internalIndex) + { + switch (internalIndex) + { + case INTERNAL_MIXED: return MIXED; + case INTERNAL_READ_ONLY_VAL: return READ_ONLY_VAL; + case INTERNAL_READ_ONLY_LIST_VAL: return READ_ONLY_LIST_VAL; + case INTERNAL_UNIQUE_NAME: return UNIQUE_NAME; + } + return super.internalConvertIndex(internalIndex); + } + + + /** + * The cached value of the '{@link #getMixed() Mixed}' attribute list. + * + * + * @see #getMixed() + * @generated + * @ordered + */ + + protected Sequence mixed = null; + + /** + * + * + * @generated + */ + public SequenceReadOnlyTypeImpl() + { + super(); + } + + /** + * + * + * @generated + */ + public Type getStaticType() + { + return ((ExpectedExceptionFactoryImpl)ExpectedExceptionFactory.INSTANCE).getSequenceReadOnlyType(); + } + + /** + * + * + * @generated + */ + public Sequence getMixed() + { + if (mixed == null) + { + mixed = createSequence(INTERNAL_MIXED); + } + return mixed; + } + /** + * + * + * @generated + */ + public String getReadOnlyVal() + { + return (String)get(getMixed(), getType(), INTERNAL_READ_ONLY_VAL); + } + /** + * + * + * @generated + */ + public boolean isSetReadOnlyVal() + { + return isSet(getMixed(), getType(), INTERNAL_READ_ONLY_VAL); + } + + /** + * + * + * @generated + */ + public String getReadOnlyListVal() + { + return (String)get(getMixed(), getType(), INTERNAL_READ_ONLY_LIST_VAL); + } + /** + * + * + * @generated + */ + public boolean isSetReadOnlyListVal() + { + return isSet(getMixed(), getType(), INTERNAL_READ_ONLY_LIST_VAL); + } + + /** + * + * + * @generated + */ + public String getUniqueName() + { + return (String)get(getMixed(), getType(), INTERNAL_UNIQUE_NAME); + } + /** + * + * + * @generated + */ + public void setUniqueName(String newUniqueName) + { + set(getMixed(), getType(), INTERNAL_UNIQUE_NAME, newUniqueName); + } + + /** + * + * + * @generated + */ + public void unsetUniqueName() + { + unset(getMixed(), getType(), INTERNAL_UNIQUE_NAME); + } + + /** + * + * + * @generated + */ + public boolean isSetUniqueName() + { + return isSet(getMixed(), getType(), INTERNAL_UNIQUE_NAME); + } + + /** + * + * + * @generated + */ + public ChangeContext inverseRemove(Object otherEnd, int propertyIndex, ChangeContext changeContext) + { + switch (propertyIndex) + { + case MIXED: + return removeFromSequence(getMixed(), otherEnd, changeContext); + } + return super.inverseRemove(otherEnd, propertyIndex, changeContext); + } + + /** + * + * + * @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 READ_ONLY_VAL: + return getReadOnlyVal(); + case READ_ONLY_LIST_VAL: + return getReadOnlyListVal(); + case UNIQUE_NAME: + return getUniqueName(); + } + return super.get(propertyIndex, resolve); + } + + /** + * + * + * @generated + */ + public void set(int propertyIndex, Object newValue) + { + switch (propertyIndex) + { + case MIXED: + setSequence(getMixed(), newValue); + return; + case UNIQUE_NAME: + setUniqueName((String)newValue); + return; + } + super.set(propertyIndex, newValue); + } + + /** + * + * + * @generated + */ + public void unset(int propertyIndex) + { + switch (propertyIndex) + { + case MIXED: + unsetSequence(getMixed()); + return; + case UNIQUE_NAME: + unsetUniqueName(); + return; + } + super.unset(propertyIndex); + } + + /** + * + * + * @generated + */ + public boolean isSet(int propertyIndex) + { + switch (propertyIndex) + { + case MIXED: + return mixed != null && !isSequenceEmpty(getMixed()); + case READ_ONLY_VAL: + return isSetReadOnlyVal(); + case READ_ONLY_LIST_VAL: + return isSetReadOnlyListVal(); + case UNIQUE_NAME: + return isSetUniqueName(); + } + return super.isSet(propertyIndex); + } + + /** + * + * + * @generated + */ + public String toString() + { + if (isProxy(this)) return super.toString(); + + StringBuffer result = new StringBuffer(super.toString()); + result.append(" (mixed: "); + result.append(mixed); + result.append(')'); + return result.toString(); + } + +} //SequenceReadOnlyTypeImpl diff --git a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/BoundsTestCase.java b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/BoundsTestCase.java index 35c9b87b2c..7f176fe033 100644 --- a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/BoundsTestCase.java +++ b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/BoundsTestCase.java @@ -1,79 +1,79 @@ -/** - * - * 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.InputStream; -import java.net.URL; - -import org.apache.tuscany.sdo.api.SDOUtil; -import org.apache.tuscany.sdo.api.SDOHelper; - -import junit.framework.TestCase; - -import commonj.sdo.*; -import commonj.sdo.helper.*; - -public class BoundsTestCase extends TestCase { - private final String TEST_MODEL = "/bounds.xsd"; - private final String TEST_NAMESPACE = "http://www.example.com/bounds"; - - private TypeHelper typeHelper; - private XSDHelper xsdHelper; - private DataFactory dataFactory; - - public void testBounds() { - Property priceProperty = typeHelper.getOpenContentProperty(TEST_NAMESPACE, "price"); - assertTrue(priceProperty.isOpenContent()); - assertEquals(SDOHelper.UNSPECIFIED, SDOUtil.getUpperBound(priceProperty)); - assertEquals(0, SDOUtil.getLowerBound(priceProperty)); - - Type quoteType = typeHelper.getType(TEST_NAMESPACE, "OpenQuote"); - DataObject quote = dataFactory.create(quoteType); - assertEquals(2, SDOUtil.getUpperBound(quote.getInstanceProperty("symbol"))); - assertEquals(0, SDOUtil.getLowerBound(quote.getInstanceProperty("symbol"))); - - //XSD default value of maxOccurs and minOccurs is 1, unbounded returns -1 for maxOccurs - Type quoteType2 = typeHelper.getType(TEST_NAMESPACE, "OpenQuote2"); - DataObject quote2 = dataFactory.create(quoteType2); - assertEquals(SDOHelper.UNBOUNDED, SDOUtil.getUpperBound(quote2.getInstanceProperty("symbol"))); - assertEquals(1, SDOUtil.getLowerBound(quote2.getInstanceProperty("symbol"))); - - //XSD default value of maxOccurs and minOccurs is 1 - Type quoteType3 = typeHelper.getType(TEST_NAMESPACE, "OpenQuote3"); - DataObject quote3 = dataFactory.create(quoteType3); - assertEquals(1, SDOUtil.getUpperBound(quote3.getInstanceProperty("symbol"))); - assertEquals(1, SDOUtil.getLowerBound(quote3.getInstanceProperty("symbol"))); - } - - protected void setUp() throws Exception { - super.setUp(); - - HelperContext hc = SDOUtil.createHelperContext(); - typeHelper = hc.getTypeHelper(); - dataFactory = hc.getDataFactory(); - xsdHelper = hc.getXSDHelper(); - - // Populate the meta data for the test (Stock Quote) model - URL url = getClass().getResource(TEST_MODEL); - InputStream inputStream = url.openStream(); - xsdHelper.define(inputStream, url.toString()); - inputStream.close(); - } +/** + * + * 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.InputStream; +import java.net.URL; + +import org.apache.tuscany.sdo.api.SDOUtil; +import org.apache.tuscany.sdo.api.SDOHelper; + +import junit.framework.TestCase; + +import commonj.sdo.*; +import commonj.sdo.helper.*; + +public class BoundsTestCase extends TestCase { + private final String TEST_MODEL = "/bounds.xsd"; + private final String TEST_NAMESPACE = "http://www.example.com/bounds"; + + private TypeHelper typeHelper; + private XSDHelper xsdHelper; + private DataFactory dataFactory; + + public void testBounds() { + Property priceProperty = typeHelper.getOpenContentProperty(TEST_NAMESPACE, "price"); + assertTrue(priceProperty.isOpenContent()); + assertEquals(SDOHelper.UNSPECIFIED, SDOUtil.getUpperBound(priceProperty)); + assertEquals(0, SDOUtil.getLowerBound(priceProperty)); + + Type quoteType = typeHelper.getType(TEST_NAMESPACE, "OpenQuote"); + DataObject quote = dataFactory.create(quoteType); + assertEquals(2, SDOUtil.getUpperBound(quote.getInstanceProperty("symbol"))); + assertEquals(0, SDOUtil.getLowerBound(quote.getInstanceProperty("symbol"))); + + //XSD default value of maxOccurs and minOccurs is 1, unbounded returns -1 for maxOccurs + Type quoteType2 = typeHelper.getType(TEST_NAMESPACE, "OpenQuote2"); + DataObject quote2 = dataFactory.create(quoteType2); + assertEquals(SDOHelper.UNBOUNDED, SDOUtil.getUpperBound(quote2.getInstanceProperty("symbol"))); + assertEquals(1, SDOUtil.getLowerBound(quote2.getInstanceProperty("symbol"))); + + //XSD default value of maxOccurs and minOccurs is 1 + Type quoteType3 = typeHelper.getType(TEST_NAMESPACE, "OpenQuote3"); + DataObject quote3 = dataFactory.create(quoteType3); + assertEquals(1, SDOUtil.getUpperBound(quote3.getInstanceProperty("symbol"))); + assertEquals(1, SDOUtil.getLowerBound(quote3.getInstanceProperty("symbol"))); + } + + protected void setUp() throws Exception { + super.setUp(); + + HelperContext hc = SDOUtil.createHelperContext(); + typeHelper = hc.getTypeHelper(); + dataFactory = hc.getDataFactory(); + xsdHelper = hc.getXSDHelper(); + + // Populate the meta data for the test (Stock Quote) model + URL url = getClass().getResource(TEST_MODEL); + InputStream inputStream = url.openStream(); + xsdHelper.define(inputStream, url.toString()); + inputStream.close(); + } } \ No newline at end of file diff --git a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/ChangeSummaryPropertyTestCase.java b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/ChangeSummaryPropertyTestCase.java index 4a62ec6135..ace509d1b4 100644 --- a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/ChangeSummaryPropertyTestCase.java +++ b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/ChangeSummaryPropertyTestCase.java @@ -1,219 +1,219 @@ -/** - * - * 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.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.math.BigDecimal; -import java.net.URL; -import java.util.List; - -import junit.framework.TestCase; - -import org.apache.tuscany.sdo.util.SDOUtil; - -import commonj.sdo.ChangeSummary; -import commonj.sdo.DataObject; -import commonj.sdo.Property; -import commonj.sdo.Sequence; -import commonj.sdo.Type; -import commonj.sdo.helper.DataFactory; -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.XMLHelper; -import commonj.sdo.helper.XSDHelper; - -public class ChangeSummaryPropertyTestCase extends TestCase { - private final String TEST_MODEL = "/simpleWithChangeSummary.xsd"; - private final String TEST_NAMESPACE = "http://www.example.com/simpleCS"; - - private final String TEST_DATA_BEFORE_UNDO = "/simpleWithChangeSummary.xml"; - private final String TEST_DATA_AFTER_UNDO = "/simpleWithChangeSummaryUndone.xml"; - - HelperContext hc; - DataFactory dataFactory; - XMLHelper xmlHelper; - - void verify(ChangeSummary cs, DataObject quote, String nameSpace, String element, String beforeUndo, String afterUndo) throws IOException { - // Stop logging changes and serialize the resulting data graph - // - cs.endLogging(); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - xmlHelper.save(quote, nameSpace, element, baos); - //xmlHelper.save(quote, nameSpace, element, System.out); - - byte[] bytes = baos.toByteArray(); - URL url = getClass().getResource(beforeUndo); - assertTrue(TestUtil.equalXmlFiles(new ByteArrayInputStream(bytes), url)); - - DataObject loaded = xmlHelper.load(new ByteArrayInputStream(bytes)).getRootObject(); - baos.reset(); - xmlHelper.save(loaded, nameSpace, element, baos); - //xmlHelper.save(loaded, nameSpace, element, System.out); - assertTrue(TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), url)); - - // Undo all changes and then serialize the resulting data graph again - // - cs.undoChanges(); - - baos.reset(); - xmlHelper.save(quote, nameSpace, element, baos); - //xmlHelper.save(quote, nameSpace, element, System.out); - - assertTrue(TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(afterUndo))); - } - - /** - * ChangeSummary property test. - */ - protected final void change(String nameSpace, String beforeUndo, String afterUndo) throws Exception { - Type quoteType = hc.getTypeHelper().getType(nameSpace, "RootQuote"); - DataObject quote = dataFactory.create(quoteType); - - ChangeSummary cs = quote.getChangeSummary(); - ChangeSummary csp = (ChangeSummary)quote.get("changes"); - - assertSame(cs, csp); - - quote.setString("symbol", "fbnt"); - quote.setString("companyName", "FlyByNightTechnology"); - quote.setBigDecimal("price", new BigDecimal("1000.0")); - DataObject child = quote.createDataObject("quotes"); - child.setBigDecimal("price", new BigDecimal("1500.0")); - child = quote.createDataObject("quotes"); - child.setBigDecimal("price", new BigDecimal("2000.0")); - child = child.createDataObject("quotes"); - child.setBigDecimal("price", new BigDecimal("2000.99")); - child = quote.createDataObject("quotes"); - child.setBigDecimal("price", new BigDecimal("2500.0")); - - // Begin logging changes - // - cs.beginLogging(); - - // Modify the data graph in various ways - // - quote.setString("symbol", "FBNT"); - quote.setBigDecimal("price", new BigDecimal("999.0")); - quote.setDouble("volume", 1000); - - child = quote.createDataObject("quotes"); - child.setBigDecimal("price", new BigDecimal("3000.0")); - child = quote.createDataObject("quotes"); - child.setBigDecimal("price", new BigDecimal("4000.0")); - - quote.getDataObject("quotes[2]").delete(); - - verify(cs, quote, nameSpace, "stockQuote", beforeUndo, afterUndo); - } - - /** - * Simple ChangeSummary property test. - */ - public void testChangeSummary() throws Exception { - change(TEST_NAMESPACE, TEST_DATA_BEFORE_UNDO, TEST_DATA_AFTER_UNDO); - } - - static final String SequenceTest_NameSpace = "http://www.example.com/sequenceCS"; - - /** - * Mixed ChangeSummary property test. - */ - public void testMixedChangeSummary() throws Exception { - change(SequenceTest_NameSpace, "/mixedChangeSummary.xml", "/mixedChangeSummaryUndone.xml"); - } - - protected final DataObject createDataObject(Type quoteType, Object value, Sequence sequence, Property property) { - DataObject child = dataFactory.create(quoteType); - child.set("symbol", value); - sequence.add(property, child); - return child; - } - - static final String SequenceTest_ELEMENT = "openQuote"; - - private XSDHelper xsdHelper; - - /** - * Open/any ChangeSummary property test. - */ - public void testOpenChangeSummary() throws Exception { - DataObject quote = dataFactory.create(xsdHelper.getGlobalProperty(SequenceTest_NameSpace, SequenceTest_ELEMENT, true).getType()); - - ChangeSummary cs = quote.getChangeSummary(); - ChangeSummary csp = (ChangeSummary)quote.get("changes"); - - assertSame(cs, csp); - - quote.set("symbol", "fbnt"); - Property property = xsdHelper.getGlobalProperty("http://www.example.com/open", "openStockQuote", true); - Type quoteType = property.getType(); - List openStockQuotes = ((DataObject)quote).getList(property); - - addQuote(openStockQuotes, quoteType, "1500.0"); - DataObject osq2 = addQuote(openStockQuotes, quoteType, "2000.0"); - addQuote(osq2.getList(property), quoteType, "2000.99"); - addQuote(openStockQuotes, quoteType, "2500.0"); - - // Begin logging changes - // - cs.beginLogging(); - - // Modify the data graph in various ways - // - quote.set("symbol", "FBNT"); - - addQuote(openStockQuotes, quoteType, "3000.0"); - addQuote(openStockQuotes, quoteType, "4000.0"); - - openStockQuotes.remove(osq2); - - - verify(cs, quote, SequenceTest_NameSpace, SequenceTest_ELEMENT, "/openChangeSummary.xml", "/openChangeSummaryUndone.xml"); - } - - private DataObject addQuote(List openStockQuotes, Type quoteType, - Object value) { - DataObject osq = dataFactory.create(quoteType); - osq.set("symbol", value); - openStockQuotes.add(osq); - return osq; - } - - void define(String model) throws Exception { - // Populate the meta data for the test model - URL url = getClass().getResource(model); - xsdHelper.define(url.openStream(), url.toString()); - } - - protected void setUp() throws Exception { - super.setUp(); - hc = SDOUtil.createHelperContext(); - xsdHelper = hc.getXSDHelper(); - dataFactory = hc.getDataFactory(); - xmlHelper = hc.getXMLHelper(); - - // Populate the meta data for the test (Stock Quote) model - define(TEST_MODEL); - - define("/SequenceChangeSummary.xsd"); - } -} +/** + * + * 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.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.math.BigDecimal; +import java.net.URL; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.ChangeSummary; +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Sequence; +import commonj.sdo.Type; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; + +public class ChangeSummaryPropertyTestCase extends TestCase { + private final String TEST_MODEL = "/simpleWithChangeSummary.xsd"; + private final String TEST_NAMESPACE = "http://www.example.com/simpleCS"; + + private final String TEST_DATA_BEFORE_UNDO = "/simpleWithChangeSummary.xml"; + private final String TEST_DATA_AFTER_UNDO = "/simpleWithChangeSummaryUndone.xml"; + + HelperContext hc; + DataFactory dataFactory; + XMLHelper xmlHelper; + + void verify(ChangeSummary cs, DataObject quote, String nameSpace, String element, String beforeUndo, String afterUndo) throws IOException { + // Stop logging changes and serialize the resulting data graph + // + cs.endLogging(); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + xmlHelper.save(quote, nameSpace, element, baos); + //xmlHelper.save(quote, nameSpace, element, System.out); + + byte[] bytes = baos.toByteArray(); + URL url = getClass().getResource(beforeUndo); + assertTrue(TestUtil.equalXmlFiles(new ByteArrayInputStream(bytes), url)); + + DataObject loaded = xmlHelper.load(new ByteArrayInputStream(bytes)).getRootObject(); + baos.reset(); + xmlHelper.save(loaded, nameSpace, element, baos); + //xmlHelper.save(loaded, nameSpace, element, System.out); + assertTrue(TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), url)); + + // Undo all changes and then serialize the resulting data graph again + // + cs.undoChanges(); + + baos.reset(); + xmlHelper.save(quote, nameSpace, element, baos); + //xmlHelper.save(quote, nameSpace, element, System.out); + + assertTrue(TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(afterUndo))); + } + + /** + * ChangeSummary property test. + */ + protected final void change(String nameSpace, String beforeUndo, String afterUndo) throws Exception { + Type quoteType = hc.getTypeHelper().getType(nameSpace, "RootQuote"); + DataObject quote = dataFactory.create(quoteType); + + ChangeSummary cs = quote.getChangeSummary(); + ChangeSummary csp = (ChangeSummary)quote.get("changes"); + + assertSame(cs, csp); + + quote.setString("symbol", "fbnt"); + quote.setString("companyName", "FlyByNightTechnology"); + quote.setBigDecimal("price", new BigDecimal("1000.0")); + DataObject child = quote.createDataObject("quotes"); + child.setBigDecimal("price", new BigDecimal("1500.0")); + child = quote.createDataObject("quotes"); + child.setBigDecimal("price", new BigDecimal("2000.0")); + child = child.createDataObject("quotes"); + child.setBigDecimal("price", new BigDecimal("2000.99")); + child = quote.createDataObject("quotes"); + child.setBigDecimal("price", new BigDecimal("2500.0")); + + // Begin logging changes + // + cs.beginLogging(); + + // Modify the data graph in various ways + // + quote.setString("symbol", "FBNT"); + quote.setBigDecimal("price", new BigDecimal("999.0")); + quote.setDouble("volume", 1000); + + child = quote.createDataObject("quotes"); + child.setBigDecimal("price", new BigDecimal("3000.0")); + child = quote.createDataObject("quotes"); + child.setBigDecimal("price", new BigDecimal("4000.0")); + + quote.getDataObject("quotes[2]").delete(); + + verify(cs, quote, nameSpace, "stockQuote", beforeUndo, afterUndo); + } + + /** + * Simple ChangeSummary property test. + */ + public void testChangeSummary() throws Exception { + change(TEST_NAMESPACE, TEST_DATA_BEFORE_UNDO, TEST_DATA_AFTER_UNDO); + } + + static final String SequenceTest_NameSpace = "http://www.example.com/sequenceCS"; + + /** + * Mixed ChangeSummary property test. + */ + public void testMixedChangeSummary() throws Exception { + change(SequenceTest_NameSpace, "/mixedChangeSummary.xml", "/mixedChangeSummaryUndone.xml"); + } + + protected final DataObject createDataObject(Type quoteType, Object value, Sequence sequence, Property property) { + DataObject child = dataFactory.create(quoteType); + child.set("symbol", value); + sequence.add(property, child); + return child; + } + + static final String SequenceTest_ELEMENT = "openQuote"; + + private XSDHelper xsdHelper; + + /** + * Open/any ChangeSummary property test. + */ + public void testOpenChangeSummary() throws Exception { + DataObject quote = dataFactory.create(xsdHelper.getGlobalProperty(SequenceTest_NameSpace, SequenceTest_ELEMENT, true).getType()); + + ChangeSummary cs = quote.getChangeSummary(); + ChangeSummary csp = (ChangeSummary)quote.get("changes"); + + assertSame(cs, csp); + + quote.set("symbol", "fbnt"); + Property property = xsdHelper.getGlobalProperty("http://www.example.com/open", "openStockQuote", true); + Type quoteType = property.getType(); + List openStockQuotes = ((DataObject)quote).getList(property); + + addQuote(openStockQuotes, quoteType, "1500.0"); + DataObject osq2 = addQuote(openStockQuotes, quoteType, "2000.0"); + addQuote(osq2.getList(property), quoteType, "2000.99"); + addQuote(openStockQuotes, quoteType, "2500.0"); + + // Begin logging changes + // + cs.beginLogging(); + + // Modify the data graph in various ways + // + quote.set("symbol", "FBNT"); + + addQuote(openStockQuotes, quoteType, "3000.0"); + addQuote(openStockQuotes, quoteType, "4000.0"); + + openStockQuotes.remove(osq2); + + + verify(cs, quote, SequenceTest_NameSpace, SequenceTest_ELEMENT, "/openChangeSummary.xml", "/openChangeSummaryUndone.xml"); + } + + private DataObject addQuote(List openStockQuotes, Type quoteType, + Object value) { + DataObject osq = dataFactory.create(quoteType); + osq.set("symbol", value); + openStockQuotes.add(osq); + return osq; + } + + void define(String model) throws Exception { + // Populate the meta data for the test model + URL url = getClass().getResource(model); + xsdHelper.define(url.openStream(), url.toString()); + } + + protected void setUp() throws Exception { + super.setUp(); + hc = SDOUtil.createHelperContext(); + xsdHelper = hc.getXSDHelper(); + dataFactory = hc.getDataFactory(); + xmlHelper = hc.getXMLHelper(); + + // Populate the meta data for the test (Stock Quote) model + define(TEST_MODEL); + + define("/SequenceChangeSummary.xsd"); + } +} diff --git a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/CrossScopeCopyTestCase.java b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/CrossScopeCopyTestCase.java index bba7fb4c1b..4a8ed34477 100644 --- a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/CrossScopeCopyTestCase.java +++ b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/CrossScopeCopyTestCase.java @@ -1,474 +1,474 @@ -/** - * - * 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.io.InputStream; -import java.math.BigDecimal; -import java.net.URL; -import java.util.Iterator; -import java.util.Vector; - -import junit.framework.TestCase; - -import org.apache.tuscany.sdo.api.SDOUtil; - -import commonj.sdo.DataObject; -import commonj.sdo.Property; -import commonj.sdo.Type; -import commonj.sdo.helper.CopyHelper; -import commonj.sdo.helper.DataFactory; -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.TypeHelper; - -public class CrossScopeCopyTestCase extends TestCase -{ - // Literals - private static final String TEST_NAMESPACE = "http://www.example.com/bank"; - private static final String BANK_MODEL = "/bank.xsd"; - private static final String BANK_TYPE = "bankType"; - private static final String BRANCH_TYPE = "branchType"; - private static final String SERVICE_TYPE = "serviceType"; - private static final String ACCOUNT_TYPE = "accountType"; - private static final String CUSTOMER_TYPE = "customerType"; - private static final String ADDRESS_TYPE = "addressType"; - private static final String DYNAMIC_TYPE = "dynamicType"; - - // SDO model objects - private HelperContext hca; - private HelperContext hcb; - private TypeHelper scopeA; - private TypeHelper scopeB; - - // SDO instance objects - private DataObject bankSDO; - private DataObject branchSDO1; - private DataObject branchSDO2; - private DataObject serviceSDO1; - private DataObject serviceSDO2; - private DataObject serviceSDO3; - private DataObject customerSDO1; - private DataObject customerSDO2; - private DataObject customerSDO3; - private DataObject customerSDO4; - - private int indent = 0; - - public void testCrossScopeCopy() throws IOException - { - CopyHelper copyHelperB = SDOUtil.createCrossScopeCopyHelper(hcb); - - // Perform Shallow Copy Test - DataObject copiedSDO = copyHelperB.copyShallow(bankSDO); - shallowCopyAssertions(bankSDO, copiedSDO); - - // Perform Deep Copy Test - copiedSDO = copyHelperB.copy(bankSDO); - deepCopyAssertions(bankSDO, copiedSDO); - - // Inter-Reference Copy - copiedSDO = copyHelperB.copy(customerSDO1); - DataObject prop = (DataObject)copiedSDO.get("HomeBranch"); - assertTrue(prop==null); - - // Perform invalid namespace test - DataObject sdo = hca.getDataFactory().create(TEST_NAMESPACE, DYNAMIC_TYPE ); - sdo.set("custNum", "099" ); - sdo.set("firstName", "John"); - sdo.set("lastName", "Doe"); - boolean failed = false; - try - { - // In this case, we are copying an object to a scope - // where the object's type has not been defined. That - // will generate a null pointer exception what we will - // catch. - copyHelperB.copy(sdo); - } - catch(java.lang.NullPointerException ex) - { - failed = true; - } - assertTrue(failed); - } - - protected void setUp() throws Exception - { - super.setUp(); - - // Create Two Scopes - hca = SDOUtil.createHelperContext(); - hcb = SDOUtil.createHelperContext(); - scopeA = hca.getTypeHelper(); - scopeB = hcb.getTypeHelper(); - - // Populate scopes with bank model now - URL url = getClass().getResource(BANK_MODEL); - InputStream inputStream = url.openStream(); - hca.getXSDHelper().define(inputStream, url.toString()); - inputStream.close(); - inputStream = url.openStream(); - hcb.getXSDHelper().define(inputStream, url.toString()); - inputStream.close(); - - // Now Populate scopeA with some dynamic models - populateScopeWithDynamicTypes(scopeA); - - // Construct Source Tree - constructSourceTree(hca.getDataFactory()); - } - - private void shallowCopyAssertions(DataObject sdo, DataObject copiedSdo) - { - assertEquals(sdo.getType().getName(), copiedSdo.getType().getName()); - assertEquals(sdo.getType().getURI(), copiedSdo.getType().getURI()); - assertNotSame(sdo.getType(), copiedSdo.getType()); - assertEquals(sdo.getInstanceProperties().size(), copiedSdo - .getInstanceProperties().size()); - - for(Iterator it = sdo.getInstanceProperties().iterator(), it2 = copiedSdo - .getInstanceProperties().iterator(); it.hasNext();) - { - Property p1 = (Property) it.next(), p2 = (Property) it2.next(); - assertEquals(p1.getName(), p2.getName()); - Object o1 = sdo.get(p1), o2 = copiedSdo.get(p2); - if(p1.getType().isDataType()) - { - assertEquals(o1, o2); - // TODO is there a way I can distinguish between mutable and - // immutable types - // so that I can do some "same object" tests - } - else - { - assertNotSame(p1, p2); - if(p2.isMany()) - { - assertEquals(copiedSdo.getList(p2).size(), 0); - } - else - { - assertNull(copiedSdo.get(p2)); - } - } - try - { - sdo.get(p2); - assertTrue(false); - } - catch(Exception e) - { - // expected route - } - try - { - copiedSdo.get(p1); - assertTrue(false); - } - catch(Exception e2) - { - // expected route - } - } - } - - private void deepCopyAssertions(DataObject sdo, DataObject copiedSdo) - { - //indent(); - - //System.out.println("checking objects of types: " - // + sdo.getType().getName() + ", " - // + copiedSdo.getType().getName()); - indent++; - - assertEquals(sdo.getType().getName(), copiedSdo.getType().getName()); - assertEquals(sdo.getType().getURI(), copiedSdo.getType().getURI()); - assertNotSame(sdo.getType(), copiedSdo.getType()); - assertEquals(sdo.getInstanceProperties().size(), copiedSdo - .getInstanceProperties().size()); - - for(Iterator it = sdo.getInstanceProperties().iterator(), it2 = copiedSdo - .getInstanceProperties().iterator(); it.hasNext();) - { - Property p1 = (Property) it.next(), p2 = (Property) it2.next(); - assertEquals(p1.getName(), p2.getName()); - Object o1 = sdo.get(p1), o2 = copiedSdo.get(p2); - if(p1.getType().isDataType()) - { - assertEquals(o1, o2); - // TODO is there a way I can distinguish between mutable and - // immutable types - // so that I can do some "same object" tests - } - else - { - assertNotSame(p1, p2); - if(p2.isMany()) - { - assertEquals(sdo.getList(p1).size(), copiedSdo.getList(p2) - .size()); - for(Iterator it3 = sdo.getList(p1).iterator(), it4 = copiedSdo - .getList(p2).iterator(); it3.hasNext();) - { - deepCopyAssertions((DataObject) it3.next(), - (DataObject) it4.next()); - } - } - else - { - deepCopyAssertions(sdo.getDataObject(p1), copiedSdo - .getDataObject(p2)); - } - } - try - { - sdo.get(p2); - assertTrue(false); - } - catch(Exception e) - { - // expected route - } - try - { - copiedSdo.get(p1); - assertTrue(false); - } - catch(Exception e2) - { - // expected route - } - } - - indent--; - } - - /* - private void indent() - { - for(int i=0; i " + - - "" + - "" + - - "" + - "" + - "" + - "" + - "" + - "" + - - "" + - "" + - "" + - "" + - "" + - "" + - "" + - - "" + - "" + - "" + - "" + - "" + - "" + - - ""; - - /** - * 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"); - } -} +/** + * + * 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 = + "" + + + "" + + "" + + + "" + + "" + + "" + + "" + + "" + + "" + + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + + "" + + "" + + "" + + "" + + "" + + "" + + + ""; + + /** + * 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"); + } +} diff --git a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineOpenContentPropertyTestCase.java b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineOpenContentPropertyTestCase.java index bbbad11f53..f6afd5c458 100644 --- a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineOpenContentPropertyTestCase.java +++ b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineOpenContentPropertyTestCase.java @@ -1,133 +1,133 @@ -/** - * - * 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.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.math.BigDecimal; -import java.net.URL; - -import org.apache.tuscany.sdo.util.SDOUtil; - -import commonj.sdo.DataObject; -import commonj.sdo.Property; -import commonj.sdo.Type; -import commonj.sdo.helper.DataFactory; -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.TypeHelper; -import commonj.sdo.helper.XMLHelper; -import commonj.sdo.helper.XSDHelper; -import junit.framework.TestCase; - - -public class DefineOpenContentPropertyTestCase extends TestCase { - private final String TEST_MODEL = "/open.xsd"; - private final String TEST_NAMESPACE = "http://www.example.com/open"; - private final String TEST_DATA = "/openContentProperty.xml"; - - private TypeHelper typeHelper; - private XSDHelper xsdHelper; - private XMLHelper xmlHelper; - private DataFactory dataFactory; - - public void testDefineOpenContentProperty() throws IOException { - Type quoteType = typeHelper.getType(TEST_NAMESPACE, "OpenQuote"); - DataObject quote = dataFactory.create(quoteType); - - Property symbolProperty = quoteType.getProperty("symbol"); - assertFalse(symbolProperty.isOpenContent()); - - quote.setString(symbolProperty, "s1"); - - Property companyProperty = typeHelper.getOpenContentProperty(TEST_NAMESPACE, "company"); - assertTrue(companyProperty.isOpenContent()); - - DataObject company = quote.createDataObject(companyProperty); - company.setString("name", "FlyByNightTechnology"); - - Property priceProperty = typeHelper.getOpenContentProperty(TEST_NAMESPACE, "price"); - assertTrue(priceProperty.isOpenContent()); - - quote.getList(priceProperty).add(new BigDecimal("1000.0")); - - // Define a new SDO open content property with simple type - DataObject p = dataFactory.create("commonj.sdo", "Property"); - p.set("type", typeHelper.getType("commonj.sdo", "Decimal")); - p.set("name", "highPrice"); - Property highPrice = typeHelper.defineOpenContentProperty(TEST_NAMESPACE, p); - assertTrue(highPrice.isOpenContent()); - - quote.setBigDecimal(highPrice, new BigDecimal("1100.0")); - - // Define a new SDO open content property with complex type - DataObject mutualFundQuotePropertyDef = dataFactory.create("commonj.sdo", "Property"); - mutualFundQuotePropertyDef.set("type", quoteType); - mutualFundQuotePropertyDef.set("name", "mutualFundQuote"); - mutualFundQuotePropertyDef.setBoolean("containment", true); - Property mutualFundQuoteProperty = typeHelper.defineOpenContentProperty(TEST_NAMESPACE, mutualFundQuotePropertyDef); - assertTrue(mutualFundQuoteProperty.isOpenContent()); - - DataObject mutualFundQuote = quote.createDataObject(mutualFundQuoteProperty); - mutualFundQuote.setString("symbol", "mutual-1"); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - xmlHelper.save(quote, TEST_NAMESPACE, "openStockQuote", baos); - - assertTrue(TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(TEST_DATA))); - - // validate existing property condition - Property duplicateProp = typeHelper.defineOpenContentProperty(TEST_NAMESPACE, p); - assertTrue(highPrice.equals(duplicateProp)); - - // validate error condition, where new property exists with different type - boolean errorCondition = false; - try - { - p = dataFactory.create("commonj.sdo", "Property"); - p.set("type", typeHelper.getType("commonj.sdo", "String")); - p.set("name", "highPrice"); - highPrice = typeHelper.defineOpenContentProperty(TEST_NAMESPACE, p); - } - catch( IllegalArgumentException ex ) - { - errorCondition = true; - } - assertTrue(errorCondition); - } - - protected void setUp() throws Exception { - super.setUp(); - - HelperContext hc = SDOUtil.createHelperContext(); - typeHelper = hc.getTypeHelper(); - dataFactory = hc.getDataFactory(); - xsdHelper = hc.getXSDHelper(); - xmlHelper = hc.getXMLHelper(); - - // Populate the meta data for the test (Stock Quote) model - URL url = getClass().getResource(TEST_MODEL); - InputStream inputStream = url.openStream(); - xsdHelper.define(inputStream, url.toString()); - inputStream.close(); - } -} +/** + * + * 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.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.net.URL; + +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Type; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; +import junit.framework.TestCase; + + +public class DefineOpenContentPropertyTestCase extends TestCase { + private final String TEST_MODEL = "/open.xsd"; + private final String TEST_NAMESPACE = "http://www.example.com/open"; + private final String TEST_DATA = "/openContentProperty.xml"; + + private TypeHelper typeHelper; + private XSDHelper xsdHelper; + private XMLHelper xmlHelper; + private DataFactory dataFactory; + + public void testDefineOpenContentProperty() throws IOException { + Type quoteType = typeHelper.getType(TEST_NAMESPACE, "OpenQuote"); + DataObject quote = dataFactory.create(quoteType); + + Property symbolProperty = quoteType.getProperty("symbol"); + assertFalse(symbolProperty.isOpenContent()); + + quote.setString(symbolProperty, "s1"); + + Property companyProperty = typeHelper.getOpenContentProperty(TEST_NAMESPACE, "company"); + assertTrue(companyProperty.isOpenContent()); + + DataObject company = quote.createDataObject(companyProperty); + company.setString("name", "FlyByNightTechnology"); + + Property priceProperty = typeHelper.getOpenContentProperty(TEST_NAMESPACE, "price"); + assertTrue(priceProperty.isOpenContent()); + + quote.getList(priceProperty).add(new BigDecimal("1000.0")); + + // Define a new SDO open content property with simple type + DataObject p = dataFactory.create("commonj.sdo", "Property"); + p.set("type", typeHelper.getType("commonj.sdo", "Decimal")); + p.set("name", "highPrice"); + Property highPrice = typeHelper.defineOpenContentProperty(TEST_NAMESPACE, p); + assertTrue(highPrice.isOpenContent()); + + quote.setBigDecimal(highPrice, new BigDecimal("1100.0")); + + // Define a new SDO open content property with complex type + DataObject mutualFundQuotePropertyDef = dataFactory.create("commonj.sdo", "Property"); + mutualFundQuotePropertyDef.set("type", quoteType); + mutualFundQuotePropertyDef.set("name", "mutualFundQuote"); + mutualFundQuotePropertyDef.setBoolean("containment", true); + Property mutualFundQuoteProperty = typeHelper.defineOpenContentProperty(TEST_NAMESPACE, mutualFundQuotePropertyDef); + assertTrue(mutualFundQuoteProperty.isOpenContent()); + + DataObject mutualFundQuote = quote.createDataObject(mutualFundQuoteProperty); + mutualFundQuote.setString("symbol", "mutual-1"); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + xmlHelper.save(quote, TEST_NAMESPACE, "openStockQuote", baos); + + assertTrue(TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(TEST_DATA))); + + // validate existing property condition + Property duplicateProp = typeHelper.defineOpenContentProperty(TEST_NAMESPACE, p); + assertTrue(highPrice.equals(duplicateProp)); + + // validate error condition, where new property exists with different type + boolean errorCondition = false; + try + { + p = dataFactory.create("commonj.sdo", "Property"); + p.set("type", typeHelper.getType("commonj.sdo", "String")); + p.set("name", "highPrice"); + highPrice = typeHelper.defineOpenContentProperty(TEST_NAMESPACE, p); + } + catch( IllegalArgumentException ex ) + { + errorCondition = true; + } + assertTrue(errorCondition); + } + + protected void setUp() throws Exception { + super.setUp(); + + HelperContext hc = SDOUtil.createHelperContext(); + typeHelper = hc.getTypeHelper(); + dataFactory = hc.getDataFactory(); + xsdHelper = hc.getXSDHelper(); + xmlHelper = hc.getXMLHelper(); + + // Populate the meta data for the test (Stock Quote) model + URL url = getClass().getResource(TEST_MODEL); + InputStream inputStream = url.openStream(); + xsdHelper.define(inputStream, url.toString()); + inputStream.close(); + } +} diff --git a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DeserializationNoSchemaTestCase.java b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DeserializationNoSchemaTestCase.java index 5bde232a72..65a838bb52 100644 --- a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DeserializationNoSchemaTestCase.java +++ b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DeserializationNoSchemaTestCase.java @@ -1,124 +1,124 @@ -/** - * - * 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.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.net.URL; -import java.util.List; - -import junit.framework.TestCase; - -import org.apache.tuscany.sdo.util.SDOUtil; - -import commonj.sdo.DataObject; -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.TypeHelper; -import commonj.sdo.helper.XMLDocument; -import commonj.sdo.helper.XMLHelper; - - -public class DeserializationNoSchemaTestCase extends TestCase -{ - HelperContext hc; - - TypeHelper th; - - private final String xmlStr = - " " + - " " + - "fbnt " + - "FlyByNightTechnology " + - "1000.0 " + - "1000.0 " + - "1000.0 " + - "1000.0 " + - "1000.0 " + - "1000.0 " + - " " + - "2000.0 " + - " " + - ""; - - public void testLoadQuoteXMLDoc() throws IOException - { - XMLHelper xmlHelper = hc.getXMLHelper(); -/* URL url = getClass().getResource("/quote.xml"); - InputStream inputStream = url.openStream();*/ - XMLDocument doc = xmlHelper.load(xmlStr); - DataObject root = doc.getRootObject(); - - List symbols = root.getList("symbol"); - DataObject symbol = (DataObject)symbols.get(0); - - String seqValue = (String)symbol.getSequence().getValue(0); - assertEquals(seqValue, "fbnt"); - - //String symbol = root.getString("symbol"); - //System.out.println("symbol: " + symbol); - } - - public void testAnyTypeContainer() throws Exception - { - HelperContext hc = SDOUtil.createHelperContext(); - - URL url = getClass().getResource("/simple.xsd"); - InputStream inputStream = url.openStream(); - hc.getXSDHelper().define(inputStream, url.toString()); - - XMLHelper xmlHelper = hc.getXMLHelper(); - url = getClass().getResource("/quoteInSOAP.xml"); - inputStream = url.openStream(); - XMLDocument doc = xmlHelper.load(inputStream); - DataObject root = doc.getRootObject(); - DataObject body = (DataObject)root.getList("Body").get(0); - DataObject stockQuote = (DataObject)body.getList("stockQuote").get(0); - - //xmlHelper.save(stockQuote, stockQuote.getType().getURI(), "stockQuote", System.out); - - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ObjectOutputStream oos = SDOUtil.createObjectOutputStream(bos, hc); - oos.writeObject(stockQuote); - oos.close(); - bos.close(); - - ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); - ObjectInputStream ois = SDOUtil.createObjectInputStream(bis, hc); - DataObject objectCopy = (DataObject)ois.readObject(); - ois.close(); - bis.close(); - - assertEquals(objectCopy.getString("symbol"), "fbnt"); - - //xmlHelper.save(objectCopy, stockQuote.getType().getURI(), "stockQuote", System.out); - } - - protected void setUp() throws Exception - { - super.setUp(); - - hc = SDOUtil.createHelperContext(); - th = hc.getTypeHelper(); - } -} +/** + * + * 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.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.net.URL; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; + + +public class DeserializationNoSchemaTestCase extends TestCase +{ + HelperContext hc; + + TypeHelper th; + + private final String xmlStr = + " " + + " " + + "fbnt " + + "FlyByNightTechnology " + + "1000.0 " + + "1000.0 " + + "1000.0 " + + "1000.0 " + + "1000.0 " + + "1000.0 " + + " " + + "2000.0 " + + " " + + ""; + + public void testLoadQuoteXMLDoc() throws IOException + { + XMLHelper xmlHelper = hc.getXMLHelper(); +/* URL url = getClass().getResource("/quote.xml"); + InputStream inputStream = url.openStream();*/ + XMLDocument doc = xmlHelper.load(xmlStr); + DataObject root = doc.getRootObject(); + + List symbols = root.getList("symbol"); + DataObject symbol = (DataObject)symbols.get(0); + + String seqValue = (String)symbol.getSequence().getValue(0); + assertEquals(seqValue, "fbnt"); + + //String symbol = root.getString("symbol"); + //System.out.println("symbol: " + symbol); + } + + public void testAnyTypeContainer() throws Exception + { + HelperContext hc = SDOUtil.createHelperContext(); + + URL url = getClass().getResource("/simple.xsd"); + InputStream inputStream = url.openStream(); + hc.getXSDHelper().define(inputStream, url.toString()); + + XMLHelper xmlHelper = hc.getXMLHelper(); + url = getClass().getResource("/quoteInSOAP.xml"); + inputStream = url.openStream(); + XMLDocument doc = xmlHelper.load(inputStream); + DataObject root = doc.getRootObject(); + DataObject body = (DataObject)root.getList("Body").get(0); + DataObject stockQuote = (DataObject)body.getList("stockQuote").get(0); + + //xmlHelper.save(stockQuote, stockQuote.getType().getURI(), "stockQuote", System.out); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = SDOUtil.createObjectOutputStream(bos, hc); + oos.writeObject(stockQuote); + oos.close(); + bos.close(); + + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + ObjectInputStream ois = SDOUtil.createObjectInputStream(bis, hc); + DataObject objectCopy = (DataObject)ois.readObject(); + ois.close(); + bis.close(); + + assertEquals(objectCopy.getString("symbol"), "fbnt"); + + //xmlHelper.save(objectCopy, stockQuote.getType().getURI(), "stockQuote", System.out); + } + + protected void setUp() throws Exception + { + super.setUp(); + + hc = SDOUtil.createHelperContext(); + th = hc.getTypeHelper(); + } +} diff --git a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DupElementTestCase.java b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DupElementTestCase.java index 3fa8b7fb04..9c4f487b6a 100644 --- a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DupElementTestCase.java +++ b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DupElementTestCase.java @@ -1,99 +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.InputStream; -import java.net.URL; -import java.util.List; -//import java.util.regex.MatchResult; -//import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import junit.framework.TestCase; - -import org.apache.tuscany.sdo.api.SDOUtil; - -import commonj.sdo.DataObject; -import commonj.sdo.Type; -import commonj.sdo.helper.HelperContext; - -public class DupElementTestCase extends TestCase { - HelperContext hc; - - private final String TEST_MODEL = "/dupelement.xsd"; - private final String TEST_URI = "http://www.example.com/dupelement"; - - protected void setUp() throws Exception { - super.setUp(); - - URL url = getClass().getResource(TEST_MODEL); - InputStream inputStream = url.openStream(); - - hc = SDOUtil.createHelperContext(); - - hc.getXSDHelper().define(inputStream, url.toString()); - - inputStream.close(); - } - - - public void test() { - Type quoteType = hc.getTypeHelper().getType(TEST_URI, "Quote"); - - DataObject quote = hc.getDataFactory().create(quoteType); - quote.set("symbol", "ACME"); - quote.set("companyName", "ACME Corp."); - - DataObject quote2 = hc.getDataFactory().create(quoteType); - - List quotes = quote.getList("quotes"); - quotes.add(quote2); - - try { - quote.set("quotes.0/symbol", "ACME-CHILD"); - quote.set("quotes.0/companyName", "ACME subsidiary corp."); - quote.setInt("quotes.0/companyNameInInt", 99); - quote.setInt("quotes.0/symbolInInt", 55); - } - catch (Exception e) { - fail("Set value on the wrong properties with the same name"); - } - assert(quote.get("quotes.0/companyName") instanceof String); - assert(quote.get("quotes.0/symbol") instanceof String); - assert(quote.get("quotes.0/companyNameInInt") instanceof Integer); - assert(quote.get("quotes.0/symbolInInt") instanceof Integer); - - String doc = hc.getXMLHelper().save(quote, "http://www.example.com/dupelement", "stockQuote"); - //System.out.println(doc); - assertTrue( - Pattern.matches("[\\s\\S]*[\\s]*ACME Corp.[\\s]*[\\s\\S]*", - doc)); - assertTrue( - Pattern.matches("[\\s\\S]*[\\s]*99[\\s]*[\\s\\S]*", - doc)); - assertTrue( - Pattern.matches("[\\s\\S]*symbol[\\s]*=[\\s]*\"55\"[\\s\\S]*", - doc)); - assertTrue( - Pattern.matches("[\\s\\S]*[\\s]*ACME-CHILD[\\s]*[\\s\\S]*", - doc)); - - } -} +/** + * + * 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.InputStream; +import java.net.URL; +import java.util.List; +//import java.util.regex.MatchResult; +//import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.api.SDOUtil; + +import commonj.sdo.DataObject; +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; + +public class DupElementTestCase extends TestCase { + HelperContext hc; + + private final String TEST_MODEL = "/dupelement.xsd"; + private final String TEST_URI = "http://www.example.com/dupelement"; + + protected void setUp() throws Exception { + super.setUp(); + + URL url = getClass().getResource(TEST_MODEL); + InputStream inputStream = url.openStream(); + + hc = SDOUtil.createHelperContext(); + + hc.getXSDHelper().define(inputStream, url.toString()); + + inputStream.close(); + } + + + public void test() { + Type quoteType = hc.getTypeHelper().getType(TEST_URI, "Quote"); + + DataObject quote = hc.getDataFactory().create(quoteType); + quote.set("symbol", "ACME"); + quote.set("companyName", "ACME Corp."); + + DataObject quote2 = hc.getDataFactory().create(quoteType); + + List quotes = quote.getList("quotes"); + quotes.add(quote2); + + try { + quote.set("quotes.0/symbol", "ACME-CHILD"); + quote.set("quotes.0/companyName", "ACME subsidiary corp."); + quote.setInt("quotes.0/companyNameInInt", 99); + quote.setInt("quotes.0/symbolInInt", 55); + } + catch (Exception e) { + fail("Set value on the wrong properties with the same name"); + } + assert(quote.get("quotes.0/companyName") instanceof String); + assert(quote.get("quotes.0/symbol") instanceof String); + assert(quote.get("quotes.0/companyNameInInt") instanceof Integer); + assert(quote.get("quotes.0/symbolInInt") instanceof Integer); + + String doc = hc.getXMLHelper().save(quote, "http://www.example.com/dupelement", "stockQuote"); + //System.out.println(doc); + assertTrue( + Pattern.matches("[\\s\\S]*[\\s]*ACME Corp.[\\s]*[\\s\\S]*", + doc)); + assertTrue( + Pattern.matches("[\\s\\S]*[\\s]*99[\\s]*[\\s\\S]*", + doc)); + assertTrue( + Pattern.matches("[\\s\\S]*symbol[\\s]*=[\\s]*\"55\"[\\s\\S]*", + doc)); + assertTrue( + Pattern.matches("[\\s\\S]*[\\s]*ACME-CHILD[\\s]*[\\s\\S]*", + doc)); + + } +} diff --git a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DynamicTypesComparisonTestCase.java b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DynamicTypesComparisonTestCase.java index 1a9deaf775..4c347867e0 100644 --- a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DynamicTypesComparisonTestCase.java +++ b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DynamicTypesComparisonTestCase.java @@ -1,256 +1,256 @@ -/** - * - * 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.ArrayList; -import java.util.List; - -import junit.framework.TestCase; - -import org.apache.tuscany.sdo.util.SDOUtil; - -import commonj.sdo.DataObject; -import commonj.sdo.Sequence; -import commonj.sdo.Type; -import commonj.sdo.helper.DataFactory; -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.TypeHelper; -import commonj.sdo.helper.XMLDocument; -import commonj.sdo.helper.XMLHelper; -import commonj.sdo.helper.XSDHelper; - -/** - * Test to compare data objects created with SDO API with one created from XML - */ -public class DynamicTypesComparisonTestCase extends TestCase { - private final String COMMONJ_SDO = "commonj.sdo"; - - private final String DYNAMIC_ROOT_TYPE_0 = "TestType0"; - - private final String DYNAMIC_TYPES_SCHEMA_STRING = "\n" + "\n" + " \n" - + " \n" + " \n" - + " \n" - + " \n" - + " \n" - + " \n" + " \n" + " \n" - + " \n" + " \n" + "\n"; - - private final String DYNAMIC_TYPES_URI = "http://www.example.com/dynamicTypesFromSchemaSimple"; - - private final String SDO_FROM_API_AND_DYN = "object created with API with dynamic type "; - - private final String SDO_FROM_API_AND_REF = "object created with API with type from XSD"; - - private final String SDO_FROM_XML_AND_REF = "object created with XML with type from XSD"; - - private final String TEST_XML_DOC_0_STRING = "\n" - + "\n" - + " This is a repeated string.\n" + " This is a repeated string.\n" - + " true\n" + " false\n" + " true\n" - + " 1\n" + " 0\n" + " 0\n" - + " 12.5\n" + " 0\n" + "\n"; - - private void comparePropertyObjects(String propName, String name1, String name2, Object propObj1, Object propObj2) { - if (propObj1 == null) { - if (propObj2 != null) { - localFail("property " + propName + " for " + name1 + " was null but " + name2 + " was '" + propObj2 - + "'"); - } - } else if (propObj2 == null) { - localFail("property " + propName + " for " + name2 + " was null but " + name1 + " was '" + propObj1 + "'"); - } else { - if (!propObj1.equals(propObj2)) { - localFail("property " + propName + " for " + name1 + " was '" + propObj1 + "' but " + name2 + " was '" - + propObj2 + "'"); - } - } - } - - private void compareSequencesIgnoringWhitespace(String name1, String name2, Sequence sequence1, Sequence sequence2) { - if (sequence1 == null) { - if (sequence2 != null) { - localFail("sequence for " + name1 + " was null but " + name2 + " was not null"); - } - } else if (sequence2 == null) { - localFail("sequence for " + name2 + " was null but " + name1 + " was not null"); - } else { - List trimmedSeq1 = new ArrayList(); - List trimmedSeq2 = new ArrayList(); - trimWhitespaceFromSequence(trimmedSeq1, sequence1); - trimWhitespaceFromSequence(trimmedSeq2, sequence2); - int size1 = trimmedSeq1.size(); - int size2 = trimmedSeq2.size(); - if (size1 != size2) { - localFail("lengths of trimmed sequences differ: " + name1 + " was " + size1 + ", " + name2 + " was " - + size2); - } else { - Object[] objArr1 = trimmedSeq1.toArray(); - Object[] objArr2 = trimmedSeq2.toArray(); - for (int i = 0; i < size1; i++) { - Object obj1 = objArr1[i]; - Object obj2 = objArr2[i]; - if (obj1 == null) { - if (obj2 != null) { - localFail("sequence for " + name1 + " had null element for which " + name2 + " had '" + obj2 - + "'"); - } - } else if (obj2 == null) { - localFail("sequence for " + name2 + " had null element for which " + name1 + " had '" + obj1 + "'"); - } else { - if (!obj1.equals(obj2)) { - localFail("sequences did not match: " + name1 + " had '" + obj1 + "' but " + name2 + " had '" - + obj2 + "'"); - } - } - } - } - } - } - - private void getAndCompareProperties(String propName, DataObject xmlAndRefTypDO, DataObject apiAndDynTypDO, - DataObject apiAndRefTypDO) { - Object xmlRefProperty = xmlAndRefTypDO.get(propName); - Object apiDynProperty = apiAndDynTypDO.get(propName); - Object apiRefProperty = apiAndRefTypDO.get(propName); - comparePropertyObjects(propName, SDO_FROM_XML_AND_REF, SDO_FROM_API_AND_DYN, xmlRefProperty, apiDynProperty); - comparePropertyObjects(propName, SDO_FROM_XML_AND_REF, SDO_FROM_API_AND_REF, xmlRefProperty, apiRefProperty); - } - - private void localFail(String message) { - // System.err.println(message); - fail(message); - } - - protected void setUp() throws Exception { - super.setUp(); - } - - private void specifyProperty(DataObject containingTypeDO, String nameString, Type typ, boolean isMany) { - DataObject subordinateProperty = containingTypeDO.createDataObject("property"); - subordinateProperty.set("name", nameString); - subordinateProperty.set("type", typ); - subordinateProperty.setBoolean("many", isMany); - } - - /** - * test #0 of Data Object primitive datatypes - */ - public void testDynamicTypesGroup0DO() throws IOException { - HelperContext hcDO = SDOUtil.createHelperContext(); - - TypeHelper thDO = hcDO.getTypeHelper(); - DataFactory dfDO = hcDO.getDataFactory(); - - // create a container object type - DataObject containerTypeDO = dfDO.create("commonj.sdo", "Type"); - containerTypeDO.set("uri", DYNAMIC_TYPES_URI); - containerTypeDO.set("name", DYNAMIC_ROOT_TYPE_0); - containerTypeDO.set("sequenced", Boolean.TRUE); - - specifyProperty(containerTypeDO, "aString", thDO.getType(COMMONJ_SDO, "String"), true); - specifyProperty(containerTypeDO, "aBoolean", thDO.getType(COMMONJ_SDO, "Boolean"), true); - specifyProperty(containerTypeDO, "aFloat", thDO.getType(COMMONJ_SDO, "Float"), true); - - Type containerType = thDO.define(containerTypeDO); - assertNotNull(containerType); - - DataObject doFromApiAndDynTyp = dfDO.create(containerType); - assertNotNull(doFromApiAndDynTyp); - doFromApiAndDynTyp.getList("aString").add("This is a repeated string."); - doFromApiAndDynTyp.getList("aString").add("This is a repeated string."); - doFromApiAndDynTyp.getList("aBoolean").add(new Boolean(true)); - doFromApiAndDynTyp.getList("aBoolean").add(new Boolean(false)); - doFromApiAndDynTyp.getList("aBoolean").add(new Boolean(true)); - doFromApiAndDynTyp.getList("aBoolean").add(new Boolean(true)); - doFromApiAndDynTyp.getList("aBoolean").add(new Boolean(false)); - doFromApiAndDynTyp.getList("aFloat").add(new Float(0)); - doFromApiAndDynTyp.getList("aFloat").add(new Float(12.5)); - doFromApiAndDynTyp.getList("aFloat").add(new Float(0)); - - Type rootType = thDO.getType(DYNAMIC_TYPES_URI, DYNAMIC_ROOT_TYPE_0); - assertNotNull(rootType); - assertSame(containerType, rootType); - - // now load xml to get a reference data object using schema - HelperContext hcRef = SDOUtil.createHelperContext(); - XSDHelper xsdHelper = hcRef.getXSDHelper(); - List typeList = xsdHelper.define(DYNAMIC_TYPES_SCHEMA_STRING); - assertNotNull(typeList); - TypeHelper thRef = hcRef.getTypeHelper(); - Type rootTypeRef = thRef.getType(DYNAMIC_TYPES_URI, DYNAMIC_ROOT_TYPE_0); - - assertNotNull(rootTypeRef); - - XMLHelper xhRef = hcRef.getXMLHelper(); - // XMLDocument docRef = - // xhRef.load(getClass().getResourceAsStream(TEST_XML_DOC_0)); - XMLDocument docRef = xhRef.load(TEST_XML_DOC_0_STRING); - DataObject doFromXmlAndRefTyp = docRef.getRootObject(); - - assertNotNull(doFromXmlAndRefTyp); - - // create a data object using dynamic API from reference type - DataFactory dfRef = hcRef.getDataFactory(); - DataObject doFromApiAndRefTyp = dfRef.create(rootTypeRef); - assertNotNull(doFromApiAndRefTyp); - doFromApiAndRefTyp.getList("aString").add("This is a repeated string."); - doFromApiAndRefTyp.getList("aString").add("This is a repeated string."); - doFromApiAndRefTyp.getList("aBoolean").add(new Boolean(true)); - doFromApiAndRefTyp.getList("aBoolean").add(new Boolean(false)); - doFromApiAndRefTyp.getList("aBoolean").add(new Boolean(true)); - doFromApiAndRefTyp.getList("aBoolean").add(new Boolean(true)); - doFromApiAndRefTyp.getList("aBoolean").add(new Boolean(false)); - doFromApiAndRefTyp.getList("aFloat").add(new Float(0)); - doFromApiAndRefTyp.getList("aFloat").add(new Float(12.5)); - doFromApiAndRefTyp.getList("aFloat").add(new Float(0)); - - getAndCompareProperties("aString", doFromXmlAndRefTyp, doFromApiAndDynTyp, doFromApiAndRefTyp); - getAndCompareProperties("aBoolean", doFromXmlAndRefTyp, doFromApiAndDynTyp, doFromApiAndRefTyp); - getAndCompareProperties("aFloat", doFromXmlAndRefTyp, doFromApiAndDynTyp, doFromApiAndRefTyp); - Sequence seqFromXmlAndRefTyp = doFromXmlAndRefTyp.getSequence(); - Sequence seqFromApiAndDynTyp = doFromApiAndDynTyp.getSequence(); - Sequence seqFromApiAndRefTyp = doFromApiAndRefTyp.getSequence(); - compareSequencesIgnoringWhitespace(SDO_FROM_XML_AND_REF, SDO_FROM_API_AND_DYN, seqFromXmlAndRefTyp, - seqFromApiAndDynTyp); - compareSequencesIgnoringWhitespace(SDO_FROM_XML_AND_REF, SDO_FROM_API_AND_REF, seqFromXmlAndRefTyp, - seqFromApiAndRefTyp); - } - - private void trimWhitespaceFromSequence(List trimmedSeq, Sequence sequence) { - if (sequence != null) { - for (int i = 0; i < sequence.size(); i++) { - Object obj = sequence.getValue(i); - if (obj instanceof String) { - String str = ((String) obj).trim(); - if (str.length() > 0) { - trimmedSeq.add(str); - } - } else { - trimmedSeq.add(obj); - } - } - } - } -} +/** + * + * 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.ArrayList; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.DataObject; +import commonj.sdo.Sequence; +import commonj.sdo.Type; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; + +/** + * Test to compare data objects created with SDO API with one created from XML + */ +public class DynamicTypesComparisonTestCase extends TestCase { + private final String COMMONJ_SDO = "commonj.sdo"; + + private final String DYNAMIC_ROOT_TYPE_0 = "TestType0"; + + private final String DYNAMIC_TYPES_SCHEMA_STRING = "\n" + "\n" + " \n" + + " \n" + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + " \n" + " \n" + + " \n" + " \n" + "\n"; + + private final String DYNAMIC_TYPES_URI = "http://www.example.com/dynamicTypesFromSchemaSimple"; + + private final String SDO_FROM_API_AND_DYN = "object created with API with dynamic type "; + + private final String SDO_FROM_API_AND_REF = "object created with API with type from XSD"; + + private final String SDO_FROM_XML_AND_REF = "object created with XML with type from XSD"; + + private final String TEST_XML_DOC_0_STRING = "\n" + + "\n" + + " This is a repeated string.\n" + " This is a repeated string.\n" + + " true\n" + " false\n" + " true\n" + + " 1\n" + " 0\n" + " 0\n" + + " 12.5\n" + " 0\n" + "\n"; + + private void comparePropertyObjects(String propName, String name1, String name2, Object propObj1, Object propObj2) { + if (propObj1 == null) { + if (propObj2 != null) { + localFail("property " + propName + " for " + name1 + " was null but " + name2 + " was '" + propObj2 + + "'"); + } + } else if (propObj2 == null) { + localFail("property " + propName + " for " + name2 + " was null but " + name1 + " was '" + propObj1 + "'"); + } else { + if (!propObj1.equals(propObj2)) { + localFail("property " + propName + " for " + name1 + " was '" + propObj1 + "' but " + name2 + " was '" + + propObj2 + "'"); + } + } + } + + private void compareSequencesIgnoringWhitespace(String name1, String name2, Sequence sequence1, Sequence sequence2) { + if (sequence1 == null) { + if (sequence2 != null) { + localFail("sequence for " + name1 + " was null but " + name2 + " was not null"); + } + } else if (sequence2 == null) { + localFail("sequence for " + name2 + " was null but " + name1 + " was not null"); + } else { + List trimmedSeq1 = new ArrayList(); + List trimmedSeq2 = new ArrayList(); + trimWhitespaceFromSequence(trimmedSeq1, sequence1); + trimWhitespaceFromSequence(trimmedSeq2, sequence2); + int size1 = trimmedSeq1.size(); + int size2 = trimmedSeq2.size(); + if (size1 != size2) { + localFail("lengths of trimmed sequences differ: " + name1 + " was " + size1 + ", " + name2 + " was " + + size2); + } else { + Object[] objArr1 = trimmedSeq1.toArray(); + Object[] objArr2 = trimmedSeq2.toArray(); + for (int i = 0; i < size1; i++) { + Object obj1 = objArr1[i]; + Object obj2 = objArr2[i]; + if (obj1 == null) { + if (obj2 != null) { + localFail("sequence for " + name1 + " had null element for which " + name2 + " had '" + obj2 + + "'"); + } + } else if (obj2 == null) { + localFail("sequence for " + name2 + " had null element for which " + name1 + " had '" + obj1 + "'"); + } else { + if (!obj1.equals(obj2)) { + localFail("sequences did not match: " + name1 + " had '" + obj1 + "' but " + name2 + " had '" + + obj2 + "'"); + } + } + } + } + } + } + + private void getAndCompareProperties(String propName, DataObject xmlAndRefTypDO, DataObject apiAndDynTypDO, + DataObject apiAndRefTypDO) { + Object xmlRefProperty = xmlAndRefTypDO.get(propName); + Object apiDynProperty = apiAndDynTypDO.get(propName); + Object apiRefProperty = apiAndRefTypDO.get(propName); + comparePropertyObjects(propName, SDO_FROM_XML_AND_REF, SDO_FROM_API_AND_DYN, xmlRefProperty, apiDynProperty); + comparePropertyObjects(propName, SDO_FROM_XML_AND_REF, SDO_FROM_API_AND_REF, xmlRefProperty, apiRefProperty); + } + + private void localFail(String message) { + // System.err.println(message); + fail(message); + } + + protected void setUp() throws Exception { + super.setUp(); + } + + private void specifyProperty(DataObject containingTypeDO, String nameString, Type typ, boolean isMany) { + DataObject subordinateProperty = containingTypeDO.createDataObject("property"); + subordinateProperty.set("name", nameString); + subordinateProperty.set("type", typ); + subordinateProperty.setBoolean("many", isMany); + } + + /** + * test #0 of Data Object primitive datatypes + */ + public void testDynamicTypesGroup0DO() throws IOException { + HelperContext hcDO = SDOUtil.createHelperContext(); + + TypeHelper thDO = hcDO.getTypeHelper(); + DataFactory dfDO = hcDO.getDataFactory(); + + // create a container object type + DataObject containerTypeDO = dfDO.create("commonj.sdo", "Type"); + containerTypeDO.set("uri", DYNAMIC_TYPES_URI); + containerTypeDO.set("name", DYNAMIC_ROOT_TYPE_0); + containerTypeDO.set("sequenced", Boolean.TRUE); + + specifyProperty(containerTypeDO, "aString", thDO.getType(COMMONJ_SDO, "String"), true); + specifyProperty(containerTypeDO, "aBoolean", thDO.getType(COMMONJ_SDO, "Boolean"), true); + specifyProperty(containerTypeDO, "aFloat", thDO.getType(COMMONJ_SDO, "Float"), true); + + Type containerType = thDO.define(containerTypeDO); + assertNotNull(containerType); + + DataObject doFromApiAndDynTyp = dfDO.create(containerType); + assertNotNull(doFromApiAndDynTyp); + doFromApiAndDynTyp.getList("aString").add("This is a repeated string."); + doFromApiAndDynTyp.getList("aString").add("This is a repeated string."); + doFromApiAndDynTyp.getList("aBoolean").add(new Boolean(true)); + doFromApiAndDynTyp.getList("aBoolean").add(new Boolean(false)); + doFromApiAndDynTyp.getList("aBoolean").add(new Boolean(true)); + doFromApiAndDynTyp.getList("aBoolean").add(new Boolean(true)); + doFromApiAndDynTyp.getList("aBoolean").add(new Boolean(false)); + doFromApiAndDynTyp.getList("aFloat").add(new Float(0)); + doFromApiAndDynTyp.getList("aFloat").add(new Float(12.5)); + doFromApiAndDynTyp.getList("aFloat").add(new Float(0)); + + Type rootType = thDO.getType(DYNAMIC_TYPES_URI, DYNAMIC_ROOT_TYPE_0); + assertNotNull(rootType); + assertSame(containerType, rootType); + + // now load xml to get a reference data object using schema + HelperContext hcRef = SDOUtil.createHelperContext(); + XSDHelper xsdHelper = hcRef.getXSDHelper(); + List typeList = xsdHelper.define(DYNAMIC_TYPES_SCHEMA_STRING); + assertNotNull(typeList); + TypeHelper thRef = hcRef.getTypeHelper(); + Type rootTypeRef = thRef.getType(DYNAMIC_TYPES_URI, DYNAMIC_ROOT_TYPE_0); + + assertNotNull(rootTypeRef); + + XMLHelper xhRef = hcRef.getXMLHelper(); + // XMLDocument docRef = + // xhRef.load(getClass().getResourceAsStream(TEST_XML_DOC_0)); + XMLDocument docRef = xhRef.load(TEST_XML_DOC_0_STRING); + DataObject doFromXmlAndRefTyp = docRef.getRootObject(); + + assertNotNull(doFromXmlAndRefTyp); + + // create a data object using dynamic API from reference type + DataFactory dfRef = hcRef.getDataFactory(); + DataObject doFromApiAndRefTyp = dfRef.create(rootTypeRef); + assertNotNull(doFromApiAndRefTyp); + doFromApiAndRefTyp.getList("aString").add("This is a repeated string."); + doFromApiAndRefTyp.getList("aString").add("This is a repeated string."); + doFromApiAndRefTyp.getList("aBoolean").add(new Boolean(true)); + doFromApiAndRefTyp.getList("aBoolean").add(new Boolean(false)); + doFromApiAndRefTyp.getList("aBoolean").add(new Boolean(true)); + doFromApiAndRefTyp.getList("aBoolean").add(new Boolean(true)); + doFromApiAndRefTyp.getList("aBoolean").add(new Boolean(false)); + doFromApiAndRefTyp.getList("aFloat").add(new Float(0)); + doFromApiAndRefTyp.getList("aFloat").add(new Float(12.5)); + doFromApiAndRefTyp.getList("aFloat").add(new Float(0)); + + getAndCompareProperties("aString", doFromXmlAndRefTyp, doFromApiAndDynTyp, doFromApiAndRefTyp); + getAndCompareProperties("aBoolean", doFromXmlAndRefTyp, doFromApiAndDynTyp, doFromApiAndRefTyp); + getAndCompareProperties("aFloat", doFromXmlAndRefTyp, doFromApiAndDynTyp, doFromApiAndRefTyp); + Sequence seqFromXmlAndRefTyp = doFromXmlAndRefTyp.getSequence(); + Sequence seqFromApiAndDynTyp = doFromApiAndDynTyp.getSequence(); + Sequence seqFromApiAndRefTyp = doFromApiAndRefTyp.getSequence(); + compareSequencesIgnoringWhitespace(SDO_FROM_XML_AND_REF, SDO_FROM_API_AND_DYN, seqFromXmlAndRefTyp, + seqFromApiAndDynTyp); + compareSequencesIgnoringWhitespace(SDO_FROM_XML_AND_REF, SDO_FROM_API_AND_REF, seqFromXmlAndRefTyp, + seqFromApiAndRefTyp); + } + + private void trimWhitespaceFromSequence(List trimmedSeq, Sequence sequence) { + if (sequence != null) { + for (int i = 0; i < sequence.size(); i++) { + Object obj = sequence.getValue(i); + if (obj instanceof String) { + String str = ((String) obj).trim(); + if (str.length() > 0) { + trimmedSeq.add(str); + } + } else { + trimmedSeq.add(obj); + } + } + } + } +} diff --git a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/ExpectedExceptionsTestCase.java b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/ExpectedExceptionsTestCase.java index 7674cda42b..af4bb4d928 100644 --- a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/ExpectedExceptionsTestCase.java +++ b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/ExpectedExceptionsTestCase.java @@ -1,1878 +1,1878 @@ -/** - * - * 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.io.InputStream; -import java.net.URL; -import java.util.List; - -import org.apache.tuscany.sdo.util.SDOUtil; - -import com.example.ExpectedException.ExpectedExceptionFactory; - -import commonj.sdo.DataGraph; -import commonj.sdo.DataObject; -import commonj.sdo.Property; -import commonj.sdo.Sequence; -import commonj.sdo.Type; -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.TypeHelper; - -import junit.framework.TestCase; - -/** - * Verifies the Exception related behavior which is explicitly identified in - * the 2.1 SDO Specification. - */ -public class ExpectedExceptionsTestCase extends TestCase { - - private static final String TEST_URI = "http://example.com/ExpectedException"; - private static final String TEST_TYPE_NAME = "ExpectedExceptionType"; - private static final String SEQ_TYPE_NAME = "SequenceReadOnlyType"; - private static boolean typeDefined = false; - private static HelperContext helperContext; - private static DataObject testDO; - private static DataObject seqDO; - - /** - * Verifies the following statement. - * Get(String path) will not throw exceptions other than ClassCastException - * if it is impossible to convert between the actual and expected types. - * Note: This test case will not be implmented because it is already covered - * by testCannnotConvertClassCastException. - */ - - public void testGetTStringClassCastExceptionOnly() { - // This test case will not be implemented. - } - - /** - * Verifies the following statement. - * get(Property property) throws an IllegalArgumentException when - * getInstanceProperties().contains(property) == false. - */ - public void testGetViaPropertyIllegalArgumentException() { - DataObject invalidPropDO = helperContext.getDataFactory().create(TEST_URI, SEQ_TYPE_NAME); - Property invalidProp = invalidPropDO.getInstanceProperty("uniqueName"); - - try { - testDO.get(invalidProp); - fail("get(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("get(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getBoolean(invalidProp); - fail("getBoolean(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBoolean(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getByte(invalidProp); - fail("getByte(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getByte(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getChar(invalidProp); - fail("getChar(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getChar(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getDouble(invalidProp); - fail("getDouble(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getDouble(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getFloat(invalidProp); - fail("getFloat(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getFloat(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getInt(invalidProp); - fail("getInt(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getInt(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getLong(invalidProp); - fail("getLong(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getLong(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getShort(invalidProp); - fail("getShort(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getShort(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getBytes(invalidProp); - fail("getBytes(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBytes(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getBigDecimal(invalidProp); - fail("getBigDecimal(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBigDecimal(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getBigInteger(invalidProp); - fail("getBigInteger(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBigInteger(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getDataObject(invalidProp); - fail("getDataObject(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getDataObject(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getDate(invalidProp); - fail("getDate(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getDate(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getString(invalidProp); - fail("getString(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getString(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getList(invalidProp); - fail("getList(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getList(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(property)== false. " + e.getClass().getName() + " was thrown."); - } - } - - /** - * Verfies the following statement. - * get(int propertyIndex) throws an IllegalArgumentException when - * propertIndex <0 or >= getInstanceProerties().size() - */ - public void testGetViaIndexIllegalArgumentException() { - int numProps = testDO.getInstanceProperties().size(); - - try { - testDO.get(-1); - fail("get(-1) should throw an IllegalArgumentException. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("get(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getBoolean(-1); - fail("getBoolean(-1) should throw an IllegalArgumentException. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBoolean(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getByte(-1); - fail("getByte(-1) should throw an IllegalArgumentException. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getByte(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getChar(-1); - fail("getChar(-1) should throw an IllegalArgumentException. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getChar(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getDouble(-1); - fail("getDouble(-1) should throw an IllegalArgumentException. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getDouble(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getFloat(-1); - fail("getFloat(-1) should throw an IllegalArgumentException. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getFloat(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getInt(-1); - fail("getInt(-1) should throw an IllegalArgumentException. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getInt(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getLong(-1); - fail("getLong(-1) should throw an IllegalArgumentException. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getLong(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getShort(-1); - fail("getShort(-1) should throw an IllegalArgumentException. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getShort(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getBytes(-1); - fail("getBytes(-1) should throw an IllegalArgumentException. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBytes(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getBigDecimal(-1); - fail("getBigDecimal(-1) should throw an IllegalArgumentException. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBigDecimal(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getBigInteger(-1); - fail("getBigInteger(-1) should throw an IllegalArgumentException. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBigInteger(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getDataObject(-1); - fail("getDataObject(-1) should throw an IllegalArgumentException. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getDataObject(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getDate(-1); - fail("getDate(-1) should throw an IllegalArgumentException. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getDate(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getString(-1); - fail("getString(-1) should throw an IllegalArgumentException. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getString(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getList(-1); - fail("getList(-1) should throw an IllegalArgumentException. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getList(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); - } - - try { - testDO.get(numProps); - fail("get(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("get(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getBoolean(numProps); - fail("getBoolean(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBoolean(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getByte(numProps); - fail("getByte(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getByte(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getChar(numProps); - fail("getChar(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getChar(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getDouble(numProps); - fail("getDouble(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getDouble(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getFloat(numProps); - fail("getFloat(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getFloat(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getInt(numProps); - fail("getInt(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getInt(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getLong(numProps); - fail("getLong(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getLong(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getShort(numProps); - fail("getShort(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getShort(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getBytes(numProps); - fail("getBytes(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBytes(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getBigDecimal(numProps); - fail("getBigDecimal(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBigDecimal(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getBigInteger(numProps); - fail("getBigInteger(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBigInteger(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getDataObject(numProps); - fail("getDataObject(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getDataObject(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getDate(numProps); - fail("getDate(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getDate(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getString(numProps); - fail("getString(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getString(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getList(numProps); - fail("getList(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("getList(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); - } - } - - /** - * Verifies the following statement. - * Using an Index out of range (index < 0 or >= getList(Property property).size()) - * will result in an IndexOutOfBoundsException. - */ - public void testListIndexOutOfBoundsException() { - List list = testDO.getList("listVal"); - -// Not fixed in TUSCANY-578 -// try { -// list.get(-1); -// fail("list.get(-1) should throw an IndexOutOfBoundsException. No Exception was thrown."); -// } catch (IndexOutOfBoundsException e) { -// // Success - do nothing -// } catch (Exception e) { -// fail("list.get(-1) should throw an IndexOutOfBoundsException. " + e.getClass().getName() + " was thrown."); -// } -// try { -// list.get(list.size()); -// fail("list.get(int) should throw an IndexOutOfBoundsException when int >= list.size(). No Exception was thrown."); -// } catch (IndexOutOfBoundsException e) { -// // Success - do nothing -// } catch (Exception e) { -// fail("list.get(int) should throw an IndexOutOfBoundsException when int >= list.size(). " + e.getClass().getName() + " was thrown."); -// } -// try { -// list.remove(-1); -// fail("list.remove(-1) should throw an IndexOutOfBoundsException. No Exception was thrown."); -// } catch (IndexOutOfBoundsException e) { -// // Success - do nothing -// } catch (Exception e) { -// fail("list.remove(-1) should throw an IndexOutOfBoundsException. " + e.getClass().getName() + " was thrown."); -// } - try { - list.remove(list.size()); - fail("list.remove(int) should throw an IndexOutOfBoundsException when int >= list.size(). No Exception was thrown."); - } catch (IndexOutOfBoundsException e) { - // Success - do nothing - } catch (Exception e) { - fail("list.remove(int) should throw an IndexOutOfBoundsException when int >= list.size(). " + e.getClass().getName() + " was thrown."); - } - } - - /** - * Verifies the following statement. - * Modification of a read-only property results in UnsupportedOperationException. - * This test case is for modifications done through the DataObject API. - */ - public void testModifyReadOnlyUnsupportedOperationException() { - Property readOnlyProp = testDO.getInstanceProperty("readOnlyVal"); - List properties = testDO.getInstanceProperties(); - Property currProp; - int readOnlyIndex = -1, i = 0, size = properties.size(); - - // Verify the precondition - assertTrue("readOnlyVal should be read-only.", readOnlyProp.isReadOnly()); - - while (readOnlyIndex < 0 && i < size) { - currProp = (Property) properties.get(i); - if (currProp.equals(readOnlyProp)) - readOnlyIndex = i; - i++; - } - - try { - testDO.set("readOnlyVal", "NewValue"); - fail("DataObject.set(string, value) should throw an UnsupportedOperationException when the Property represented by string is read-only. No Exception was thrown."); - } catch (UnsupportedOperationException e) { - // Success - do nothing - } catch (Exception e) { - fail("DataObject.set(string, value) should throw an UnsupportedOperationException when the Property represented by string is read-only. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.set(readOnlyProp, "NewValue"); - System.out.println("propname =" + readOnlyProp.getName()); - fail("DataObject.set(property, value) should throw an UnsupportedOperationException when the Property represented by property is read-only. No Exception was thrown."); - } catch (UnsupportedOperationException e) { - // Success - do nothing - } catch (Exception e) { - fail("DataObject.set(property, value) should throw an UnsupportedOperationException when the Property represented by property is read-only. " + e.getClass().getName() + " was thrown."); - } - assertTrue("The test case could not procede because the index of the read only Property was not found.", readOnlyIndex > -1); - try { - testDO.set(readOnlyIndex, "NewValue"); - fail("DataObject.set(index, value) should throw an UnsupportedOperationException when the Property represented by index is read-only. No Exception was thrown."); - } catch (UnsupportedOperationException e) { - // Success - do nothing - } catch (Exception e) { - fail("DataObject.set(index, value) should throw an UnsupportedOperationException when the Property represented by index is read-only. " + e.getClass().getName() + " was thrown."); - } - - try { - testDO.unset("readOnlyVal"); - fail("DataObject.unset(string) should throw an UnsupportedOperationException when the Property represented by string is read-only. No Exception was thrown."); - } catch (UnsupportedOperationException e) { - // Success - do nothing - } catch (Exception e) { - fail("DataObject.unset(string) should throw an UnsupportedOperationException when the Property represented by string is read-only. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.unset(readOnlyProp); - fail("DataObject.unset(property) should throw an UnsupportedOperationException when the Property represented by property is read-only. No Exception was thrown."); - } catch (UnsupportedOperationException e) { - // Success - do nothing - } catch (Exception e) { - fail("DataObject.unset(property) should throw an UnsupportedOperationException when the Property represented by property is read-only. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.unset(readOnlyIndex); - fail("DataObject.unset(index) should throw an UnsupportedOperationException when the Property represented by index is read-only. No Exception was thrown."); - } catch (UnsupportedOperationException e) { - // Success - do nothing - } catch (Exception e) { - fail("DataObject.unset(index) should throw an UnsupportedOperationException when the Property represented by index is read-only. " + e.getClass().getName() + " was thrown."); - } - } - - /** - * Verifies the following statement. - * Modification of a read-only property results in UnsupportedOperationException. - * This test case is for modification done through the List API. - */ - public void testModifyReadOnlyUnsupportedOperationExceptionList() { - Property readOnlyProp = testDO.getInstanceProperty("readOnlyVal"); - List properties = testDO.getInstanceProperties(); - Property currProp; - int readOnlyIndex = -1, i = 0, size = properties.size(); - - while (readOnlyIndex < 0 && i < size) { - currProp = (Property) properties.get(i); - if (currProp.equals(readOnlyProp)) - readOnlyIndex = i; - i++; - } - -// Not fixed in TUSCANY-578 -// try { -// List temp = testDO.getList("readOnlyListVal"); -// temp.add("String to add."); -// fail("DataObject.getList(path).add(value) should throw an UnsupportedOperationException when the Property represented by path is read-only. No Exception was thrown."); -// } catch (UnsupportedOperationException e) { -// // Success - do nothing -// } catch (Exception e) { -// fail("DataObject.getList(path).add(value) should throw an IllegalArgumentException when the Property represented by path is read-only. " + e.getClass().getName() + " was thrown."); -// } -// try { -// Sequence temp = testDO.getSequence(); -// temp.add("readOnlyListVal", "String to add."); -// fail("DataObject.getSequence().add(path, value) should throw an UnsupportedOperationException when the Property represtend by path is read-only. No Exception was thrown."); -// } catch (UnsupportedOperationException e) { -// // Success - do nothing -// } catch (Exception e) { -// fail("DataObject.getSequence().add(path, value) should throw an UnsupportedOperationException when the Property represtend by path is read-only. " + e.getClass().getName() + " was thrown."); -// } - } - - /** - * Verifies the following statement. - * Modification of a read-only property results in UnsupportedOperationException. - * This test case is for modification done through the List API. - */ - public void testModifyReadOnlyUnsupportedOperationExceptionSequence() { - Property readOnlyProp = seqDO.getInstanceProperty("readOnlyVal"); - List properties = seqDO.getInstanceProperties(); - Property currProp; - int readOnlyIndex = -1, i = 0, size = properties.size(); - - while (readOnlyIndex < 0 && i < size) { - currProp = (Property) properties.get(i); - if (currProp.equals(readOnlyProp)) - readOnlyIndex = i; - i++; - } - -// Not fixed in TUSCANY-578 -// try { -// Sequence sequence = seqDO.getSequence(); -// sequence.add(readOnlyProp, "New Value"); -// fail("Sequence.add(property, value) should throw an UnsupportedOperationException when the Property represented by property is read-only. No Exception was thrown."); -// } catch (UnsupportedOperationException e) { -// // Success - do nothing -// } catch (Exception e) { -// fail("Sequence.add(property, value) should throw an UnsupportedOperationException when the Property represented by property is read-only. " + e.getClass().getName() + " was thrown."); -// } - } - - /** - * Verifies the following statement. - * A ClassCastException results when cannot convert between value and requested Type. - */ - - public void testCannotConvertClassCastException() { - // Attempt conversion from boolean - - try { - testDO.getByte("booleanVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getChar("booleanVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getDouble("booleanVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getFloat("booleanVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getInt("booleanVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getLong("booleanVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getShort("booleanVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getBytes("booleanVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getBigDecimal("booleanVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getBigInteger("booleanVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getDate("booleanVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - - // Attempt conversion from byte - try { - testDO.getBoolean("byteVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getChar("byteVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getBigDecimal("byteVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getBigInteger("byteVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getDate("byteVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getBytes("byteVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - // Attempt conversion from character - try { - testDO.getBoolean("charVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getByte("charVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getDouble("charVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getFloat("charVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getInt("charVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getLong("charVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getShort("charVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getBytes("charVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getBigDecimal("charVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getBigInteger("charVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getDate("charVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - -// Attempt conversion from double - try { - testDO.getBoolean("doubleVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getChar("doubleVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getBytes("doubleVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getDate("doubleVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - -// Attempt conversion from float - try { - testDO.getBoolean("floatVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getChar("floatVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getBytes("floatVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getDate("floatVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - -// Attempt conversion from int - try { - testDO.getBoolean("intVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getChar("intVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getBytes("intVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getDate("intVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - -// Attempt conversion from long - try { - testDO.getBoolean("longVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getChar("longVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getBytes("longVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - -// Attempt conversion from short - try { - testDO.getBoolean("shortVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getChar("shortVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getBytes("shortVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getBigDecimal("shortVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getBigInteger("shortVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getDate("shortVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - -// Attempt conversion from bytes - try { - testDO.getBoolean("bytesVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getByte("bytesVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getChar("bytesVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getDouble("bytesVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getFloat("bytesVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getInt("bytesVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getLong("bytesVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getShort("bytesVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getBigDecimal("bytesVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getDate("bytesVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - -// Attempt conversion from decimal - try { - testDO.getBoolean("decimalVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getByte("decimalVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getChar("decimalVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getShort("decimalVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getBytes("decimalVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getDate("decimalVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - -// Attempt conversion from BigInteger - try { - testDO.getBoolean("integerVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getByte("integerVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getChar("integerVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getShort("integerVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getDate("integerVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - -// Attempt conversion from date - try { - testDO.getBoolean("dateVal"); - } catch (ClassCastException e) { - // success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getByte("dateVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getChar("dateVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getDouble("dateVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getFloat("dateVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getInt("dateVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getShort("dateVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getBytes("dateVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getBigDecimal("dateVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - try { - testDO.getBigInteger("dateVal"); - } catch (ClassCastException e) { -// success - do nothing - } catch (Exception e) { - fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); - } - } - - - /** - * Verifies the following statement. - * Mixing single-valued and multi-valued Property access results in - * ClassCastException. - */ - public void testMixSingleMultiValueClassCastException() { - Property testedProp = testDO.getInstanceProperty("intVal"); - List properties = testDO.getInstanceProperties(); - Property currProp; - int testedIndex = -1, i = 0, size = properties.size(); - - while (testedIndex < 0 && i < size) { - currProp = (Property) properties.get(i); - - if (currProp.equals(testedProp)) - testedIndex = i; - i++; - } - - try { - testDO.getList("intVal"); - fail("getList(string) should throw a ClassCastException when the property represented by string is single-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getList(string) should throw a ClassCastException when the property represented by string is single-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getList(testedProp); - fail("getList(property) should throw a ClassCastException when the property represented by property is single-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getList(property) should throw a ClassCastException when the property represented by property is single-valued. " + e.getClass().getName() + " was thrown."); - } - - assertTrue("The test case could not procede because the index of the single-valued Property was not found.", testedIndex > -1); - - try { - testDO.getList(testedIndex); - fail("getList(index) should throw a ClassCastException when the property represented by index is single-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getList(index) should throw a ClassCastException when the property represented by index is single-valued. " + e.getClass().getName() + " was thrown."); - } - - testedProp = testDO.getInstanceProperty("listVal"); - testedIndex = -1; - i = 0; - while (testedIndex < 0 && i < size) { - currProp = (Property) properties.get(i); - if (currProp.equals(testedProp)) - testedIndex = i; - i++; - } - - try { - testDO.getBoolean("listVal"); - fail("getBoolean(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBoolean(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getByte("listVal"); - fail("getByte(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getByte(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getChar("listVal"); - fail("getChar(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getChar(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getDouble("listVal"); - fail("getDouble(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getDouble(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getFloat("listVal"); - fail("getFloat(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getFloat(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getInt("listVal"); - fail("getInt(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getInt(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getLong("listVal"); - fail("getLong(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getLong(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getShort("listVal"); - fail("getShort(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getShort(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getBytes("listVal"); - fail("getBytes(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBytes(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getBigDecimal("listVal"); - fail("getBigDecimal(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBigDecimal(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getBigInteger("listVal"); - fail("getBigInteger(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBigInteger(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getDataObject("listVal"); - fail("getDataObject(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getDataObject(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getDate("listVal"); - fail("getDate(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getDate(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getString("listVal"); - fail("getString(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getString(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); - } - - try { - testDO.getBoolean(testedProp); - fail("getBoolean(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBoolean(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getByte(testedProp); - fail("getByte(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getByte(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getChar(testedProp); - fail("getChar(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getChar(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getDouble(testedProp); - fail("getDouble(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getDouble(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getFloat(testedProp); - fail("getFloat(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getFloat(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getInt(testedProp); - fail("getInt(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getInt(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getLong(testedProp); - fail("getLong(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getLong(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getShort(testedProp); - fail("getShort(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getShort(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getBytes(testedProp); - fail("getBytes(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBytes(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getBigDecimal(testedProp); - fail("getBigDecimal(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBigDecimal(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getBigInteger(testedProp); - fail("getBigInteger(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBigInteger(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getDataObject(testedProp); - fail("getDataObject(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getDataObject(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getDate(testedProp); - fail("getDate(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getDate(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getString(testedProp); - fail("getString(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getString(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); - } - - assertTrue("The test case could not procede because the index of the multi-valued Property was not found.", testedIndex > -1); - - try { - testDO.getBoolean(testedIndex); - fail("getBoolean(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBoolean(index) should throw a ClassCastException when the property represented by is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getByte(testedIndex); - fail("getByte(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getByte(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getChar(testedIndex); - fail("getChar(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getChar(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getDouble(testedIndex); - fail("getDouble(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getDouble(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getFloat(testedIndex); - fail("getFloat(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getFloat(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getInt(testedIndex); - fail("getInt(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getInt(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getLong(testedIndex); - fail("getLong(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getLong(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getShort(testedIndex); - fail("getShort(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getShort(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getBytes(testedIndex); - fail("getBytes(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBytes(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getBigDecimal(testedIndex); - fail("getBigDecimal(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBigDecimal(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getBigInteger(testedIndex); - fail("getBigInteger(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getBigInteger(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getDataObject(testedIndex); - fail("getDataObject(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getDataObject(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getDate(testedIndex); - fail("getDate(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getDate(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); - } - try { - testDO.getString(testedIndex); - fail("getString(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); - } catch (ClassCastException e) { - // Success - do nothing - } catch (Exception e) { - fail("getString(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); - } - } - - /* - /** - * Verifies the following statement. - * Establishing circular containment results in an IllegalArgumentException. - * Note: This test case will not be implemented because it has been determined - * that the statement will be removed from the spec. - */ - /* - public void testContainmentCycleIllegalArgumentException() { - // This test case will not be implemented. - } - */ - - /** - * Verifies the following statement. - * An empty DataGraph can have a root assigned by the createRootObject() methods. - * However, if a previous root DataObject exists than an IllegalStateException is - * thrown. - */ - public void testCreateRootObjectAgainIllegalStateException() { - DataGraph dataGraph = SDOUtil.createDataGraph(); - Type type = testDO.getType(); - - // verify the initial condition - assertNull("The DataGraph should have been created without a root DataObject.", dataGraph.getRootObject()); - assertNotNull("DataObject.getType() returned null.", type); - - dataGraph.createRootObject(type); - - // verify the pre-condition - assertNotNull("The DataGraph.createRootObject() should have created a root DataObject for the DataGraph.", dataGraph.getRootObject()); - - try { - dataGraph.createRootObject(type); - fail("DataGraph.createRootObject(Type) should throw an IllegalStateException a root Object already exists for the DataGraph. No Exception was thrown."); - } catch (IllegalStateException e) { - // Success - do nothing - } catch (Exception e) { - fail("DataGraph.createRootObject(Type) should throw an IllegalStateException a root Object already exists for the DataGraph. " + e.getClass().getName() + " was thrown."); - } - } - - /** - * Verifies the following statement. - * DataFactory.create() throws an IllegalArgumentException if the instanceClass does - * not correspond to a Type this factory can instantiate. - */ - public void testDataFactoryCreateIllegalArgumentException() { - try { - helperContext.getDataFactory().create(java.lang.Object.class); - fail("DataFactory.create(Object) should throw an IllegalArgumentException when it cannot instantiate the Type specified. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("DataFactory.create(Object) should throw an IllegalArgumentException when it cannot instantiate the Type specified. " + e.getClass().getName() + " was thrown."); - } - - try { - helperContext.getDataFactory().create(commonj.sdo.DataObject.class); - fail("DataFactory.create(DataObject) should throw an IllegalArgumentException when it cannot instantiate the Type specified. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("DataFactory.create(DataObject) should throw an IllegalArgumentException when it cannot instantiate the Type specified. " + e.getClass().getName() + " was thrown."); - } - - try { - helperContext.getDataFactory().create(commonj.sdo.ChangeSummary.class); - fail("DataFactory.create(ChangeSummary) should throw an IllegalArgumentException when it cannot instantiate the Type specified. No Exception was thrown."); - } catch (IllegalArgumentException e) { - // Success - do nothing - } catch (Exception e) { - fail("DataFactory.create(ChangeSummary) should throw an IllegalArgumentException when it cannot instantiate the Type specified. " + e.getClass().getName() + " was thrown."); - } - } - - /** - * Defines the Type the first time through. - */ - public void setUp() { - if (!typeDefined) { - helperContext = SDOUtil.createHelperContext(); -// createWithXSD(helperContext); -// createDynamically(helperContext); - createStatically(helperContext); - typeDefined = true; - } -// testDO = helperContext.getDataFactory().create(TEST_URI, TEST_TYPE_NAME); -// seqDO = helperContext.getDataFactory().create(TEST_URI, SEQ_TYPE_NAME); - testDO = (DataObject) ExpectedExceptionFactory.INSTANCE.createExpectedExceptionType(); - seqDO = (DataObject) ExpectedExceptionFactory.INSTANCE.createSequenceReadOnlyType(); - } - - public static void createStatically(HelperContext hc) { - ExpectedExceptionFactory.INSTANCE.register(hc); - } - - public static void createWithXSD(HelperContext hc) { - // Populate the meta data for the test model - URL url = ExpectedExceptionsTestCase.class.getResource("/expectedExceptions.xsd"); - try { - InputStream inputStream = url.openStream(); - hc.getXSDHelper().define(inputStream, url.toString()); - inputStream.close(); - } catch(IOException e) { - e.printStackTrace(); - } - } - - /** - * createDynamically() creates the SDO Types using the TypeHelper. This - * method should be kept in synch with the XSD used for - * createDynamicallyWithStaticResources. The same XSD is used for the static - * generation of SDO Types using XSD2JavaGenerator. - */ - public static void createDynamically(HelperContext hc) { - - TypeHelper types = hc.getTypeHelper(); - Type stringType = types.getType("commonj.sdo", "String"); - Type intType = types.getType("commonj.sdo", "Int"); - Type booleanType = types.getType("commonj.sdo", "Boolean"); - Type byteType = types.getType("commonj.sdo", "Byte"); - Type decimalType = types.getType("commonj.sdo", "Decimal"); - Type floatType = types.getType("commonj.sdo", "Float"); - Type doubleType = types.getType("commonj.sdo", "Double"); - Type dateType = types.getType("commonj.sdo", "Date"); - Type shortType = types.getType("commonj.sdo", "Short"); - Type longType = types.getType("commonj.sdo", "Long"); - Type bytesType = types.getType("commonj.sdo", "Bytes"); - Type integerType = types.getType("commonj.sdo", "Integer"); - Type charType = types.getType("commonj.sdo", "Character"); - - DataObject testType = hc.getDataFactory().create("commonj.sdo", "Type"); - testType.set("uri", TEST_URI); - testType.set("name", TEST_TYPE_NAME); - - DataObject stringProperty = testType.createDataObject("property"); - stringProperty.set("name", "stringVal"); - stringProperty.set("type", stringType); - - DataObject booleanProperty = testType.createDataObject("property"); - booleanProperty.set("name", "booleanVal"); - booleanProperty.set("type", booleanType); - - DataObject byteProperty = testType.createDataObject("property"); - byteProperty.set("name", "byteVal"); - byteProperty.set("type", byteType); - - DataObject decimalProperty = testType.createDataObject("property"); - decimalProperty.set("name", "decimalVal"); - decimalProperty.set("type", decimalType); - - DataObject intProperty = testType.createDataObject("property"); - intProperty.set("name", "intVal"); - intProperty.set("type", intType); - - DataObject floatProperty = testType.createDataObject("property"); - floatProperty.set("name", "floatVal"); - floatProperty.set("type", floatType); - - DataObject doubleProperty = testType.createDataObject("property"); - doubleProperty.set("name", "doubleVal"); - doubleProperty.set("type", doubleType); - - DataObject dateProperty = testType.createDataObject("property"); - dateProperty.set("name", "dateVal"); - dateProperty.set("type", dateType); - - DataObject shortProperty = testType.createDataObject("property"); - shortProperty.set("name", "shortVal"); - shortProperty.set("type", shortType); - - DataObject longProperty = testType.createDataObject("property"); - longProperty.set("name", "longVal"); - longProperty.set("type", longType); - - DataObject childrenProperty = testType.createDataObject("property"); - childrenProperty.set("name", "listVal"); - childrenProperty.setBoolean("many", true); - childrenProperty.set("type", stringType); - - DataObject bytesProperty = testType.createDataObject("property"); - bytesProperty.set("name", "bytesVal"); - bytesProperty.set("type", bytesType); - - DataObject integerProperty = testType.createDataObject("property"); - integerProperty.set("name", "integerVal"); - integerProperty.set("type", integerType); - - DataObject charProperty = testType.createDataObject("property"); - charProperty.set("name", "charVal"); - charProperty.set("type", charType); - - DataObject readOnlyProperty = testType.createDataObject("property"); - readOnlyProperty.set("name", "readOnlyVal"); - readOnlyProperty.set("type", stringType); - readOnlyProperty.setBoolean("readOnly", true); - - DataObject readOnlyListProperty = testType.createDataObject("property"); - readOnlyListProperty.set("name", "readOnlyListVal"); - readOnlyListProperty.set("type", stringType); - readOnlyListProperty.setBoolean("readOnly", true); - readOnlyListProperty.setBoolean("many", true); - - types.define(testType); - - DataObject seqType = hc.getDataFactory().create("commonj.sdo", "Type"); - seqType.set("uri", TEST_URI); - seqType.set("name", SEQ_TYPE_NAME); - seqType.setBoolean("sequenced", true); - - DataObject seqROProperty = seqType.createDataObject("property"); - seqROProperty.set("name", "readOnlyVal"); - seqROProperty.set("type", stringType); - seqROProperty.setBoolean("readOnly", true); - - DataObject seqROListProperty = seqType.createDataObject("property"); - seqROListProperty.set("name", "readOnlyListVal"); - seqROListProperty.set("type", stringType); - seqROListProperty.setBoolean("readOnly", true); - seqROListProperty.setBoolean("many", true); - - DataObject uniqueNameProperty = seqType.createDataObject("property"); - uniqueNameProperty.set("name", "uniqueName"); - uniqueNameProperty.set("type", stringType); - - types.define(seqType); - } +/** + * + * 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.io.InputStream; +import java.net.URL; +import java.util.List; + +import org.apache.tuscany.sdo.util.SDOUtil; + +import com.example.ExpectedException.ExpectedExceptionFactory; + +import commonj.sdo.DataGraph; +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Sequence; +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.TypeHelper; + +import junit.framework.TestCase; + +/** + * Verifies the Exception related behavior which is explicitly identified in + * the 2.1 SDO Specification. + */ +public class ExpectedExceptionsTestCase extends TestCase { + + private static final String TEST_URI = "http://example.com/ExpectedException"; + private static final String TEST_TYPE_NAME = "ExpectedExceptionType"; + private static final String SEQ_TYPE_NAME = "SequenceReadOnlyType"; + private static boolean typeDefined = false; + private static HelperContext helperContext; + private static DataObject testDO; + private static DataObject seqDO; + + /** + * Verifies the following statement. + * Get(String path) will not throw exceptions other than ClassCastException + * if it is impossible to convert between the actual and expected types. + * Note: This test case will not be implmented because it is already covered + * by testCannnotConvertClassCastException. + */ + + public void testGetTStringClassCastExceptionOnly() { + // This test case will not be implemented. + } + + /** + * Verifies the following statement. + * get(Property property) throws an IllegalArgumentException when + * getInstanceProperties().contains(property) == false. + */ + public void testGetViaPropertyIllegalArgumentException() { + DataObject invalidPropDO = helperContext.getDataFactory().create(TEST_URI, SEQ_TYPE_NAME); + Property invalidProp = invalidPropDO.getInstanceProperty("uniqueName"); + + try { + testDO.get(invalidProp); + fail("get(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("get(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getBoolean(invalidProp); + fail("getBoolean(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBoolean(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getByte(invalidProp); + fail("getByte(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getByte(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getChar(invalidProp); + fail("getChar(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getChar(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getDouble(invalidProp); + fail("getDouble(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getDouble(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getFloat(invalidProp); + fail("getFloat(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getFloat(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getInt(invalidProp); + fail("getInt(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getInt(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getLong(invalidProp); + fail("getLong(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getLong(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getShort(invalidProp); + fail("getShort(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getShort(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getBytes(invalidProp); + fail("getBytes(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBytes(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getBigDecimal(invalidProp); + fail("getBigDecimal(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBigDecimal(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getBigInteger(invalidProp); + fail("getBigInteger(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBigInteger(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getDataObject(invalidProp); + fail("getDataObject(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getDataObject(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getDate(invalidProp); + fail("getDate(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getDate(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getString(invalidProp); + fail("getString(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getString(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getList(invalidProp); + fail("getList(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(propert)== false. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getList(Property property) should throw an IllegalArgumentException when getInstanceProperties().contains(property)== false. " + e.getClass().getName() + " was thrown."); + } + } + + /** + * Verfies the following statement. + * get(int propertyIndex) throws an IllegalArgumentException when + * propertIndex <0 or >= getInstanceProerties().size() + */ + public void testGetViaIndexIllegalArgumentException() { + int numProps = testDO.getInstanceProperties().size(); + + try { + testDO.get(-1); + fail("get(-1) should throw an IllegalArgumentException. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("get(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getBoolean(-1); + fail("getBoolean(-1) should throw an IllegalArgumentException. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBoolean(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getByte(-1); + fail("getByte(-1) should throw an IllegalArgumentException. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getByte(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getChar(-1); + fail("getChar(-1) should throw an IllegalArgumentException. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getChar(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getDouble(-1); + fail("getDouble(-1) should throw an IllegalArgumentException. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getDouble(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getFloat(-1); + fail("getFloat(-1) should throw an IllegalArgumentException. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getFloat(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getInt(-1); + fail("getInt(-1) should throw an IllegalArgumentException. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getInt(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getLong(-1); + fail("getLong(-1) should throw an IllegalArgumentException. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getLong(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getShort(-1); + fail("getShort(-1) should throw an IllegalArgumentException. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getShort(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getBytes(-1); + fail("getBytes(-1) should throw an IllegalArgumentException. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBytes(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getBigDecimal(-1); + fail("getBigDecimal(-1) should throw an IllegalArgumentException. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBigDecimal(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getBigInteger(-1); + fail("getBigInteger(-1) should throw an IllegalArgumentException. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBigInteger(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getDataObject(-1); + fail("getDataObject(-1) should throw an IllegalArgumentException. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getDataObject(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getDate(-1); + fail("getDate(-1) should throw an IllegalArgumentException. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getDate(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getString(-1); + fail("getString(-1) should throw an IllegalArgumentException. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getString(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getList(-1); + fail("getList(-1) should throw an IllegalArgumentException. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getList(-1) should throw an IllegalArgumentException. " + e.getClass().getName() + " was thrown."); + } + + try { + testDO.get(numProps); + fail("get(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("get(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getBoolean(numProps); + fail("getBoolean(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBoolean(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getByte(numProps); + fail("getByte(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getByte(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getChar(numProps); + fail("getChar(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getChar(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getDouble(numProps); + fail("getDouble(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getDouble(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getFloat(numProps); + fail("getFloat(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getFloat(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getInt(numProps); + fail("getInt(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getInt(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getLong(numProps); + fail("getLong(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getLong(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getShort(numProps); + fail("getShort(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getShort(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getBytes(numProps); + fail("getBytes(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBytes(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getBigDecimal(numProps); + fail("getBigDecimal(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBigDecimal(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getBigInteger(numProps); + fail("getBigInteger(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBigInteger(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getDataObject(numProps); + fail("getDataObject(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getDataObject(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getDate(numProps); + fail("getDate(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getDate(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getString(numProps); + fail("getString(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getString(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getList(numProps); + fail("getList(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("getList(int) should throw an IllegalArgumentException when int >= getInstanceProperties.size(). " + e.getClass().getName() + " was thrown."); + } + } + + /** + * Verifies the following statement. + * Using an Index out of range (index < 0 or >= getList(Property property).size()) + * will result in an IndexOutOfBoundsException. + */ + public void testListIndexOutOfBoundsException() { + List list = testDO.getList("listVal"); + +// Not fixed in TUSCANY-578 +// try { +// list.get(-1); +// fail("list.get(-1) should throw an IndexOutOfBoundsException. No Exception was thrown."); +// } catch (IndexOutOfBoundsException e) { +// // Success - do nothing +// } catch (Exception e) { +// fail("list.get(-1) should throw an IndexOutOfBoundsException. " + e.getClass().getName() + " was thrown."); +// } +// try { +// list.get(list.size()); +// fail("list.get(int) should throw an IndexOutOfBoundsException when int >= list.size(). No Exception was thrown."); +// } catch (IndexOutOfBoundsException e) { +// // Success - do nothing +// } catch (Exception e) { +// fail("list.get(int) should throw an IndexOutOfBoundsException when int >= list.size(). " + e.getClass().getName() + " was thrown."); +// } +// try { +// list.remove(-1); +// fail("list.remove(-1) should throw an IndexOutOfBoundsException. No Exception was thrown."); +// } catch (IndexOutOfBoundsException e) { +// // Success - do nothing +// } catch (Exception e) { +// fail("list.remove(-1) should throw an IndexOutOfBoundsException. " + e.getClass().getName() + " was thrown."); +// } + try { + list.remove(list.size()); + fail("list.remove(int) should throw an IndexOutOfBoundsException when int >= list.size(). No Exception was thrown."); + } catch (IndexOutOfBoundsException e) { + // Success - do nothing + } catch (Exception e) { + fail("list.remove(int) should throw an IndexOutOfBoundsException when int >= list.size(). " + e.getClass().getName() + " was thrown."); + } + } + + /** + * Verifies the following statement. + * Modification of a read-only property results in UnsupportedOperationException. + * This test case is for modifications done through the DataObject API. + */ + public void testModifyReadOnlyUnsupportedOperationException() { + Property readOnlyProp = testDO.getInstanceProperty("readOnlyVal"); + List properties = testDO.getInstanceProperties(); + Property currProp; + int readOnlyIndex = -1, i = 0, size = properties.size(); + + // Verify the precondition + assertTrue("readOnlyVal should be read-only.", readOnlyProp.isReadOnly()); + + while (readOnlyIndex < 0 && i < size) { + currProp = (Property) properties.get(i); + if (currProp.equals(readOnlyProp)) + readOnlyIndex = i; + i++; + } + + try { + testDO.set("readOnlyVal", "NewValue"); + fail("DataObject.set(string, value) should throw an UnsupportedOperationException when the Property represented by string is read-only. No Exception was thrown."); + } catch (UnsupportedOperationException e) { + // Success - do nothing + } catch (Exception e) { + fail("DataObject.set(string, value) should throw an UnsupportedOperationException when the Property represented by string is read-only. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.set(readOnlyProp, "NewValue"); + System.out.println("propname =" + readOnlyProp.getName()); + fail("DataObject.set(property, value) should throw an UnsupportedOperationException when the Property represented by property is read-only. No Exception was thrown."); + } catch (UnsupportedOperationException e) { + // Success - do nothing + } catch (Exception e) { + fail("DataObject.set(property, value) should throw an UnsupportedOperationException when the Property represented by property is read-only. " + e.getClass().getName() + " was thrown."); + } + assertTrue("The test case could not procede because the index of the read only Property was not found.", readOnlyIndex > -1); + try { + testDO.set(readOnlyIndex, "NewValue"); + fail("DataObject.set(index, value) should throw an UnsupportedOperationException when the Property represented by index is read-only. No Exception was thrown."); + } catch (UnsupportedOperationException e) { + // Success - do nothing + } catch (Exception e) { + fail("DataObject.set(index, value) should throw an UnsupportedOperationException when the Property represented by index is read-only. " + e.getClass().getName() + " was thrown."); + } + + try { + testDO.unset("readOnlyVal"); + fail("DataObject.unset(string) should throw an UnsupportedOperationException when the Property represented by string is read-only. No Exception was thrown."); + } catch (UnsupportedOperationException e) { + // Success - do nothing + } catch (Exception e) { + fail("DataObject.unset(string) should throw an UnsupportedOperationException when the Property represented by string is read-only. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.unset(readOnlyProp); + fail("DataObject.unset(property) should throw an UnsupportedOperationException when the Property represented by property is read-only. No Exception was thrown."); + } catch (UnsupportedOperationException e) { + // Success - do nothing + } catch (Exception e) { + fail("DataObject.unset(property) should throw an UnsupportedOperationException when the Property represented by property is read-only. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.unset(readOnlyIndex); + fail("DataObject.unset(index) should throw an UnsupportedOperationException when the Property represented by index is read-only. No Exception was thrown."); + } catch (UnsupportedOperationException e) { + // Success - do nothing + } catch (Exception e) { + fail("DataObject.unset(index) should throw an UnsupportedOperationException when the Property represented by index is read-only. " + e.getClass().getName() + " was thrown."); + } + } + + /** + * Verifies the following statement. + * Modification of a read-only property results in UnsupportedOperationException. + * This test case is for modification done through the List API. + */ + public void testModifyReadOnlyUnsupportedOperationExceptionList() { + Property readOnlyProp = testDO.getInstanceProperty("readOnlyVal"); + List properties = testDO.getInstanceProperties(); + Property currProp; + int readOnlyIndex = -1, i = 0, size = properties.size(); + + while (readOnlyIndex < 0 && i < size) { + currProp = (Property) properties.get(i); + if (currProp.equals(readOnlyProp)) + readOnlyIndex = i; + i++; + } + +// Not fixed in TUSCANY-578 +// try { +// List temp = testDO.getList("readOnlyListVal"); +// temp.add("String to add."); +// fail("DataObject.getList(path).add(value) should throw an UnsupportedOperationException when the Property represented by path is read-only. No Exception was thrown."); +// } catch (UnsupportedOperationException e) { +// // Success - do nothing +// } catch (Exception e) { +// fail("DataObject.getList(path).add(value) should throw an IllegalArgumentException when the Property represented by path is read-only. " + e.getClass().getName() + " was thrown."); +// } +// try { +// Sequence temp = testDO.getSequence(); +// temp.add("readOnlyListVal", "String to add."); +// fail("DataObject.getSequence().add(path, value) should throw an UnsupportedOperationException when the Property represtend by path is read-only. No Exception was thrown."); +// } catch (UnsupportedOperationException e) { +// // Success - do nothing +// } catch (Exception e) { +// fail("DataObject.getSequence().add(path, value) should throw an UnsupportedOperationException when the Property represtend by path is read-only. " + e.getClass().getName() + " was thrown."); +// } + } + + /** + * Verifies the following statement. + * Modification of a read-only property results in UnsupportedOperationException. + * This test case is for modification done through the List API. + */ + public void testModifyReadOnlyUnsupportedOperationExceptionSequence() { + Property readOnlyProp = seqDO.getInstanceProperty("readOnlyVal"); + List properties = seqDO.getInstanceProperties(); + Property currProp; + int readOnlyIndex = -1, i = 0, size = properties.size(); + + while (readOnlyIndex < 0 && i < size) { + currProp = (Property) properties.get(i); + if (currProp.equals(readOnlyProp)) + readOnlyIndex = i; + i++; + } + +// Not fixed in TUSCANY-578 +// try { +// Sequence sequence = seqDO.getSequence(); +// sequence.add(readOnlyProp, "New Value"); +// fail("Sequence.add(property, value) should throw an UnsupportedOperationException when the Property represented by property is read-only. No Exception was thrown."); +// } catch (UnsupportedOperationException e) { +// // Success - do nothing +// } catch (Exception e) { +// fail("Sequence.add(property, value) should throw an UnsupportedOperationException when the Property represented by property is read-only. " + e.getClass().getName() + " was thrown."); +// } + } + + /** + * Verifies the following statement. + * A ClassCastException results when cannot convert between value and requested Type. + */ + + public void testCannotConvertClassCastException() { + // Attempt conversion from boolean + + try { + testDO.getByte("booleanVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getChar("booleanVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getDouble("booleanVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getFloat("booleanVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getInt("booleanVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getLong("booleanVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getShort("booleanVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getBytes("booleanVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getBigDecimal("booleanVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getBigInteger("booleanVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getDate("booleanVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + + // Attempt conversion from byte + try { + testDO.getBoolean("byteVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getChar("byteVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getBigDecimal("byteVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getBigInteger("byteVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getDate("byteVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getBytes("byteVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + // Attempt conversion from character + try { + testDO.getBoolean("charVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getByte("charVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getDouble("charVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getFloat("charVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getInt("charVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getLong("charVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getShort("charVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getBytes("charVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getBigDecimal("charVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getBigInteger("charVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getDate("charVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + +// Attempt conversion from double + try { + testDO.getBoolean("doubleVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getChar("doubleVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getBytes("doubleVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getDate("doubleVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + +// Attempt conversion from float + try { + testDO.getBoolean("floatVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getChar("floatVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getBytes("floatVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getDate("floatVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + +// Attempt conversion from int + try { + testDO.getBoolean("intVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getChar("intVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getBytes("intVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getDate("intVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + +// Attempt conversion from long + try { + testDO.getBoolean("longVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getChar("longVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getBytes("longVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + +// Attempt conversion from short + try { + testDO.getBoolean("shortVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getChar("shortVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getBytes("shortVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getBigDecimal("shortVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getBigInteger("shortVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getDate("shortVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + +// Attempt conversion from bytes + try { + testDO.getBoolean("bytesVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getByte("bytesVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getChar("bytesVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getDouble("bytesVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getFloat("bytesVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getInt("bytesVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getLong("bytesVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getShort("bytesVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getBigDecimal("bytesVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getDate("bytesVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + +// Attempt conversion from decimal + try { + testDO.getBoolean("decimalVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getByte("decimalVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getChar("decimalVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getShort("decimalVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getBytes("decimalVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getDate("decimalVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + +// Attempt conversion from BigInteger + try { + testDO.getBoolean("integerVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getByte("integerVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getChar("integerVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getShort("integerVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getDate("integerVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + +// Attempt conversion from date + try { + testDO.getBoolean("dateVal"); + } catch (ClassCastException e) { + // success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getByte("dateVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getChar("dateVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getDouble("dateVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getFloat("dateVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getInt("dateVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getShort("dateVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getBytes("dateVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getBigDecimal("dateVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + try { + testDO.getBigInteger("dateVal"); + } catch (ClassCastException e) { +// success - do nothing + } catch (Exception e) { + fail("Attempted implicit unsupported conversion did not throw the correct Exception. Expected: ClassCastException. Received: " + e.getClass().getName()); + } + } + + + /** + * Verifies the following statement. + * Mixing single-valued and multi-valued Property access results in + * ClassCastException. + */ + public void testMixSingleMultiValueClassCastException() { + Property testedProp = testDO.getInstanceProperty("intVal"); + List properties = testDO.getInstanceProperties(); + Property currProp; + int testedIndex = -1, i = 0, size = properties.size(); + + while (testedIndex < 0 && i < size) { + currProp = (Property) properties.get(i); + + if (currProp.equals(testedProp)) + testedIndex = i; + i++; + } + + try { + testDO.getList("intVal"); + fail("getList(string) should throw a ClassCastException when the property represented by string is single-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getList(string) should throw a ClassCastException when the property represented by string is single-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getList(testedProp); + fail("getList(property) should throw a ClassCastException when the property represented by property is single-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getList(property) should throw a ClassCastException when the property represented by property is single-valued. " + e.getClass().getName() + " was thrown."); + } + + assertTrue("The test case could not procede because the index of the single-valued Property was not found.", testedIndex > -1); + + try { + testDO.getList(testedIndex); + fail("getList(index) should throw a ClassCastException when the property represented by index is single-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getList(index) should throw a ClassCastException when the property represented by index is single-valued. " + e.getClass().getName() + " was thrown."); + } + + testedProp = testDO.getInstanceProperty("listVal"); + testedIndex = -1; + i = 0; + while (testedIndex < 0 && i < size) { + currProp = (Property) properties.get(i); + if (currProp.equals(testedProp)) + testedIndex = i; + i++; + } + + try { + testDO.getBoolean("listVal"); + fail("getBoolean(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBoolean(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getByte("listVal"); + fail("getByte(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getByte(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getChar("listVal"); + fail("getChar(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getChar(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getDouble("listVal"); + fail("getDouble(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getDouble(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getFloat("listVal"); + fail("getFloat(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getFloat(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getInt("listVal"); + fail("getInt(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getInt(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getLong("listVal"); + fail("getLong(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getLong(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getShort("listVal"); + fail("getShort(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getShort(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getBytes("listVal"); + fail("getBytes(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBytes(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getBigDecimal("listVal"); + fail("getBigDecimal(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBigDecimal(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getBigInteger("listVal"); + fail("getBigInteger(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBigInteger(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getDataObject("listVal"); + fail("getDataObject(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getDataObject(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getDate("listVal"); + fail("getDate(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getDate(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getString("listVal"); + fail("getString(string) should throw a ClassCastException when the property represented by string is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getString(string) should throw a ClassCastException when the property represented by string is multi-valued. " + e.getClass().getName() + " was thrown."); + } + + try { + testDO.getBoolean(testedProp); + fail("getBoolean(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBoolean(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getByte(testedProp); + fail("getByte(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getByte(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getChar(testedProp); + fail("getChar(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getChar(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getDouble(testedProp); + fail("getDouble(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getDouble(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getFloat(testedProp); + fail("getFloat(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getFloat(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getInt(testedProp); + fail("getInt(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getInt(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getLong(testedProp); + fail("getLong(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getLong(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getShort(testedProp); + fail("getShort(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getShort(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getBytes(testedProp); + fail("getBytes(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBytes(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getBigDecimal(testedProp); + fail("getBigDecimal(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBigDecimal(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getBigInteger(testedProp); + fail("getBigInteger(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBigInteger(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getDataObject(testedProp); + fail("getDataObject(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getDataObject(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getDate(testedProp); + fail("getDate(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getDate(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getString(testedProp); + fail("getString(property) should throw a ClassCastException when the property represented by property is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getString(property) should throw a ClassCastException when the property represented by property is multi-valued. " + e.getClass().getName() + " was thrown."); + } + + assertTrue("The test case could not procede because the index of the multi-valued Property was not found.", testedIndex > -1); + + try { + testDO.getBoolean(testedIndex); + fail("getBoolean(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBoolean(index) should throw a ClassCastException when the property represented by is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getByte(testedIndex); + fail("getByte(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getByte(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getChar(testedIndex); + fail("getChar(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getChar(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getDouble(testedIndex); + fail("getDouble(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getDouble(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getFloat(testedIndex); + fail("getFloat(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getFloat(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getInt(testedIndex); + fail("getInt(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getInt(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getLong(testedIndex); + fail("getLong(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getLong(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getShort(testedIndex); + fail("getShort(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getShort(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getBytes(testedIndex); + fail("getBytes(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBytes(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getBigDecimal(testedIndex); + fail("getBigDecimal(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBigDecimal(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getBigInteger(testedIndex); + fail("getBigInteger(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getBigInteger(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getDataObject(testedIndex); + fail("getDataObject(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getDataObject(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getDate(testedIndex); + fail("getDate(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getDate(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); + } + try { + testDO.getString(testedIndex); + fail("getString(index) should throw a ClassCastException when the property represented by index is multi-valued. No Exception was thrown."); + } catch (ClassCastException e) { + // Success - do nothing + } catch (Exception e) { + fail("getString(index) should throw a ClassCastException when the property represented by index is multi-valued. " + e.getClass().getName() + " was thrown."); + } + } + + /* + /** + * Verifies the following statement. + * Establishing circular containment results in an IllegalArgumentException. + * Note: This test case will not be implemented because it has been determined + * that the statement will be removed from the spec. + */ + /* + public void testContainmentCycleIllegalArgumentException() { + // This test case will not be implemented. + } + */ + + /** + * Verifies the following statement. + * An empty DataGraph can have a root assigned by the createRootObject() methods. + * However, if a previous root DataObject exists than an IllegalStateException is + * thrown. + */ + public void testCreateRootObjectAgainIllegalStateException() { + DataGraph dataGraph = SDOUtil.createDataGraph(); + Type type = testDO.getType(); + + // verify the initial condition + assertNull("The DataGraph should have been created without a root DataObject.", dataGraph.getRootObject()); + assertNotNull("DataObject.getType() returned null.", type); + + dataGraph.createRootObject(type); + + // verify the pre-condition + assertNotNull("The DataGraph.createRootObject() should have created a root DataObject for the DataGraph.", dataGraph.getRootObject()); + + try { + dataGraph.createRootObject(type); + fail("DataGraph.createRootObject(Type) should throw an IllegalStateException a root Object already exists for the DataGraph. No Exception was thrown."); + } catch (IllegalStateException e) { + // Success - do nothing + } catch (Exception e) { + fail("DataGraph.createRootObject(Type) should throw an IllegalStateException a root Object already exists for the DataGraph. " + e.getClass().getName() + " was thrown."); + } + } + + /** + * Verifies the following statement. + * DataFactory.create() throws an IllegalArgumentException if the instanceClass does + * not correspond to a Type this factory can instantiate. + */ + public void testDataFactoryCreateIllegalArgumentException() { + try { + helperContext.getDataFactory().create(java.lang.Object.class); + fail("DataFactory.create(Object) should throw an IllegalArgumentException when it cannot instantiate the Type specified. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("DataFactory.create(Object) should throw an IllegalArgumentException when it cannot instantiate the Type specified. " + e.getClass().getName() + " was thrown."); + } + + try { + helperContext.getDataFactory().create(commonj.sdo.DataObject.class); + fail("DataFactory.create(DataObject) should throw an IllegalArgumentException when it cannot instantiate the Type specified. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("DataFactory.create(DataObject) should throw an IllegalArgumentException when it cannot instantiate the Type specified. " + e.getClass().getName() + " was thrown."); + } + + try { + helperContext.getDataFactory().create(commonj.sdo.ChangeSummary.class); + fail("DataFactory.create(ChangeSummary) should throw an IllegalArgumentException when it cannot instantiate the Type specified. No Exception was thrown."); + } catch (IllegalArgumentException e) { + // Success - do nothing + } catch (Exception e) { + fail("DataFactory.create(ChangeSummary) should throw an IllegalArgumentException when it cannot instantiate the Type specified. " + e.getClass().getName() + " was thrown."); + } + } + + /** + * Defines the Type the first time through. + */ + public void setUp() { + if (!typeDefined) { + helperContext = SDOUtil.createHelperContext(); +// createWithXSD(helperContext); +// createDynamically(helperContext); + createStatically(helperContext); + typeDefined = true; + } +// testDO = helperContext.getDataFactory().create(TEST_URI, TEST_TYPE_NAME); +// seqDO = helperContext.getDataFactory().create(TEST_URI, SEQ_TYPE_NAME); + testDO = (DataObject) ExpectedExceptionFactory.INSTANCE.createExpectedExceptionType(); + seqDO = (DataObject) ExpectedExceptionFactory.INSTANCE.createSequenceReadOnlyType(); + } + + public static void createStatically(HelperContext hc) { + ExpectedExceptionFactory.INSTANCE.register(hc); + } + + public static void createWithXSD(HelperContext hc) { + // Populate the meta data for the test model + URL url = ExpectedExceptionsTestCase.class.getResource("/expectedExceptions.xsd"); + try { + InputStream inputStream = url.openStream(); + hc.getXSDHelper().define(inputStream, url.toString()); + inputStream.close(); + } catch(IOException e) { + e.printStackTrace(); + } + } + + /** + * createDynamically() creates the SDO Types using the TypeHelper. This + * method should be kept in synch with the XSD used for + * createDynamicallyWithStaticResources. The same XSD is used for the static + * generation of SDO Types using XSD2JavaGenerator. + */ + public static void createDynamically(HelperContext hc) { + + TypeHelper types = hc.getTypeHelper(); + Type stringType = types.getType("commonj.sdo", "String"); + Type intType = types.getType("commonj.sdo", "Int"); + Type booleanType = types.getType("commonj.sdo", "Boolean"); + Type byteType = types.getType("commonj.sdo", "Byte"); + Type decimalType = types.getType("commonj.sdo", "Decimal"); + Type floatType = types.getType("commonj.sdo", "Float"); + Type doubleType = types.getType("commonj.sdo", "Double"); + Type dateType = types.getType("commonj.sdo", "Date"); + Type shortType = types.getType("commonj.sdo", "Short"); + Type longType = types.getType("commonj.sdo", "Long"); + Type bytesType = types.getType("commonj.sdo", "Bytes"); + Type integerType = types.getType("commonj.sdo", "Integer"); + Type charType = types.getType("commonj.sdo", "Character"); + + DataObject testType = hc.getDataFactory().create("commonj.sdo", "Type"); + testType.set("uri", TEST_URI); + testType.set("name", TEST_TYPE_NAME); + + DataObject stringProperty = testType.createDataObject("property"); + stringProperty.set("name", "stringVal"); + stringProperty.set("type", stringType); + + DataObject booleanProperty = testType.createDataObject("property"); + booleanProperty.set("name", "booleanVal"); + booleanProperty.set("type", booleanType); + + DataObject byteProperty = testType.createDataObject("property"); + byteProperty.set("name", "byteVal"); + byteProperty.set("type", byteType); + + DataObject decimalProperty = testType.createDataObject("property"); + decimalProperty.set("name", "decimalVal"); + decimalProperty.set("type", decimalType); + + DataObject intProperty = testType.createDataObject("property"); + intProperty.set("name", "intVal"); + intProperty.set("type", intType); + + DataObject floatProperty = testType.createDataObject("property"); + floatProperty.set("name", "floatVal"); + floatProperty.set("type", floatType); + + DataObject doubleProperty = testType.createDataObject("property"); + doubleProperty.set("name", "doubleVal"); + doubleProperty.set("type", doubleType); + + DataObject dateProperty = testType.createDataObject("property"); + dateProperty.set("name", "dateVal"); + dateProperty.set("type", dateType); + + DataObject shortProperty = testType.createDataObject("property"); + shortProperty.set("name", "shortVal"); + shortProperty.set("type", shortType); + + DataObject longProperty = testType.createDataObject("property"); + longProperty.set("name", "longVal"); + longProperty.set("type", longType); + + DataObject childrenProperty = testType.createDataObject("property"); + childrenProperty.set("name", "listVal"); + childrenProperty.setBoolean("many", true); + childrenProperty.set("type", stringType); + + DataObject bytesProperty = testType.createDataObject("property"); + bytesProperty.set("name", "bytesVal"); + bytesProperty.set("type", bytesType); + + DataObject integerProperty = testType.createDataObject("property"); + integerProperty.set("name", "integerVal"); + integerProperty.set("type", integerType); + + DataObject charProperty = testType.createDataObject("property"); + charProperty.set("name", "charVal"); + charProperty.set("type", charType); + + DataObject readOnlyProperty = testType.createDataObject("property"); + readOnlyProperty.set("name", "readOnlyVal"); + readOnlyProperty.set("type", stringType); + readOnlyProperty.setBoolean("readOnly", true); + + DataObject readOnlyListProperty = testType.createDataObject("property"); + readOnlyListProperty.set("name", "readOnlyListVal"); + readOnlyListProperty.set("type", stringType); + readOnlyListProperty.setBoolean("readOnly", true); + readOnlyListProperty.setBoolean("many", true); + + types.define(testType); + + DataObject seqType = hc.getDataFactory().create("commonj.sdo", "Type"); + seqType.set("uri", TEST_URI); + seqType.set("name", SEQ_TYPE_NAME); + seqType.setBoolean("sequenced", true); + + DataObject seqROProperty = seqType.createDataObject("property"); + seqROProperty.set("name", "readOnlyVal"); + seqROProperty.set("type", stringType); + seqROProperty.setBoolean("readOnly", true); + + DataObject seqROListProperty = seqType.createDataObject("property"); + seqROListProperty.set("name", "readOnlyListVal"); + seqROListProperty.set("type", stringType); + seqROListProperty.setBoolean("readOnly", true); + seqROListProperty.setBoolean("many", true); + + DataObject uniqueNameProperty = seqType.createDataObject("property"); + uniqueNameProperty.set("name", "uniqueName"); + uniqueNameProperty.set("type", stringType); + + types.define(seqType); + } } \ No newline at end of file diff --git a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/JavaSerializeDeserializeTestCase.java b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/JavaSerializeDeserializeTestCase.java index 56a293cde0..df69555d76 100644 --- a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/JavaSerializeDeserializeTestCase.java +++ b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/JavaSerializeDeserializeTestCase.java @@ -1,297 +1,297 @@ -/** - * - * 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.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.ArrayList; -import java.util.List; - -import junit.framework.TestCase; - -import org.apache.tuscany.sdo.util.SDOUtil; - -import commonj.sdo.DataGraph; -import commonj.sdo.DataObject; -import commonj.sdo.Type; -import commonj.sdo.helper.DataFactory; -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.TypeHelper; - -public class JavaSerializeDeserializeTestCase extends TestCase -{ - - public void testScopeDefinedSerializeDeserializeOfDataObject() - { - HelperContext hc = SDOUtil.createHelperContext(); - Object originalDataObject = createDynamically(hc,true); - - runSerializeDeserialize((DataObject)originalDataObject, hc); - } - - public void testScopeDefinedSerializeDeserializeOfDataGraph() - { - HelperContext hc = SDOUtil.createHelperContext(); - DataGraph testDO = (DataGraph)createDynamically(hc,false); - - runSerializeDeserializeWithDataGraph(testDO, hc); - } - - private String xsdString = "" + - "" + - "" + - "" + - "" + - "" + - "" + - "" + - "" + - - "" + - "" + - "" + - "" + - "" + - "" + - ""; - - public void testLargePayload() - { - HelperContext hc = SDOUtil.createHelperContext(); - hc.getXSDHelper().define(xsdString); - DataObject company = hc.getDataFactory().create("http://www.example.com/simple", "Company"); - company.setString("symbol", "EXAMPLE"); - company.setString("companyName", "Example Inc."); - List employees = company.getList("employees"); - DataObject employee; - for (int i=0; i<1000; i++) { - employee = hc.getDataFactory().create("http://www.example.com/simple", "Employee"); - employee.setString("employeeID", "ID #" + i); - employee.setString("employeeName", "Empoyee #" + i); - employees.add(employee); - } - try { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ObjectOutputStream oos = SDOUtil.createObjectOutputStream(bos, hc); - oos.writeObject(company); - oos.flush(); - byte[] bytes = bos.toByteArray(); - oos.close(); - bos.close(); - - ByteArrayInputStream bis = new ByteArrayInputStream(bytes); - ObjectInputStream ois = SDOUtil.createObjectInputStream(bis, hc); - ois.readObject(); - ois.close(); - bis.close(); - } - catch (Exception e) { - e.printStackTrace(); - fail("An Exception occurred while deserializing the output of the serialization: " + e.toString()); - } - } - - - /** - * Serialize the DataObject then Deserialize the output. - * to testDO. - * @param testDO - * @param scope - */ - - public void runSerializeDeserialize(DataObject originalDataObject, HelperContext hc) - { - - populateFields(originalDataObject); - DataObject tempDO = null; - ByteArrayOutputStream baos = null; - - try - { - baos = serialize(originalDataObject, hc); - - } - catch (Exception e) - { - e.printStackTrace(); - fail("An Exception occurred while serializing the DataObject: " + e.toString()); - } - - try - { - tempDO = deserialize(baos, hc); - - } - catch (Exception e) - { - e.printStackTrace(); - fail("An Exception occurred while deserializing the output of the serialization: " + e.toString()); - } - - assertNotNull("Deserialization returned a null value.", tempDO); - - assertSame(tempDO.getType(), originalDataObject.getType()); - - - } - - /** - * Serialize the DataGraph - * @param dataGraph - * @param scope - */ - public void runSerializeDeserializeWithDataGraph(DataGraph dataGraph, HelperContext hc) - { - DataObject originalDataObject = dataGraph.getRootObject(); - populateFields(originalDataObject); - DataObject tempDO = null; - ByteArrayOutputStream baos = null; - - try - { - baos = serialize(dataGraph, hc); - - } - catch (Exception e) - { - e.printStackTrace(); - fail("An Exception occurred while serializing the DataObject: " + e.toString()); - } - - try - { - tempDO = deserialize(baos, hc); - - } - catch (Exception e) - { - e.printStackTrace(); - fail("An Exception occurred while deserializing the output of the serialization: " + e.toString()); - } - - assertNotNull("Deserialization returned a null value.", tempDO); - - assertSame(tempDO.getType(), originalDataObject.getType()); - - - - } - - /** - * serializeDataObject is a private method to be called by the other methods - * in the ScrenarioLibrary - * - * @param dataObject - * @param fileName - * @throws IOException - */ - public ByteArrayOutputStream serialize(Object object, HelperContext hc) throws IOException - { - //FileOutputStream fos = new FileOutputStream("temp"); - ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream(); - ObjectOutputStream out = SDOUtil.createObjectOutputStream(byteArrayOutput, hc); - out.writeObject(object); - out.close(); - return byteArrayOutput; - } - - /** - * deserializeDataObject is a private method to be called by the other - * methods in the ScrenarioLibrary - * - * @param fileName - * @return - * @throws IOException - * @throws ClassNotFoundException - */ - public DataObject deserialize(ByteArrayOutputStream baos, HelperContext hc) throws IOException, ClassNotFoundException - { - //FileInputStream fis = new FileInputStream("temp"); - ObjectInputStream input = null; - ByteArrayInputStream byteArrayInput = new ByteArrayInputStream(baos.toByteArray()); - - input = SDOUtil.createObjectInputStream(byteArrayInput, hc); - - Object object = input.readObject(); - input.close(); - if(object instanceof DataGraph) - return ((DataGraph)object).getRootObject(); - else - return (DataObject)object; - } - - /** - * populateFields uses set to set each of the fields in the - * DataObject. It is used to ensure a known set of expected values that are - * not other than the default values for the various fields. - * - * @param testDO - * @throws ExpectedConditionError - */ - public static void populateFields(DataObject testDO) - { - - testDO.setString("stringVal", "Testing"); - - } - /** - * createDynamically() creates the SDO Types using the TypeHelper. This method should be kept in - * synch with the XSD used for createDynamicallyWithStaticResources. The same XSD is used for - * the static generation of SDO Types using XSD2JavaGenerator. - */ - public Object createDynamically(HelperContext hc, boolean createDataObject) - { - - TypeHelper types = hc.getTypeHelper(); - DataFactory dataFactory = hc.getDataFactory(); - - Type stringType = types.getType("commonj.sdo", "String"); - - DataObject testType = dataFactory.create("commonj.sdo", "Type"); - testType.set("uri", "http://www.example.com/api_test"); - testType.set("name", "APITest"); - - DataObject stringProperty = testType.createDataObject("property"); - stringProperty.set("name", "stringVal"); - stringProperty.set("type", stringType); - - - List types2Define = new ArrayList(); - types2Define.add(testType); - List apiXSD = types.define(types2Define); - Type apiXSDType = (Type) apiXSD.get(0); - - if(createDataObject) - return dataFactory.create(apiXSDType);; - - // Create an empty DataGraph and attach the document root to it. Otherwise, where is the documentRoot ? - DataGraph dataGraph = SDOUtil.createDataGraph(); - /*DataObject testDO =*/ dataGraph.createRootObject(apiXSDType); - - - return dataGraph; - - } -} +/** + * + * 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.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.DataGraph; +import commonj.sdo.DataObject; +import commonj.sdo.Type; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.TypeHelper; + +public class JavaSerializeDeserializeTestCase extends TestCase +{ + + public void testScopeDefinedSerializeDeserializeOfDataObject() + { + HelperContext hc = SDOUtil.createHelperContext(); + Object originalDataObject = createDynamically(hc,true); + + runSerializeDeserialize((DataObject)originalDataObject, hc); + } + + public void testScopeDefinedSerializeDeserializeOfDataGraph() + { + HelperContext hc = SDOUtil.createHelperContext(); + DataGraph testDO = (DataGraph)createDynamically(hc,false); + + runSerializeDeserializeWithDataGraph(testDO, hc); + } + + private String xsdString = "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + public void testLargePayload() + { + HelperContext hc = SDOUtil.createHelperContext(); + hc.getXSDHelper().define(xsdString); + DataObject company = hc.getDataFactory().create("http://www.example.com/simple", "Company"); + company.setString("symbol", "EXAMPLE"); + company.setString("companyName", "Example Inc."); + List employees = company.getList("employees"); + DataObject employee; + for (int i=0; i<1000; i++) { + employee = hc.getDataFactory().create("http://www.example.com/simple", "Employee"); + employee.setString("employeeID", "ID #" + i); + employee.setString("employeeName", "Empoyee #" + i); + employees.add(employee); + } + try { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = SDOUtil.createObjectOutputStream(bos, hc); + oos.writeObject(company); + oos.flush(); + byte[] bytes = bos.toByteArray(); + oos.close(); + bos.close(); + + ByteArrayInputStream bis = new ByteArrayInputStream(bytes); + ObjectInputStream ois = SDOUtil.createObjectInputStream(bis, hc); + ois.readObject(); + ois.close(); + bis.close(); + } + catch (Exception e) { + e.printStackTrace(); + fail("An Exception occurred while deserializing the output of the serialization: " + e.toString()); + } + } + + + /** + * Serialize the DataObject then Deserialize the output. + * to testDO. + * @param testDO + * @param scope + */ + + public void runSerializeDeserialize(DataObject originalDataObject, HelperContext hc) + { + + populateFields(originalDataObject); + DataObject tempDO = null; + ByteArrayOutputStream baos = null; + + try + { + baos = serialize(originalDataObject, hc); + + } + catch (Exception e) + { + e.printStackTrace(); + fail("An Exception occurred while serializing the DataObject: " + e.toString()); + } + + try + { + tempDO = deserialize(baos, hc); + + } + catch (Exception e) + { + e.printStackTrace(); + fail("An Exception occurred while deserializing the output of the serialization: " + e.toString()); + } + + assertNotNull("Deserialization returned a null value.", tempDO); + + assertSame(tempDO.getType(), originalDataObject.getType()); + + + } + + /** + * Serialize the DataGraph + * @param dataGraph + * @param scope + */ + public void runSerializeDeserializeWithDataGraph(DataGraph dataGraph, HelperContext hc) + { + DataObject originalDataObject = dataGraph.getRootObject(); + populateFields(originalDataObject); + DataObject tempDO = null; + ByteArrayOutputStream baos = null; + + try + { + baos = serialize(dataGraph, hc); + + } + catch (Exception e) + { + e.printStackTrace(); + fail("An Exception occurred while serializing the DataObject: " + e.toString()); + } + + try + { + tempDO = deserialize(baos, hc); + + } + catch (Exception e) + { + e.printStackTrace(); + fail("An Exception occurred while deserializing the output of the serialization: " + e.toString()); + } + + assertNotNull("Deserialization returned a null value.", tempDO); + + assertSame(tempDO.getType(), originalDataObject.getType()); + + + + } + + /** + * serializeDataObject is a private method to be called by the other methods + * in the ScrenarioLibrary + * + * @param dataObject + * @param fileName + * @throws IOException + */ + public ByteArrayOutputStream serialize(Object object, HelperContext hc) throws IOException + { + //FileOutputStream fos = new FileOutputStream("temp"); + ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream(); + ObjectOutputStream out = SDOUtil.createObjectOutputStream(byteArrayOutput, hc); + out.writeObject(object); + out.close(); + return byteArrayOutput; + } + + /** + * deserializeDataObject is a private method to be called by the other + * methods in the ScrenarioLibrary + * + * @param fileName + * @return + * @throws IOException + * @throws ClassNotFoundException + */ + public DataObject deserialize(ByteArrayOutputStream baos, HelperContext hc) throws IOException, ClassNotFoundException + { + //FileInputStream fis = new FileInputStream("temp"); + ObjectInputStream input = null; + ByteArrayInputStream byteArrayInput = new ByteArrayInputStream(baos.toByteArray()); + + input = SDOUtil.createObjectInputStream(byteArrayInput, hc); + + Object object = input.readObject(); + input.close(); + if(object instanceof DataGraph) + return ((DataGraph)object).getRootObject(); + else + return (DataObject)object; + } + + /** + * populateFields uses set to set each of the fields in the + * DataObject. It is used to ensure a known set of expected values that are + * not other than the default values for the various fields. + * + * @param testDO + * @throws ExpectedConditionError + */ + public static void populateFields(DataObject testDO) + { + + testDO.setString("stringVal", "Testing"); + + } + /** + * createDynamically() creates the SDO Types using the TypeHelper. This method should be kept in + * synch with the XSD used for createDynamicallyWithStaticResources. The same XSD is used for + * the static generation of SDO Types using XSD2JavaGenerator. + */ + public Object createDynamically(HelperContext hc, boolean createDataObject) + { + + TypeHelper types = hc.getTypeHelper(); + DataFactory dataFactory = hc.getDataFactory(); + + Type stringType = types.getType("commonj.sdo", "String"); + + DataObject testType = dataFactory.create("commonj.sdo", "Type"); + testType.set("uri", "http://www.example.com/api_test"); + testType.set("name", "APITest"); + + DataObject stringProperty = testType.createDataObject("property"); + stringProperty.set("name", "stringVal"); + stringProperty.set("type", stringType); + + + List types2Define = new ArrayList(); + types2Define.add(testType); + List apiXSD = types.define(types2Define); + Type apiXSDType = (Type) apiXSD.get(0); + + if(createDataObject) + return dataFactory.create(apiXSDType);; + + // Create an empty DataGraph and attach the document root to it. Otherwise, where is the documentRoot ? + DataGraph dataGraph = SDOUtil.createDataGraph(); + /*DataObject testDO =*/ dataGraph.createRootObject(apiXSDType); + + + return dataGraph; + + } +} diff --git a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/MetadataInstancePropertiesTestCase.java b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/MetadataInstancePropertiesTestCase.java index 4bb0f3a061..885153b62e 100644 --- a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/MetadataInstancePropertiesTestCase.java +++ b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/MetadataInstancePropertiesTestCase.java @@ -1,243 +1,243 @@ -/** - * - * 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.InputStream; -import java.net.URL; -import java.util.List; - -import junit.framework.TestCase; - -import org.apache.tuscany.sdo.api.SDOUtil; - -import commonj.sdo.DataObject; -import commonj.sdo.Property; -import commonj.sdo.Type; -import commonj.sdo.helper.DataFactory; -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.TypeHelper; -import commonj.sdo.helper.XSDHelper; - - -public class MetadataInstancePropertiesTestCase extends TestCase -{ - private final String TEST_MODEL = "/TypePropertyMetadataInfo.xsd"; - private final String TEST_NAMESPACE = "http://www.example.com/metadata/retrievaltest"; - private final String DYNAMIC_TEST_NAMESPACE = "http://www.example.com/metadata/dynamicmetadata"; - - private HelperContext helperContext; - private TypeHelper typeHelper; - private XSDHelper xsdHelper; - private DataFactory dataFactory; - - public void testXSDTypeProperties() - { - // Note: We won't check the actual value of XSD instance properties yet since they're not defined - // in the SDO spec yet. - - //displayInstanceProperties(TEST_NAMESPACE); - - Type type = typeHelper.getType(TEST_NAMESPACE, "Example"); - assertTrue(getInstanceProperty(type, "appinfo") != null); - assertTrue(getInstanceProperty(type, "foo") == null); - - Property property = type.getProperty("number"); - assertTrue(getInstanceProperty(property, "appinfo") != null); - assertTrue(getInstanceProperty(property, "foo") == null); - - property = type.getProperty("Exampletype"); - assertTrue(getInstanceProperty(property, "appinfo") != null); - assertTrue(getInstanceProperty(property, "foo") == null); - - type = typeHelper.getType(TEST_NAMESPACE, "ExampleNumber"); - assertTrue(getInstanceProperty(type, "appinfo") != null); - assertTrue(getInstanceProperty(type, "minInclusive") != null); - assertTrue(getInstanceProperty(type, "maxInclusive") != null); - assertTrue(getInstanceProperty(type, "foo") == null); - - type = typeHelper.getType(TEST_NAMESPACE, "ExampleRating"); - assertTrue(getInstanceProperty(type, "enumeration") != null); - assertTrue(getInstanceProperty(type, "foo") == null); - - type = typeHelper.getType(TEST_NAMESPACE, "PhoneNumber"); - assertTrue(getInstanceProperty(type, "appinfo") != null); - assertTrue(getInstanceProperty(type, "length") != null); - assertTrue(getInstanceProperty(type, "pattern") != null); - assertTrue(getInstanceProperty(type, "foo") == null); - } - - public void testDynamicTypeProperties() - { - // Create dynamic model - Type intType = typeHelper.getType("commonj.sdo", "Int"); - Type stringType = typeHelper.getType("commonj.sdo", "String"); - - Property openContentProperty = typeHelper.getOpenContentProperty("commonj.sdo/xml", "xmlElement"); - - // create a new Type for Customers - DataObject customerType = dataFactory.create("commonj.sdo", "Type"); - customerType.set("uri", DYNAMIC_TEST_NAMESPACE); - customerType.set("name", "Customer"); - customerType.set(openContentProperty, Boolean.TRUE); - - // create a customer number property - DataObject custNumProperty = customerType.createDataObject("property"); - custNumProperty.set("name", "custNum"); - custNumProperty.set("type", intType); - - // create a first name property - DataObject firstNameProperty = - customerType.createDataObject("property"); - firstNameProperty.set("name", "firstName"); - firstNameProperty.set("type", stringType); - firstNameProperty.set(openContentProperty, Boolean.FALSE); - - // create a last name property - DataObject lastNameProperty = customerType.createDataObject("property"); - lastNameProperty.set("name", "lastName"); - lastNameProperty.set("type", stringType); - - // now define the Customer type so that customers can be made - typeHelper.define(customerType); - - //displayInstanceProperties(DYNAMIC_TEST_NAMESPACE); - - Type type = typeHelper.getType(DYNAMIC_TEST_NAMESPACE, "Customer"); - assertTrue(getInstanceProperty(type, "xmlElement") == openContentProperty); - assertTrue(type.get(openContentProperty) == Boolean.TRUE); - assertTrue(getInstanceProperty(type, "foo") == null); - - Property property = type.getProperty("custNum"); - assertTrue(getInstanceProperty(property, "xmlElement") == null); - assertTrue(getInstanceProperty(property, "foo") == null); - - property = type.getProperty("firstName"); - assertTrue(getInstanceProperty(property, "xmlElement") == openContentProperty); - assertTrue(property.get(openContentProperty) == Boolean.FALSE); - assertTrue(getInstanceProperty(property, "foo") == null); - - property = type.getProperty("lastName"); - assertTrue(getInstanceProperty(property, "xmlElement") == null); - assertTrue(getInstanceProperty(property, "foo") == null); - } - - //Amita - public void testEnumProperty() - { - Type type = typeHelper.getType(TEST_NAMESPACE, "ExampleRating"); - assertTrue(getInstanceProperty(type, "enumeration") != null); - List enumFacet = SDOUtil.getEnumerationFacet(type); - assertEquals(3, enumFacet.size()); - assertEquals("", enumFacet.get(0)); - assertEquals("Good", enumFacet.get(1)); - assertEquals("Bad", enumFacet.get(2)); - } - - //Amita - public void testPatternProperty() - { - Type type = typeHelper.getType(TEST_NAMESPACE, "PhoneNumber"); - assertTrue(getInstanceProperty(type, "pattern") != null); - List patternFacet = SDOUtil.getPatternFacet(type); - assertEquals(2, patternFacet.size()); - assertEquals("\\d{3}-\\d{4}", patternFacet.get(0)); - assertEquals("\\d{6}-\\d{8}", patternFacet.get(1)); - } - - public void setUp() throws Exception - { - super.setUp(); - - helperContext = SDOUtil.createHelperContext(); - - typeHelper = helperContext.getTypeHelper(); - xsdHelper = helperContext.getXSDHelper(); - dataFactory = helperContext.getDataFactory(); - - URL url = getClass().getResource(TEST_MODEL); - InputStream inputStream = url.openStream(); - - xsdHelper.define(inputStream, url.toString()); - inputStream.close(); - } - - public Property getInstanceProperty(Type type, String propertyName) - { - return getInstanceProperty(type.getInstanceProperties(), propertyName); - } - - public Property getInstanceProperty(Property property, String propertyName) - { - return getInstanceProperty(property.getInstanceProperties(), propertyName); - } - - private Property getInstanceProperty(List instProps, String propertyName) - { - for (int i = 0; i < instProps.size(); i++) - { - Property prop = (Property)instProps.get(i); - if (propertyName.equals(prop.getName())) - return prop; - } - return null; - } - - private void displayInstanceProperties(Type type) - { - System.out.println("Type's name: " + type.getName()); - List instProps = type.getInstanceProperties(); - for (int i = 0; i < instProps.size(); i++) - { - Property prop = (Property)instProps.get(i); - System.out.println("\tType's instance property name: " + prop.getName()); - System.out.println("\tType's instance property value: \"" + type.get(prop) + "\""); - } - } - - private void displayInstanceProperties(Property prop) - { - System.out.println("\tProperty's name: " + prop.getName()); - List propsInstProps = prop.getInstanceProperties(); - for (int j = 0; j < propsInstProps.size(); j++) - { - Property propsInstProp = (Property)propsInstProps.get(j); - System.out.println("\t\tProperty's instance property name: " + propsInstProp.getName()); - System.out.println("\t\tProperty's instance property value: \"" + prop.get(propsInstProp) + "\""); - } - } - - public void displayInstanceProperties(String namespace) - { - List types = SDOUtil.getTypes(helperContext, namespace); - for (int i = 0; i < types.size(); i++) - { - Type type = (Type)types.get(i); - displayInstanceProperties(type); - List properties = type.getProperties(); - for (int j = 0; j < properties.size(); j++) - { - Property property = (Property)properties.get(j); - displayInstanceProperties(property); - } - System.out.println("**************************************"); - } - } - -} +/** + * + * 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.InputStream; +import java.net.URL; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.api.SDOUtil; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Type; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XSDHelper; + + +public class MetadataInstancePropertiesTestCase extends TestCase +{ + private final String TEST_MODEL = "/TypePropertyMetadataInfo.xsd"; + private final String TEST_NAMESPACE = "http://www.example.com/metadata/retrievaltest"; + private final String DYNAMIC_TEST_NAMESPACE = "http://www.example.com/metadata/dynamicmetadata"; + + private HelperContext helperContext; + private TypeHelper typeHelper; + private XSDHelper xsdHelper; + private DataFactory dataFactory; + + public void testXSDTypeProperties() + { + // Note: We won't check the actual value of XSD instance properties yet since they're not defined + // in the SDO spec yet. + + //displayInstanceProperties(TEST_NAMESPACE); + + Type type = typeHelper.getType(TEST_NAMESPACE, "Example"); + assertTrue(getInstanceProperty(type, "appinfo") != null); + assertTrue(getInstanceProperty(type, "foo") == null); + + Property property = type.getProperty("number"); + assertTrue(getInstanceProperty(property, "appinfo") != null); + assertTrue(getInstanceProperty(property, "foo") == null); + + property = type.getProperty("Exampletype"); + assertTrue(getInstanceProperty(property, "appinfo") != null); + assertTrue(getInstanceProperty(property, "foo") == null); + + type = typeHelper.getType(TEST_NAMESPACE, "ExampleNumber"); + assertTrue(getInstanceProperty(type, "appinfo") != null); + assertTrue(getInstanceProperty(type, "minInclusive") != null); + assertTrue(getInstanceProperty(type, "maxInclusive") != null); + assertTrue(getInstanceProperty(type, "foo") == null); + + type = typeHelper.getType(TEST_NAMESPACE, "ExampleRating"); + assertTrue(getInstanceProperty(type, "enumeration") != null); + assertTrue(getInstanceProperty(type, "foo") == null); + + type = typeHelper.getType(TEST_NAMESPACE, "PhoneNumber"); + assertTrue(getInstanceProperty(type, "appinfo") != null); + assertTrue(getInstanceProperty(type, "length") != null); + assertTrue(getInstanceProperty(type, "pattern") != null); + assertTrue(getInstanceProperty(type, "foo") == null); + } + + public void testDynamicTypeProperties() + { + // Create dynamic model + Type intType = typeHelper.getType("commonj.sdo", "Int"); + Type stringType = typeHelper.getType("commonj.sdo", "String"); + + Property openContentProperty = typeHelper.getOpenContentProperty("commonj.sdo/xml", "xmlElement"); + + // create a new Type for Customers + DataObject customerType = dataFactory.create("commonj.sdo", "Type"); + customerType.set("uri", DYNAMIC_TEST_NAMESPACE); + customerType.set("name", "Customer"); + customerType.set(openContentProperty, Boolean.TRUE); + + // create a customer number property + DataObject custNumProperty = customerType.createDataObject("property"); + custNumProperty.set("name", "custNum"); + custNumProperty.set("type", intType); + + // create a first name property + DataObject firstNameProperty = + customerType.createDataObject("property"); + firstNameProperty.set("name", "firstName"); + firstNameProperty.set("type", stringType); + firstNameProperty.set(openContentProperty, Boolean.FALSE); + + // create a last name property + DataObject lastNameProperty = customerType.createDataObject("property"); + lastNameProperty.set("name", "lastName"); + lastNameProperty.set("type", stringType); + + // now define the Customer type so that customers can be made + typeHelper.define(customerType); + + //displayInstanceProperties(DYNAMIC_TEST_NAMESPACE); + + Type type = typeHelper.getType(DYNAMIC_TEST_NAMESPACE, "Customer"); + assertTrue(getInstanceProperty(type, "xmlElement") == openContentProperty); + assertTrue(type.get(openContentProperty) == Boolean.TRUE); + assertTrue(getInstanceProperty(type, "foo") == null); + + Property property = type.getProperty("custNum"); + assertTrue(getInstanceProperty(property, "xmlElement") == null); + assertTrue(getInstanceProperty(property, "foo") == null); + + property = type.getProperty("firstName"); + assertTrue(getInstanceProperty(property, "xmlElement") == openContentProperty); + assertTrue(property.get(openContentProperty) == Boolean.FALSE); + assertTrue(getInstanceProperty(property, "foo") == null); + + property = type.getProperty("lastName"); + assertTrue(getInstanceProperty(property, "xmlElement") == null); + assertTrue(getInstanceProperty(property, "foo") == null); + } + + //Amita + public void testEnumProperty() + { + Type type = typeHelper.getType(TEST_NAMESPACE, "ExampleRating"); + assertTrue(getInstanceProperty(type, "enumeration") != null); + List enumFacet = SDOUtil.getEnumerationFacet(type); + assertEquals(3, enumFacet.size()); + assertEquals("", enumFacet.get(0)); + assertEquals("Good", enumFacet.get(1)); + assertEquals("Bad", enumFacet.get(2)); + } + + //Amita + public void testPatternProperty() + { + Type type = typeHelper.getType(TEST_NAMESPACE, "PhoneNumber"); + assertTrue(getInstanceProperty(type, "pattern") != null); + List patternFacet = SDOUtil.getPatternFacet(type); + assertEquals(2, patternFacet.size()); + assertEquals("\\d{3}-\\d{4}", patternFacet.get(0)); + assertEquals("\\d{6}-\\d{8}", patternFacet.get(1)); + } + + public void setUp() throws Exception + { + super.setUp(); + + helperContext = SDOUtil.createHelperContext(); + + typeHelper = helperContext.getTypeHelper(); + xsdHelper = helperContext.getXSDHelper(); + dataFactory = helperContext.getDataFactory(); + + URL url = getClass().getResource(TEST_MODEL); + InputStream inputStream = url.openStream(); + + xsdHelper.define(inputStream, url.toString()); + inputStream.close(); + } + + public Property getInstanceProperty(Type type, String propertyName) + { + return getInstanceProperty(type.getInstanceProperties(), propertyName); + } + + public Property getInstanceProperty(Property property, String propertyName) + { + return getInstanceProperty(property.getInstanceProperties(), propertyName); + } + + private Property getInstanceProperty(List instProps, String propertyName) + { + for (int i = 0; i < instProps.size(); i++) + { + Property prop = (Property)instProps.get(i); + if (propertyName.equals(prop.getName())) + return prop; + } + return null; + } + + private void displayInstanceProperties(Type type) + { + System.out.println("Type's name: " + type.getName()); + List instProps = type.getInstanceProperties(); + for (int i = 0; i < instProps.size(); i++) + { + Property prop = (Property)instProps.get(i); + System.out.println("\tType's instance property name: " + prop.getName()); + System.out.println("\tType's instance property value: \"" + type.get(prop) + "\""); + } + } + + private void displayInstanceProperties(Property prop) + { + System.out.println("\tProperty's name: " + prop.getName()); + List propsInstProps = prop.getInstanceProperties(); + for (int j = 0; j < propsInstProps.size(); j++) + { + Property propsInstProp = (Property)propsInstProps.get(j); + System.out.println("\t\tProperty's instance property name: " + propsInstProp.getName()); + System.out.println("\t\tProperty's instance property value: \"" + prop.get(propsInstProp) + "\""); + } + } + + public void displayInstanceProperties(String namespace) + { + List types = SDOUtil.getTypes(helperContext, namespace); + for (int i = 0; i < types.size(); i++) + { + Type type = (Type)types.get(i); + displayInstanceProperties(type); + List properties = type.getProperties(); + for (int j = 0; j < properties.size(); j++) + { + Property property = (Property)properties.get(j); + displayInstanceProperties(property); + } + System.out.println("**************************************"); + } + } + +} diff --git a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/NeverStaleChangeSummaryTestCase.java b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/NeverStaleChangeSummaryTestCase.java index 69c8e447df..544672a8b1 100644 --- a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/NeverStaleChangeSummaryTestCase.java +++ b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/NeverStaleChangeSummaryTestCase.java @@ -1,76 +1,76 @@ -/** - * - * 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.InputStream; -import java.net.URL; - -import junit.framework.TestCase; - -import commonj.sdo.ChangeSummary; -import commonj.sdo.DataObject; -import commonj.sdo.Type; -import commonj.sdo.helper.DataFactory; -import commonj.sdo.helper.TypeHelper; -import commonj.sdo.helper.XSDHelper; - -public class NeverStaleChangeSummaryTestCase extends TestCase { - private final String TEST_MODEL = "/simpleWithChangeSummary.xsd"; - private final String TEST_NAMESPACE = "http://www.example.com/simpleCS"; - - /** - * Simple ChangeSummary test. - */ - public void testChangeSummary() throws Exception { - Type quoteType = TypeHelper.INSTANCE.getType(TEST_NAMESPACE, "RootQuote"); - DataObject quote = DataFactory.INSTANCE.create(quoteType); - - ChangeSummary cs = quote.getChangeSummary(); - - // Begin logging changes - // - cs.beginLogging(); - - DataObject child = quote.createDataObject("quotes"); - cs.isCreated(child); - child = quote.createDataObject("quotes"); - assertTrue(cs.isCreated(child)); - - // Stop logging changes and print the resulting data graph to stdout - // - cs.endLogging(); - - cs.isCreated(child); - - cs.undoChanges(); - - assertFalse(cs.isCreated(child)); - } - - protected void setUp() throws Exception { - super.setUp(); - - // Populate the meta data for the test (Stock Quote) model - URL url = getClass().getResource(TEST_MODEL); - InputStream inputStream = url.openStream(); - XSDHelper.INSTANCE.define(inputStream, url.toString()); - inputStream.close(); - } +/** + * + * 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.InputStream; +import java.net.URL; + +import junit.framework.TestCase; + +import commonj.sdo.ChangeSummary; +import commonj.sdo.DataObject; +import commonj.sdo.Type; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XSDHelper; + +public class NeverStaleChangeSummaryTestCase extends TestCase { + private final String TEST_MODEL = "/simpleWithChangeSummary.xsd"; + private final String TEST_NAMESPACE = "http://www.example.com/simpleCS"; + + /** + * Simple ChangeSummary test. + */ + public void testChangeSummary() throws Exception { + Type quoteType = TypeHelper.INSTANCE.getType(TEST_NAMESPACE, "RootQuote"); + DataObject quote = DataFactory.INSTANCE.create(quoteType); + + ChangeSummary cs = quote.getChangeSummary(); + + // Begin logging changes + // + cs.beginLogging(); + + DataObject child = quote.createDataObject("quotes"); + cs.isCreated(child); + child = quote.createDataObject("quotes"); + assertTrue(cs.isCreated(child)); + + // Stop logging changes and print the resulting data graph to stdout + // + cs.endLogging(); + + cs.isCreated(child); + + cs.undoChanges(); + + assertFalse(cs.isCreated(child)); + } + + protected void setUp() throws Exception { + super.setUp(); + + // Populate the meta data for the test (Stock Quote) model + URL url = getClass().getResource(TEST_MODEL); + InputStream inputStream = url.openStream(); + XSDHelper.INSTANCE.define(inputStream, url.toString()); + inputStream.close(); + } } \ No newline at end of file diff --git a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/NotificationTestCase.java b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/NotificationTestCase.java index 65765bd2d1..5d1637865b 100644 --- a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/NotificationTestCase.java +++ b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/NotificationTestCase.java @@ -1,186 +1,186 @@ -/** - * - * 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.io.InputStream; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; - -import junit.framework.TestCase; - -import org.apache.tuscany.sdo.api.SDOUtil; -import org.apache.tuscany.sdo.api.Event; -import org.apache.tuscany.sdo.impl.ListenerBase; - -import commonj.sdo.DataObject; -import commonj.sdo.Type; -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.TypeHelper; - -/** - * Test DataObject Property value change notification - */ -public class NotificationTestCase extends TestCase { - - HelperContext hc; - TypeHelper th; - - private class Observer extends ListenerBase { - - private int notificationCount; - private Event lastEvent; - - public int getNotificationCount() { - return notificationCount; - } - - public Event getLastEvent() { - return lastEvent; - } - - public Observer() { - notificationCount = 0; - } - - public void eventNotification(Event e) { - - if (e.getEventType() != Event.REMOVE_LISTENER) { - notificationCount++; - lastEvent = e; - } - } - - } - - public void testTransitions() throws IOException { - final String TEST_MODEL = "/simple.xsd"; - final String TEST_NAMESPACE = "http://www.example.com/simple"; - - // Populate the meta data for the test (Stock Quote) model - URL url = getClass().getResource(TEST_MODEL); - InputStream inputStream = url.openStream(); - hc.getXSDHelper().define(inputStream, url.toString()); - inputStream.close(); - - Type quoteType = th.getType(TEST_NAMESPACE, "Quote"); - DataObject quote = hc.getDataFactory().create(quoteType); - Observer o = new Observer(); - SDOUtil.addChangeListener(quote, o); - - Event e; - - String firstName = "FlyByNightTechnology"; - - int changeCount = 0; - - quote.setString("companyName", firstName); - assertEquals(++changeCount, o.getNotificationCount()); - e = o.getLastEvent(); - assertEquals(Event.SET, e.getEventType()); - assertEquals(null, e.getOldValue()); - assertFalse(e.wasSet()); - - quote.setString("companyName", "FBNT"); - e = o.getLastEvent(); - assertTrue(e.wasSet()); - - assertEquals(firstName, e.getOldValue()); - assertEquals(++changeCount, o.getNotificationCount()); - assertEquals("companyName", e.getProperty().getName()); - - SDOUtil.removeChangeListener(quote, o); - - quote.setString("companyName", "3rdValue"); - e = o.getLastEvent(); - - assertEquals(firstName, e.getOldValue()); - assertEquals(changeCount /* no ++ */, o.getNotificationCount()); - - SDOUtil.addChangeListener(quote, o); - - quote.setString("companyName", "3rdValue"); - assertEquals(++changeCount, o.getNotificationCount()); - e = o.getLastEvent(); - assertTrue(e.isTouch()); - assertTrue(e.wasSet()); - - quote.unset("companyName"); - assertEquals(++changeCount, o.getNotificationCount()); - e = o.getLastEvent(); - assertTrue(e.wasSet()); - - - quote.set("companyName", "4thValue"); - assertEquals(++changeCount, o.getNotificationCount()); - e = o.getLastEvent(); - assertFalse(e.wasSet()); - - assertEquals(Event.NO_INDEX, e.getPosition()); - - DataObject child = quote.createDataObject("quotes"); - assertEquals(++changeCount, o.getNotificationCount()); - e = o.getLastEvent(); - assertFalse(e.wasSet()); - assertEquals(0, e.getPosition()); - assertEquals(Event.ADD, e.getEventType()); - - DataObject child2 = quote.createDataObject("quotes"); - assertEquals(++changeCount, o.getNotificationCount()); - e = o.getLastEvent(); - assertTrue(e.wasSet()); // the quotes property was previously set to a non empty list - assertEquals(1, e.getPosition()); - - child2.setString("companyName", "subsidiary"); - - assertEquals(changeCount /* no ++ */, o.getNotificationCount()); // not monitoring the child - - quote.getList("quotes").clear(); - e = o.getLastEvent(); - assertEquals(++changeCount, o.getNotificationCount()); - assertEquals(Event.REMOVE_MANY, e.getEventType()); - - List newList = new ArrayList(); - - newList.add(hc.getDataFactory().create(quoteType)); - newList.add(hc.getDataFactory().create(quoteType)); - - quote.getList("quotes").addAll(newList); - e = o.getLastEvent(); - assertEquals(++changeCount, o.getNotificationCount()); - assertEquals(Event.ADD_MANY, e.getEventType()); - - - - - } - - - protected void setUp() throws Exception { - super.setUp(); - - hc = SDOUtil.createHelperContext(); - th = hc.getTypeHelper(); - - } - -} +/** + * + * 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.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.api.SDOUtil; +import org.apache.tuscany.sdo.api.Event; +import org.apache.tuscany.sdo.impl.ListenerBase; + +import commonj.sdo.DataObject; +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.TypeHelper; + +/** + * Test DataObject Property value change notification + */ +public class NotificationTestCase extends TestCase { + + HelperContext hc; + TypeHelper th; + + private class Observer extends ListenerBase { + + private int notificationCount; + private Event lastEvent; + + public int getNotificationCount() { + return notificationCount; + } + + public Event getLastEvent() { + return lastEvent; + } + + public Observer() { + notificationCount = 0; + } + + public void eventNotification(Event e) { + + if (e.getEventType() != Event.REMOVE_LISTENER) { + notificationCount++; + lastEvent = e; + } + } + + } + + public void testTransitions() throws IOException { + final String TEST_MODEL = "/simple.xsd"; + final String TEST_NAMESPACE = "http://www.example.com/simple"; + + // Populate the meta data for the test (Stock Quote) model + URL url = getClass().getResource(TEST_MODEL); + InputStream inputStream = url.openStream(); + hc.getXSDHelper().define(inputStream, url.toString()); + inputStream.close(); + + Type quoteType = th.getType(TEST_NAMESPACE, "Quote"); + DataObject quote = hc.getDataFactory().create(quoteType); + Observer o = new Observer(); + SDOUtil.addChangeListener(quote, o); + + Event e; + + String firstName = "FlyByNightTechnology"; + + int changeCount = 0; + + quote.setString("companyName", firstName); + assertEquals(++changeCount, o.getNotificationCount()); + e = o.getLastEvent(); + assertEquals(Event.SET, e.getEventType()); + assertEquals(null, e.getOldValue()); + assertFalse(e.wasSet()); + + quote.setString("companyName", "FBNT"); + e = o.getLastEvent(); + assertTrue(e.wasSet()); + + assertEquals(firstName, e.getOldValue()); + assertEquals(++changeCount, o.getNotificationCount()); + assertEquals("companyName", e.getProperty().getName()); + + SDOUtil.removeChangeListener(quote, o); + + quote.setString("companyName", "3rdValue"); + e = o.getLastEvent(); + + assertEquals(firstName, e.getOldValue()); + assertEquals(changeCount /* no ++ */, o.getNotificationCount()); + + SDOUtil.addChangeListener(quote, o); + + quote.setString("companyName", "3rdValue"); + assertEquals(++changeCount, o.getNotificationCount()); + e = o.getLastEvent(); + assertTrue(e.isTouch()); + assertTrue(e.wasSet()); + + quote.unset("companyName"); + assertEquals(++changeCount, o.getNotificationCount()); + e = o.getLastEvent(); + assertTrue(e.wasSet()); + + + quote.set("companyName", "4thValue"); + assertEquals(++changeCount, o.getNotificationCount()); + e = o.getLastEvent(); + assertFalse(e.wasSet()); + + assertEquals(Event.NO_INDEX, e.getPosition()); + + DataObject child = quote.createDataObject("quotes"); + assertEquals(++changeCount, o.getNotificationCount()); + e = o.getLastEvent(); + assertFalse(e.wasSet()); + assertEquals(0, e.getPosition()); + assertEquals(Event.ADD, e.getEventType()); + + DataObject child2 = quote.createDataObject("quotes"); + assertEquals(++changeCount, o.getNotificationCount()); + e = o.getLastEvent(); + assertTrue(e.wasSet()); // the quotes property was previously set to a non empty list + assertEquals(1, e.getPosition()); + + child2.setString("companyName", "subsidiary"); + + assertEquals(changeCount /* no ++ */, o.getNotificationCount()); // not monitoring the child + + quote.getList("quotes").clear(); + e = o.getLastEvent(); + assertEquals(++changeCount, o.getNotificationCount()); + assertEquals(Event.REMOVE_MANY, e.getEventType()); + + List newList = new ArrayList(); + + newList.add(hc.getDataFactory().create(quoteType)); + newList.add(hc.getDataFactory().create(quoteType)); + + quote.getList("quotes").addAll(newList); + e = o.getLastEvent(); + assertEquals(++changeCount, o.getNotificationCount()); + assertEquals(Event.ADD_MANY, e.getEventType()); + + + + + } + + + protected void setUp() throws Exception { + super.setUp(); + + hc = SDOUtil.createHelperContext(); + th = hc.getTypeHelper(); + + } + +} diff --git a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SequenceTestCase.java b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SequenceTestCase.java index b547f45d1c..e02ace5d2a 100644 --- a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SequenceTestCase.java +++ b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SequenceTestCase.java @@ -1,100 +1,100 @@ -/** - * - * 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.util.List; - -import junit.framework.TestCase; - -import org.apache.tuscany.sdo.util.SDOUtil; - -import commonj.sdo.DataObject; -import commonj.sdo.Property; -import commonj.sdo.Sequence; -import commonj.sdo.Type; -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.XSDHelper; - -public class SequenceTestCase extends TestCase { - HelperContext hc; - Type type; - Property localA, choiceX, choiceY, localB, open; - - String xml = ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""; - - protected void setUp() throws Exception { - super.setUp(); - hc = SDOUtil.createHelperContext(); - hc.getXSDHelper().define(xml); - type = hc.getTypeHelper().getType("testNS", "Sequenced"); - localA = type.getProperty("localA"); - choiceX = type.getProperty("choiceX"); - choiceY = type.getProperty("choiceY"); - localB = type.getProperty("localB"); - XSDHelper xsdHelper = hc.getXSDHelper(); - open = xsdHelper.getGlobalProperty("testNS", "open", true); - } - - public void testSequenced() { - DataObject dataObject = hc.getDataFactory().create(type); - Sequence sequence = dataObject.getSequence(); - - sequence.add(choiceX, "x1"); - sequence.add(0, localA, "a"); - sequence.add(choiceY, "y1"); - sequence.add(choiceX, "x2"); - sequence.add(localB, "b"); - sequence.add(open, "open"); - - List list = dataObject.getList(localA); - assertEquals(list.size(), 1); - assertEquals(list.get(0), "a"); - - assertEquals(dataObject.getString(localB), "b"); - - list = dataObject.getList(choiceX); - assertEquals(list.size(), 2); - assertEquals(list.get(0), "x1"); - assertEquals(list.get(1), "x2"); - - list = dataObject.getList(choiceY); - assertEquals(list.size(), 1); - assertEquals(list.get(0), "y1"); - - list = dataObject.getList(open); - assertEquals(list.size(), 1); - assertEquals(list.get(0), "open"); - } - -} +/** + * + * 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.util.List; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Sequence; +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XSDHelper; + +public class SequenceTestCase extends TestCase { + HelperContext hc; + Type type; + Property localA, choiceX, choiceY, localB, open; + + String xml = ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""; + + protected void setUp() throws Exception { + super.setUp(); + hc = SDOUtil.createHelperContext(); + hc.getXSDHelper().define(xml); + type = hc.getTypeHelper().getType("testNS", "Sequenced"); + localA = type.getProperty("localA"); + choiceX = type.getProperty("choiceX"); + choiceY = type.getProperty("choiceY"); + localB = type.getProperty("localB"); + XSDHelper xsdHelper = hc.getXSDHelper(); + open = xsdHelper.getGlobalProperty("testNS", "open", true); + } + + public void testSequenced() { + DataObject dataObject = hc.getDataFactory().create(type); + Sequence sequence = dataObject.getSequence(); + + sequence.add(choiceX, "x1"); + sequence.add(0, localA, "a"); + sequence.add(choiceY, "y1"); + sequence.add(choiceX, "x2"); + sequence.add(localB, "b"); + sequence.add(open, "open"); + + List list = dataObject.getList(localA); + assertEquals(list.size(), 1); + assertEquals(list.get(0), "a"); + + assertEquals(dataObject.getString(localB), "b"); + + list = dataObject.getList(choiceX); + assertEquals(list.size(), 2); + assertEquals(list.get(0), "x1"); + assertEquals(list.get(1), "x2"); + + list = dataObject.getList(choiceY); + assertEquals(list.size(), 1); + assertEquals(list.get(0), "y1"); + + list = dataObject.getList(open); + assertEquals(list.size(), 1); + assertEquals(list.get(0), "open"); + } + +} diff --git a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SerializeTypesTestCase.java b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SerializeTypesTestCase.java index 7fe1196eb6..a8e00d5eb2 100644 --- a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SerializeTypesTestCase.java +++ b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SerializeTypesTestCase.java @@ -1,190 +1,190 @@ -/** - * - * 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.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.util.ArrayList; -import java.util.List; - -import junit.framework.TestCase; - -import org.apache.tuscany.sdo.api.SDOUtil; - -import commonj.sdo.DataGraph; -import commonj.sdo.DataObject; -import commonj.sdo.Type; -import commonj.sdo.helper.DataFactory; -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.TypeHelper; -import commonj.sdo.helper.XMLDocument; - -public class SerializeTypesTestCase extends TestCase { - - HelperContext hc; - - protected void setUp() throws Exception { - super.setUp(); - hc = SDOUtil.createHelperContext(); - } - - public void testSerializeTypesRoundTrip() throws Exception { - TypeHelper types = hc.getTypeHelper(); - DataFactory factory = hc.getDataFactory(); - - Type intType = types.getType("commonj.sdo", "Int"); - Type stringType = types.getType("commonj.sdo", "String"); - - // create a new Type for Addresses - DataObject addressType = factory.create("commonj.sdo", "Type"); - addressType.set("uri", "http://example.com/address"); - addressType.set("name", "Address"); - - // create a address street property - DataObject addrStProperty = addressType.createDataObject("property"); - addrStProperty.set("name", "addrSt"); - addrStProperty.set("type", stringType); - - // create a new Type for Customers - DataObject customerType = factory.create("commonj.sdo", "Type"); - customerType.set("uri", "http://example.com/customer"); - customerType.set("name", "Customer"); - - // create a customer number property - DataObject custNumProperty = customerType.createDataObject("property"); - custNumProperty.set("name", "custNum"); - custNumProperty.set("type", intType); - - // create a first name property - DataObject firstNameProperty = customerType.createDataObject("property"); - firstNameProperty.set("name", "firstName"); - firstNameProperty.set("type", stringType); - - // create a last name property - DataObject lastNameProperty = customerType.createDataObject("property"); - lastNameProperty.set("name", "lastName"); - lastNameProperty.set("type", stringType); - - // create an address property - DataObject addressProperty = customerType.createDataObject("property"); - addressProperty.set("name", "address"); - addressProperty.set("type", addressType); - addressProperty.setBoolean("containment", true); - - // now define the Address and Customer type so that addresses and customers can be made - List types2define = new ArrayList(); - types2define.add(addressType); - types2define.add(customerType); - List typesDefined = types.define(types2define); - - // Create an empty data graph and add a root object, an instance of customerType - // - - DataGraph dataGraph = SDOUtil.createDataGraph(); - Type customerTypeDefined = (Type) typesDefined.get(1); - DataObject customer1 = dataGraph.createRootObject(customerTypeDefined); - - customer1.setInt("custNum", 1); - customer1.set("firstName", "John"); - customer1.set("lastName", "Adams"); - DataObject address = customer1.createDataObject("address"); - address.set("addrSt", "577 Airport Blvd"); - - SDOUtil.registerDataGraphTypes(dataGraph, typesDefined); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - SDOUtil.saveDataGraph(dataGraph, baos, null); - //SDOUtil.saveDataGraph(dataGraph, System.out, null); - - byte[] serialized = baos.toByteArray(); - ByteArrayInputStream bais = new ByteArrayInputStream(serialized); - DataGraph loadedDataGraph = SDOUtil.loadDataGraph(bais, null, hc); - - DataObject loadedRootObject = loadedDataGraph.getRootObject(); - assertNotSame(loadedRootObject.getType(), customer1.getType()); - - // EqualityHelper requires same Type - assertEquals(loadedRootObject.getInt("custNum"), customer1.getInt("custNum")); - assertEquals(loadedRootObject.get("firstName"), customer1.get("firstName")); - assertEquals(loadedRootObject.get("lastName"), customer1.get("lastName")); - DataObject loadedAddress = loadedRootObject.getDataObject("address"); - assertEquals(loadedAddress.get("addrSt"), address.get("addrSt")); - } - - private String xsdString = - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - ""; - - - private String testString = "Hello World"; - private String testStringInBase64 = "SGVsbG8gV29ybGQ="; - private String testStringInHex = "48656C6C6F20576F726C64"; - - public void testSerializeXSDBase64BinaryRoundTrip() throws Exception { - hc.getXSDHelper().define(xsdString); - - DataObject typeTest = hc.getDataFactory().create("http://www.example.com/simple", "BytesTypeTest"); - typeTest.setBytes("base64Binary", testString.getBytes()); - - String output = hc.getXMLHelper().save(typeTest, typeTest.getType().getURI(), "bytesTypeTest"); - - String startTag = ""; - String endTag = ""; - int start = output.indexOf(startTag) + startTag.length(); - int end = output.indexOf(endTag); - - String value = output.substring(start, end); - assertEquals(testStringInBase64, value); - - XMLDocument xmlDoc = hc.getXMLHelper().load(output); - typeTest = xmlDoc.getRootObject(); - assertEquals(testString, new String(typeTest.getBytes("base64Binary"))); - } - - public void testSerializeXSDHexBinaryRoundTrip() throws Exception { - hc.getXSDHelper().define(xsdString); - - DataObject typeTest = hc.getDataFactory().create("http://www.example.com/simple", "BytesTypeTest"); - typeTest.setBytes("hexBinary", testString.getBytes()); - - String output = hc.getXMLHelper().save(typeTest, typeTest.getType().getURI(), "bytesTypeTest"); - - String startTag = ""; - String endTag = ""; - int start = output.indexOf(startTag) + startTag.length(); - int end = output.indexOf(endTag); - - String value = output.substring(start, end); - assertEquals(testStringInHex, value); - - XMLDocument xmlDoc = hc.getXMLHelper().load(output); - typeTest = xmlDoc.getRootObject(); - assertEquals(testString, new String(typeTest.getBytes("hexBinary"))); - } -} +/** + * + * 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.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.api.SDOUtil; + +import commonj.sdo.DataGraph; +import commonj.sdo.DataObject; +import commonj.sdo.Type; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XMLDocument; + +public class SerializeTypesTestCase extends TestCase { + + HelperContext hc; + + protected void setUp() throws Exception { + super.setUp(); + hc = SDOUtil.createHelperContext(); + } + + public void testSerializeTypesRoundTrip() throws Exception { + TypeHelper types = hc.getTypeHelper(); + DataFactory factory = hc.getDataFactory(); + + Type intType = types.getType("commonj.sdo", "Int"); + Type stringType = types.getType("commonj.sdo", "String"); + + // create a new Type for Addresses + DataObject addressType = factory.create("commonj.sdo", "Type"); + addressType.set("uri", "http://example.com/address"); + addressType.set("name", "Address"); + + // create a address street property + DataObject addrStProperty = addressType.createDataObject("property"); + addrStProperty.set("name", "addrSt"); + addrStProperty.set("type", stringType); + + // create a new Type for Customers + DataObject customerType = factory.create("commonj.sdo", "Type"); + customerType.set("uri", "http://example.com/customer"); + customerType.set("name", "Customer"); + + // create a customer number property + DataObject custNumProperty = customerType.createDataObject("property"); + custNumProperty.set("name", "custNum"); + custNumProperty.set("type", intType); + + // create a first name property + DataObject firstNameProperty = customerType.createDataObject("property"); + firstNameProperty.set("name", "firstName"); + firstNameProperty.set("type", stringType); + + // create a last name property + DataObject lastNameProperty = customerType.createDataObject("property"); + lastNameProperty.set("name", "lastName"); + lastNameProperty.set("type", stringType); + + // create an address property + DataObject addressProperty = customerType.createDataObject("property"); + addressProperty.set("name", "address"); + addressProperty.set("type", addressType); + addressProperty.setBoolean("containment", true); + + // now define the Address and Customer type so that addresses and customers can be made + List types2define = new ArrayList(); + types2define.add(addressType); + types2define.add(customerType); + List typesDefined = types.define(types2define); + + // Create an empty data graph and add a root object, an instance of customerType + // + + DataGraph dataGraph = SDOUtil.createDataGraph(); + Type customerTypeDefined = (Type) typesDefined.get(1); + DataObject customer1 = dataGraph.createRootObject(customerTypeDefined); + + customer1.setInt("custNum", 1); + customer1.set("firstName", "John"); + customer1.set("lastName", "Adams"); + DataObject address = customer1.createDataObject("address"); + address.set("addrSt", "577 Airport Blvd"); + + SDOUtil.registerDataGraphTypes(dataGraph, typesDefined); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + SDOUtil.saveDataGraph(dataGraph, baos, null); + //SDOUtil.saveDataGraph(dataGraph, System.out, null); + + byte[] serialized = baos.toByteArray(); + ByteArrayInputStream bais = new ByteArrayInputStream(serialized); + DataGraph loadedDataGraph = SDOUtil.loadDataGraph(bais, null, hc); + + DataObject loadedRootObject = loadedDataGraph.getRootObject(); + assertNotSame(loadedRootObject.getType(), customer1.getType()); + + // EqualityHelper requires same Type + assertEquals(loadedRootObject.getInt("custNum"), customer1.getInt("custNum")); + assertEquals(loadedRootObject.get("firstName"), customer1.get("firstName")); + assertEquals(loadedRootObject.get("lastName"), customer1.get("lastName")); + DataObject loadedAddress = loadedRootObject.getDataObject("address"); + assertEquals(loadedAddress.get("addrSt"), address.get("addrSt")); + } + + private String xsdString = + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + + private String testString = "Hello World"; + private String testStringInBase64 = "SGVsbG8gV29ybGQ="; + private String testStringInHex = "48656C6C6F20576F726C64"; + + public void testSerializeXSDBase64BinaryRoundTrip() throws Exception { + hc.getXSDHelper().define(xsdString); + + DataObject typeTest = hc.getDataFactory().create("http://www.example.com/simple", "BytesTypeTest"); + typeTest.setBytes("base64Binary", testString.getBytes()); + + String output = hc.getXMLHelper().save(typeTest, typeTest.getType().getURI(), "bytesTypeTest"); + + String startTag = ""; + String endTag = ""; + int start = output.indexOf(startTag) + startTag.length(); + int end = output.indexOf(endTag); + + String value = output.substring(start, end); + assertEquals(testStringInBase64, value); + + XMLDocument xmlDoc = hc.getXMLHelper().load(output); + typeTest = xmlDoc.getRootObject(); + assertEquals(testString, new String(typeTest.getBytes("base64Binary"))); + } + + public void testSerializeXSDHexBinaryRoundTrip() throws Exception { + hc.getXSDHelper().define(xsdString); + + DataObject typeTest = hc.getDataFactory().create("http://www.example.com/simple", "BytesTypeTest"); + typeTest.setBytes("hexBinary", testString.getBytes()); + + String output = hc.getXMLHelper().save(typeTest, typeTest.getType().getURI(), "bytesTypeTest"); + + String startTag = ""; + String endTag = ""; + int start = output.indexOf(startTag) + startTag.length(); + int end = output.indexOf(endTag); + + String value = output.substring(start, end); + assertEquals(testStringInHex, value); + + XMLDocument xmlDoc = hc.getXMLHelper().load(output); + typeTest = xmlDoc.getRootObject(); + assertEquals(testString, new String(typeTest.getBytes("hexBinary"))); + } +} diff --git a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/TypeHelperTestCase.java b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/TypeHelperTestCase.java index 8fad877d4b..60a484290f 100644 --- a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/TypeHelperTestCase.java +++ b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/TypeHelperTestCase.java @@ -1,45 +1,45 @@ -/** - * - * 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.util.List; - -import junit.framework.TestCase; - -import org.apache.tuscany.sdo.api.SDOUtil; - -import commonj.sdo.helper.HelperContext; - - -public class TypeHelperTestCase extends TestCase { - - - HelperContext hc; - - protected void setUp() throws Exception { - super.setUp(); - hc = SDOUtil.createHelperContext(); - } - - public void testGetType() { - assertTrue(hc.getTypeHelper().getType(List.class) == null ); - } - -} +/** + * + * 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.util.List; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.api.SDOUtil; + +import commonj.sdo.helper.HelperContext; + + +public class TypeHelperTestCase extends TestCase { + + + HelperContext hc; + + protected void setUp() throws Exception { + super.setUp(); + hc = SDOUtil.createHelperContext(); + } + + public void testGetType() { + assertTrue(hc.getTypeHelper().getType(List.class) == null ); + } + +} diff --git a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XMLLoadOptionsTestCase.java b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XMLLoadOptionsTestCase.java index ac8d04b683..d58b070a90 100644 --- a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XMLLoadOptionsTestCase.java +++ b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XMLLoadOptionsTestCase.java @@ -1,192 +1,192 @@ -/** - * - * 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.io.StringReader; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import junit.framework.TestCase; - -import org.apache.tuscany.sdo.SDOPackage; -import org.apache.tuscany.sdo.api.SDOHelper; -import org.apache.tuscany.sdo.api.SDOUtil; -import org.apache.tuscany.sdo.api.XMLStreamHelper; -import org.eclipse.emf.ecore.resource.Resource; - -import commonj.sdo.DataObject; -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.XMLDocument; -import commonj.sdo.helper.XMLHelper; - -public class XMLLoadOptionsTestCase extends TestCase { - XMLHelper xmlHelper; - Map options; - - protected void setUp() throws Exception { - super.setUp(); - } - - //SDOUtil->SDOHelper->SDOHelperImpl->HelperContextImpl->XMLHelperImpl - public void testXMLOptionsSchema1() throws IOException{ - final String TEST_XML_DOCUMENT = "/SchemaLocationTestCase.xml"; - - options = new HashMap(); - options.put(SDOHelper.XMLOptions.XML_LOAD_SCHEMA, Boolean.TRUE); - - final XMLHelper xmlHelper = SDOUtil.createHelperContext(true, options).getXMLHelper(); - - final XMLDocument xmlDoc = xmlHelper.load(getClass().getResourceAsStream(TEST_XML_DOCUMENT), "whatever", null); - final DataObject root = xmlDoc.getRootObject(); - assertNotSame(root.getType(), SDOPackage.eINSTANCE.getAnyTypeDataObject()); - } - -// SDOUtil->SDOHelper->SDOHelperImpl->HelperContextImpl->XMLHelperImpl - public void testXMLOptionsSchema2() throws IOException{ - final String TEST_XML_DOCUMENT = "/SchemaLocationTestCase.xml"; - - options = new HashMap(); - options.put(SDOHelper.XMLOptions.XML_LOAD_SCHEMA, Boolean.FALSE); - final XMLHelper xmlHelper = SDOUtil.createHelperContext(true, options).getXMLHelper(); - final XMLDocument xmlDoc = xmlHelper.load(getClass().getResourceAsStream(TEST_XML_DOCUMENT), "whatever", null); - final DataObject root = xmlDoc.getRootObject(); - assertSame(root.getType(), SDOPackage.eINSTANCE.getAnyTypeDataObject()); - } - - public void testXMLOptionsLax1() throws IOException{ - options = new HashMap(); - /* - * turn off default behaviour of tolerating malformed xml - * tests using this option and bad xml should demonstrate failure to load - */ - options.put(SDOHelper.XMLOptions.XML_LOAD_LAX_FORM, new Integer(0)); - final HelperContext hc = SDOUtil.createHelperContext(true, options); - hc.getXSDHelper().define( - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""); - - final String xml=""+ - ""+ -""; - - /* - * this malformed xml will not load, as lax is forced OFF - * changing p:unqualifiedElement to unqualifiedElement - * will work */ - try{ - hc.getXMLHelper().load(new StringReader(xml), null, null); - fail(); - } catch (final Resource.IOWrappedException featureNotFound) { - assertTrue(true); - } - - } - - public void testXMLOptionsLax2() throws IOException{ - options = new HashMap(); - /* - * turn on default behaviour of tolerating malformed xml - * tests using this option and bad xml will load - */ - options.put(SDOHelper.XMLOptions.XML_LOAD_LAX_FORM, new Integer(1)); - final HelperContext hc = SDOUtil.createHelperContext(true, options); - hc.getXSDHelper().define( - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""); - - final String xml=""+ - ""+ - ""+ - ""; - - /* - * this malformed xml will load, as lax is forced ON - */ - assertNotNull(hc.getXMLHelper().load(new StringReader(xml), null, null).getRootObject()); - } - - //SDOUtil->SDOHelper->SDOHelperImpl->XMLStreamHelperImpl->XMLDocumentImpl - public void testXMLStreamHelper() throws IOException, XMLStreamException{ - options = new HashMap(); - /* - * turn off default behaviour of tolerating malformed xml - * tests using this option and bad xml will load - */ - options.put(SDOHelper.XMLOptions.XML_LOAD_LAX_FORM, new Integer(1)); - final HelperContext hc = SDOUtil.createHelperContext(false, options); - final XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(hc); - hc.getXSDHelper().define( - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""); - - final String xml=""+ - ""+ - ""+ - ""; - - final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); - final XMLStreamReader reader1 = inputFactory.createXMLStreamReader(new StringReader(xml)); - int event = reader1.getEventType(); - while (!(event == XMLStreamConstants.START_ELEMENT)){ - event = reader1.next(); - } - final DataObject dataObject = streamHelper.loadObject(reader1); - /* - * this malformed xml will load, as lax is forced ON - */ - assertNotNull(dataObject); - } -} +/** + * + * 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.io.StringReader; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.SDOPackage; +import org.apache.tuscany.sdo.api.SDOHelper; +import org.apache.tuscany.sdo.api.SDOUtil; +import org.apache.tuscany.sdo.api.XMLStreamHelper; +import org.eclipse.emf.ecore.resource.Resource; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; + +public class XMLLoadOptionsTestCase extends TestCase { + XMLHelper xmlHelper; + Map options; + + protected void setUp() throws Exception { + super.setUp(); + } + + //SDOUtil->SDOHelper->SDOHelperImpl->HelperContextImpl->XMLHelperImpl + public void testXMLOptionsSchema1() throws IOException{ + final String TEST_XML_DOCUMENT = "/SchemaLocationTestCase.xml"; + + options = new HashMap(); + options.put(SDOHelper.XMLOptions.XML_LOAD_SCHEMA, Boolean.TRUE); + + final XMLHelper xmlHelper = SDOUtil.createHelperContext(true, options).getXMLHelper(); + + final XMLDocument xmlDoc = xmlHelper.load(getClass().getResourceAsStream(TEST_XML_DOCUMENT), "whatever", null); + final DataObject root = xmlDoc.getRootObject(); + assertNotSame(root.getType(), SDOPackage.eINSTANCE.getAnyTypeDataObject()); + } + +// SDOUtil->SDOHelper->SDOHelperImpl->HelperContextImpl->XMLHelperImpl + public void testXMLOptionsSchema2() throws IOException{ + final String TEST_XML_DOCUMENT = "/SchemaLocationTestCase.xml"; + + options = new HashMap(); + options.put(SDOHelper.XMLOptions.XML_LOAD_SCHEMA, Boolean.FALSE); + final XMLHelper xmlHelper = SDOUtil.createHelperContext(true, options).getXMLHelper(); + final XMLDocument xmlDoc = xmlHelper.load(getClass().getResourceAsStream(TEST_XML_DOCUMENT), "whatever", null); + final DataObject root = xmlDoc.getRootObject(); + assertSame(root.getType(), SDOPackage.eINSTANCE.getAnyTypeDataObject()); + } + + public void testXMLOptionsLax1() throws IOException{ + options = new HashMap(); + /* + * turn off default behaviour of tolerating malformed xml + * tests using this option and bad xml should demonstrate failure to load + */ + options.put(SDOHelper.XMLOptions.XML_LOAD_LAX_FORM, new Integer(0)); + final HelperContext hc = SDOUtil.createHelperContext(true, options); + hc.getXSDHelper().define( + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""); + + final String xml=""+ + ""+ +""; + + /* + * this malformed xml will not load, as lax is forced OFF + * changing p:unqualifiedElement to unqualifiedElement + * will work */ + try{ + hc.getXMLHelper().load(new StringReader(xml), null, null); + fail(); + } catch (final Resource.IOWrappedException featureNotFound) { + assertTrue(true); + } + + } + + public void testXMLOptionsLax2() throws IOException{ + options = new HashMap(); + /* + * turn on default behaviour of tolerating malformed xml + * tests using this option and bad xml will load + */ + options.put(SDOHelper.XMLOptions.XML_LOAD_LAX_FORM, new Integer(1)); + final HelperContext hc = SDOUtil.createHelperContext(true, options); + hc.getXSDHelper().define( + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""); + + final String xml=""+ + ""+ + ""+ + ""; + + /* + * this malformed xml will load, as lax is forced ON + */ + assertNotNull(hc.getXMLHelper().load(new StringReader(xml), null, null).getRootObject()); + } + + //SDOUtil->SDOHelper->SDOHelperImpl->XMLStreamHelperImpl->XMLDocumentImpl + public void testXMLStreamHelper() throws IOException, XMLStreamException{ + options = new HashMap(); + /* + * turn off default behaviour of tolerating malformed xml + * tests using this option and bad xml will load + */ + options.put(SDOHelper.XMLOptions.XML_LOAD_LAX_FORM, new Integer(1)); + final HelperContext hc = SDOUtil.createHelperContext(false, options); + final XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(hc); + hc.getXSDHelper().define( + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""); + + final String xml=""+ + ""+ + ""+ + ""; + + final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + final XMLStreamReader reader1 = inputFactory.createXMLStreamReader(new StringReader(xml)); + int event = reader1.getEventType(); + while (!(event == XMLStreamConstants.START_ELEMENT)){ + event = reader1.next(); + } + final DataObject dataObject = streamHelper.loadObject(reader1); + /* + * this malformed xml will load, as lax is forced ON + */ + assertNotNull(dataObject); + } +} diff --git a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XMLSaveOptionsTestCase.java b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XMLSaveOptionsTestCase.java index 49b4be48a9..27b750b0ff 100644 --- a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XMLSaveOptionsTestCase.java +++ b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XMLSaveOptionsTestCase.java @@ -1,147 +1,147 @@ -/** - * - * 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.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringWriter; -import java.net.URL; -import java.util.HashMap; - -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamWriter; - -import junit.framework.TestCase; - -import org.apache.tuscany.sdo.api.SDOHelper; -import org.apache.tuscany.sdo.api.SDOUtil; -import org.apache.tuscany.sdo.api.XMLStreamHelper; - -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.XMLDocument; -import commonj.sdo.helper.XMLHelper; -import commonj.sdo.helper.XSDHelper; - -public class XMLSaveOptionsTestCase extends TestCase { - HelperContext hc; - private XSDHelper xsdHelper; - XMLHelper xmlh; - XMLStreamHelper xmlStreamHelper; - static final String INDENT = " ", MARGIN = " ", LINE_BREAK = "\n"; - String formatted1 = MARGIN+ "" +LINE_BREAK+ - MARGIN+ "" +LINE_BREAK+ - MARGIN+INDENT+ "FBNT" +LINE_BREAK+ - MARGIN+INDENT+ "FlyByNightTechnology" +LINE_BREAK+ - MARGIN+INDENT+ "999.0" +LINE_BREAK+ - MARGIN+INDENT+ "1000.0" +LINE_BREAK+ - MARGIN+INDENT+ "" +LINE_BREAK+ - MARGIN+INDENT+INDENT+ "1500.0" +LINE_BREAK+ - MARGIN+INDENT+ "" +LINE_BREAK+ - MARGIN+INDENT+ "" +LINE_BREAK+ - MARGIN+INDENT+INDENT+ "2500.0" +LINE_BREAK+ - MARGIN+INDENT+ "" +LINE_BREAK+ - MARGIN+INDENT+ "" +LINE_BREAK+ - MARGIN+INDENT+INDENT+ "3000.0" +LINE_BREAK+ - MARGIN+INDENT+ "" +LINE_BREAK+ - MARGIN+INDENT+ "" +LINE_BREAK+ - MARGIN+INDENT+INDENT+ "4000.0" +LINE_BREAK+ - MARGIN+INDENT+ "" +LINE_BREAK+ - MARGIN+INDENT+ "" +LINE_BREAK+ - MARGIN+INDENT+INDENT+ "" +LINE_BREAK+ - MARGIN+INDENT+INDENT+INDENT+ "fbnt" +LINE_BREAK+ - MARGIN+INDENT+INDENT+INDENT+ "1000.0" +LINE_BREAK+ - MARGIN+INDENT+INDENT+INDENT+ "" +LINE_BREAK+ - MARGIN+INDENT+INDENT+INDENT+ "2000.02000.99" +LINE_BREAK+ - MARGIN+INDENT+INDENT+INDENT+ "" +LINE_BREAK+ - MARGIN+INDENT+INDENT+ "" +LINE_BREAK+ - MARGIN+INDENT+ "" +LINE_BREAK+ - MARGIN+ ""; - - String formatted2 = - //MARGIN+ "" +LINE_BREAK+ - MARGIN+ "" +LINE_BREAK+ - MARGIN+INDENT+"fbnt" +LINE_BREAK+ - MARGIN+INDENT+"FlyByNightTechnology" +LINE_BREAK+ - MARGIN+INDENT+"1000.0" +LINE_BREAK+ - MARGIN+INDENT+"1000.0" +LINE_BREAK+ - MARGIN+INDENT+"1000.0" +LINE_BREAK+ - MARGIN+INDENT+"1000.0" +LINE_BREAK+ - MARGIN+INDENT+"1000.0" +LINE_BREAK+ - MARGIN+INDENT+"1000.0" +LINE_BREAK+ - MARGIN+"" +LINE_BREAK; - - void define(final String model) throws IOException { - // Populate the meta data for the test model - final URL url = getClass().getResource(model); - xsdHelper.define(url.openStream(), url.toString()); - } - - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - //use XMLHelper - public void testSaveXMLDocumentXMLHelper() throws IOException { - final HashMap options = new HashMap(); - options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_INDENT, INDENT); - options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_MARGIN, MARGIN); - options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_LINE_BREAK, LINE_BREAK); - hc = SDOUtil.createHelperContext(false,options); - xsdHelper = hc.getXSDHelper(); - xmlh = hc.getXMLHelper(); - - // Populate the meta data for the test (Stock Quote) model - define("/simpleWithChangeSummary.xsd"); - final XMLDocument doc = xmlh.load(getClass().getResource("/simpleWithChangeSummary.xml").openStream()); - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - xmlh.save(xmlh.createDocument(doc.getRootObject(), doc.getRootElementURI(), doc.getRootElementName()), baos, null); - assertEquals(formatted1, baos.toString()); - } - - //use XMLStreamHelper - public void testSaveXMLDocumentXMLStreamHelper() throws Exception { - final HashMap options = new HashMap(); - options.put(SDOHelper.XMLOptions.XML_LOAD_SCHEMA, Boolean.FALSE); - options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_INDENT, INDENT); - options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_MARGIN, MARGIN); - options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_LINE_BREAK, LINE_BREAK); - final HelperContext hc = SDOUtil.createHelperContext(false, options); - xmlStreamHelper = SDOUtil.createXMLStreamHelper(hc); - - xsdHelper = hc.getXSDHelper(); - define("/simple.xsd"); - - final InputStream inStrm = getClass().getResourceAsStream("/shallowquote.xml"); - final XMLDocument document = hc.getXMLHelper().load(inStrm, null, null); - - final XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); - final StringWriter writer = new StringWriter(); - final XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer); - - xmlStreamHelper.save(document, streamWriter, null); - streamWriter.flush(); - assertEquals(formatted2, writer.toString()); - } -} +/** + * + * 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.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringWriter; +import java.net.URL; +import java.util.HashMap; + +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamWriter; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.api.SDOHelper; +import org.apache.tuscany.sdo.api.SDOUtil; +import org.apache.tuscany.sdo.api.XMLStreamHelper; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; + +public class XMLSaveOptionsTestCase extends TestCase { + HelperContext hc; + private XSDHelper xsdHelper; + XMLHelper xmlh; + XMLStreamHelper xmlStreamHelper; + static final String INDENT = " ", MARGIN = " ", LINE_BREAK = "\n"; + String formatted1 = MARGIN+ "" +LINE_BREAK+ + MARGIN+ "" +LINE_BREAK+ + MARGIN+INDENT+ "FBNT" +LINE_BREAK+ + MARGIN+INDENT+ "FlyByNightTechnology" +LINE_BREAK+ + MARGIN+INDENT+ "999.0" +LINE_BREAK+ + MARGIN+INDENT+ "1000.0" +LINE_BREAK+ + MARGIN+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+INDENT+ "1500.0" +LINE_BREAK+ + MARGIN+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+INDENT+ "2500.0" +LINE_BREAK+ + MARGIN+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+INDENT+ "3000.0" +LINE_BREAK+ + MARGIN+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+INDENT+ "4000.0" +LINE_BREAK+ + MARGIN+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+INDENT+INDENT+ "fbnt" +LINE_BREAK+ + MARGIN+INDENT+INDENT+INDENT+ "1000.0" +LINE_BREAK+ + MARGIN+INDENT+INDENT+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+INDENT+INDENT+ "2000.02000.99" +LINE_BREAK+ + MARGIN+INDENT+INDENT+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+ "" +LINE_BREAK+ + MARGIN+ ""; + + String formatted2 = + //MARGIN+ "" +LINE_BREAK+ + MARGIN+ "" +LINE_BREAK+ + MARGIN+INDENT+"fbnt" +LINE_BREAK+ + MARGIN+INDENT+"FlyByNightTechnology" +LINE_BREAK+ + MARGIN+INDENT+"1000.0" +LINE_BREAK+ + MARGIN+INDENT+"1000.0" +LINE_BREAK+ + MARGIN+INDENT+"1000.0" +LINE_BREAK+ + MARGIN+INDENT+"1000.0" +LINE_BREAK+ + MARGIN+INDENT+"1000.0" +LINE_BREAK+ + MARGIN+INDENT+"1000.0" +LINE_BREAK+ + MARGIN+"" +LINE_BREAK; + + void define(final String model) throws IOException { + // Populate the meta data for the test model + final URL url = getClass().getResource(model); + xsdHelper.define(url.openStream(), url.toString()); + } + + protected void setUp() throws Exception { + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + //use XMLHelper + public void testSaveXMLDocumentXMLHelper() throws IOException { + final HashMap options = new HashMap(); + options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_INDENT, INDENT); + options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_MARGIN, MARGIN); + options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_LINE_BREAK, LINE_BREAK); + hc = SDOUtil.createHelperContext(false,options); + xsdHelper = hc.getXSDHelper(); + xmlh = hc.getXMLHelper(); + + // Populate the meta data for the test (Stock Quote) model + define("/simpleWithChangeSummary.xsd"); + final XMLDocument doc = xmlh.load(getClass().getResource("/simpleWithChangeSummary.xml").openStream()); + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + xmlh.save(xmlh.createDocument(doc.getRootObject(), doc.getRootElementURI(), doc.getRootElementName()), baos, null); + assertEquals(formatted1, baos.toString()); + } + + //use XMLStreamHelper + public void testSaveXMLDocumentXMLStreamHelper() throws Exception { + final HashMap options = new HashMap(); + options.put(SDOHelper.XMLOptions.XML_LOAD_SCHEMA, Boolean.FALSE); + options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_INDENT, INDENT); + options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_MARGIN, MARGIN); + options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_LINE_BREAK, LINE_BREAK); + final HelperContext hc = SDOUtil.createHelperContext(false, options); + xmlStreamHelper = SDOUtil.createXMLStreamHelper(hc); + + xsdHelper = hc.getXSDHelper(); + define("/simple.xsd"); + + final InputStream inStrm = getClass().getResourceAsStream("/shallowquote.xml"); + final XMLDocument document = hc.getXMLHelper().load(inStrm, null, null); + + final XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); + final StringWriter writer = new StringWriter(); + final XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer); + + xmlStreamHelper.save(document, streamWriter, null); + streamWriter.flush(); + assertEquals(formatted2, writer.toString()); + } +} diff --git a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XMLUnknownPropertiesTestCase.java b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XMLUnknownPropertiesTestCase.java index 63e92503c1..8824ae7f13 100644 --- a/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XMLUnknownPropertiesTestCase.java +++ b/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XMLUnknownPropertiesTestCase.java @@ -1,132 +1,132 @@ -/** - * - * 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.ByteArrayOutputStream; -import java.io.IOException; -import java.io.StringReader; -import java.util.HashMap; -import java.util.Map; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.sdo.SDOPackage; -import org.apache.tuscany.sdo.api.SDOHelper; -import org.apache.tuscany.sdo.api.SDOUtil; -import commonj.sdo.DataObject; -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.XMLDocument; -import commonj.sdo.helper.XMLHelper; - -public class XMLUnknownPropertiesTestCase extends TestCase { - XMLHelper xmlHelper; - Map options; - - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - // SDOUtil->SDOHelper->SDOHelperImpl->HelperContextImpl->XMLHelperImpl - public void testOptionUnknownProperties() throws IOException { - options = new HashMap(); - options.put(SDOHelper.XMLOptions.XML_LOAD_UNKNOWN_PROPERTIES, Boolean.TRUE); - - final HelperContext hc = SDOUtil.createHelperContext(true); - hc - .getXSDHelper() - .define("" + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + ""); - - final String xml = - "" + "" - + "my test data0" - + "my test data1" - + ""; - - try { - final XMLDocument xmlDoc = hc.getXMLHelper().load(new StringReader(xml), null, options);// pass - // during - // invoke - - final DataObject root = xmlDoc.getRootObject(); - assertNotSame(root.getType(), SDOPackage.eINSTANCE.getAnyTypeDataObject()); - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - hc.getXMLHelper().save(xmlDoc, baos, null); - assertTrue(baos.toString().indexOf("my test data0") != -1); - assertTrue(baos.toString().indexOf("my test data1") != -1); - } catch (final Exception e) {// (Resource.IOWrappedException featureNotFound) - e.printStackTrace(); - } - } - - public void testOptionUnknownProperties2() throws IOException { - options = new HashMap(); - options.put(SDOHelper.XMLOptions.XML_LOAD_UNKNOWN_PROPERTIES, Boolean.FALSE); - - final HelperContext hc = SDOUtil.createHelperContext(true); - hc - .getXSDHelper() - .define("" + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + ""); - - final String xml = - "" + "" - + "my test data" - + "my test data" - + ""; - - try { - final XMLDocument xmlDoc = hc.getXMLHelper().load(new StringReader(xml), null, options);// pass - // on - // invokation - final DataObject root = xmlDoc.getRootObject(); - assertNotSame(root.getType(), SDOPackage.eINSTANCE.getAnyTypeDataObject()); - fail(); - } catch (final Exception e) {// (Resource.IOWrappedException featureNotFound) - // e.printStackTrace(); - if (e.getMessage().indexOf("telem") != -1) { - Assert.assertTrue(true); - } - } - } -} +/** + * + * 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.ByteArrayOutputStream; +import java.io.IOException; +import java.io.StringReader; +import java.util.HashMap; +import java.util.Map; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.SDOPackage; +import org.apache.tuscany.sdo.api.SDOHelper; +import org.apache.tuscany.sdo.api.SDOUtil; +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; + +public class XMLUnknownPropertiesTestCase extends TestCase { + XMLHelper xmlHelper; + Map options; + + protected void setUp() throws Exception { + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + // SDOUtil->SDOHelper->SDOHelperImpl->HelperContextImpl->XMLHelperImpl + public void testOptionUnknownProperties() throws IOException { + options = new HashMap(); + options.put(SDOHelper.XMLOptions.XML_LOAD_UNKNOWN_PROPERTIES, Boolean.TRUE); + + final HelperContext hc = SDOUtil.createHelperContext(true); + hc + .getXSDHelper() + .define("" + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""); + + final String xml = + "" + "" + + "my test data0" + + "my test data1" + + ""; + + try { + final XMLDocument xmlDoc = hc.getXMLHelper().load(new StringReader(xml), null, options);// pass + // during + // invoke + + final DataObject root = xmlDoc.getRootObject(); + assertNotSame(root.getType(), SDOPackage.eINSTANCE.getAnyTypeDataObject()); + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + hc.getXMLHelper().save(xmlDoc, baos, null); + assertTrue(baos.toString().indexOf("my test data0") != -1); + assertTrue(baos.toString().indexOf("my test data1") != -1); + } catch (final Exception e) {// (Resource.IOWrappedException featureNotFound) + e.printStackTrace(); + } + } + + public void testOptionUnknownProperties2() throws IOException { + options = new HashMap(); + options.put(SDOHelper.XMLOptions.XML_LOAD_UNKNOWN_PROPERTIES, Boolean.FALSE); + + final HelperContext hc = SDOUtil.createHelperContext(true); + hc + .getXSDHelper() + .define("" + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""); + + final String xml = + "" + "" + + "my test data" + + "my test data" + + ""; + + try { + final XMLDocument xmlDoc = hc.getXMLHelper().load(new StringReader(xml), null, options);// pass + // on + // invokation + final DataObject root = xmlDoc.getRootObject(); + assertNotSame(root.getType(), SDOPackage.eINSTANCE.getAnyTypeDataObject()); + fail(); + } catch (final Exception e) {// (Resource.IOWrappedException featureNotFound) + // e.printStackTrace(); + if (e.getMessage().indexOf("telem") != -1) { + Assert.assertTrue(true); + } + } + } +} diff --git a/java/sdo/impl/src/test/resources/TypePropertyMetadataInfo.xsd b/java/sdo/impl/src/test/resources/TypePropertyMetadataInfo.xsd index be5bc2c3e7..7a78772733 100644 --- a/java/sdo/impl/src/test/resources/TypePropertyMetadataInfo.xsd +++ b/java/sdo/impl/src/test/resources/TypePropertyMetadataInfo.xsd @@ -1,97 +1,97 @@ - - - - - - - - - - - - - - - forest.jpg - - - - - - - - - - getNumber - setNumber - - - - - - - - - - getPhonetype - setPhonetype - - - - - - - - - - - This is the metadata for defining the ExampleNumber type. - - - - - - - - - - - - This is the metadata for defining the PhoneNumber type. - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + forest.jpg + + + + + + + + + + getNumber + setNumber + + + + + + + + + + getPhonetype + setPhonetype + + + + + + + + + + + This is the metadata for defining the ExampleNumber type. + + + + + + + + + + + + This is the metadata for defining the PhoneNumber type. + + + + + + + + + + + + + + + + + + diff --git a/java/sdo/impl/src/test/resources/bounds.xsd b/java/sdo/impl/src/test/resources/bounds.xsd index 31b621d575..4d92d6e1fe 100644 --- a/java/sdo/impl/src/test/resources/bounds.xsd +++ b/java/sdo/impl/src/test/resources/bounds.xsd @@ -1,45 +1,45 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/sdo/impl/src/test/resources/dupelement.xsd b/java/sdo/impl/src/test/resources/dupelement.xsd index 9707a881c4..da2f6920d4 100644 --- a/java/sdo/impl/src/test/resources/dupelement.xsd +++ b/java/sdo/impl/src/test/resources/dupelement.xsd @@ -1,39 +1,39 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + diff --git a/java/sdo/impl/src/test/resources/expectedExceptions.xsd b/java/sdo/impl/src/test/resources/expectedExceptions.xsd index 79f90d311d..cd12447cd9 100644 --- a/java/sdo/impl/src/test/resources/expectedExceptions.xsd +++ b/java/sdo/impl/src/test/resources/expectedExceptions.xsd @@ -1,67 +1,67 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/sdo/impl/src/test/resources/openContentProperty.xml b/java/sdo/impl/src/test/resources/openContentProperty.xml index 03608365c0..68f4c116eb 100644 --- a/java/sdo/impl/src/test/resources/openContentProperty.xml +++ b/java/sdo/impl/src/test/resources/openContentProperty.xml @@ -1,12 +1,12 @@ - - - s1 - - FlyByNightTechnology - - 1000.0 - 1100.0 - - mutual-1 - + + + s1 + + FlyByNightTechnology + + 1000.0 + 1100.0 + + mutual-1 + \ No newline at end of file diff --git a/java/sdo/impl/src/test/resources/sdoModel.xsd b/java/sdo/impl/src/test/resources/sdoModel.xsd index 645b7b700a..6b596c5b36 100644 --- a/java/sdo/impl/src/test/resources/sdoModel.xsd +++ b/java/sdo/impl/src/test/resources/sdoModel.xsd @@ -1,28 +1,28 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/java/sdo/impl/src/test/resources/shallowquote1.xml b/java/sdo/impl/src/test/resources/shallowquote1.xml index 0cdb2fbce8..a9bb2bf330 100644 --- a/java/sdo/impl/src/test/resources/shallowquote1.xml +++ b/java/sdo/impl/src/test/resources/shallowquote1.xml @@ -1,29 +1,29 @@ - - - - fbnt - FlyByNightTechnology - 1000.0 - 1000.0 - 1000.0 - 1000.0 - 1000.0 - 1000.0 - + + + + fbnt + FlyByNightTechnology + 1000.0 + 1000.0 + 1000.0 + 1000.0 + 1000.0 + 1000.0 + diff --git a/java/sdo/impl/src/test/resources/simple2.xsd b/java/sdo/impl/src/test/resources/simple2.xsd index 4be4bac95b..53bace49b5 100644 --- a/java/sdo/impl/src/test/resources/simple2.xsd +++ b/java/sdo/impl/src/test/resources/simple2.xsd @@ -1,41 +1,41 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/sdo/impl/src/test/resources/simpleWithChangeSummary.xml b/java/sdo/impl/src/test/resources/simpleWithChangeSummary.xml index d8ecf8f398..2f29fc00f0 100644 --- a/java/sdo/impl/src/test/resources/simpleWithChangeSummary.xml +++ b/java/sdo/impl/src/test/resources/simpleWithChangeSummary.xml @@ -1,28 +1,28 @@ - - - FBNT - FlyByNightTechnology - 999.0 - 1000.0 - - 1500.0 - - - 2500.0 - - - 3000.0 - - - 4000.0 - - - - fbnt - 1000.0 - - 2000.02000.99 - - - + + + FBNT + FlyByNightTechnology + 999.0 + 1000.0 + + 1500.0 + + + 2500.0 + + + 3000.0 + + + 4000.0 + + + + fbnt + 1000.0 + + 2000.02000.99 + + + \ No newline at end of file diff --git a/java/sdo/impl/src/test/resources/simpleWithChangeSummaryUndone.xml b/java/sdo/impl/src/test/resources/simpleWithChangeSummaryUndone.xml index e2bbc56d2d..a9c675b6c3 100644 --- a/java/sdo/impl/src/test/resources/simpleWithChangeSummaryUndone.xml +++ b/java/sdo/impl/src/test/resources/simpleWithChangeSummaryUndone.xml @@ -1,19 +1,19 @@ - - - fbnt - FlyByNightTechnology - 1000.0 - - 1500.0 - - - 2000.0 - - 2000.99 - - - - 2500.0 - - + + + fbnt + FlyByNightTechnology + 1000.0 + + 1500.0 + + + 2000.0 + + 2000.99 + + + + 2500.0 + + \ No newline at end of file diff --git a/java/sdo/impl/src/test/resources/substitutionValues1.xml b/java/sdo/impl/src/test/resources/substitutionValues1.xml index cc10d9a435..c534eb9370 100644 --- a/java/sdo/impl/src/test/resources/substitutionValues1.xml +++ b/java/sdo/impl/src/test/resources/substitutionValues1.xml @@ -1,23 +1,23 @@ - - - - gm - ngh - + + + + gm + ngh + diff --git a/java/sdo/impl/src/test/resources/substitutionValues2.xml b/java/sdo/impl/src/test/resources/substitutionValues2.xml index d3870bf140..d90d0f3a0c 100644 --- a/java/sdo/impl/src/test/resources/substitutionValues2.xml +++ b/java/sdo/impl/src/test/resources/substitutionValues2.xml @@ -1,23 +1,23 @@ - - - - gh - ngh - + + + + gh + ngh + -- cgit v1.2.3