From bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a Mon Sep 17 00:00:00 2001 From: dims Date: Tue, 17 Jun 2008 00:23:01 +0000 Subject: Move Tuscany from Incubator to top level. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68 --- .../runtime/core/src/commonj/Makefile.am | 18 + .../runtime/core/src/commonj/sdo/ChangeSummary.cpp | 30 + .../runtime/core/src/commonj/sdo/ChangeSummary.h | 209 + .../core/src/commonj/sdo/ChangeSummaryBuilder.cpp | 1147 +++++ .../core/src/commonj/sdo/ChangeSummaryBuilder.h | 303 ++ .../core/src/commonj/sdo/ChangeSummaryImpl.cpp | 1592 +++++++ .../core/src/commonj/sdo/ChangeSummaryImpl.h | 405 ++ .../core/src/commonj/sdo/ChangedDataObjectList.h | 93 + .../src/commonj/sdo/ChangedDataObjectListImpl.cpp | 248 + .../src/commonj/sdo/ChangedDataObjectListImpl.h | 99 + .../runtime/core/src/commonj/sdo/CopyHelper.cpp | 598 +++ .../runtime/core/src/commonj/sdo/CopyHelper.h | 76 + .../runtime/core/src/commonj/sdo/DASProperty.cpp | 34 + .../runtime/core/src/commonj/sdo/DASProperty.h | 48 + .../runtime/core/src/commonj/sdo/DASType.cpp | 34 + .../runtime/core/src/commonj/sdo/DASType.h | 55 + .../runtime/core/src/commonj/sdo/DASValue.cpp | 59 + .../runtime/core/src/commonj/sdo/DASValue.h | 56 + .../runtime/core/src/commonj/sdo/DASValues.cpp | 70 + .../runtime/core/src/commonj/sdo/DASValues.h | 59 + .../runtime/core/src/commonj/sdo/DataFactory.cpp | 53 + .../runtime/core/src/commonj/sdo/DataFactory.h | 806 ++++ .../core/src/commonj/sdo/DataFactoryImpl.cpp | 2141 +++++++++ .../runtime/core/src/commonj/sdo/DataFactoryImpl.h | 697 +++ .../runtime/core/src/commonj/sdo/DataGraph.cpp | 35 + .../runtime/core/src/commonj/sdo/DataGraph.h | 105 + .../runtime/core/src/commonj/sdo/DataGraphImpl.cpp | 147 + .../runtime/core/src/commonj/sdo/DataGraphImpl.h | 112 + .../runtime/core/src/commonj/sdo/DataObject.cpp | 33 + .../runtime/core/src/commonj/sdo/DataObject.h | 594 +++ .../core/src/commonj/sdo/DataObjectImpl.cpp | 4910 ++++++++++++++++++++ .../runtime/core/src/commonj/sdo/DataObjectImpl.h | 729 +++ .../core/src/commonj/sdo/DataObjectInstance.cpp | 71 + .../core/src/commonj/sdo/DataObjectInstance.h | 62 + .../core/src/commonj/sdo/DataObjectList.cpp | 43 + .../runtime/core/src/commonj/sdo/DataObjectList.h | 202 + .../core/src/commonj/sdo/DataObjectListImpl.cpp | 1129 +++++ .../core/src/commonj/sdo/DataObjectListImpl.h | 224 + .../runtime/core/src/commonj/sdo/DataTypeInfo.cpp | 54 + .../runtime/core/src/commonj/sdo/DataTypeInfo.h | 137 + .../core/src/commonj/sdo/DefaultLogWriter.cpp | 55 + .../core/src/commonj/sdo/DefaultLogWriter.h | 54 + .../core/src/commonj/sdo/EqualityHelper.cpp | 372 ++ .../runtime/core/src/commonj/sdo/EqualityHelper.h | 99 + .../core/src/commonj/sdo/GroupDefinition.cpp | 36 + .../runtime/core/src/commonj/sdo/GroupDefinition.h | 59 + .../runtime/core/src/commonj/sdo/GroupEvent.cpp | 65 + .../runtime/core/src/commonj/sdo/GroupEvent.h | 70 + .../core/src/commonj/sdo/HelperProvider.cpp | 49 + .../runtime/core/src/commonj/sdo/HelperProvider.h | 67 + .../runtime/core/src/commonj/sdo/LogWriter.cpp | 34 + .../runtime/core/src/commonj/sdo/LogWriter.h | 46 + .../runtime/core/src/commonj/sdo/Logger.cpp | 102 + .../runtime/core/src/commonj/sdo/Logger.h | 71 + .../runtime/core/src/commonj/sdo/Logging.h | 171 + .../runtime/core/src/commonj/sdo/Makefile.am | 106 + .../core/src/commonj/sdo/ParserErrorSetter.cpp | 40 + .../core/src/commonj/sdo/ParserErrorSetter.h | 51 + .../runtime/core/src/commonj/sdo/Property.cpp | 44 + .../runtime/core/src/commonj/sdo/Property.h | 207 + .../core/src/commonj/sdo/PropertyDefinition.cpp | 323 ++ .../core/src/commonj/sdo/PropertyDefinition.h | 135 + .../src/commonj/sdo/PropertyDefinitionImpl.cpp | 46 + .../core/src/commonj/sdo/PropertyDefinitionImpl.h | 90 + .../runtime/core/src/commonj/sdo/PropertyImpl.cpp | 594 +++ .../runtime/core/src/commonj/sdo/PropertyImpl.h | 294 ++ .../runtime/core/src/commonj/sdo/PropertyList.cpp | 95 + .../runtime/core/src/commonj/sdo/PropertyList.h | 89 + .../core/src/commonj/sdo/PropertySetting.cpp | 68 + .../runtime/core/src/commonj/sdo/PropertySetting.h | 65 + .../core/src/commonj/sdo/RefCountingObject.cpp | 83 + .../core/src/commonj/sdo/RefCountingObject.h | 67 + .../core/src/commonj/sdo/RefCountingPointer.cpp | 155 + .../core/src/commonj/sdo/RefCountingPointer.h | 198 + .../runtime/core/src/commonj/sdo/SAX2Attribute.cpp | 51 + .../runtime/core/src/commonj/sdo/SAX2Attribute.h | 66 + .../core/src/commonj/sdo/SAX2Attributes.cpp | 129 + .../runtime/core/src/commonj/sdo/SAX2Attributes.h | 80 + .../core/src/commonj/sdo/SAX2Namespaces.cpp | 95 + .../runtime/core/src/commonj/sdo/SAX2Namespaces.h | 69 + .../runtime/core/src/commonj/sdo/SAX2Parser.cpp | 531 +++ .../runtime/core/src/commonj/sdo/SAX2Parser.h | 117 + .../runtime/core/src/commonj/sdo/SDO.h | 62 + .../core/src/commonj/sdo/SDODataConverter.cpp | 1130 +++++ .../core/src/commonj/sdo/SDODataConverter.h | 83 + .../runtime/core/src/commonj/sdo/SDODate.cpp | 76 + .../runtime/core/src/commonj/sdo/SDODate.h | 79 + .../core/src/commonj/sdo/SDORuntimeException.cpp | 255 + .../core/src/commonj/sdo/SDORuntimeException.h | 519 +++ .../runtime/core/src/commonj/sdo/SDOSAX2Parser.cpp | 1547 ++++++ .../runtime/core/src/commonj/sdo/SDOSAX2Parser.h | 179 + .../runtime/core/src/commonj/sdo/SDOSPI.h | 27 + .../core/src/commonj/sdo/SDOSchemaSAX2Parser.cpp | 1421 ++++++ .../core/src/commonj/sdo/SDOSchemaSAX2Parser.h | 235 + .../runtime/core/src/commonj/sdo/SDOString.h | 31 + .../runtime/core/src/commonj/sdo/SDOUserMacros.h | 30 + .../runtime/core/src/commonj/sdo/SDOUtils.cpp | 442 ++ .../runtime/core/src/commonj/sdo/SDOUtils.h | 80 + .../runtime/core/src/commonj/sdo/SDOValue.cpp | 236 + .../runtime/core/src/commonj/sdo/SDOValue.h | 258 + .../core/src/commonj/sdo/SDOXMLBufferWriter.cpp | 57 + .../core/src/commonj/sdo/SDOXMLBufferWriter.h | 53 + .../core/src/commonj/sdo/SDOXMLFileWriter.cpp | 46 + .../core/src/commonj/sdo/SDOXMLFileWriter.h | 54 + .../core/src/commonj/sdo/SDOXMLStreamWriter.cpp | 52 + .../core/src/commonj/sdo/SDOXMLStreamWriter.h | 56 + .../runtime/core/src/commonj/sdo/SDOXMLString.cpp | 234 + .../runtime/core/src/commonj/sdo/SDOXMLString.h | 94 + .../runtime/core/src/commonj/sdo/SDOXMLWriter.cpp | 1410 ++++++ .../runtime/core/src/commonj/sdo/SDOXMLWriter.h | 147 + .../core/src/commonj/sdo/SDOXSDBufferWriter.cpp | 55 + .../core/src/commonj/sdo/SDOXSDBufferWriter.h | 54 + .../core/src/commonj/sdo/SDOXSDFileWriter.cpp | 45 + .../core/src/commonj/sdo/SDOXSDFileWriter.h | 53 + .../core/src/commonj/sdo/SDOXSDStreamWriter.cpp | 53 + .../core/src/commonj/sdo/SDOXSDStreamWriter.h | 57 + .../runtime/core/src/commonj/sdo/SDOXSDWriter.cpp | 845 ++++ .../runtime/core/src/commonj/sdo/SDOXSDWriter.h | 77 + .../runtime/core/src/commonj/sdo/SchemaInfo.cpp | 39 + .../runtime/core/src/commonj/sdo/SchemaInfo.h | 64 + .../runtime/core/src/commonj/sdo/SdoCheck.cpp | 29 + .../runtime/core/src/commonj/sdo/SdoCheck.h | 35 + .../runtime/core/src/commonj/sdo/SdoRuntime.cpp | 66 + .../runtime/core/src/commonj/sdo/SdoRuntime.h | 76 + .../runtime/core/src/commonj/sdo/Sequence.cpp | 39 + .../runtime/core/src/commonj/sdo/Sequence.h | 319 ++ .../runtime/core/src/commonj/sdo/SequenceImpl.cpp | 1328 ++++++ .../runtime/core/src/commonj/sdo/SequenceImpl.h | 405 ++ .../runtime/core/src/commonj/sdo/Setting.cpp | 308 ++ .../runtime/core/src/commonj/sdo/Setting.h | 151 + .../runtime/core/src/commonj/sdo/SettingList.cpp | 115 + .../runtime/core/src/commonj/sdo/SettingList.h | 77 + .../runtime/core/src/commonj/sdo/Type.cpp | 38 + .../runtime/core/src/commonj/sdo/Type.h | 233 + .../core/src/commonj/sdo/TypeDefinition.cpp | 256 + .../runtime/core/src/commonj/sdo/TypeDefinition.h | 121 + .../core/src/commonj/sdo/TypeDefinitionImpl.cpp | 45 + .../core/src/commonj/sdo/TypeDefinitionImpl.h | 83 + .../core/src/commonj/sdo/TypeDefinitions.cpp | 82 + .../runtime/core/src/commonj/sdo/TypeDefinitions.h | 68 + .../core/src/commonj/sdo/TypeDefinitionsImpl.cpp | 51 + .../core/src/commonj/sdo/TypeDefinitionsImpl.h | 57 + .../runtime/core/src/commonj/sdo/TypeImpl.cpp | 4077 ++++++++++++++++ .../runtime/core/src/commonj/sdo/TypeImpl.h | 348 ++ .../runtime/core/src/commonj/sdo/TypeList.cpp | 86 + .../runtime/core/src/commonj/sdo/TypeList.h | 58 + .../runtime/core/src/commonj/sdo/XMLDocument.cpp | 33 + .../runtime/core/src/commonj/sdo/XMLDocument.h | 151 + .../core/src/commonj/sdo/XMLDocumentImpl.cpp | 87 + .../runtime/core/src/commonj/sdo/XMLDocumentImpl.h | 102 + .../runtime/core/src/commonj/sdo/XMLHelper.cpp | 36 + .../runtime/core/src/commonj/sdo/XMLHelper.h | 184 + .../runtime/core/src/commonj/sdo/XMLHelperImpl.cpp | 400 ++ .../runtime/core/src/commonj/sdo/XMLHelperImpl.h | 184 + .../runtime/core/src/commonj/sdo/XMLQName.cpp | 86 + .../runtime/core/src/commonj/sdo/XMLQName.h | 68 + .../runtime/core/src/commonj/sdo/XSDHelper.cpp | 37 + .../runtime/core/src/commonj/sdo/XSDHelper.h | 152 + .../runtime/core/src/commonj/sdo/XSDHelperImpl.cpp | 665 +++ .../runtime/core/src/commonj/sdo/XSDHelperImpl.h | 172 + .../core/src/commonj/sdo/XSDPropertyInfo.cpp | 55 + .../runtime/core/src/commonj/sdo/XSDPropertyInfo.h | 61 + .../runtime/core/src/commonj/sdo/XSDTypeInfo.cpp | 54 + .../runtime/core/src/commonj/sdo/XSDTypeInfo.h | 54 + .../runtime/core/src/commonj/sdo/XpathHelper.cpp | 88 + .../runtime/core/src/commonj/sdo/XpathHelper.h | 57 + .../runtime/core/src/commonj/sdo/disable_warn.h | 29 + .../runtime/core/src/commonj/sdo/export.h | 49 + 168 files changed, 44345 insertions(+) create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/Makefile.am create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummary.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummary.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummaryBuilder.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummaryBuilder.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummaryImpl.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummaryImpl.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangedDataObjectList.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangedDataObjectListImpl.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangedDataObjectListImpl.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/CopyHelper.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/CopyHelper.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASProperty.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASProperty.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASType.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASType.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASValue.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASValue.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASValues.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASValues.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataFactory.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataFactory.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataFactoryImpl.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataGraph.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataGraph.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataGraphImpl.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataGraphImpl.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObject.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObject.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectImpl.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectImpl.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectInstance.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectInstance.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectList.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectList.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectListImpl.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectListImpl.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataTypeInfo.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataTypeInfo.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DefaultLogWriter.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DefaultLogWriter.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/EqualityHelper.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/EqualityHelper.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/GroupDefinition.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/GroupDefinition.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/GroupEvent.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/GroupEvent.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/HelperProvider.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/HelperProvider.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/LogWriter.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/LogWriter.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Logger.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Logger.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Logging.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Makefile.am create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ParserErrorSetter.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ParserErrorSetter.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Property.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Property.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyDefinition.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyDefinition.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyDefinitionImpl.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyDefinitionImpl.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyImpl.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyImpl.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyList.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyList.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertySetting.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertySetting.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/RefCountingObject.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/RefCountingObject.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/RefCountingPointer.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/RefCountingPointer.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Attribute.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Attribute.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Attributes.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Attributes.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Namespaces.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Namespaces.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Parser.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Parser.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDO.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODataConverter.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODataConverter.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODate.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODate.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDORuntimeException.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDORuntimeException.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOSAX2Parser.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOSAX2Parser.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOSPI.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOSchemaSAX2Parser.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOSchemaSAX2Parser.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOString.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOUserMacros.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOUtils.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOUtils.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOValue.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOValue.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLBufferWriter.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLBufferWriter.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLFileWriter.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLFileWriter.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLStreamWriter.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLStreamWriter.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLString.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLString.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLWriter.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLWriter.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDBufferWriter.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDBufferWriter.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDFileWriter.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDFileWriter.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDStreamWriter.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDStreamWriter.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDWriter.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDWriter.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SchemaInfo.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SchemaInfo.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SdoCheck.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SdoCheck.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SdoRuntime.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SdoRuntime.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Sequence.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Sequence.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SequenceImpl.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SequenceImpl.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Setting.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Setting.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SettingList.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SettingList.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Type.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Type.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinition.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinition.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitionImpl.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitionImpl.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitions.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitions.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitionsImpl.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitionsImpl.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeImpl.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeImpl.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeList.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeList.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLDocument.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLDocument.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLDocumentImpl.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLDocumentImpl.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLHelper.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLHelper.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLHelperImpl.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLHelperImpl.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLQName.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLQName.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDHelper.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDHelper.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDHelperImpl.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDHelperImpl.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDPropertyInfo.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDPropertyInfo.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDTypeInfo.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDTypeInfo.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XpathHelper.cpp create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XpathHelper.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/disable_warn.h create mode 100644 branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/export.h (limited to 'branches/sdo-cpp-pre2.1/runtime/core/src/commonj') diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/Makefile.am b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/Makefile.am new file mode 100644 index 0000000000..cc127b70dc --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/Makefile.am @@ -0,0 +1,18 @@ +# 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. + +SUBDIRS = sdo diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummary.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummary.cpp new file mode 100644 index 0000000000..384956471c --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummary.cpp @@ -0,0 +1,30 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/Logger.h" + +#include "commonj/sdo/ChangeSummary.h" +namespace commonj{ +namespace sdo{ + +}; +}; + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummary.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummary.h new file mode 100644 index 0000000000..8e39904b65 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummary.h @@ -0,0 +1,209 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _CHANGESUMMARY_H_ +#define _CHANGESUMMARY_H_ +#include "commonj/sdo/export.h" + + +#include "commonj/sdo/SettingList.h" +#include "commonj/sdo/ChangedDataObjectList.h" + + +namespace commonj{ +namespace sdo { + + /** + * + * A change summary is used to record changes to the objects in a data graph. + * This allows applications to efficiently and incrementally update + * back-end storage when required. + */ + + class ChangeSummary + { + public: + + /** getChangedDataObjects() returns a list of changed objects. + * + * The new and modified objects in the list are references to objects that + * are associated with this change summary. + * The deleted objects in the list are references to copies of the objects + * as they appeared at the time that event logging was enabled; + * if the deleted objects have references to other objects, + * the references will also refer to copies of the target objects. + * Return a list of changed data objects. + */ + + virtual SDO_API ChangedDataObjectList& getChangedDataObjects() = 0; + + + /** getOldValues returns a list of old values as settings. + * + * Returns a list of Settings + * that represent the property values of the given dataObject + * at the point when logging began. + * In the case of a deleted object, + * the list will include Settings for all the properties. + * An old value Setting indicates the value at the + * point logging begins. A setting is only produced for + * modified objects if either the old value differs from the current value or + * if the isSet differs from the current value. + * No Settings are produced for created objects. + * Param dataObject the object in question. + * Return a list of settings. + */ + + virtual SDO_API SettingList& getOldValues(DataObjectPtr dataObject) = 0; + + /** getOldXpath returns the old path before the setting. + * + * Returns a path where the object was located before the setting took place. + */ + + + virtual SDO_API const char* getOldXpath(RefCountingPointer dol) = 0; + + /** beginLogging() sets the change summary in logging mode. + * + * The change summary is initially inactive. Setting it to logging mode + * starts the process of recording all the settings made. + */ + + virtual SDO_API void beginLogging() = 0; + + /** endLogging() stops logging. + * + * This method stops logging, but does not clear out the change summary. + * The changes are valid until the summary is next set to logging, at which time + * all old settings are lost. + */ + + virtual SDO_API void endLogging() = 0; + + + + /** isLogging() returns true if logging is enabled. + * + * Indicates whether change logging is on (true) or off (false). + */ + + virtual SDO_API bool isLogging() = 0; + + + + /** isCreated() returns true if the object was created during logging. + * + * Returns whether or not the specified data object was created while logging. + * Any object that was added to the data graph + * but was not in the data graph when logging began, + * will be considered created. + * Param dataObject the data object in question. + * Return true if the specified data object was created. + */ + + virtual SDO_API bool isCreated(DataObjectPtr dataObject) = 0; + + /** isDeleted() - true if the object was deleted during logging. + * + * Returns whether or not the specified data object was deleted while logging. + * Any object that is not contained by the data graph will be considered + * deleted. + * Param dataObject the data object in question. + * Return true if the specified data object was deleted. + */ + + virtual SDO_API bool isDeleted(DataObjectPtr dataObject) = 0; + + + /** isModified() - true if the object was changed during logging. + * + * Returns whether or not the specified data object was updated while logging. + * An object that was contained in the data graph when logging began, + * and remains in the graph when logging ends will be considered for changes. + * An object considered modified must have at least one old value Setting. + * Param dataObject the data object in question. + * Return true if the specified data object was modified. + */ + + virtual SDO_API bool isModified(DataObjectPtr dataObject) = 0; + + /** getOldValue() gets the setting showing the old value. + * + * Returns a setting for the specified property + * representing the property value of the given dataObject + * at the point when logging began. + * Returns null if the property has not changed and + * has not been deleted. + * Param dataObject the object in question. + * Param property the property of the object. + * Return the Setting for the specified property. + */ + + virtual SDO_API const Setting& getOldValue(DataObjectPtr dataObject, const Property& property) = 0; + + /** getOldContainer() gets the container before the setting. + * + * Returns the value of the container data object + * at the point when logging began. + * Param dataObject the object in question. + * Return the old container data object. + */ + + virtual SDO_API DataObjectPtr getOldContainer(DataObjectPtr dataObject) = 0; + + /** getOldContainmentProperty() - gives the property before setting. + * + * Returns the value of the containment property data object property + * at the point when logging began. + * Param dataObject the object in question. + * Return the old containment property. + */ + + virtual SDO_API const Property& getOldContainmentProperty(DataObjectPtr dataObject) = 0; + + /** undoChanges() - Not Implemented. + * + * NOT IMPLEMENTED + * + * Undoes all changes in the log to restore the tree of + * DataObjects to its original state when logging began. + * isLogging() is unchanged. The log is cleared. + */ + + virtual SDO_API void undoChanges() = 0; + + /** getOldSequence() - Not Implemented. + * + * NOT IMPLEMENTED + * + * This method gives back the sequence of a data object as it + * appeared when logging was switched on. The data object may be + * a deleted data object or a changed data object. If the + * data object was not sequenced, this returns null. + */ + + virtual SDO_API SequencePtr getOldSequence(DataObjectPtr dataObject) = 0; + +}; +}; +}; +#endif //_CHANGESUMMARY_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummaryBuilder.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummaryBuilder.cpp new file mode 100644 index 0000000000..c26e1197c6 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummaryBuilder.cpp @@ -0,0 +1,1147 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/ChangeSummaryBuilder.h" + +#include "commonj/sdo/SDORuntimeException.h" +#include "commonj/sdo/ChangeSummary.h" +#include "commonj/sdo/XSDPropertyInfo.h" +#include "commonj/sdo/XMLQName.h" +#include "commonj/sdo/DASProperty.h" +#include "commonj/sdo/Logging.h" + +#include +#include +namespace commonj +{ + namespace sdo + { + +// ======================================================================== +// Constructor/Destructor +// ======================================================================== + + ChangeSummaryBuilder::ChangeSummaryBuilder( + DataFactoryPtr df, + DataObjectPtr& rootDO) + + : dataFactory(df), + rootDataObject(rootDO) + + + { + LOGINFO(INFO,"CSBuilder constructor"); + currentState = baseState; + } + + ChangeSummaryBuilder::~ChangeSummaryBuilder() + { + LOGINFO(INFO,"CSBuilder destructor"); + } + + +// ======================================================================== +// Deletion handling +// ======================================================================== + + void ChangeSummaryBuilder::populateDeletion(ChangeSummaryImpl* csi,DataObjectPtr dob, + int currentIndex) + { + LOGENTRY(INFO,"CSBuilder populateDeletion"); + try { + + std::list::iterator attributesiter; + std::list::iterator elementsiter; + + for (attributesiter= deletions[currentIndex].attributes.begin(); + attributesiter!= deletions[currentIndex].attributes.end(); + ++attributesiter) + { + + LOGINFO_1(INFO,"CSBuilder Populate deletion attribute:%s", + (const char*)((*attributesiter).name)); + + dob->setCString((const char*)((*attributesiter).name), + (const char*)((*attributesiter).value)); + } + for (elementsiter= deletions[currentIndex].elements.begin(); + elementsiter!= deletions[currentIndex].elements.end(); + ++elementsiter) + { + + LOGINFO_1(INFO,"CSBuilder:Populate deletion element:%s", + (const char*)((*elementsiter).name)); + + SDOXMLString value = (*elementsiter).value; + SDOXMLString prop = (*elementsiter).name; + + if ((*elementsiter).isDeletion) + { + for (unsigned int i = 0; i < deletions.size(); i++) + { + if (value.equals (deletions[i].reference)) + { + if (deletions[i].dob == 0) + { + handleDeletion(csi,i,dob,(*elementsiter).value, + (*elementsiter).name); + } + // dob may have been set by the line above. + if (deletions[i].dob != 0) + { + DataObjectList& dli = dob->getList((const char*)prop); + dli.insert(0,deletions[i].dob); + } + break; + } + } + } + else + { + DataObjectList& dli = dob->getList((const char*)prop); + dli.append((const char*)value); + } + } + } + catch (SDORuntimeException e) + { + LOGSDOEXCEPTION(ERROR,"Error populating a deletion record",e); + } + LOGEXIT(INFO,"CSBuilder populateDeletion"); + return; + } + + +// ======================================================================== +// Deletion handling +// ======================================================================== + + void ChangeSummaryBuilder::handleDeletion( + ChangeSummaryImpl* csi, + int currentIndex, + DataObjectPtr cont, + SDOXMLString path, + SDOXMLString prop) + { + LOGENTRY(INFO,"CSBuilder handleDeletion(2)"); + + if (deletions[currentIndex].completedprocessing) + { + LOGEXIT(INFO,"CSBuilder handleDeletion(2) - Exit1"); + return; + } + + const Property& p = cont->getProperty((const char*)prop); + DataObjectPtr dob = dataFactory->create( + p.getType()); + populateDeletion(csi,dob,currentIndex); + deletions[currentIndex].dob = dob; + deletions[currentIndex].completedprocessing=true; + csi->appendToDeletions(p,dob,cont,path); + + LOGEXIT(INFO,"CSBuilder handleDeletion(2) - Exit2"); + + return; + } + +// ======================================================================== +// Deletion handling +// ======================================================================== + + void ChangeSummaryBuilder::handleDeletion( + ChangeSummaryImpl* csi, + int currentIndex, + SDOXMLString path) + { + + // find the original container - and see if it + // still exists. + // supposing the container doesnt exist, we need + // to process the deletion of that one first, or + // locate it in the already deleted elements. + + LOGENTRY(INFO,"CSBuilder:handleDeletion"); + + if (deletions[currentIndex].completedprocessing) + { + LOGEXIT(INFO,"CSBuilder:handleDeletion - Exit1"); + return; + } + + int index = path.lastIndexOf('/'); + if (index < 0) + { + LOGERROR(WARNING,"CSBuilder logs deletion of the root object - not possible"); + LOGEXIT(INFO,"CSBuilder:handleDeletion - Exit2"); + return; + } + + SDOXMLString prop = + path.substring(index+1); + SDOXMLString contpath = + path.substring(0,index); + + index = prop.lastIndexOf('.'); + if (index >= 0) prop = prop.substring(0,index); + + index = prop.lastIndexOf('['); + if (index >= 0) prop = prop.substring(0,index); + + DataObjectPtr cont; + + if (contpath.isNull()) + { + cont = rootDataObject; + + LOGINFO_1(INFO,"Handling deletion from root of %s",(const char*)prop); + } + else + { + try { + cont = rootDataObject->getDataObject((const char*)contpath); + LOGINFO_2(INFO,"Handling deletion from %s of %s", + (const char*)contpath,(const char*)prop); + } + catch (SDORuntimeException e) + { + cont = 0; + LOGINFO(INFO,"Container was a deleted object"); + } + } + + if (cont != 0) + { + handleDeletion(csi,currentIndex,cont,path,prop); + LOGEXIT(INFO,"CSBuilder:handleDeletion - Exit3"); + return; + } + else + { + // this data object was also deleted + cont = csi->matchDeletedObject(contpath); + if (cont != 0) + { + // we found a previously deleted object for + // the container. + handleDeletion(csi,currentIndex,cont,path,prop); + LOGEXIT(INFO,"CSBuilder:handleDeletion - Exit4"); + return; + } + + } + + // it could be a deletion which has not been processed yet + for (unsigned int i = 0; i < deletions.size(); i++) + { + if (contpath.equals (deletions[i].reference)) + { + // matching deletion found + if (i == currentIndex) + { + LOGERROR(WARNING,"Loop detected in handling deletes"); + LOGEXIT(INFO,"CSBuilder:handleDeletion - Exit5"); + return; + } + // Handle the deletion first + handleDeletion(csi,i,contpath); + LOGEXIT(INFO,"CSBuilder:handleDeletion - Exit6"); + return; + } + } + LOGERROR(WARNING,"Failed to find a matching delete "); + LOGEXIT(INFO,"CSBuilder:handleDeletion - Exit7"); + return; + } + +// ======================================================================== +// Deletion handling +// ======================================================================== + + SDOXMLString ChangeSummaryBuilder::shiftedIndex(int index) + { + int pos = createDeletes[index].value.lastIndexOf('.'); + if (pos < 0) return createDeletes[index].value; + + int val = atoi((const char*)(createDeletes[index]. + value.substring(pos+1))); + + char buf[10]; + + sprintf(buf, ".%d", val + createDeletes[index].indexshift); + + return createDeletes[index].value.substring(0,pos) + buf; + } + +// ======================================================================== +// Deletion handling +// ======================================================================== + + void ChangeSummaryBuilder::shiftIndices(int index, int delta) + { + int pos = createDeletes[index].value.lastIndexOf('.'); + if (pos < 0) return; + + SDOXMLString refstring = createDeletes[index].value.substring(0,pos); + pos = atoi((const char*)(createDeletes[index].value.substring(pos+1))); + + for (unsigned int k=index+1;k= pos) + { + createDeletes[k].indexshift += delta; + } + } + } + +// ======================================================================== +// Rebuilding of a change summary from the lists +// ======================================================================== + + void ChangeSummaryBuilder::buildChangeSummary( + DataObjectPtr changeSummaryDO) + { + LOGENTRY(INFO,"CSBuilder:buildChangeSummary"); + + unsigned int i; + + try { + if (changeSummaryDO == 0) + { + // there is no summary data object to rebuild + LOGEXIT(INFO,"CSBuilder:buildChangeSummary Exit1"); + return; + } + ChangeSummary* cs = changeSummaryDO->getChangeSummary(); + if (cs == 0) + { + // there is no change summary - this shouldnt happen + LOGEXIT(INFO,"CSBuilder:buildChangeSummary Exit2"); + return; + } + + ChangeSummaryImpl* csi = (ChangeSummaryImpl*)cs; + + // add the creations and deletions in order + + for (i = 0; i < createDeletes.size(); i++) + { + + LOGINFO_1(INFO,"CSBuilder:create/delete:%s", + (const char*)(createDeletes[i].value)); + + SDOXMLString thispath; + + if (createDeletes[i].indexshift != 0) + { + thispath = shiftedIndex(i); + } + else + { + thispath = createDeletes[i].value; + } + + if (!createDeletes[i].type.equals("delete")) + { + DataObjectPtr dob; + if (thispath.isNull()) + { + dob = rootDataObject; + } + else + { + dob = rootDataObject->getDataObject((const char*)thispath); + } + if (dob != 0) { + + LOGINFO(INFO,"CSBuilder:add create to change summary"); + + csi->appendToCreations(dob->getContainmentProperty(), + dob, dob->getContainer()); + shiftIndices(i,-1); + } + else + { + LOGERROR_1(WARNING,"Failed to find object at %s", + (const char*)createDeletes[i].value); + } + } + else + { + // its a deletion - match it. + for (unsigned int j = 0; j < deletions.size(); j++) + { + if (deletions[j].completedprocessing)continue; + + if (thispath.equals (deletions[j].reference)) + { + // matching deletion found + LOGINFO_1(INFO,"CSBuilder:matched delete:%s", + (const char*)deletions[j].reference); + + handleDeletion(csi, j,createDeletes[i].value); + // update the path on any higher items in the current + // many-valued property. + shiftIndices(i,1); + + break; + } + } + } + } + + // add the changes + + std::list::iterator a; + std::list::iterator e; + + for (unsigned i = 0; i< changes.size(); i++) + { + DataObjectPtr dob; + if (changes[i].reference.isNull()) + { + dob = rootDataObject; + } + else + { + dob = rootDataObject->getDataObject((const char*)changes[i].reference); + } + if (dob != 0) + { + LOGINFO_1(INFO,"Located a change at %s", + (const char*)changes[i].reference); + + // Need to get the changelogitem, and append settings to + // it.Append attributes + + for (a=changes[i].attributes.begin(); + a != changes[i].attributes.end();++a) + { + const Property& p = dob->getProperty((const char*)((*a).name)); + if (p.getType().isDataType()) + { + csi->appendToChanges( + p,dob,(*a).value,0); + } + else + { + for (unsigned int j = 0; j < deletions.size(); j++) + { + if ((*a).value.equals (deletions[j].reference)) + { + csi->appendToChanges( + p,dob,deletions[j].dob,0); + break; + } + } + } + } + for (e=changes[i].elements.begin(); + e != changes[i].elements.end();++e) + { + const Property& p = dob->getProperty + ((const char*)((*e).name)); + if ((*e).isDeletion) + { + + LOGINFO_1(INFO,"CSBuilder Change was a deletion of:%s", + (const char*)((*e).path)); + + for (unsigned int j = 0; j < deletions.size(); j++) + { + if ((*e).path.equals (deletions[j].reference)) + { + // matching deletion found + if (deletions[j].dob != 0) + { + csi->appendToChanges( + p,dob,deletions[j].dob,(*e).index); + } + break; + } + } + } + else if ((*e).isReference) + { + LOGINFO_2(INFO,"CSBuilder:Change was a reference from:%s to %s" , + (const char*)((*e).path), + (const char*)((*e).value)); + + DataObjectPtr pdob = rootDataObject->getDataObject((const char*)(*e).value); + if (pdob != 0) + { + csi->appendToChanges(p,dob,pdob,(*e).index); + } + } + else + { + LOGINFO_1(INFO,"CSBuilder:Change was a many valued item:%s" , + (const char*)((*e).name)); + + csi->appendToChanges(p,dob,(*e).value,(*e).index); + } + + } + } + else + { + LOGERROR_1(WARNING,"CSBuilder:Failed to find object at %s", + (const char*)(changes[i].reference)); + } + } + } + catch (SDORuntimeException e) + { + LOGSDOEXCEPTION(ERROR,"CSBuilder:Error rebuilding change summary",e); + } + LOGEXIT(INFO,"CSBuilder:buildChangeSummary Exit3"); + } + +// ======================================================================== +// Parsing code +// ======================================================================== + + void ChangeSummaryBuilder::processStart( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes) + { + char cbuf[32]; + int i; + + LOGENTRY(INFO,"CSBuilder:processStart"); + + if (currentState == baseState) + { + if (localname.equalsIgnoreCase("create") || + localname.equalsIgnoreCase("delete")) + { + currentState = dealingWithCreateDelete; + // will be expecting a chars message to give the + // contents + + createDeletes.push_back(createDelete(localname)); + + LOGINFO_1(INFO,"CSBuilder: Processing a %s",(const char*)localname); + LOGEXIT(INFO,"CSBuilder:processStart Exit1"); + return; + } + else + { + // we are starting a new change record here + currentState = dealingWithChange; + + // we expect the entry to have an sdo:ref, and possibly + // some attributes for the changed single-values + SDOXMLString ref = attributes.getValue("ref"); + + if (ref.isNull()) + { + LOGERROR(INFO,"CSBuilder:Problem with change reference"); + ref = SDOXMLString("Unknown"); + } + + currentChange = change(localname, ref); + + LOGINFO_2(INFO,"CSBuilder: Processing a change:%s:%s", + (const char*)localname, + (const char*)ref); + + currentLocation.clear(); + + if (ref.equals("#/")) + { + ref = SDOXMLString("#"); + } + + currentLocation.push_back(ref); + + // clear out the change state - if there was any. + + changeIndex = 0; + previousChange = SDOXMLString(""); + + // now insert any remaining attributes of this change + + for (i=0; i < attributes.size(); i++) + { + // push all the attributes into the change record. + SDOXMLString name = attributes[i].getName(); + if (!name.equalsIgnoreCase("ref")) + { + SDOXMLString value = attributes[i].getValue(); + currentChange.addAttribute( + changeAttribute(name,value)); + } + } + } + LOGEXIT(INFO,"CSBuilder:processStart Exit2"); + return; + } + + // We are not in the base state - we could be in a change or a deletion + // We are now dropping into an element, which could be either a many-valued + // primitive type, or a placeholder in list of deletions, or a deletion + // record. + + if (currentState == dealingWithChange) + { + + if (!previousChange.equals(localname)) + { + changeIndex = 0; + previousChange = localname; + } + else + { + changeIndex++; + } + + + sprintf(cbuf,"%d",changeIndex); + currentLocation.push_back(localname + "." + cbuf); + + // build the current location... + SDOXMLString curr_loc = ""; + + if (currentLocation.size() > 0) + { + for (unsigned int pi = 0; pi < currentLocation.size()-1; pi++) + { + curr_loc = curr_loc + currentLocation[pi]; + curr_loc = curr_loc + "/"; + } + curr_loc = curr_loc + currentLocation[currentLocation.size()-1]; + } + + LOGINFO_1(INFO,"CSBuilder: Dropping into an element of a change:%s", + (const char*)localname); + LOGINFO_1(INFO,"CSBuilder:currentLocation:%s", + (const char*)curr_loc); + + // First case - its a placeholder for an element in a list + // all we have to do is keep track of the list index. + + if (attributes.size() == 1) + { + SDOXMLString name = attributes[0].getName(); + if (name.equalsIgnoreCase("ref")) + { + currentState = dealingWithChangeElement; + currentChange.addElement( + changeElement(localname, curr_loc, + attributes[0].getValue(), true, false)); + + LOGEXIT(INFO,"CSBuilder:processStart Exit3"); + return; + } + } + + if (attributes.size() == 0) + { + // It could be a many-valued primitive, or + // a deletion with no attributes + // can we match the current path to a known deletion? + + bool isDelete = false; + + for (unsigned int i = 0; i < createDeletes.size(); i++) + { + if (createDeletes[i].type.equals("delete")) + { + if (curr_loc.equals(createDeletes[i].value)) + { + LOGINFO(INFO,"CSBuilder: An existing delete was found"); + + isDelete = true; + break; // out of the for loop + } + } + } + if (!isDelete) + { + LOGINFO(INFO,"CSBuilder: Change with no atts and not deletion- an element"); + + // and will get picked up by the 'characters' method. + currentState = dealingWithChangeElement; + currentLocalName = SDOXMLString(localname); + + LOGEXIT(INFO,"CSBuilder:processStart Exit4"); + return; + } + } + + currentChange.addElement(changeElement(localname, curr_loc, false, true)); + currentDeletion = deletion(localname, curr_loc); + + LOGINFO_2(INFO,"CSBuilder: Found a deletion:%s:%s", + (const char*)localname, + (const char*)curr_loc); + + + // clear out the change state - if there was any. + deletionLevel = 0; + deletionIndex = 0; + previousDeletion = SDOXMLString(""); + + currentState = dealingWithDeletion; + + // Now add the attributes if there are any. + + for (int i=0; i < attributes.size(); i++) + { + // push all the attributes into the deletion record. + SDOXMLString name = attributes[i].getName(); + if (!name.equalsIgnoreCase("ref")) + { + SDOXMLString value = attributes[i].getValue(); + currentDeletion.addAttribute( + deletionAttribute(name,value)); + } + } + + LOGEXIT(INFO,"CSBuilder:processStart Exit5"); + return; + } + if (currentState == dealingWithDeletion) + { + // we are already in a deletion, and entering an element + if (!previousDeletion.equals(localname)) + { + deletionIndex = 0; + previousDeletion = localname; + } + else + { + deletionIndex++; + } + + sprintf(cbuf,"%d",deletionIndex); + currentLocation.push_back(localname + "." + cbuf); + + // First case - its a placeholder for an element in a list + // all we have to do is keep track of the list index. + + if (attributes.size() == 1) + { + SDOXMLString name = attributes[0].getName(); + if (name.equalsIgnoreCase("ref")) + { + LOGINFO(INFO,"CSBuilder: The element is a reference to an existing entry in a list"); + + currentState = dealingWithDeletionElement; + + LOGEXIT(INFO,"CSBuilder:processStart Exit6"); + return; + } + } + + SDOXMLString curr_loc = ""; + if (currentLocation.size() > 0) + { + for (unsigned int pi = 0; pi < currentLocation.size()-1; pi++) + { + curr_loc = curr_loc + currentLocation[pi]; + curr_loc = curr_loc + "/"; + } + curr_loc = curr_loc + currentLocation[currentLocation.size()-1]; + } + + if (attributes.size() == 0) + { + // It could be a many-valued primitive, or + // a deletion with no attributes + // can we match the current path to a known deletion? + bool isDelete = false; + + for (unsigned int i = 0; i < createDeletes.size(); i++) + { + if (createDeletes[i].type.equals("delete")) + { + if (curr_loc.equals(createDeletes[i].value)) + { + LOGINFO(INFO,"CSBuilder: An existing delete was found - its a delete"); + + isDelete = true; + break; // out of the for loop + } + } + } + if (!isDelete) + { + LOGINFO(INFO,"CSBuilder: Found a change with no atts, and no deletion matches - its an element"); + + // and will get picked up by the 'characters' method. + currentState = dealingWithDeletionElement; + + LOGEXIT(INFO,"CSBuilder:processStart Exit7"); + return; + } + } + + + // We are starting a new deletion record + + LOGINFO_2(INFO,"CSBuilder: Found a deletion within a deletion:%s:%s", + (const char*)localname, (const char*)curr_loc); + + deletionList.push_back(deletionListElement(currentDeletion,deletionIndex, + previousDeletion)); + + currentDeletion = deletion(localname, curr_loc); + + // we are in a nested delete - so record the level such that we can pop state + // from the deletionList on coming back out of this. + + deletionLevel++; + //deletionIndex = 0; + previousDeletion = SDOXMLString(""); + + currentState = dealingWithDeletion; + + // Now add the attributes if there are any. + + for (int i=0; i < attributes.size(); i++) + { + // push all the attributes into the deletion record. + SDOXMLString name = attributes[i].getName(); + if (!name.equalsIgnoreCase("ref")) + { + SDOXMLString value = attributes[i].getValue(); + currentDeletion.addAttribute( + deletionAttribute(name,value)); + } + } + + LOGEXIT(INFO,"CSBuilder:processStart Exit8"); + return; + + } + } + +// ======================================================================== +// Parser ends an element +// ======================================================================== + + void ChangeSummaryBuilder::processEnd( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI) + { + + LOGENTRY(INFO,"CSBuilder:processEnd"); + + if (currentState == dealingWithCreateDelete) + { + // its already been completed by the characters message + currentState = baseState; + LOGEXIT(INFO,"CSBuilder:processEnd Exit1"); + return; + } + else if (currentState == dealingWithChangeElement) + { + // its already been completed by the characters message + currentState = dealingWithChange; + currentLocation.pop_back(); + LOGEXIT(INFO,"CSBuilder:processEnd Exit2"); + return; + } + else if (currentState == dealingWithDeletionElement) + { + // its already been completed by the characters message + currentState = dealingWithDeletion; + currentLocation.pop_back(); + LOGEXIT(INFO,"CSBuilder:processEnd Exit3"); + return; + } + else if (currentState == dealingWithChange) + { + // we should have finished, there are no nested changes + currentState = baseState; + changes.push_back(currentChange); + currentLocation.clear(); + LOGEXIT(INFO,"CSBuilder:processEnd Exit4"); + return; + } + else if (currentState == dealingWithDeletion) + { + currentLocation.pop_back(); + deletions.push_back(currentDeletion); + if (deletionLevel > 0) + { + deletionLevel--; + if (deletionList.size() > 0) + { + int index = deletionIndex; + SDOXMLString path = currentDeletion.reference; + SDOXMLString name = currentDeletion.name; + + deletionListElement dl = deletionList[deletionList.size()-1]; + currentDeletion = dl.del; + deletionIndex = dl.index; + previousDeletion = dl.previous; + deletionList.pop_back(); + // and insert the inside deletion in the outside one. + currentDeletion.insertElement(deletionElement( + name, path,index)); + } + + LOGEXIT(INFO,"CSBuilder:processEnd Exit5"); + return; + } + else + { + currentState = dealingWithChange; + + LOGEXIT(INFO,"CSBuilder:processEnd Exit6"); + return; + } + } + } + +// ======================================================================== +// Parse characters +// ======================================================================== + + + void ChangeSummaryBuilder::processChars( + const SDOXMLString& chars) + { + LOGENTRY(INFO,"CSBuilder:processChars"); + + if (currentState == dealingWithCreateDelete) + { + // this is text within a create/delete indicating the + // value of the item deleted/created. + if (createDeletes.size() > 0) + { + createDeletes[createDeletes.size()-1].value = chars; + LOGINFO_1(INFO,"CSBuilder:characters create/delete:%s", + (const char*)chars); + } + LOGEXIT(INFO,"CSBuilder:processChars Exit1"); + return; + } + else if (currentState == dealingWithChangeElement) + { + changeElement ce = changeElement(currentLocalName, previousChange, false, false); + ce.value = chars; + ce.index = changeIndex; + currentChange.addElement(ce); + + LOGINFO_1(INFO,"CSBuilder: Characters in a change element:%s", + (const char *)chars); + + LOGEXIT(INFO,"CSBuilder:processChars Exit2"); + return; + } + else if (currentState == dealingWithDeletionElement) + { + deletionElement ce = deletionElement(previousDeletion); + ce.value = chars; + ce.index = deletionIndex; + currentDeletion.addElement(ce); + + LOGINFO_1(INFO,"CSBuilder: Characters in a deletion element:%s", + (const char *)chars); + + LOGEXIT(INFO,"CSBuilder:processChars Exit3"); + return; + } + + LOGINFO_1(INFO,"CSBuilder: Characters in nothing!!:%s", + (const char *)chars); + LOGEXIT(INFO,"CSBuilder:processChars Exit4"); + } + + +// ======================================================================== +// Classes holding temporary parsed information +// ======================================================================== + + + ///////////////////////////////////////////////// + // An element in the list of creates/deletes + ///////////////////////////////////////////////// + + createDelete::createDelete() + { + } + + createDelete::createDelete(SDOXMLString intype) : + type(intype) + { + indexshift = 0; + } + + createDelete::~createDelete() + { + } + + ///////////////////////////////////////////////// + // An element in the list of changes + ///////////////////////////////////////////////// + + changeAttribute::changeAttribute() + { + } + + changeAttribute::changeAttribute(SDOXMLString inname, + SDOXMLString invalue): name(inname), value(invalue) + { + } + + changeAttribute::~changeAttribute() + { + } + + changeElement::changeElement() + { + } + + changeElement::changeElement(SDOXMLString inname, + SDOXMLString inpath, bool isRef, bool isDel) + : name(inname) , path(inpath) + { + isReference=isRef; + isDeletion= isDel; + } + + changeElement::changeElement(SDOXMLString inname, + SDOXMLString inpath, + SDOXMLString invalue, bool isRef, bool isDel) + : name(inname), value(invalue), path(inpath) + { + isReference=isRef; + isDeletion= isDel; + } + + changeElement::~changeElement() + { + } + + change::change() + { + } + + change::change(SDOXMLString inname, SDOXMLString ref): + name(inname), reference(ref) + { + } + + void change::addAttribute(changeAttribute ca) + { + attributes.push_back(ca); + } + + void change::addElement(changeElement ce) + { + elements.push_back(ce); + } + + ///////////////////////////////////////////////// + // An element in the list of deletions + ///////////////////////////////////////////////// + + deletionAttribute::deletionAttribute() + { + } + + deletionAttribute::deletionAttribute(SDOXMLString inname, + SDOXMLString invalue): name(inname), value(invalue) + { + } + + deletionAttribute::~deletionAttribute() + { + } + + deletionElement::deletionElement() + { + } + + deletionElement::deletionElement(SDOXMLString inname) + : name(inname) + { + isDeletion = false; + } + + deletionElement::deletionElement(SDOXMLString inname, + SDOXMLString inpath, int inindex) + : name(inname), value(inpath), index(inindex) + { + isDeletion = true; + } + + deletionElement::~deletionElement() + { + } + + deletion::deletion() + { + } + + deletion::deletion(SDOXMLString inname, SDOXMLString ref): + name(inname), reference(ref) + { + completedprocessing=false; + } + + void deletion::addAttribute(deletionAttribute ca) + { + attributes.push_back(ca); + } + + void deletion::addElement(deletionElement ce) + { + elements.push_back(ce); + } + + void deletion::insertElement(deletionElement ce) + { + elements.insert(elements.begin(),ce); + } + + deletionListElement::deletionListElement() + { + } + + deletionListElement::deletionListElement( + deletion in_del, + int in_index, + SDOXMLString in_prev): + del(in_del), index(in_index), previous(in_prev) + { + } + + } // End - namespace sdo +} // End - namespace commonj + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummaryBuilder.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummaryBuilder.h new file mode 100644 index 0000000000..59e158aeed --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummaryBuilder.h @@ -0,0 +1,303 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + + +#ifndef _CHANGESUMMARYBUILDER_H_ +#define _CHANGESUMMARYBUILDER_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/SAX2Parser.h" +#include "commonj/sdo/DataFactory.h" +#include "commonj/sdo/DataObject.h" +#include "commonj/sdo/SAX2Namespaces.h" +#include "commonj/sdo/PropertySetting.h" +#include "commonj/sdo/ChangeSummaryImpl.h" + + +#include + +namespace commonj +{ + namespace sdo + { + +/** + * createDelete is a class holding a creation or deletion in + * a change summary builder. + * When rebuilding a change summary from the serialized version + * creates and deletes are stored in these until they can be + * converted into a change summary. + */ + + + class createDelete + { + public: + createDelete(); + createDelete(SDOXMLString intype); + virtual ~createDelete(); + SDOXMLString type; + SDOXMLString value; + int indexshift; + }; + +/** + * changeAttribute is a class holding a changed attribute in a + * change summary builder. + * When rebuilding a change summary from the serialized version + * changes are stored in these until they can be + * converted into a change summary. + */ + + class changeAttribute + { + public: + changeAttribute(); + changeAttribute(SDOXMLString inname, + SDOXMLString invalue); + virtual ~changeAttribute(); + SDOXMLString name; + SDOXMLString value; + }; + +/** + * changeElement is a class holding a changed element in a change summary builder. + * When rebuilding a change summary from the serialized version + * changes are stored in these until they can be + * converted into a change summary. + */ + class changeElement + { + public: + changeElement(); + changeElement(SDOXMLString inname, + SDOXMLString inpath, bool isRef, bool isDel); + changeElement(SDOXMLString inname, + SDOXMLString inpath, + SDOXMLString invalue, bool isRef, bool isDel); + virtual ~changeElement(); + SDOXMLString name; + SDOXMLString value; + SDOXMLString path; + bool isReference; + bool isDeletion; + int index; + }; + +/** + * change is a class holding a change in a change summary builder. + * When rebuilding a change summary from the serialized version + * changes are stored in these until they can be + * converted into a change summary. + * Changes consist of changeAttributes and changeElements + */ + + + class change + { + public: + change(); + change(SDOXMLString inname, SDOXMLString ref); + void addAttribute(changeAttribute ca); + void addElement(changeElement ce); + std::list attributes; + std::list elements; + SDOXMLString name; + SDOXMLString reference; + }; + +/** + * deletionAttribute is a class holding a deletion attribute in a change summary builder. + * When rebuilding a change summary from the serialized version + * deletions are stored in these until they can be + * converted into a change summary. + * Changes consist of deletionAttributes and deletionElements + */ + class deletionAttribute + { + public: + deletionAttribute(); + deletionAttribute(SDOXMLString inname, + SDOXMLString invalue); + virtual ~deletionAttribute(); + SDOXMLString name; + SDOXMLString value; + }; + +/** + * deletionElement is a class holding a deletion element in a change summary builder. + * When rebuilding a change summary from the serialized version + * deletions are stored in these until they can be + * converted into a change summary. + * Changes consist of deletionAttributes and deletionElements + */ + class deletionElement + { + public: + deletionElement(); + deletionElement(SDOXMLString inname); + deletionElement(SDOXMLString inname, + SDOXMLString inpath, int inindex); + virtual ~deletionElement(); + SDOXMLString name; + SDOXMLString value; + bool isDeletion; + int index; + }; + + +/** + * deletions is a class holding a deletion in a change summary builder. + * When rebuilding a change summary from the serialized version + * deletions are stored in these until they can be + * converted into a change summary. + * Changes consist of deletionAttributes and deletionElements + */ + + class deletion + { + public: + deletion(); + deletion(SDOXMLString inname, SDOXMLString ref); + void addAttribute(deletionAttribute ca); + void addElement(deletionElement ce); + void insertElement(deletionElement ce); + SDOXMLString name; + SDOXMLString reference; + DataObjectPtr dob; /* the recreated one*/ + std::list attributes; + std::list elements; + bool completedprocessing; + }; + + /** deletionListElement is an item in a list of deletions in a change summary builder. + * + * All the deletions are stored whilst rebuilding a change + * summary, then applied. These list elements hold them. + */ + + class deletionListElement + { + public: + deletionListElement(); + deletionListElement(deletion in_del, int in_index, SDOXMLString in_prev); + SDOXMLString previous; + deletion del; + int index; + }; + +/** + * The ChangeSummaryBuilder recreates a change summary from the + * XML representations of the changes, creations and deletions. + * It does this by populating a list of changes as though they had + * been applied to the current data graph. + */ + + class ChangeSummaryBuilder + { + + + public: + + enum CsState + { + baseState, + dealingWithCreateDelete, + dealingWithChange, + dealingWithChangeElement, + dealingWithDeletion, + dealingWithDeletionElement + }; + + + ChangeSummaryBuilder( + DataFactoryPtr df, + DataObjectPtr& rootDO); + + virtual ~ChangeSummaryBuilder(); + + + virtual void processStart( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes); + + virtual void processChars( + const SDOXMLString& chars); + + virtual void processEnd( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI); + + virtual void buildChangeSummary( + DataObjectPtr changeSummaryDO); + + virtual void populateDeletion(ChangeSummaryImpl* csi, DataObjectPtr dob, + int index); + + virtual void handleDeletion( + ChangeSummaryImpl* csi, + int currentIndex, + DataObjectPtr cont, + SDOXMLString path, + SDOXMLString prop); + + virtual void handleDeletion(ChangeSummaryImpl* csi, + int index, + SDOXMLString path); + + void shiftIndices(int index, int delta); + + SDOXMLString shiftedIndex(int index); + + + private: + DataFactoryPtr dataFactory; + DataObjectPtr& rootDataObject; + + CsState currentState; + + std::vector deletionList; + std::vector currentLocation; + std::vector createDeletes; + + std::vector changes; + change currentChange; + SDOXMLString previousChange; + SDOXMLString currentLocalName; + int changeIndex; + + std::vector deletions; + deletion currentDeletion; + SDOXMLString previousDeletion; + int deletionIndex; + int deletionLevel; + + + }; + } // End - namespace sdo +} // End - namespace commonj + +#endif //_CHANGESUMMARYBUILDER_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummaryImpl.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummaryImpl.cpp new file mode 100644 index 0000000000..24694676cc --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummaryImpl.cpp @@ -0,0 +1,1592 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/ChangeSummaryImpl.h" + +#include "commonj/sdo/DataObjectImpl.h" + +#include "commonj/sdo/Property.h" +#include "commonj/sdo/Type.h" +#include "commonj/sdo/TypeList.h" +#include "commonj/sdo/Sequence.h" +#include "commonj/sdo/DataObject.h" +#include "commonj/sdo/DataObjectList.h" +#include "commonj/sdo/SDORuntimeException.h" +#include "commonj/sdo/Logging.h" + +#include + +namespace commonj{ +namespace sdo{ + + + // Initializes an empty change summary, so we know one is required + ChangeSummaryImpl::ChangeSummaryImpl() + { + logging = false; + } + + ChangeSummaryImpl::~ChangeSummaryImpl() + { + //Force logging off or bad things will happen! + logging = false; + + /** + * These remove the logitems, so cause the + * refcounts of the data objects to drop, and + * delete the settings lists. + */ + deletedMap.clear(); + createdMap.clear(); + changedMap.clear(); + changedDataObjects.clear(); + } + + SequencePtr ChangeSummaryImpl::getOldSequence(DataObjectPtr dob) + { + DELETELOG_MAP::iterator deleteLogIter; + + DataObject* ob = dob; + deleteLogIter = deletedMap.find((DataObjectImpl*)ob); + + if (deleteLogIter != deletedMap.end()) + { + return (deleteLogIter->second).getSequence(); + } + + CHANGELOG_MAP::iterator changeLogIter; + + changeLogIter = changedMap.find((DataObjectImpl*)ob); + + if (changeLogIter != changedMap.end()) + { + return (changeLogIter->second).getSequence(); + } + return NULL; + + } + + void ChangeSummaryImpl::removeFromChanges(DataObjectImpl* ob) + { + int i = changedDataObjects.size(); + + /** + * this is used to remove only the most recent change. + * A deletion has occurred, and there was a creation, so + * we remove the creation. There cannot be a change after the + * creation, so the last entry in changes is the creation. + * there could be a previous deletion of the same object, so + * we should not clear the whole list. + */ + while (i > 0) + { + i--; + + + if (changedDataObjects.get(i) == ob) + { + changedDataObjects.remove(i); + return; + } + } + } + + DataObjectPtr ChangeSummaryImpl::matchDeletedObject(SDOXMLString path) + { + DELETELOG_MAP::iterator deleteLogIter; + + for (deleteLogIter = deletedMap.begin(); + deleteLogIter != deletedMap.end(); ++deleteLogIter) + { + if ( + path.equals( + SDOXMLString((deleteLogIter->second).getOldXpath()) + ) + ) + { + return deleteLogIter->first; + } + } + return DataObjectPtr(0); + } + + + + void ChangeSummaryImpl::logDeletion(DataObjectImpl* ob, + DataObjectImpl* container, const Property& prop, + const char* oldpath, bool loggingChildren) + { + LOGINFO_1(INFO,"ChangeSummary:LogDelete:%s", + ob->getType().getName()); + + /** + * The object is about to be deleted, so we need + * all its property Settings recorded in the list + * of changed data objects. We also need to know + * its old container, container property, and + * value. + */ + + // find any properties which are data objects, log their + // deletion first. + + unsigned int i; + + // Trace for change summaries + + LOGINFO_2(INFO,"ChangeSummary logs a deletion of property %s type %s", + prop.getName(), prop.getType().getName()); + + + CREATELOG_MAP::iterator createLogIter; + CHANGELOG_MAP::iterator changeLogIter; + + createLogIter = createdMap.find(ob); + if (createLogIter != createdMap.end()) + { + // would need to remove it from the created list. + LOGINFO(INFO,"ChangeSummary: The deletion was already created - just removing it"); + + removeFromChanges(ob); + createdMap.erase(ob); + // find the container in the change map. + + changeLogIter = changedMap.find(container); + if (changeLogIter != changedMap.end()) + { + // would hope there was an entry + unsigned int index; + if (prop.isMany()) + { + DataObjectList& dl = container->getList(prop); + for (index=0;indexsecond).getSettings(); + + for (int j=0 ; j < slist.size();j++) + { + if (!strcmp(slist.get(j)->getProperty().getName(), + prop.getName()) + + + && slist.get(j)->getIndex() == + index) + { + // these are settings of the same prop/index, we + // need to remove this entry + slist.remove(j); + // and if this was the only change, then we + // need to remoe the container from the changes + if (slist.size() == 0) + { + changedMap.erase(container); + removeFromChanges(container); + } + break; // must not continue - size is now wrong + } + } + } + return; + } + + DELETELOG_MAP::iterator deleteLogIter; + + deleteLogIter = deletedMap.find(ob); + + if (deleteLogIter != deletedMap.end()) + { + LOGINFO(INFO,"ChangeSummary - delete an already deleted object"); + return; + } + + PropertyList pl = ob->getInstanceProperties(); + DataObject* dob; + + if (loggingChildren) + { + for (i=0; i < pl.size(); i++) + { + if (pl[i].getType().isDataObjectType()) + { + if (pl[i].isMany()) { + DataObjectList& dl = ob->getList(pl[i]); + for (int j = dl.size() - 1; j>=0; j--) + { + dob = dl[j]; + if (dob)logDeletion((DataObjectImpl*)dob,ob,pl[i], + dob->objectToXPath(), true); + } + } + else { + dob = ob->getDataObject(pl[i]); + if (dob)logDeletion((DataObjectImpl*)(dob),ob,pl[i], + dob->objectToXPath(), true); + } + } + } + } + + + // build a Setting list for the set properties + + deletedMap.insert(std::make_pair(ob,deleteLogItem( + (DataObject*)ob, prop,ob->getSequence(), + oldpath, + container))); + deleteLogIter = deletedMap.find(ob); + SettingList& sl = (deleteLogIter->second).getSettings(); + + void* value; + unsigned int len; + + for (i=0; i < pl.size(); i++) + { + //if (!pl[i].getType().isDataType()) continue; + + if (!ob->isSet(pl[i])) + { + sl.append(new Setting(false,false, 0,0,pl[i],0)); + continue; + } + if (pl[i].isMany()) + { + + DataObjectList& dol = ob->getList(pl[i]); + for (int j=dol.size()-1;j >= 0; j--) + { + // needs to be the data object in cases where... + if (pl[i].getType().isDataType()) { + setPropValue(&value,&len,ob,pl[j]); + sl.append(new Setting(true,false,value,len,pl[i],j)); + } + else { + value = (void*)dol[j]; + sl.append(new Setting(true,false,value,0,pl[i],j)); + } + } + } + else + { + setPropValue(&value,&len,ob,pl[i]); + sl.append(new Setting(true,ob->isNull(pl[i]),value,len,pl[i],0)); + } + + } + + + changeLogIter = changedMap.find(ob); + if (changeLogIter != changedMap.end()) + { + // we have already changed this object, so we need the old values + // from the change, and to remove the changed map entry + LOGINFO(INFO,"ChangeSummary found a deleted item in then changes"); + + (deleteLogIter->second).setSequence((changeLogIter->second).getSequence()); + + SettingList& slist = (changeLogIter->second).getSettings(); + + for (int j=0 ; j < slist.size();j++) + { + for (int i=0;igetProperty().getName(), + sl.get(i)->getProperty().getName()) + + + && slist.get(j)->getIndex() == + sl.get(i)->getIndex()) + { + // these are settings of the same prop/index, we + // need the old value to get transferred. + sl.remove(i); + sl.insert(i,new Setting(*(slist.get(j)))); + + } + } + } + LOGINFO(INFO, "ChangeSummary: Erasing from changes"); + changedMap.erase(ob); + } + // We append deleted objects to the changed list - this list gives + // those data objects which have been affected - we then look at their + // current and old property values to find out whether they have been + // deleted or created. + else + { + changedDataObjects.append(ob, ChangedDataObjectList::Delete); + } + + LOGINFO(INFO,"ChangeSummary: Deletion being added to the list"); + + return; + } + + void ChangeSummaryImpl::logCreation(DataObjectImpl* ob, + DataObjectImpl* container, const Property& prop) + { + + LOGINFO_1(INFO,"ChangeSummary:LogCreate of type:%s",ob->getType().getName()); + + // These we just need to record the fact that they + // are present. We dont have an original value to + // store. + // log a change to the container of this object + // + + DELETELOG_MAP::iterator deleteLogIter; + + deleteLogIter = deletedMap.find(ob); + if (deleteLogIter != deletedMap.end()) + { + // can happen - a delete is really a removal from the tree. + // Adding back an object which you held a pointer to is just + // a re-creation. + LOGINFO(INFO,"ChangeSummary: Adding in a pre-deleted object"); + } + + // we should check if this object has sub-objects, they will + // need to be created too + + PropertyList pl = ob->getInstanceProperties(); + for (unsigned int p=0;pisSet(thisprop)) + { + DataObject* dp; + + if (thisprop.isMany()) + { + DataObjectList& dol = ob->getList(thisprop); + for (unsigned int ds = 0; ds < dol.size(); ds++) + { + dp = dol[ds]; + if (!dp) continue; + logCreation((DataObjectImpl*)dp,ob,thisprop); + } + } + else + { + dp = ob->getDataObject(thisprop); + if (dp) + { + logCreation((DataObjectImpl*)dp,ob,thisprop); + } + } + } + } + } + + CREATELOG_MAP::iterator createLogIter; + + createLogIter = createdMap.find(ob); + if (createLogIter != createdMap.end()) + { + // this could be a reference - we dont add it twice. + LOGINFO(INFO,"ChangeSummary: No need to log creation twice"); + return; + } + + // We append created objects to the changed list - this list gives + // those data objects which have been affected - we then look at their + // current and old property values to find out whether they have been + // deleted or created. + changedDataObjects.append(ob, ChangedDataObjectList::Create); + + createdMap.insert(std::make_pair(ob,createLogItem(ob->getType(),prop,container))); + return; + } + + + void ChangeSummaryImpl::setPropValue(void** value, unsigned int* len, DataObjectImpl* ob, const Property& prop) + { + + *len = 0; + switch (prop.getTypeEnum()) + { + case Type::BooleanType: + *value = new long; + if (!ob->isSet(prop) && !prop.isDefaulted()) + { + *(long*)value = 0; + } + else + { + *(long*)*value = (long)ob->getBoolean(prop); + } + break; + case Type::ByteType: + *value = new long; + if (!ob->isSet(prop) && !prop.isDefaulted()) + { + *(long*)value = 0; + } + else + { + *(long*)*value = (long)ob->getByte(prop); + } + break; + case Type::CharacterType: + *value = new long; + if (!ob->isSet(prop) && !prop.isDefaulted()) + { + *(long*)value = 0; + } + else + { + *(long*)*value = (long)ob->getCharacter(prop); + } + break; + case Type::IntegerType: + *value = new long; + if (!ob->isSet(prop) && !prop.isDefaulted()) + { + *(long*)value = 0; + } + else + { + *(long*)*value = (long)ob->getInteger(prop); + } + break; + case Type::ShortType: + *value = new long; + if (!ob->isSet(prop) && !prop.isDefaulted()) + { + *(long*)value = 0; + } + else + { + *(long*)*value = (long)ob->getShort(prop); + } + break; + case Type::DoubleType: + *value = new long double; + if (!ob->isSet(prop) && !prop.isDefaulted()) + { + *(long double*)value = (long double)0; + } + else + { + *(long double*)*value = (long double)ob->getDouble(prop); + } + break; + case Type::FloatType: + *value = new float; + if (!ob->isSet(prop) && !prop.isDefaulted()) + { + *(float*)value = (float)0; + } + else + { + *(float*)*value = (float)ob->getFloat(prop); + } + break; + case Type::LongType: + *value = new int64_t; + if (!ob->isSet(prop) && !prop.isDefaulted()) + { + *(int64_t*)value = (int64_t)0; + } + else + { + *(int64_t*)*value = (int64_t)ob->getLong(prop); + } + break; + case Type::DateType: + *value = new long; + if (!ob->isSet(prop) && !prop.isDefaulted()) + { + *(long*)value = (long)0; + } + else + { + *(long*)*value = (long)(ob->getDate(prop).getTime()); + } + break; + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::StringType: + case Type::UriType: + if (!ob->isSet(prop) && !prop.isDefaulted()) + { + *value = 0; + *len = 0; + } + else + { + unsigned int siz = ob->getLength(prop); + if (siz > 0) { + *value = new wchar_t[siz]; + *len = ob->getString(prop,(wchar_t*)*value, siz); + } + else { + *value = 0; + *len = 0; + } + } + break; + case Type::BytesType: + if (!ob->isSet(prop) && !prop.isDefaulted()) + { + *value = 0; + *len = 0; + } + else + { + unsigned int siz = ob->getLength(prop); + if (siz > 0) { + *value = new char[siz]; + *len = ob->getBytes(prop,(char*)*value, siz); + } + else { + *value = 0; + *len = 0; + } + } + break; + case Type::OtherTypes: + case Type::DataObjectType: + case Type::ChangeSummaryType: + if (!ob->isSet(prop) && !prop.isDefaulted()) + { + *value = 0; + } + else + { + *value = (void*)ob->getDataObject(prop); + } + break; + default: + SDO_THROW_EXCEPTION("(ChangeSummary)setPropValue" , + SDOUnsupportedOperationException, "Type is not recognised and cannot be saved"); + break; + } + } + + void ChangeSummaryImpl::setManyPropValue(void** value, unsigned int *len, DataObjectImpl* ob, + DataObjectImpl* listob, const Property& prop) + { + + *len = 0; + switch (prop.getTypeEnum()) + { + case Type::BooleanType: + *value = new long; + if (!ob->isSet(prop) && !prop.isDefaulted()) + { + *(long*)value = (long)0; + } + else + { + *(long*)*value = (long)listob->getBoolean(); + } + break; + case Type::ByteType: + *value = new long; + if (!ob->isSet(prop) && !prop.isDefaulted()) + { + *(long*)value = (long)0; + } + else + { + *(long*)*value = (long)listob->getByte(); + } + break; + case Type::CharacterType: + *value = new long; + if (!ob->isSet(prop) && !prop.isDefaulted()) + { + *(long*)value = (long)0; + } + else + { + *(long*)*value = (long)listob->getCharacter(); + } + break; + case Type::IntegerType: + *value = new long; + if (!ob->isSet(prop) && !prop.isDefaulted()) + { + *(long*)value = (long)0; + } + else + { + *(long*)*value = (long)listob->getInteger(); + } + break; + case Type::ShortType: + *value = new long; + if (!ob->isSet(prop) && !prop.isDefaulted()) + { + *(long*)value = (long)0; + } + else + { + *(long*)*value = (long)listob->getShort(); + } + break; + case Type::DoubleType: + *value = new long double; + if (!ob->isSet(prop) && !prop.isDefaulted()) + { + *(long double*)value = (long double)0; + } + else + { + *(long double*)*value = (long double)listob->getDouble(); + } + break; + case Type::FloatType: + *value = new float; + if (!ob->isSet(prop) && !prop.isDefaulted()) + { + *(float*)value = (float)0; + } + else + { + *(float*)*value = (float)listob->getFloat(); + } + break; + case Type::LongType: + *value = new int64_t; + if (!ob->isSet(prop) && !prop.isDefaulted()) + { + *(int64_t*)value = (int64_t)0; + } + else + { + *(int64_t*)*value = (int64_t)listob->getLong(); + } + break; + case Type::DateType: + *value = new long; + if (!ob->isSet(prop) && !prop.isDefaulted()) + { + *(long*)value = (long)0; + } + else + { + *(long*)*value = (long)(listob->getDate().getTime()); + } + break; + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::StringType: + case Type::UriType: + if (!ob->isSet(prop) && !prop.isDefaulted()) + { + *value = 0; + *len = 0; + } + else + { + unsigned int siz = listob->getLength(prop); + if (siz > 0) + { + *value = new wchar_t[siz]; + *len = listob->getString((wchar_t*)*value, siz); + } + } + break; + case Type::BytesType: + if (!ob->isSet(prop) && !prop.isDefaulted()) + { + *value = 0; + *len = 0; + } + else + { + unsigned int siz = listob->getLength(prop); + if (siz > 0) + { + *value = new char[siz]; + *len = listob->getBytes((char*)*value, siz); + } + } + break; + + case Type::OtherTypes: + case Type::DataObjectType: + case Type::ChangeSummaryType: + SDO_THROW_EXCEPTION("(ChangeSummary)setManyPropValue" , + SDOUnsupportedOperationException, "A many prop data object value is being set"); + //*value = (void*)ob; + break; + default: + SDO_THROW_EXCEPTION("(ChangeSummary)setManyPropValue" , + SDOUnsupportedOperationException, "Type is not recognised and cannot be saved"); + break; + } + } + + void ChangeSummaryImpl::logChange(DataObjectImpl* ob, + const Property& prop) + { + // need to record the old value, unless the object + // is in the created list, in which case we store + // nothing. + + LOGINFO_1(INFO,"ChangeSummary:LogChange %s",prop.getName()); + + CREATELOG_MAP::iterator createLogIter; + + unsigned int len; + + createLogIter = createdMap.find(ob); + if (createLogIter != createdMap.end()) + { + LOGINFO(INFO,"ChangeSummary: no need to log change"); + return; + } + + DELETELOG_MAP::iterator deleteLogIter; + + deleteLogIter = deletedMap.find(ob); + if (deleteLogIter != deletedMap.end()) + { + LOGINFO(INFO,"ChangeSummary: no need to log change - already deleted"); + return; + } + + CHANGELOG_MAP::iterator changeLogIter; + + changeLogIter = changedMap.find(ob); + if (changeLogIter == changedMap.end()) + { + LOGINFO(INFO,"ChangeSummary: A change to an object which was not previously changed"); + changedMap.insert(std::make_pair(ob, changeLogItem(ob->getType(),prop, + ob->getSequence(), ob))); + changedDataObjects.append(ob, ChangedDataObjectList::Change); + } + else + { + LOGINFO(INFO,"ChangeSummary: A change to an object which has already been changed"); + } + + changeLogIter = changedMap.find(ob); + if (changeLogIter == changedMap.end()) + { + LOGINFO(INFO,"ChangeSummary: Problem - no changes to append to"); + return; + } + + SettingList& slist = (changeLogIter->second).getSettings(); + + void* value; + + for (int i=0;igetProperty().getName(),prop.getName())) + { + LOGINFO(INFO,"ChangeSummary: Change of a property which was already changed - ignore"); + return; + } + } + + // need to check if the property has already been set, + // There could be many Settings if the item was a list, + // but we dont care here about that. + + if (!ob->isSet(prop)) + { + slist.append(new Setting(false,false,0,0,prop,0)); + return; + } + + if (prop.isMany()) + { + // We are appending, not modifying + // we need to store the list as it was. + + LOGINFO(INFO,"ChangeSummary: logging a change to a many valued property"); + + DataObjectList& dol = ob->getList(prop); + if (dol.size() == 0) + { + slist.append(new Setting(false,false,0,0,prop,0)); + return; + } + for (unsigned int i=0;i< dol.size(); i++) + { + DataObject* dob = dol[i]; + if (prop.getType().isDataType()) { + setManyPropValue(&value, &len, (DataObjectImpl*)ob, + (DataObjectImpl*)dob, prop); + slist.append(new Setting(true,false,value,len,prop,i)); + } + else{ + value = (void*)dob; + slist.append(new Setting(true,false,value,0,prop,i)); + } + } + } + else + { + setPropValue(&value,&len,ob,prop); + slist.append(new Setting(true,ob->isNull(prop),value,len,prop,0)); + } + + return; + } + + + + void ChangeSummaryImpl::undoChanges() + { + // TODO + /* Plan for undoChanges: + + There are three lists of information. + The created list is a list of data objects which were created during logging. + These data objects will have current state, and will represent the value of a + property of their containing object. As they had no state before they were + created, the undoChanges needs to unSet the property values for these first. + + The deleted list contains a list of objects which were deleted. The objects + themselves are not valid, but can be used to obtain a list of settings + representing the values of the properties at the time the object was + deleted. Here are recursive create is needed to re-create an object + similar to the deleted one, and set its properties using the settings. + The deleted object may well contain other deleted objects as its + property values, so these too will have entries in the deleted list, and + need to be found and re-created. + + The changed list holds a list of settings for properties of data objects + which have been changed. These objects may also be in the deleted list, so# + may not be valid. They will not be in the created list. First check that + the object is not in the deleted list. If it is, then the changes need to + be applied to the data object which we created when undoing the deleted list, + otherwise we just apply the change to a data object which exists. + */ + + /* what about items in many-valued properties? I guess we need to check and + search the values returned for the list to find the object to delete*/ + LOGINFO(INFO,"ChangeSummary UndoChanges not implemented"); + return; + } + + + void ChangeSummaryImpl::beginLogging() + { + + // Clear down the lists and their contents, if there was already + // some activity. + + if (logging) endLogging(); + changedMap.clear(); + deletedMap.clear(); + createdMap.clear(); + changedDataObjects.clear(); + + LOGINFO(INFO,"ChangeSummary: logging switched on"); + + logging = true; + return; + } + + void ChangeSummaryImpl::endLogging() + { + logging = false; + + LOGINFO(INFO,"ChangeSummary: logging switched off"); + + return; + } + + bool ChangeSummaryImpl::isLogging() + { + return logging; + } + +/////////////////////////////////////////////////////////////////////////////////////// + void ChangeSummaryImpl::debugPrint(){} +// { +// ChangedDataObjectList& dol = getChangedDataObjects(); +// +// CREATELOG_MAP::iterator createLogIter; +// DELETELOG_MAP::iterator deleteLogIter; +// CHANGELOG_MAP::iterator changeLogIter; +// +// for (int i=0;igetLongValue(); +// break; +// case Type::DateType: +// cout << "Date:" << sl[j].getDateValue().getTime(); +// break; +// case Type::BigDecimalType: +// case Type::BigIntegerType: +// case Type::StringType: +// case Type::UriType: +// { +// unsigned int len = sl[j].getLength(); +// if (len > 0) { +// wchar_t* buf = new wchar_t[len]; +// len = sl[j].getStringValue(buf,len); +// cout <<"String type" ; +// for (int i=0;i 0) { +// char* buf = new char[len]; +// len = sl[j].getBytesValue(buf,len); +// cout <<"Bytes type" ; +// for (int i=0;isecond).getSettings()); + } + changeLogIter = changedMap.find((DataObjectImpl*)dob); + if (changeLogIter != changedMap.end()){ + return ((changeLogIter->second).getSettings()); + } + SDO_THROW_EXCEPTION("(ChangeSummary(getOldValues" , + SDOIndexOutOfRangeException, "Data object is not in the change summary"); + } + + + + const char* ChangeSummaryImpl::getOldXpath(RefCountingPointer dol) + { + DELETELOG_MAP::iterator deleteLogIter; + DataObject* dob = dol; + deleteLogIter = deletedMap.find((DataObjectImpl*)dob); + if (deleteLogIter != deletedMap.end()){ + return ((deleteLogIter->second).getOldXpath()); + } + return 0; + } + + + const Setting& ChangeSummaryImpl::getOldValue(DataObjectPtr dol, const Property& property) + { + DELETELOG_MAP::iterator deleteLogIter; + CHANGELOG_MAP::iterator changeLogIter; + DataObject* dob = dol; + + deleteLogIter = deletedMap.find((DataObjectImpl*)dob); + if (deleteLogIter != deletedMap.end()) + { + SettingList& sl = (deleteLogIter->second).getSettings(); + for (int i=0;i < sl.size(); i++) + { + if (!strcmp(property.getName(), + sl.get(i)->getProperty().getName())) + return (*sl.get(i)); + } + } + + changeLogIter = changedMap.find((DataObjectImpl*)dob); + if (changeLogIter != changedMap.end()) + { + SettingList& sl = (changeLogIter->second).getSettings(); + for (int i=0;i < sl.size(); i++) + { + if (!strcmp(property.getName(), + sl.get(i)->getProperty().getName())) + return (*sl.get(i)); + } + } + + SDO_THROW_EXCEPTION("(ChangeSummary(getOldValue)" , + SDOIndexOutOfRangeException, "Data object is not in the change summary"); + } + + DataObjectPtr ChangeSummaryImpl::getOldContainer(DataObjectPtr dol) + { + CHANGELOG_MAP::iterator changeLogIter; + DataObject* dob = dol; + changeLogIter = changedMap.find((DataObjectImpl*)dob); + + if (changeLogIter != changedMap.end()) + { + return (changeLogIter->second).getOldContainer(); + } + return 0; + } + + const Property& ChangeSummaryImpl::getOldContainmentProperty(DataObjectPtr dol) + { + CHANGELOG_MAP::iterator changeLogIter; + DataObject* dob = dol; + changeLogIter = changedMap.find((DataObjectImpl*)dob); + + if (changeLogIter == changedMap.end()) + { + SDO_THROW_EXCEPTION("(ChangeSummary(getOldContainmentProperty)" , + SDOIndexOutOfRangeException, "Data object is not in the change summary"); + } + return (changeLogIter->second).getOldContainmentProperty(); + } + + + // + // Creations and deletions can be just logged in the normal + // way. Changes have to be handled specially, because we + // need the old value, but the data object now contains the + // current value. + // + + void ChangeSummaryImpl::appendToCreations(const Property& p, + DataObjectPtr dob, DataObjectPtr cont) + { + LOGINFO(INFO,"ChangeSummary: Appending to creations list"); + DataObject* pdob = (DataObject*)dob; + DataObject* pcont = (DataObject*)cont; + logCreation((DataObjectImpl*)pdob,(DataObjectImpl*)pcont,p); + return; + } + + + void ChangeSummaryImpl::appendToDeletions(const Property& p, + DataObjectPtr dob, DataObjectPtr cont, const char* oldpath ) + { + DELETELOG_MAP::iterator deleteLogIter; + + LOGINFO_1(INFO,"ChangeSummary:Appending to deletions list %s",oldpath); + + DataObject* pdob = (DataObject*)dob; + DataObject* pcont = (DataObject*)cont; + logDeletion((DataObjectImpl*)pdob,(DataObjectImpl*)pcont,p, + oldpath, false); + return; + } + + + unsigned int ChangeSummaryImpl::stringConvert(char** value, const char* c, const Property& p) + { + // code duplicated from typeimpl + switch (p.getTypeEnum()) + { + case Type::BooleanType: + *value = new char[sizeof(long)]; + if ((c == 0) || strcmp(c,"true")) + { + *(long*)*value = 0; + } + else + { + *(long*)*value = 1; + } + return sizeof(long); + + case Type::ByteType: + case Type::CharacterType: + case Type::IntegerType: + case Type::ShortType: + *value = new char[sizeof(long)]; + *(long*)*value = atoi(c); + return sizeof(long); + + case Type::DoubleType: + *value = new char[sizeof(long double)]; + // TODO - atof not suitable here + *(long double*)*value = (long double)atof(c); + return sizeof(long double); + + case Type::FloatType: + *value = new char[sizeof(float)]; + *(float*)*value = (float)atof(c); + return sizeof(float); + + case Type::LongType: + *value = new char[sizeof(int64_t)]; +#if defined(WIN32) || defined (_WINDOWS) + *(int64_t*)*value = (int64_t)_atoi64(c); +#else + *(int64_t*)*value = (int64_t)strtoll(c, NULL, 0); +#endif + return sizeof(int64_t); + + case Type::DateType: + *value = new char[sizeof(time_t)]; + *(time_t*)*value = (time_t)atoi(c); + return sizeof(time_t); + + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::StringType: + case Type::UriType: + { + char* vw = new char[(strlen(c)+1)*sizeof(wchar_t)]; + wchar_t* pvw = (wchar_t*)vw; + for (unsigned int i=0;i< strlen(c);i++) + { + pvw[i] = (wchar_t)c[i]; + } + pvw[strlen(c)] = 0; + *value = vw; + return strlen(c); + } + break; + case Type::BytesType: + { + char* vc = new char[strlen(c)+1]; + for (unsigned int i=0;i< strlen(c);i++) + { + vc[i] = (char)c[i]; + } + vc[strlen(c)] = 0; + *value = vc; + return strlen(c); + } + break; + + case Type::OtherTypes: + case Type::DataObjectType: + case Type::ChangeSummaryType: + default: + { + std::string msg("Cannot set CString on object of type:"); + msg += p.getType().getName(); + SDO_THROW_EXCEPTION("setString" , + SDOInvalidConversionException, msg.c_str()); + break; + } + } + return 0; + } + + void ChangeSummaryImpl::appendToChanges(const Property& p, + DataObjectPtr dob , SDOXMLString value, int index) + { + CHANGELOG_MAP::iterator changeLogIter; + + LOGINFO(INFO,"ChangeSummary Appending to changes list"); + + DataObject* pdob = (DataObject*)dob; + + + changeLogIter = changedMap.find((DataObjectImpl*)pdob); + if (changeLogIter == changedMap.end()) + { + + LOGINFO(INFO,"ChangeSummary: A change to an object which was not previously changed"); + + changedMap.insert(std::make_pair((DataObjectImpl*)pdob, + changeLogItem(dob->getType(),p, + dob->getSequence(), (DataObjectImpl*)pdob))); + changedDataObjects.append((DataObjectImpl*)pdob, + ChangedDataObjectList::Change); + } + + changeLogIter = changedMap.find((DataObjectImpl*)pdob); + if (changeLogIter == changedMap.end()) + { + + LOGINFO(INFO,"ChangeSummary: no changes to append to"); + + return; + } + + SettingList& slist = (changeLogIter->second).getSettings(); + + // simply need to insert a setting - no requirement to validate + // against existing settings + + char* datavalue = 0; + + unsigned int len = stringConvert(&datavalue, (const char*)value , p); + + slist.append(new Setting(true,false,datavalue,len,p,index)); + + // The datavalue will be freed by the deletion of the setting later + } + + + void ChangeSummaryImpl::appendToChanges(const Property& p, + DataObjectPtr dob , DataObjectPtr indob, int index) + { + CHANGELOG_MAP::iterator changeLogIter; + + LOGINFO(INFO,"ChangeSummary Appending to changes list (2)"); + + DataObject* pdob = (DataObject*)dob; + + changeLogIter = changedMap.find((DataObjectImpl*)pdob); + if (changeLogIter == changedMap.end()) + { + LOGINFO(INFO,"ChangeSummary: A change to an object which was not previously changed"); + + changedMap.insert(std::make_pair((DataObjectImpl*)pdob, + changeLogItem(dob->getType(),p, + dob->getSequence(), (DataObjectImpl*)pdob))); + changedDataObjects.append((DataObjectImpl*)pdob, + ChangedDataObjectList::Change); + } + + changeLogIter = changedMap.find((DataObjectImpl*)pdob); + if (changeLogIter == changedMap.end()) + { + LOGINFO(INFO,"ChangeSummary: Problem - no changes to append to"); + + return; + } + + SettingList& slist = (changeLogIter->second).getSettings(); + + // simply need to insert a setting - no requirement to validate + // against existing settings + + + slist.append(new Setting(true,false,(void*)indob,0,p,index)); + + } + + + + + ///////////////////////////////////////////////////////////// + // log items are for all lists, but contain different things + // depending on whether they are deletions, additions... + ///////////////////////////////////////////////////////////// + + createLogItem::createLogItem(const Type& tp, const Property& prop, + DataObjectImpl* cont) : + theOldContainmentProperty(prop), theOldContainer(cont), + theType(tp) + { + } + + DataObjectImpl* createLogItem::getOldContainer() + { + return theOldContainer; + } + + const Type& createLogItem::getOldType() + { + return theType; + } + + const Property& createLogItem::getOldContainmentProperty() + { + return theOldContainmentProperty; + } + + + + changeLogItem::changeLogItem(const Type& tp, + const Property& prop, + SequencePtr seq, + DataObjectImpl* cont) : + theOldContainmentProperty(prop), theOldContainer(cont), + theType(tp) + { + if (seq) + { + theSequence = new SequenceImpl((SequenceImpl*)seq); + } + else + { + theSequence = 0; + } + } + + changeLogItem::changeLogItem(const changeLogItem& cin) : + theOldContainmentProperty(cin.theOldContainmentProperty), + theType(cin.theType) + { + if (cin.theSequence) theSequence = new SequenceImpl((SequenceImpl*)cin.theSequence); + else theSequence = 0; + theOldContainer = cin.theOldContainer; + theSettings = cin.theSettings; + + } + + changeLogItem::~changeLogItem() + { + if (theSequence) delete theSequence; + } + + DataObjectImpl* changeLogItem::getOldContainer() + { + return theOldContainer; + } + + const Type& changeLogItem::getOldType() + { + return theType; + } + + const Property& changeLogItem::getOldContainmentProperty() + { + return theOldContainmentProperty; + } + + SettingList& changeLogItem::getSettings() + { + return theSettings; + } + + SequencePtr changeLogItem::getSequence() + { + return theSequence; + } + + + deleteLogItem::deleteLogItem(DataObject* dob, + const Property& prop, SequencePtr seq , + const char* oldpath, DataObjectImpl* cont + ) : + theOldContainmentProperty(prop), theOldContainer(cont), + theActualObject(dob), + theType(dob->getType()) + { + if (seq) + { + theSequence = new SequenceImpl((SequenceImpl*)seq); + } + else + { + theSequence = 0; + } + if (oldpath !=0 && strlen(oldpath) != 0) + { + theOldXpath = new char[strlen(oldpath)+1]; + strcpy(theOldXpath,oldpath); + } + else + { + theOldXpath = 0; + } + } + + const char* deleteLogItem::getOldXpath() + { + return theOldXpath; + } + + DataObjectImpl* deleteLogItem::getOldContainer() + { + return theOldContainer; + } + + deleteLogItem::deleteLogItem(const deleteLogItem& cin): + theOldContainmentProperty(cin.theOldContainmentProperty), + theType(cin.theType), theActualObject(cin.theActualObject) + { + if (cin.theSequence) theSequence = new SequenceImpl((SequenceImpl*)cin.theSequence); + else theSequence = 0; + theOldContainer = cin.theOldContainer; + theSettings = cin.theSettings; + if (cin.theOldXpath != 0) + { + theOldXpath = new char[strlen(cin.theOldXpath) + 1]; + strcpy(theOldXpath, cin.theOldXpath); + } + else + { + theOldXpath = 0; + } + } + + deleteLogItem::~deleteLogItem() + { + theActualObject = 0; + if (theSequence) delete theSequence; + if (theOldXpath != 0) + { + delete[] theOldXpath; + } + } + + const Type& deleteLogItem::getOldType() + { + return theType; + } + + const Property& deleteLogItem::getOldContainmentProperty() + { + return theOldContainmentProperty; + } + + SettingList& deleteLogItem::getSettings() + { + return theSettings; + } + + SequencePtr deleteLogItem::getSequence() + { + return theSequence; + } + + void deleteLogItem::setSequence(SequencePtr s) + { + if (theSequence) delete theSequence; + if (s) { + theSequence = new SequenceImpl((SequenceImpl*)s); + } + else { + theSequence = 0; + } + return; + } + +}; +}; + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummaryImpl.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummaryImpl.h new file mode 100644 index 0000000000..6137532315 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangeSummaryImpl.h @@ -0,0 +1,405 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _CHANGESUMMARYIMPL_H_ +#define _CHANGESUMMARYIMPL_H_ + +#include "commonj/sdo/disable_warn.h" + + +#include "commonj/sdo/ChangedDataObjectListImpl.h" +#include "commonj/sdo/SettingList.h" +#include "commonj/sdo/ChangeSummary.h" +#include "commonj/sdo/RefCountingPointer.h" +#include "commonj/sdo/SDOXMLString.h" + +#include + +namespace commonj{ +namespace sdo { + + + /** + * ChangeLogItem is a part of a change summary. + * The change summary consisists of change items, + * deletion items and creation items. They are held in three + * lists as they have slightly different contents. + * The change log items hold old values for all the changes to + * properties of the data object concerned. + */ + + class changeLogItem { + + public: + + changeLogItem(const Type& tp, const Property& prop,SequencePtr seq, + DataObjectImpl* cont = 0 ); + changeLogItem(const changeLogItem& cin); + ~changeLogItem(); + DataObjectImpl* getOldContainer(); + const Property& getOldContainmentProperty(); + const Type& getOldType(); + SettingList& getSettings(); + SequencePtr getSequence(); + + private: + + const Property& theOldContainmentProperty; + DataObjectImpl* theOldContainer; + const Type& theType; + SettingList theSettings; + SequencePtr theSequence; + }; + + /** + * CreateLogItem is a part of a change summary. + * The change summary consisists of change items, + * deletion items and creation items. They are held in three + * lists as they have slightly different contents. + * The create log items hold the data object itself, + * and details of its container. + */ + + + class createLogItem { + + public: + + createLogItem(const Type& tp, const Property& prop, DataObjectImpl* cont = 0); + + + DataObjectImpl* getOldContainer(); + const Property& getOldContainmentProperty(); + const Type& getOldType(); + + private: + + const Property& theOldContainmentProperty; + DataObjectImpl* theOldContainer; + const Type& theType; + }; + + /** + * DeleteLogItem is a part of a change summary. + * The change summary consisists of change items, + * deletion items and creation items. They are held in three + * lists as they have slightly different contents. + * The delete log items hold the old data object , and + * details of the properties as they were before deletion + */ + + class deleteLogItem { + + public: + + + deleteLogItem(DataObject* dob, const Property& prop, + SequencePtr seq,const char *oldpath, + DataObjectImpl* cont = 0); + + + deleteLogItem(const deleteLogItem& cin); + ~deleteLogItem(); + DataObjectImpl* getOldContainer(); + const Property& getOldContainmentProperty(); + const Type& getOldType(); + const char* getOldXpath(); + SettingList& getSettings(); + SequencePtr getSequence(); + void setSequence(SequencePtr s); + + private: + + const Property& theOldContainmentProperty; + DataObjectImpl* theOldContainer; + + /** theActualObject + * A counting pointer to the object is held, such that the + * object is not freed, even if deleted. This rcp will not + * be used to refer to the object, but makes sure that the + * object does not reuse a memory address of a previously + * deleted object until the change summary is destroyed. + */ + + RefCountingPointer theActualObject; + const Type& theType; + SettingList theSettings; + SequencePtr theSequence; + char * theOldXpath; + }; + + + /** ChangeSummaryImpl implements the abstract class ChangeSummary. + * The change summary consisists of change items, + * deletion items and creation items. They are held in three + * lists as they have slightly different contents. + */ + + class ChangeSummaryImpl : public ChangeSummary + { + public: + ChangeSummaryImpl(); + + virtual ~ChangeSummaryImpl(); + + /** + * The new and modified objects in the list are references to objects that + * are associated with this change summary. + * The deleted objects in the list are references to copies of the objects + * as they appeared at the time that event logging was enabled; + * if the deleted objects have references to other objects, + * the references will also refer to copies of the target objects. + * Return a list of changed data objects. + */ + + virtual ChangedDataObjectList& getChangedDataObjects(); + + + /** getOldSettings returns a list of settings. + * Returns a list of Settings + * that represent the property values of the given dataObject + * at the point when logging began. + * In the case of a deleted object, + * the list will include Settings for all the properties. + * An old value Setting indicates the value at the + * point logging begins. A setting is only produced for + * modified objects if either the old value differs from the current value or + * if the isSet differs from the current value. + * No Settings are produced for created objects. + * Param dataObject the object in question. + * Return a list of settings. + */ + virtual SettingList& getOldValues(DataObjectPtr dataObject); + + /** getOldXpath returns the old path before the setting. + * + * Returns a path where the object was located before the setting took place. + */ + virtual const char* getOldXpath(RefCountingPointer dol); + + + /** beginLogging() sets the change summary in logging mode. + * + * The change summary is initially inactive. Setting it to logging mode + * starts the process of recording all the settings made. + */ + + virtual void beginLogging(); + + /** endLogging() stops logging. + * + * This method stops logging, but does not clear out the change summary. + * The changes are valid until the summary is next set to logging, at which time + * all old settings are lost. + */ + virtual void endLogging(); + + + + /** isLogging() returns true if logging is enabled. + * + * Indicates whether change logging is on (true) or off (false). + */ + + virtual bool isLogging(); + + + + /** isCreated() returns true if the object was created during logging. + * + * Returns whether or not the specified data object was created while logging. + * Any object that was added to the data graph + * but was not in the data graph when logging began, + * will be considered created. + * Param dataObject the data object in question. + * Return true if the specified data object was created. + */ + virtual bool isCreated(DataObjectPtr dataObject); + + /** isDeleted() - true if the object was deleted during logging. + * + * Returns whether or not the specified data object was deleted while logging. + * Any object that is not contained by the data graph will be considered + * deleted. + * Param dataObject the data object in question. + * Return true if the specified data object was deleted. + */ + virtual bool isDeleted(DataObjectPtr dataObject); + + + /** isModified() - true if the object was changed during logging. + * + * Returns whether or not the specified data object was updated while logging. + * An object that was contained in the data graph when logging began, + * and remains in the graph when logging ends will be considered for changes. + * An object considered modified must have at least one old value Setting. + * Param dataObject the data object in question. + * Return true if the specified data object was modified. + */ + virtual bool isModified(DataObjectPtr dataObject); + + /** getOldValue() gets the setting showing the old value. + * + * Returns a setting for the specified property + * representing the property value of the given dataObject + * at the point when logging began. + * Returns null if the property has not changed and + * has not been deleted. + * Param dataObject the object in question. + * Param property the property of the object. + * Return the Setting for the specified property. + */ + + virtual const Setting& getOldValue(DataObjectPtr dataObject, const Property& property); + + /** getOldContainer() gets the container before the setting. + * + * Returns the value of the container data object + * at the point when logging began. + * Param dataObject the object in question. + * Return the old container data object. + */ + virtual DataObjectPtr getOldContainer(DataObjectPtr dataObject); + + /** getOldContainmentProperty() - gives the property before setting. + * + * Returns the value of the containment property data object property + * at the point when logging began. + * Param dataObject the object in question. + * Return the old containment property. + */ + virtual const Property& getOldContainmentProperty(DataObjectPtr dataObject); + + /** undoChanges() - Not Implemented. + * + * NOT IMPLEMENTED + * + * Undoes all changes in the log to restore the tree of + * DataObjects to its original state when logging began. + * isLogging() is unchanged. The log is cleared. + */ + virtual void undoChanges(); + + /** getOldSequence() - Not Implemented. + * + * NOT IMPLEMENTED + * + * This method gives back the sequence of a data object as it + * appeared when logging was switched on. The data object may be + * a deleted data object or a changed data object. If the + * data object was not sequenced, this returns null. + */ + + virtual SDO_API SequencePtr getOldSequence(DataObjectPtr dataObject); + + bool isInCreatedMap(DataObjectImpl* ob); + + void logDeletion(DataObjectImpl* ob, + DataObjectImpl* cont, const Property& prop, + const char* oldpath, + bool loggingChildren = true + ); + + void logCreation(DataObjectImpl* ob, + DataObjectImpl* cont, const Property& prop + ); + + void logChange(DataObjectImpl* ob, const Property& prop + ); + + + SDO_API void debugPrint(); + + void removeFromChanges(DataObjectImpl* ob); + + + /** + * appendToCreations is used by deserialization + * This method helps to rebuild a change summary by populating the + * lists without the changes actually being logged. + */ + + void appendToCreations(const Property& p, + DataObjectPtr dob, + DataObjectPtr cont); + + + /** + * appendToDeletions is used by deserialization + * This method helps to rebuild a change summary by populating the + * lists without the changes actually being logged. + */ + void appendToDeletions(const Property& p, + DataObjectPtr dob, + DataObjectPtr cont, + const char* oldpath); + + + unsigned int stringConvert( + char** value, + const char* c, + const Property& p); + + /** + * appendToChangesis used by deserialization + * This method helps to rebuild a change summary by populating the + * lists without the changes actually being logged. + */ + + void appendToChanges(const Property& p, + DataObjectPtr dob, + SDOXMLString value, + int index); + + void appendToChanges(const Property& p, + DataObjectPtr dob, + DataObjectPtr pdob, + int index); + + DataObjectPtr matchDeletedObject(SDOXMLString path); + + + private: + + + void setPropValue(void** value, unsigned int *len, DataObjectImpl* ob, const Property& prop); + void setManyPropValue(void** value, unsigned int *len, DataObjectImpl* ob, + DataObjectImpl* listob, const Property& prop); + bool logging; + + typedef std::map CREATELOG_MAP; + typedef std::map DELETELOG_MAP; + typedef std::map CHANGELOG_MAP; + + CHANGELOG_MAP changedMap; + CREATELOG_MAP createdMap; + DELETELOG_MAP deletedMap; + + ChangedDataObjectListImpl changedDataObjects; + + + + + +}; +}; +}; +#endif //_CHANGESUMMARYIMPL_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangedDataObjectList.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangedDataObjectList.h new file mode 100644 index 0000000000..ed4ee8e585 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangedDataObjectList.h @@ -0,0 +1,93 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _CHANGEDDATAOBJECTLIST_H_ +#define _CHANGEDDATAOBJECTLIST_H_ + + +#include "commonj/sdo/RefCountingPointer.h" + +#include + +/** + * namespace commonj is the root namespace for SDO + */ + +namespace commonj{ + +/** + * sdo is the namespace holding the SDO core + */ + +namespace sdo{ + +class DataObject; + +/** + * + * A list for holding a record of changes which have happened + * during logging in a change summary. + */ + +class ChangedDataObjectList +{ + +public: + +/** \enum ChangeType + * + * An enum for create, change or delete types in a change record + */ + enum ChangeType + { + Undefined, + Create, + Change, + Delete + }; + +/** [] is the index operator. + * + * Gets the nth element of a list + */ + virtual SDO_API DataObjectPtr operator[] (unsigned int pos) = 0; + virtual SDO_API const DataObjectPtr operator[] (unsigned int pos) const = 0; + +/** size() returns the number of list elements. + * + * Returns the number of list elements + */ + + virtual SDO_API unsigned int size () const = 0; + +/** getType() returns the type of a list element. + * + * The type of change is one of the enum ChangeType, being a + * creation, a deletion or an update. + */ + + virtual SDO_API ChangeType getType(unsigned int index) = 0; + +}; +}; +}; +#endif + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangedDataObjectListImpl.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangedDataObjectListImpl.cpp new file mode 100644 index 0000000000..b98a33d411 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangedDataObjectListImpl.cpp @@ -0,0 +1,248 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/ChangedDataObjectListImpl.h" + + +#include +#include "commonj/sdo/Property.h" +#include "commonj/sdo/Type.h" +#include "commonj/sdo/DataObject.h" +#include "commonj/sdo/Logger.h" +#include "commonj/sdo/SDORuntimeException.h" +#include "commonj/sdo/DataObjectImpl.h" + + +namespace commonj{ +namespace sdo { + + /** CDOListElement + * + * constructor + */ + + CDOListElement::CDOListElement() + { + theObject = 0; + theType = ChangedDataObjectList::Undefined; + } + + /** CDOListElement + * + * constructor from a data object and a change + */ + + CDOListElement::CDOListElement(DataObject* in, ChangedDataObjectList::ChangeType type) + { + theObject = in; + theType = type; + } + + /** ~CDOListElement() + * + * destructor + */ + + CDOListElement::~CDOListElement() + { + } + + /** getObject() + * + * return the changed data object + */ + + DataObject* CDOListElement::getObject() const + { + return theObject; + } + + /** + * + * return the type of change getType() + */ + + ChangedDataObjectList::ChangeType CDOListElement::getType() const + { + return theType; + } + + /** ChangedDataObjectListImpl + * + * constructor + */ + + ChangedDataObjectListImpl::ChangedDataObjectListImpl(CHANGEDDATAOBJECT_VECTOR p) : plist (p) + { + } + + /** ChangedDataObjectListImpl + * + * copy constructor + */ + + ChangedDataObjectListImpl::ChangedDataObjectListImpl(const ChangedDataObjectListImpl &pin) + { + plist = std::vector< CDOListElement >(pin.getVec()); + } + + /** ChangedDataObjectListImpl + * + * default constructor + */ + + ChangedDataObjectListImpl::ChangedDataObjectListImpl() + { + } + + + /** ~ChangedDataObjectListImpl + * + * destructor + */ + + ChangedDataObjectListImpl::~ChangedDataObjectListImpl() + { + } + + /** [] index operator + * + * + */ + + RefCountingPointer ChangedDataObjectListImpl::operator[] (unsigned int pos) + { + validateIndex(pos); + return plist[pos].getObject(); + } + + /** [] index operator + * + * + */ + + const RefCountingPointer ChangedDataObjectListImpl::operator[] (unsigned int pos) const + { + validateIndex(pos); + return plist[pos].getObject(); + } + + /** get() gets an element at the index. + * + */ + + DataObject* ChangedDataObjectListImpl::get(unsigned int pos) + { + validateIndex(pos); + return plist[pos].getObject(); + } + + /** size() returns the length of the list. + * + * + */ + + unsigned int ChangedDataObjectListImpl::size () const + { + return plist.size(); + } + + /** getVec() + * gets the vector which actually stores the data objects. + */ + + CHANGEDDATAOBJECT_VECTOR ChangedDataObjectListImpl::getVec() const + { + return plist; + } + + /** getType() + * returns the type of the change. + */ + + ChangedDataObjectList::ChangeType ChangedDataObjectListImpl::getType(unsigned int pos) + { + validateIndex(pos); + return plist[pos].getType(); + } + + + /** insert() + * inserts an element into the list. + */ + + void ChangedDataObjectListImpl::insert (unsigned int index, + DataObject *d, ChangedDataObjectList::ChangeType type) + { + plist.insert(plist.begin()+index, CDOListElement((DataObject*)d,type)); + } + + /** append() + * appends to the end of the list. + */ + + void ChangedDataObjectListImpl::append (DataObject *d, ChangedDataObjectList::ChangeType type) + { + plist.push_back(CDOListElement((DataObject*)d, type)); + } + + /** clear() + * empties the list. + */ + + void ChangedDataObjectListImpl::clear () + { + plist.clear(); + } + + + /** remove() + * removes an item from the list. + */ + + void ChangedDataObjectListImpl::remove(unsigned int index) + { + validateIndex(index); + plist.erase(plist.begin() +index); + return ; + } + + /** validateIndex() + * checks that the index is in range. + */ + + void ChangedDataObjectListImpl::validateIndex(unsigned int index) const + { + if ((index < 0) || (index >= size())) + { + std::string msg("Invalid index : "); + msg += index; + SDO_THROW_EXCEPTION("(ChangeSummary)validateIndex", SDOIndexOutOfRangeException, + msg.c_str()); + + } + + } + + +}; +}; + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangedDataObjectListImpl.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangedDataObjectListImpl.h new file mode 100644 index 0000000000..9baa6747e9 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ChangedDataObjectListImpl.h @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef _ChangedDataObjectListImplIMPL_H_ +#define _ChangedDataObjectListImplIMPL_H_ + +#include "commonj/sdo/disable_warn.h" + + +#include + +#include "commonj/sdo/ChangedDataObjectList.h" +namespace commonj{ +namespace sdo{ + +class DataObjectImpl; +class DataObject; + +/** + * CDOListElement is an element of the changed data object list + * in a change summary,it may be a delete, addition or change. + */ + +class CDOListElement +{ +public: + CDOListElement (); + CDOListElement (DataObject* in, ChangedDataObjectList::ChangeType type); + virtual ~CDOListElement(); + virtual ChangedDataObjectList::ChangeType getType() const; + virtual DataObject* getObject() const; +private: + DataObject* theObject; + ChangedDataObjectList::ChangeType theType; +}; + +typedef std::vector< CDOListElement > CHANGEDDATAOBJECT_VECTOR; + + +/** + * ChangedDataObjectListImpl implements ChangedDataObjectList, part of a + * change summary. + * This is the list of objects which have been altered during + * logging of a change summary. + */ + +class ChangedDataObjectListImpl : public ChangedDataObjectList +{ + +public: + ChangedDataObjectListImpl(CHANGEDDATAOBJECT_VECTOR p); + ChangedDataObjectListImpl(const ChangedDataObjectListImpl &pin); + ChangedDataObjectListImpl(); + + virtual ~ChangedDataObjectListImpl(); + virtual DataObjectPtr operator[] (unsigned int pos); + virtual const DataObjectPtr operator[] (unsigned int pos) const; + virtual DataObject* get(unsigned int pos); + virtual ChangedDataObjectList::ChangeType getType(unsigned int pos); + + + virtual unsigned int size () const; + + virtual void insert (unsigned int index, DataObject *d, ChangedDataObjectList::ChangeType type); + + virtual void append (DataObject* d, ChangedDataObjectList::ChangeType type); + + virtual void clear(); + + virtual void remove (unsigned int index); + + +private: + CHANGEDDATAOBJECT_VECTOR plist; + CHANGEDDATAOBJECT_VECTOR getVec() const; + + void validateIndex(unsigned int index) const; +}; +}; +}; +#endif diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/CopyHelper.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/CopyHelper.cpp new file mode 100644 index 0000000000..d05fc9d9c8 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/CopyHelper.cpp @@ -0,0 +1,598 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/Property.h" +#include "commonj/sdo/Type.h" +#include "commonj/sdo/TypeList.h" +#include "commonj/sdo/Sequence.h" +#include "commonj/sdo/RefCountingPointer.h" +#include "commonj/sdo/DataObjectImpl.h" + + +#include "commonj/sdo/CopyHelper.h" + +#include +using namespace std; +namespace commonj{ +namespace sdo{ + + /** CopyHelper provides static copying helper functions. + * + * CopyHelper provides shallow and deep copy of data objects. + * copyShallow() copies the DataType members of the data object. + * copy() copies all the members and recurses downwards though + * the data graph + */ + + void CopyHelper::transferitem(DataObjectPtr to, DataObjectPtr from, const Property& p) + { + if (from->isNull(p)) { + to->setNull(p); + return; + } + + switch (p.getTypeEnum()) + { + case Type::BooleanType: + to->setBoolean( p, from->getBoolean(p)); + break; + case Type::ByteType: + to->setByte( p, from->getByte(p)); + break; + case Type::CharacterType: + to->setCharacter( p, from->getCharacter(p)); + break; + case Type::IntegerType: + to->setInteger( p, from->getInteger(p)); + break; + case Type::ShortType: + to->setShort( p,from->getShort(p)); + break; + case Type::DoubleType: + to->setDouble( p, from->getDouble(p)); + break; + case Type::FloatType: + to->setFloat( p, from->getFloat(p)); + break; + case Type::LongType: + to->setLong( p, from->getLong(p)); + break; + case Type::DateType: + to->setDate( p, from->getDate(p)); + break; + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::UriType: + case Type::StringType: + { + unsigned int siz = from->getLength(p); + if (siz > 0) + { + wchar_t * buf = new wchar_t[siz]; + from->getString(p,buf, siz); + to->setString(p, buf, siz); + delete[] buf; + } + else + { + // property is set to a NULL value + to->setString(p, (const wchar_t*)0, 0); + } + } + break; + case Type::BytesType: + { + unsigned int siz = from->getLength(p); + if (siz > 0) + { + char * buf = new char[siz]; + from->getBytes(p,buf, siz); + to->setBytes(p, buf, siz); + delete buf; + } + else + { + // property is set to a NULL value + to->setBytes(p, (const char*)0, 0); + } + } + break; + default: + break; + } // switch + } + + void CopyHelper::transferlist(DataObjectList& to, DataObjectList& from, Type::Types t) + { + for (unsigned int i=0;i< from.size(); i++) + { + switch (t) + { + case Type::BooleanType: + to.append(from.getBoolean(i)); + break; + case Type::ByteType: + to.append(from.getByte(i)); + break; + case Type::CharacterType: + to.append(from.getCharacter(i)); + break; +#if __WORDSIZE ==64 + case Type::IntegerType: + to.append((int64_t)(from.getInteger(i))); + break; +#else + case Type::IntegerType: + to.append(from.getInteger(i)); + break; +#endif + case Type::ShortType: + to.append(from.getShort(i)); + break; + case Type::DoubleType: + to.append(from.getDouble(i)); + break; + case Type::FloatType: + to.append(from.getFloat(i)); + break; + case Type::LongType: + to.append(from.getLong(i)); + break; + case Type::DateType: + to.append(from.getDate(i)); + break; + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::UriType: + case Type::StringType: + { + unsigned int siz = from.getLength(i); + if (siz > 0) + { + wchar_t * buf = new wchar_t[siz]; + from.getString(i,buf,siz); + to.append(buf,siz); + delete buf; + } + else + { + // Property is set to a NULL value + to.append((const wchar_t*)0, 0); + } + } + break; + + case Type::BytesType: + { + unsigned int siz = from.getLength(i); + if (siz > 0) + { + char * buf = new char[siz]; + from.getBytes(i,buf,siz); + to.append(buf,siz); + delete buf; + } + else + { + // Property is set to a NULL value + to.append((const char*)0, 0); + } + } + break; + + default: + break; + } // case + } // for + } // method + + + + void CopyHelper::transfersequenceitem(Sequence *to, Sequence *from, const Property& p, int index) + { + switch (p.getTypeEnum()) + { + case Type::BooleanType: + to->addBoolean( p, from->getBooleanValue(index)); + break; + case Type::ByteType: + to->addByte( p, from->getByteValue(index)); + break; + case Type::CharacterType: + to->addCharacter( p, from->getCharacterValue(index)); + break; + case Type::IntegerType: + to->addInteger( p, from->getIntegerValue(index)); + break; + case Type::ShortType: + to->addShort( p,from->getShortValue(index)); + break; + case Type::DoubleType: + to->addDouble( p, from->getDoubleValue(index)); + break; + case Type::FloatType: + to->addFloat( p, from->getFloatValue(index)); + break; + case Type::LongType: + to->addLong( p, from->getLongValue(index)); + break; + case Type::DateType: + to->addDate( p, from->getDateValue(index)); + break; + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::UriType: + case Type::StringType: + { + unsigned int siz = from->getLength(index); + if (siz > 0) + { + wchar_t * buf = new wchar_t[siz]; + from->getStringValue(index, buf, siz); + to->addString(p, buf, siz); + delete[] buf; + } + else + { + // property is set to a NULL value + to->addString(p, 0, 0); + } + } + break; + case Type::BytesType: + { + unsigned int siz = from->getLength(index); + if (siz > 0) + { + char * buf = new char[siz]; + from->getBytesValue(index, buf, siz); + to->addBytes(p, buf, siz); + delete buf; + } + else + { + // property is set to a NULL value + to->addBytes(p, 0, 0); + } + } + break; + default: + break; + } // switch + } + + /** CopyHelper provides static copying helper functions. + * + * copyShallow() copies the DataType members of the data object. + * copy() copies all the members and recurses downwards though + * the data graph + */ + DataObjectPtr CopyHelper::copyShallow(DataObjectPtr dataObject) + { + return internalCopy(dataObject, false); + + } + + /** CopyHelper provides static copying helper functions. + * + * copyShallow() copies the DataType members of the data object. + * copy() copies all the members and recurses downwards though + * the data graph + */ + DataObjectPtr CopyHelper::copy(DataObjectPtr dataObject) + { + DataObjectPtr newob = internalCopy(dataObject, true); + resolveReferences(dataObject, newob); + return newob; + } + + DataObjectPtr CopyHelper::internalCopy(DataObjectPtr dataObject, + bool fullCopy) + { + + DataObject* theob = dataObject; + if (!theob) return 0; + + DataFactoryPtr fac = ((DataObjectImpl*)theob)->getDataFactory(); + if (!fac) return 0; + + const Type& t = dataObject->getType(); + DataObjectPtr newob = fac->create(t); + if (!newob) return 0; + + if ( dataObject->getType().isSequencedType() ) + { + Sequence* fromSequence = dataObject->getSequence(); + int sequence_length = fromSequence->size(); + + Sequence* toSequence = newob->getSequence(); + + for (int i=0;i < sequence_length; i++) + { + if ( fromSequence->isText(i) ) + { + const char *text = fromSequence->getCStringValue(i); + toSequence->addText(i, text); + } + else + { + const Property& seqProperty = fromSequence->getProperty(i); + SDOXMLString seqPropertyName = seqProperty.getName(); + const Type& seqPropertyType = seqProperty.getType(); + + if (seqPropertyType.isDataObjectType()) + { + if (!fullCopy) + { + continue; + } + else + { + DataObjectPtr dob; + + // retrieve the data object to be copied + if (seqProperty.isMany()) + { + int index = fromSequence->getListIndex(i); + dob = dataObject->getList(seqProperty)[index]; + } + else + { + dob = dataObject->getDataObject(seqProperty); + } + + // do the copying of referencing + if (dob) + { + // Handle non-containment reference to DataObject + if (seqProperty.isReference()) + { + // add just the reference into the sequence + // This will be resolved to a new reference later + // This is really bad but we need to add something to the + // sequence here to maintain the ordering + toSequence->addDataObject(seqProperty, 0); + } + else + { + // make a copy of the data object itself + // and add it to the sequence + toSequence->addDataObject(seqProperty, + internalCopy(dob, + true)); + } + } + } + } + else + { + // Sequence member is a primitive + transfersequenceitem(toSequence, + fromSequence, + seqProperty, + i); + + } + } // is it a text element + } // for all elements in sequence + } + else + { + PropertyList pl = dataObject->getInstanceProperties(); + for (unsigned int i=0;i < pl.size(); i++) + { + if (dataObject->isSet(pl[i])) + { + // data objects are only copied in the deep copy case + if (pl[i].getType().isDataObjectType()) + { + if (!fullCopy) + { + continue; + } + else + { + if (pl[i].isMany()) + { + DataObjectList& dolold = dataObject->getList(pl[i]); + DataObjectList& dolnew = newob->getList(pl[i]); + for (unsigned int li=0;li< dolold.size(); li++) + { + // references are maintained to the old object if it + // is outside of the copy tree + if (pl[i].isReference()) + { + // have to resolve references in a 2nd pass + } + else + { + dolnew.append(internalCopy(dolold[li],true)); + } + } + } + else + { + if (dataObject->isNull(pl[i])) { + newob->setNull(pl[i]); + continue; + } + + DataObjectPtr dob = dataObject->getDataObject(pl[i]); + if (pl[i].isReference()) + { + // have to resolve references in a 2nd pass + } + else + { + newob->setDataObject(pl[i],internalCopy(dob,true)); + } + } + } + } + else + { + if (pl[i].isMany()) + { + DataObjectList& dolold = dataObject->getList(pl[i]); + DataObjectList& dolnew = newob->getList(pl[i]); + transferlist(dolnew,dolold, pl[i].getTypeEnum()); + } + else + { + transferitem(newob,dataObject, pl[i]); + } + } // else + } + } + } + + return newob; + } + + void CopyHelper::resolveReferences(DataObjectPtr oldDO, DataObjectPtr newDO) + { + // Iterate through the properties to find references. + // If the reference is to a DataObject with the copied tree then we can + // set it to reference the DO in the new tree, otherwise it is left unset. + + findReferences(oldDO, newDO, oldDO, newDO); + + } + + void CopyHelper::findReferences(DataObjectPtr oldDO, DataObjectPtr newDO, + DataObjectPtr obj, DataObjectPtr newObj) + { + if (!obj) return; + + if ( obj->getType().isSequencedType() ) + { + Sequence* fromSequence = obj->getSequence(); + int sequence_length = fromSequence->size(); + + Sequence* toSequence = newObj->getSequence(); + + for (int i=0;i < sequence_length; i++) + { + if (!fromSequence->isText(i) ) + { + const Property& seqProperty = fromSequence->getProperty(i); + SDOXMLString seqPropertyName = seqProperty.getName(); + const Type& seqPropertyType = seqProperty.getType(); + + if (seqProperty.isReference()) + { + DataObjectPtr ref = findReference(oldDO, newDO, fromSequence->getDataObjectValue(i)); + if (ref) + { + if (seqProperty.isMany()) + { + int index = fromSequence->getListIndex(i); + newObj->getList(seqProperty).setDataObject(index, ref); + } + else + { + toSequence->setDataObjectValue(i, ref); + } + + } + } + else if (seqPropertyType.isDataObjectType()) + { + findReferences(oldDO, newDO, fromSequence->getDataObjectValue(i), toSequence->getDataObjectValue(i)); + } + } + + } // for all elements in sequence + + } + else + { + PropertyList pl = obj->getInstanceProperties(); + for (unsigned int i=0;i < pl.size(); i++) + { + if (!obj->isSet(pl[i])) + continue; + + if (!pl[i].getType().isDataObjectType()) + continue; + + if (pl[i].isMany()) + { + DataObjectList& dolold = obj->getList(pl[i]); + DataObjectList& dolnew = newObj->getList(pl[i]); + for (unsigned int li=0;li< dolold.size(); li++) + { + if (pl[i].isReference()) + { + DataObjectPtr ref = findReference(oldDO, newDO, dolold[li]); + if (ref) + { + dolnew.setDataObject(li, ref); + } + } + else + { + findReferences(oldDO, newDO, dolold[li], dolnew[li]); + } + } + } + else + { + if (pl[i].isReference()) + { + DataObjectPtr ref = findReference(oldDO, newDO, obj->getDataObject(pl[i])); + if (ref) + { + newObj->setDataObject(pl[i], ref); + } + } + else + { + findReferences(oldDO, newDO, obj->getDataObject(pl[i]), newObj->getDataObject(pl[i])); + } + } + } + } + } + + DataObjectPtr CopyHelper::findReference(DataObjectPtr oldDO, DataObjectPtr newDO, DataObjectPtr ref) + { + SDOString rootXPath = oldDO->objectToXPath(); + SDOString refXPath = ref->objectToXPath(); + + DataObjectPtr newRef; + if (refXPath.find(refXPath) == 0) + { + SDOString relXPath = refXPath.substr(rootXPath.length()); + if (relXPath == "") + newRef = newDO; + if (relXPath.find("/") == 0) + relXPath = relXPath.substr(1); + newRef = newDO->getDataObject(relXPath); + } + + return newRef; + } + + +} +}; + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/CopyHelper.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/CopyHelper.h new file mode 100644 index 0000000000..f0da4dd869 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/CopyHelper.h @@ -0,0 +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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _COPYHELPER_H_ +#define _COPYHELPER_H_ + + +#include "commonj/sdo/DataObject.h" +#include "commonj/sdo/RefCountingPointer.h" + +namespace commonj{ +namespace sdo{ + + /** CopyHelper provides static copying helper functions. + * + * CopyHelper provides shallow and deep copy of data objects. + * copyShallow() copies the DataType members of the data object. + * copy() copies all the members and recurses downwards though + * the data graph + */ + +class CopyHelper +{ + public: + + /** CopyHelper provides static copying helper functions. + * + * CopyHelper provides shallow and deep copy of data objects. + * copyShallow() copies the DataType members of the data object. + * copy() copies all the members and recurses downwards though + * the data graph + */ + static SDO_API DataObjectPtr copyShallow(DataObjectPtr dataObject); + + /** CopyHelper provides static copying helper functions. + * + * CopyHelper provides shallow and deep copy of data objects. + * copyShallow() copies the DataType members of the data object. + * copy() copies all the members and recurses downwards though + * the data graph + */ + static SDO_API DataObjectPtr copy(DataObjectPtr dataObject); + + private: + static void transferlist(DataObjectList& to, DataObjectList& from, Type::Types t); + static void transferitem(DataObjectPtr to, DataObjectPtr from, const Property& p); + static void transfersequenceitem(Sequence *to, Sequence *from, const Property& p, int index); + + static DataObjectPtr internalCopy(DataObjectPtr dataObject, bool fullCopy); + static void resolveReferences(DataObjectPtr oldDO, DataObjectPtr newDO); + static void findReferences(DataObjectPtr oldDO, DataObjectPtr newDO, DataObjectPtr obj, DataObjectPtr newObj); + static DataObjectPtr findReference(DataObjectPtr oldDO, DataObjectPtr newDO, DataObjectPtr ref); + +}; +}; +}; + +#endif //_COPYHELPER_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASProperty.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASProperty.cpp new file mode 100644 index 0000000000..15354d0d61 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASProperty.cpp @@ -0,0 +1,34 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/DASProperty.h" + + +namespace commonj{ +namespace sdo{ + + + DASProperty::~DASProperty() + { + } +}; +}; + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASProperty.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASProperty.h new file mode 100644 index 0000000000..6ebf241723 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASProperty.h @@ -0,0 +1,48 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _DASPROPERTY_H_ +#define _DASPROPERTY_H_ +#include "commonj/sdo/Property.h" +#include "commonj/sdo/DASValues.h" + +#include "commonj/sdo/disable_warn.h" + +namespace commonj{ +namespace sdo{ + +/** + * DASProperty is a class to provide data access services + * with a more flexible Property + */ + + class DASProperty : public Property, public DASValues +{ + public: + + virtual ~DASProperty(); + + + +}; +}; +}; +#endif //_DMSDATAOBJECT_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASType.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASType.cpp new file mode 100644 index 0000000000..2f44f220de --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASType.cpp @@ -0,0 +1,34 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/DASType.h" + + +namespace commonj{ +namespace sdo{ + + + DASType::~DASType() + { + } +}; +}; + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASType.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASType.h new file mode 100644 index 0000000000..62d924a4f1 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASType.h @@ -0,0 +1,55 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _DASTYPE_H_ +#define _DASTYPE_H_ + +#include "commonj/sdo/disable_warn.h" + + +#include "commonj/sdo/Type.h" +#include "commonj/sdo/DASValues.h" +namespace commonj{ +namespace sdo{ + +/** + * DASType is a class to provide data access services + * with a more flexible Type + */ + +class DASType : public Type, public DASValues +{ + public: + + virtual ~DASType(); + + + + virtual void setOpen(bool set) = 0; + virtual void setSequenced( bool set) = 0; + virtual void setBaseType( const Type* type, bool isRestriction=false) = 0; + + + +}; +}; +}; +#endif //_DASDATAOBJECT_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASValue.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASValue.cpp new file mode 100644 index 0000000000..3275b6db7d --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASValue.cpp @@ -0,0 +1,59 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/DASValue.h" + + +namespace commonj +{ + namespace sdo + { + + DASValue::DASValue() + { + } + + DASValue::DASValue(const char* val) + : value(val) + { + } + + DASValue::DASValue(const SDOString& val) + : value(val) + { + } + + DASValue::~DASValue() + { + + } + + const char* DASValue::getValue() const + { + return value.c_str(); + } + + + } +} +// end - namespace sdo + + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASValue.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASValue.h new file mode 100644 index 0000000000..d102961180 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASValue.h @@ -0,0 +1,56 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _SDO_DASValue_H_ +#define _SDO_DASValue_H_ + + +#include "commonj/sdo/export.h" +#include "commonj/sdo/SDOString.h" +#include "string" + + +namespace commonj +{ + namespace sdo + { + +/** + * DASValue is a class to hold information required by data + * access services but not required by the data factory. + */ + class DASValue + { + public: + SDO_API DASValue(); + SDO_API DASValue(const char* value); + SDO_API DASValue(const SDOString& value); + SDO_API virtual ~DASValue(); + SDO_API const char* getValue() const; + + private: + SDOString value; + + }; + + } +} +#endif //_SDO_DASValue_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASValues.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASValues.cpp new file mode 100644 index 0000000000..f94397cc87 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASValues.cpp @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/DASValues.h" + +using namespace std; +namespace commonj +{ + namespace sdo + { + +/** + * DASValues is a class to hold list of information required by data + * access services but not required by the data factory. + */ + + DASValues::~DASValues() + { + DASValue_MAP::iterator propertyIter; + for (propertyIter = properties.begin() ; propertyIter != properties.end() ; ++propertyIter) + { + delete propertyIter->second; + } + } + + void DASValues::setDASValue(const char* name, DASValue* property) + { + DASValue* prop = getDASValue(name); + if (prop != 0 && prop != property) + { + delete prop; + } + properties[name] = property; + } + + DASValue* DASValues::getDASValue(const char* name) + { + DASValue_MAP::iterator propertyIter; + propertyIter = properties.find(name); + if(propertyIter != properties.end()) + { + return propertyIter->second; + } + return NULL; + + } + + } +} +// end - namespace sdo + + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASValues.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASValues.h new file mode 100644 index 0000000000..f5dec7fa41 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DASValues.h @@ -0,0 +1,59 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _SDO_DASValues_H_ +#define _SDO_DASValues_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/export.h" +#include "commonj/sdo/DASValue.h" +#include "map" +#include "string" + + + +namespace commonj +{ + namespace sdo + { + +/** + * DASValues is a class to hold list of information required by data + * access services but not required by the data factory. + */ + + class DASValues + { + public: + SDO_API virtual ~DASValues(); + SDO_API virtual void setDASValue(const char* name, DASValue* value); + SDO_API virtual DASValue* getDASValue(const char* name); + private: + + typedef std::map DASValue_MAP; + DASValue_MAP properties; + + }; + + } +} +#endif //_SDO_DASValues_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataFactory.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataFactory.cpp new file mode 100644 index 0000000000..0f1981f853 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataFactory.cpp @@ -0,0 +1,53 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/DataFactory.h" +#include "commonj/sdo/DataFactoryImpl.h" + +namespace commonj{ +namespace sdo{ + +/** + * DataFactory holds metadata and creates DataObjects. + * + * The DataFactory holds properties and types loaded from XSD, or + * created using the DataFactory API. + */ + + DataFactory::~DataFactory() + { + } + + RefCountingPointer DataFactory::getDataFactory() + { + DataFactory* dob = (DataFactory*)(new DataFactoryImpl()); + return RefCountingPointer (dob); + } + + RefCountingPointer DataFactory::clone() + { + const DataFactoryImpl* df = (const DataFactoryImpl*)this; + DataFactory* dob = (DataFactory*)(new DataFactoryImpl(*df)); + return RefCountingPointer (dob); + } + +}; +}; diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataFactory.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataFactory.h new file mode 100644 index 0000000000..32e0782ee0 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataFactory.h @@ -0,0 +1,806 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _DATAFACTORY_H_ +#define _DATAFACTORY_H_ + +#include "commonj/sdo/export.h" + +#include "commonj/sdo/TypeList.h" + +#include "commonj/sdo/RefCountingObject.h" +#include "commonj/sdo/RefCountingPointer.h" +#include "commonj/sdo/SDODate.h" +#include "commonj/sdo/DASValue.h" +#include "commonj/sdo/SDOString.h" + + +namespace commonj{ +namespace sdo{ + +class DataObject; +class Type; + +/** + * DataFactory holds metadata and creates DataObjects. + * + * The DataFactory holds properties and types loaded from XSD, or + * created using the DataFactory API. + */ + +class DataFactory : public RefCountingObject +{ + public: + + + /** + * getDataFactory is static and gets a data factory + * + * Static method to get a new data factory, with a set of base Types defined. + * With the data factory returned, either load Type definitions + * from XSD, or use the DataFactory APIs to define the types. + */ + + static SDO_API DataFactoryPtr getDataFactory(); + + virtual SDO_API ~DataFactory(); + + + /** + * DataFactory::clone copies a data factory + * + * Copy the data factory, and return a new data factory which + * has the same properties and types, but is still able to have + * new types added to it. + */ + + SDO_API virtual DataFactoryPtr clone(); + + /** + * DataFactory::create creates a data object. + * + * Create a data object based on the type specified as a parameter + * Once a data object has been created by this factory, the metadata + * (types and properties) may no longer be altered. + */ + + SDO_API virtual DataObjectPtr create(const char* uri, const char* typeName) = 0; + + SDO_API virtual DataObjectPtr create(const SDOString& uri, const SDOString& typeName) = 0; + + SDO_API virtual DataObjectPtr create(const Type& type) = 0; + + /** + * DataFactory::getType gets a type back from the factory. + * + * Get a type as specified in the data factory. Useful for creating + * data objects or querying properties. + */ + + virtual const Type& getType(const char* uri, const char* inTypeName) const = 0; + + virtual const Type& getType(const SDOString& uri, const SDOString& inTypeName) const = 0; + + + /** + * DataFactory::getTypes gets a list of types back from the factory. + * + * Get all the types available within this data factory. Useful for + * validating whether a data object is of the correct type to be + * usable. + */ + + virtual TypeList getTypes() const = 0; + + /** + * DataFactory::addType adds a type definition. + * + * Add a type defintion to the factory. (Properties may be added later). + * The type is defined by its uri and name. + * -# The type may be sequenced - and therefore work with a sequence API. + * -# The type may be open, indicating that it may have extra properties + * added at runtime. + * -# The type may be abstract, so the data factory will not permit creation + * of instances. + * -# The type may be a data type, indicating that is will not have properties. + * The Type may inherit from another type, but that is specified later with a + * call to setBaseType(). + */ + + + virtual SDO_API void addType(const char* uri, const char* inTypeName, + bool isSequenced = false, + bool isOpen = false, + bool isAbstract = false, + bool isDataType = false) = 0; + + virtual SDO_API void addType(const SDOString& uri, const SDOString& inTypeName, + bool isSequenced = false, + bool isOpen = false, + bool isAbstract = false, + bool isDataType = false) = 0; + + + /** + * DataFactory::setBaseType allows inheritance + * + * The type specified second in the parameters becomes the basetype + * of the first parameter. + * The second type will have all the properties of its baser type, followed + * by any additional properties of its own. The property indices of the properties + * of the subclass will begin at one more than the total number of + * properties of the supertype + * This relationship is fixed when the first data object of any type is + * created by the factory. Up to that point the base type may be changed. + * + */ + + virtual SDO_API void setBaseType( + const Type& type, + const Type& base, + bool isRestriction = false) = 0; + + virtual SDO_API void setBaseType( + const char* typeuri, + const char* typenam, + const char* baseuri, + const char* basename, + bool isRestriction = false) = 0; + + virtual SDO_API void setBaseType( + const SDOString& typeuri, + const SDOString& typenam, + const SDOString& baseuri, + const SDOString& basename, + bool isRestriction = false) = 0; + + + /** + * Generate a typesafe interface for a given data factory + * test code. + */ + + virtual SDO_API bool generateInterface(const char* fileroot, + const char *factoryname) = 0; + + virtual SDO_API bool generateInterface(const SDOString& fileroot, + const SDOString& factoryname) = 0; + + + + /** + * DataFactory::setAlias sets an alternative name + * + * A Type may be known to the data factory by several different names. + * This method adds a new name for an existing property. + * + */ + + virtual SDO_API void setAlias(const char* typeuri, + const char* typenam, + const char* alias) = 0; + + virtual SDO_API void setAlias(const SDOString& typeuri, + const SDOString& typenam, + const SDOString& alias) = 0; + + /** + * DataFactory::addPropertyToType adds properties + * + * The various addPropertyToType methods add a property to an + * existing type in the factory, specifying the name of the new property, + * and the type of the new property - which must also be an existing type + * in this factory. + * -# The new property may be many-valued - so it will be a list of values. + * -# The property may be read-only , and may not be altered by user code - + * However the value may be changed by data access service code. + * -# The property may be containment. + * The type of a property may be DataType, or DataObjectType (see Types). + * If the property is a DataType, then the actual value of the property is held + * within the data object containing the property. + * If the property is a DataObjectType, it may be containment, or reference. + * Containment indicates that the value of the property is contained in the + * data object, whilst reference indicates that the property is only a pointer to + * a value somewhere else in the data graph. + * + */ + + + virtual SDO_API void addPropertyToType(const char* uri, + const char* inTypeName, + const char* propname, + const char* propTypeUri, + const char* propTypeName, + bool isMany, + bool isReadOnly , + bool isContainment ) = 0; + + virtual SDO_API void addPropertyToType(const SDOString& uri, + const SDOString& inTypeName, + const SDOString& propname, + const SDOString& propTypeUri, + const SDOString& propTypeName, + bool isMany , + bool isReadOnly , + bool isContainment ) = 0; + + virtual SDO_API void addPropertyToType(const char* uri, + const char* inTypeName, + const char* propname, + const Type& propType, + bool isMany , + bool isReadOnly , + bool isContainment ) = 0; + + virtual SDO_API void addPropertyToType(const SDOString& uri, + const SDOString& inTypeName, + const SDOString& propname, + const Type& propType, + bool isMany , + bool isReadOnly , + bool isContainment ) = 0; + + virtual SDO_API void addPropertyToType(const Type& type, + const char* propname, + const Type& propType, + bool isMany , + bool isReadOnly , + bool isContainment ) = 0; + + virtual SDO_API void addPropertyToType(const Type& type, + const SDOString& propname, + const Type& propType, + bool isMany , + bool isReadOnly , + bool isContainment ) = 0; + + virtual SDO_API void addPropertyToType(const Type& type, + const char* propname, + const char* propTypeUri, + const char* propTypeName, + bool isMany , + bool isReadOnly , + bool isContainment ) = 0; + + virtual SDO_API void addPropertyToType(const Type& type, + const SDOString& propname, + const SDOString& propTypeUri, + const SDOString& propTypeName, + bool isMany , + bool isReadOnly , + bool isContainment ) = 0; + + virtual SDO_API void addPropertyToType(const char* uri, + const char* inTypeName, + const char* propname, + const char* propTypeUri, + const char* propTypeName, + bool isMany = false) =0; + + virtual SDO_API void addPropertyToType(const SDOString& uri, + const SDOString& inTypeName, + const SDOString& propname, + const SDOString& propTypeUri, + const SDOString& propTypeName, + bool isMany = false) =0; + + virtual SDO_API void addPropertyToType(const char* uri, + const char* inTypeName, + const char* propname, + const Type& propType, + bool isMany = false) =0; + + virtual SDO_API void addPropertyToType(const SDOString& uri, + const SDOString& inTypeName, + const SDOString& propname, + const Type& propType, + bool isMany = false) =0; + + virtual SDO_API void addPropertyToType(const Type& type, + const char* propname, + const Type& propType, + bool isMany = false) =0; + + virtual SDO_API void addPropertyToType(const Type& type, + const SDOString& propname, + const Type& propType, + bool isMany = false) =0; + + virtual SDO_API void addPropertyToType(const Type& type, + const char* propname, + const char* propTypeUri, + const char* propTypeName, + bool isMany = false) =0; + + virtual SDO_API void addPropertyToType(const Type& type, + const SDOString& propname, + const SDOString& propTypeUri, + const SDOString& propTypeName, + bool isMany = false) =0; + + /** + * DataFactory::setOpposite sets an opposite name + * + * NOT IMPLEMENTED. + * + */ + + virtual SDO_API void setOpposite( + const Type& type, + const char* propName, + const Type& oppositetype, + const char* oppositePropName) = 0; + + virtual SDO_API void setOpposite( + const Type& type, + const SDOString& propName, + const Type& oppositetype, + const SDOString& oppositePropName) = 0; + + /** + * DataFactory::setAlias sets a property alias name + * + * A property, like a type, may be known to the factory by several + * names. + */ + + virtual SDO_API void setAlias(const char* typeuri, + const char* typname, + const char* propname, + const char* alias) = 0; + + virtual SDO_API void setAlias(const SDOString& typeuri, + const SDOString& typname, + const SDOString& propname, + const SDOString& alias) = 0; + + /** + * DataFactory::setPropertySubstitute sets a substitute for a property + * + * A property is of a specified type. However this method specifies another type + * which will be accepted by the data factory at runtime as a substitute for this + * property, and will be inserted into the parent data object as though it was + * a value for this property. The substitute name is then used for this property + * as a sort of alias. + * names. + */ + + virtual SDO_API void setPropertySubstitute( + const char* uri, + const char* inTypeName, + const char* propname, + const char* subname, + const char* subTypeUri, + const char* subTypeName) = 0; + + virtual SDO_API void setPropertySubstitute( + const SDOString& uri, + const SDOString& inTypeName, + const SDOString& propname, + const SDOString& subname, + const SDOString& subTypeUri, + const SDOString& subTypeName) = 0; + + virtual SDO_API void setPropertySubstitute( + const Type& containertype, + const char* propname, + const char* subname, + const Type& subtype) = 0; + + virtual SDO_API void setPropertySubstitute( + const Type& containertype, + const SDOString& propname, + const SDOString& subname, + const Type& subtype) = 0; + + + /** + * DataFactory::setDefault sets a default value for a property + * + * When querying the value of a property of a data object, that property + * may be set - indicating that a value has been assigned, or unset - indicating that + * no value has yet been assigned. + * If there is no value assigned, then a default value may be returned for that + * property. + * This method allows the data factory to define that default value. + * There is no default value for a DataObjectType. There are overloads for + * each of the primitive DataTypes. + */ + + virtual SDO_API void setDefault( + const Type& t, + const char* propname, + bool b ) = 0; + + virtual SDO_API void setDefault( + const Type& t, + const SDOString& propname, + bool b ) = 0; + + virtual SDO_API void setDefault( + const Type& t, + const char* propname , + char c) = 0; + + virtual SDO_API void setDefault( + const Type& t, + const SDOString& propname , + char c) = 0; + + virtual SDO_API void setDefault( + const Type& t, + const char* propname , + wchar_t c) = 0; + + virtual SDO_API void setDefault( + const Type& t, + const SDOString& propname , + wchar_t c) = 0; + + virtual SDO_API void setDefault( + const Type& t, + const char* propname , + char* c) = 0; + + virtual SDO_API void setDefault( + const Type& t, + const SDOString& propname , + SDOString& outstr) = 0; + + virtual SDO_API void setDefault( + const Type& t, + const char* propname , + short s) = 0; + + virtual SDO_API void setDefault( + const Type& t, + const SDOString& propname , + short s) = 0; + + +#if __WORDSIZE !=64 + virtual SDO_API void setDefault( + const Type& t, + const char* propname , + long l) = 0; + + virtual SDO_API void setDefault( + const Type& t, + const SDOString& propname , + long l) = 0; +#endif + + virtual SDO_API void setDefault( + const Type& t, + const char* propname , + int64_t i) = 0; + + virtual SDO_API void setDefault( + const Type& t, + const SDOString& propname , + int64_t i) = 0; + + virtual SDO_API void setDefault( + const Type& t, + const char* propname , + float f) = 0; + + virtual SDO_API void setDefault( + const Type& t, + const SDOString& propname , + float f) = 0; + + virtual SDO_API void setDefault( + const Type& t, + const char* propname , + long double d) = 0; + + virtual SDO_API void setDefault( + const Type& t, + const SDOString& propname , + long double d) = 0; + + virtual SDO_API void setDefault( + const Type& t, + const char* propname , + const wchar_t* c, + unsigned int len) = 0; + + virtual SDO_API void setDefault( + const Type& t, + const SDOString& propname , + const wchar_t* c, + unsigned int len) = 0; + + virtual SDO_API void setDefault( + const Type& t, + const char* propname , + const char* c, + unsigned int len) = 0; + + virtual SDO_API void setDefault( + const Type& t, + const SDOString& propname , + const SDOString& c, + unsigned int len) = 0; + + + virtual SDO_API void setDefault( + const Type& t, + const char* propname , + const SDODate dat) = 0; + + virtual SDO_API void setDefault( + const Type& t, + const SDOString& propname , + const SDODate dat) = 0; + + virtual SDO_API void setDefault( + const char* typuri, + const char* typnam, + const char* propname, + bool b ) = 0; + + virtual SDO_API void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname, + bool b ) = 0; + + virtual SDO_API void setDefault( + const char* typuri, + const char* typnam, + const char* propname , + char c) = 0; + + virtual SDO_API void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname , + char c) = 0; + + virtual SDO_API void setDefault( + const char* typuri, + const char* typnam, + const char* propname , + wchar_t c) = 0; + + virtual SDO_API void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname , + wchar_t c) = 0; + + virtual SDO_API void setDefault( + const char* typuri, + const char* typnam, + const char* propname , + char* c) = 0; + + virtual SDO_API void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname , + SDOString& c) = 0; + + virtual SDO_API void setDefault( + const char* typuri, + const char* typnam, + const char* propname , + short s) = 0; + + virtual SDO_API void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname , + short s) = 0; + + +#if __WORDSIZE !=64 + virtual SDO_API void setDefault( + const char* typuri, + const char* typnam, + const char* propname , + long l) = 0; + + virtual SDO_API void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname , + long l) = 0; + +#endif + + virtual SDO_API void setDefault( + const char* typuri, + const char* typnam, + const char* propname , + int64_t i) = 0; + + virtual SDO_API void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname , + int64_t i) = 0; + + virtual SDO_API void setDefault( + const char* typuri, + const char* typnam, + const char* propname , + float f) = 0; + + virtual SDO_API void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname , + float f) = 0; + + virtual SDO_API void setDefault( + const char* typuri, + const char* typnam, + const char* propname , + long double d) = 0; + + virtual SDO_API void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname , + long double d) = 0; + + virtual SDO_API void setDefault( + const char* typuri, + const char* typnam, + const char* propname , + const wchar_t* c, + unsigned int len) = 0; + + virtual SDO_API void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname , + const wchar_t* c, + unsigned int len) = 0; + + virtual SDO_API void setDefault( + const char* typuri, + const char* typnam, + const char* propname , + const char* c, + unsigned int len) = 0; + + virtual SDO_API void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname , + const SDOString& c, + unsigned int len) = 0; + + virtual SDO_API void setDefault( + const char* typuri, + const char* typnam, + const char* propname , + const SDODate dat) = 0; + + virtual SDO_API void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname , + const SDODate dat) = 0; + + + /** + * DAS values are used by a DAS implementation + */ + + virtual SDO_API void setDASValue( + const Type& type, + const char* name, + DASValue* value) = 0; + + virtual SDO_API void setDASValue( + const Type& type, + const SDOString& name, + DASValue* value) = 0; + + virtual SDO_API void setDASValue( + const char* typeuri, + const char* typenam, + const char* name, + DASValue* value) = 0; + + virtual SDO_API void setDASValue( + const SDOString& typeuri, + const SDOString& typenam, + const SDOString& name, + DASValue* value) = 0; + + virtual SDO_API DASValue* getDASValue( + const Type& type, + const char* name) const = 0; + + virtual SDO_API DASValue* getDASValue( + const Type& type, + const SDOString& name) const = 0; + + virtual SDO_API DASValue* getDASValue( + const char* typeuri, + const char* typenam, + const char* name) const = 0; + + virtual SDO_API DASValue* getDASValue( + const SDOString& typeuri, + const SDOString& typenam, + const SDOString& name) const = 0; + + virtual SDO_API void setDASValue( + const Type& type, + const char* propertyName, + const char* name, + DASValue* value) = 0; + + virtual SDO_API void setDASValue( + const Type& type, + const SDOString& propertyName, + const SDOString& name, + DASValue* value) = 0; + + virtual SDO_API void setDASValue( + const char* typeuri, + const char* typenam, + const char* propertyName, + const char* name, + DASValue* value) = 0; + + virtual SDO_API void setDASValue( + const SDOString& typeuri, + const SDOString& typenam, + const SDOString& propertyName, + const SDOString& name, + DASValue* value) = 0; + + virtual SDO_API DASValue* getDASValue( + const Type& type, + const char* propertyName, + const char* name) const = 0; + + virtual SDO_API DASValue* getDASValue( + const Type& type, + const SDOString& propertyName, + const SDOString& name) const = 0; + + virtual SDO_API DASValue* getDASValue( + const char* typeuri, + const char* typenam, + const char* propertyName, + const char* name) const = 0; + + virtual SDO_API DASValue* getDASValue( + const SDOString& typeuri, + const SDOString& typenam, + const SDOString& propertyName, + const SDOString& name) const = 0; + + virtual void resolve() = 0; + + }; +}; +}; +#endif //_DATAFACTORY_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp new file mode 100644 index 0000000000..4d1e3640c3 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp @@ -0,0 +1,2141 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +////////////////////////////////////////////////////////////////////// +// DataFactoryImpl.cpp: implementation of the DataFactory class. +// +////////////////////////////////////////////////////////////////////// +#include "commonj/sdo/SDORuntimeException.h" + +#include "commonj/sdo/DataFactoryImpl.h" +#include "commonj/sdo/DataObjectImpl.h" + +#include "commonj/sdo/Logger.h" + +#include "commonj/sdo/SDOUtils.h" + +#include "commonj/sdo/PropertyList.h" + +#include +#include + + +using namespace std; +using namespace commonj::sdo; + +namespace commonj{ +namespace sdo { + +// =================================================================== +// Constructor +// =================================================================== +DataFactoryImpl::DataFactoryImpl() +{ + + /* add the primitives to every mdg - */ + + isResolved = false; + addType(Type::SDOTypeNamespaceURI,"BigDecimal"); + addType(Type::SDOTypeNamespaceURI,"BigInteger"); + addType(Type::SDOTypeNamespaceURI,"Boolean"); + + addType(Type::SDOTypeNamespaceURI,"Byte"); + addType(Type::SDOTypeNamespaceURI,"Bytes"); + addType(Type::SDOTypeNamespaceURI,"Character"); + + addType(Type::SDOTypeNamespaceURI,"String"); + addType(Type::SDOTypeNamespaceURI,"DataObject"); + addType(Type::SDOTypeNamespaceURI,"OpenDataObject", true, true, false, false); + addType(Type::SDOTypeNamespaceURI,"Date"); + addType(Type::SDOTypeNamespaceURI,"Double"); + addType(Type::SDOTypeNamespaceURI,"Float"); + addType(Type::SDOTypeNamespaceURI,"Integer"); + addType(Type::SDOTypeNamespaceURI,"Long"); + addType(Type::SDOTypeNamespaceURI,"Short"); + addType(Type::SDOTypeNamespaceURI,"URI"); + + // abstract + addType(Type::SDOTypeNamespaceURI,"ChangeSummary"); + +} + +// =================================================================== +// Destructor +// =================================================================== +DataFactoryImpl::~DataFactoryImpl() +{ + + resolvePending.clear(); + + TYPES_MAP::iterator typeIter; + for (typeIter = types.begin() ; typeIter != types.end() ; ++typeIter) + { + if (strncmp((typeIter->first).c_str(),"ALIAS::", 7)) + { + delete typeIter->second; + } + } +} + +// =================================================================== +// copy constructor +// =================================================================== +DataFactoryImpl::DataFactoryImpl(const DataFactoryImpl& inmdg) +{ + isResolved = false; + copyTypes(inmdg); +} + +// =================================================================== +// Assignment operator +// =================================================================== +DataFactoryImpl& DataFactoryImpl::operator=(const DataFactoryImpl& inmdg) +{ + if (this != &inmdg) + { + copyTypes(inmdg); + } + return *this; +} + +// =================================================================== +// copy Types to this DataFactory +// =================================================================== +void DataFactoryImpl::copyTypes(const DataFactoryImpl& inmdg) +{ + + + TYPES_MAP::const_iterator typeIter; + TYPES_MAP::iterator typeIter2; + SDOString fullTypeName; + + for (typeIter = inmdg.types.begin() ; typeIter != inmdg.types.end() ; ++typeIter) + { + // add this type to this metadata + addType((typeIter->second)->getURI(), (typeIter->second)->getName()); + + // re-find the type we just added. + getFullTypeName(fullTypeName, + (typeIter->second)->getURI(), + (typeIter->second)->getName()); + typeIter2 = types.find(fullTypeName); + + // copy the aliases , if there are any. + + if ((typeIter->second)->getAliasCount() > 0) + { + for (unsigned int j=0;j<(typeIter->second)->getAliasCount();j++) + { + (typeIter2->second)->setAlias( + (typeIter->second)->getAlias()); + } + } + + + // Now add all the properties + const std::list props = typeIter->second->getPropertyListReference(); + + for (std::list::const_iterator i = props.begin(); + i != props.end(); + i++) + { + // Ensure the properties type is added + const Type& propType = (*i)->getType(); + addType(propType.getURI(), propType.getName()); + + // Now add the property + addPropertyToType((typeIter->second)->getURI(), + (typeIter->second)->getName(), + (*i)->getName(), + propType.getURI(), + propType.getName(), + (*i)->isMany(), + (*i)->isReadOnly(), + (*i)->isContainment()); + + // copy the aliases if there are any. + if ((*i)->getAliasCount() > 0) + { + + PropertyImpl* p = (typeIter2->second)-> + getPropertyImpl((*i)->getName()); + if (p != 0) + { + for (unsigned int j=0;jgetAliasCount();j++) + { + p->setAlias((*i)->getAlias(j)); + } + } + + } + + } // end - iterate over Properties + } // end - iterate over Types +} + +// =================================================================== +// addType - adds a new Type if it does not already exist +// =================================================================== +void DataFactoryImpl::addType(const char* uri, const char* inTypeName, + bool isSeq, + bool isOp, + bool isAbs, + bool isData) +{ + addType(uri,inTypeName,isSeq,isOp,isAbs,isData,false); +} + +void DataFactoryImpl::addType(const SDOString& uri, const SDOString& inTypeName, + bool isSeq, + bool isOp, + bool isAbs, + bool isData) +{ + addType(uri.c_str(),inTypeName.c_str(),isSeq,isOp,isAbs,isData,false); +} + +bool empty(const char* inTypeName) +{ + return inTypeName == 0 || strlen(inTypeName) == 0; +} +void assertTypeName(const char* inTypeName, const char* function) +{ + if (empty(inTypeName)) + { + SDO_THROW_EXCEPTION(function, + SDOIllegalArgumentException, " Type has empty name"); + } +} + +void DataFactoryImpl::addType(const char* uri, const char* inTypeName, + bool isSeq, + bool isOp, + bool isAbs, + bool isData, + bool isFromList) +{ + assertTypeName(inTypeName, "DataFactory::addType"); + + SDOString typeUri; + + if (uri) + typeUri = uri; + if (findType(typeUri, inTypeName) == 0) + { + SDOString fullTypeName; + getFullTypeName(fullTypeName, uri, inTypeName); + types[fullTypeName] = new TypeImpl(uri, inTypeName, isSeq, isOp, isAbs, isData, isFromList); + resolvePending[fullTypeName] = types[fullTypeName]; + } +} + +void DataFactoryImpl::addType(const SDOString& uri, const SDOString& inTypeName, + bool isSeq, + bool isOp, + bool isAbs, + bool isData, + bool isFromList) +{ + addType(uri.c_str(), inTypeName.c_str(), isSeq, isOp, isAbs, isData, isFromList); +} + +// =================================================================== +// Check whether a change summary would clash. +// =================================================================== + +bool DataFactoryImpl::recursiveCheck(TypeImpl* cs, TypeImpl* t) +{ + if (cs->isDataType()) return false; + + if (! strcmp(cs->getName(), t->getName()) && + ! strcmp(cs->getURI() , t->getURI()) ) + { + return true; + } + + const std::list pl = cs->getPropertyListReference(); + + for (std::list::const_iterator j = pl.begin(); + j != pl.end(); + j++) + { + if (recursiveCheck((TypeImpl*)&((*j)->getType()), t)) return true; + } + return false; +} + +// =================================================================== +// Check whether a change summary would clash. +// =================================================================== +bool DataFactoryImpl::checkForValidChangeSummary(TypeImpl* t) +{ + // None of the containing types can have a cs already. + // None of the properties of this type can hold a type + // which has a change summary. + + if (t->isResolved) + { + SDO_THROW_EXCEPTION("DataFactory::checkForValidChangeSummary", + SDOUnsupportedOperationException, "Adding Change Summary after type completed"); + } + + if (cstypes.size() > 0) { + for (unsigned int i = 0 ;i < cstypes.size(); i++) + { + if (recursiveCheck(cstypes[i], t)) + { + return false; + + } + } + } + cstypes.push_back(t); + return true; +} + +const char*const addPropertyToType = "DataFactory::addPropertyToType"; +void assertNames(const char* inTypeName, const char* propname) +{ + assertTypeName(inTypeName, addPropertyToType); + if (empty(propname)) + { + SDO_THROW_EXCEPTION(addPropertyToType, + SDOIllegalArgumentException, " Property has an empty name"); + } +} + +// =================================================================== +// addPropertyToType - adds a Property to an existing Type +// =================================================================== +void DataFactoryImpl::addPropertyToType(const char* uri, + const char* inTypeName, + const char* propname, + const char* propTypeUri, + const char* propTypeName, + bool many) +{ + assertNames(inTypeName, propname); + SDOString fullPropTypeName; + getFullTypeName(fullPropTypeName, propTypeUri, propTypeName); + + TYPES_MAP::iterator typeIter; + typeIter = types.find(fullPropTypeName); + if (typeIter != types.end()) + { + addPropertyToType(uri,inTypeName, + propname, + propTypeUri, + propTypeName, + many, + false, + !(typeIter->second)->isDataType()); + } +} + +void DataFactoryImpl::addPropertyToType(const SDOString& uri, + const SDOString& inTypeName, + const SDOString& propname, + const SDOString& propTypeUri, + const SDOString& propTypeName, + bool many) +{ + addPropertyToType(uri.c_str(), inTypeName.c_str(), propname.c_str(), propTypeUri.c_str(), propTypeName.c_str(), many); +} + +void DataFactoryImpl::addPropertyToType(const char* uri, + const char* inTypeName, + const char* propname, + const char* propTypeUri, + const char* propTypeName, + bool many, + bool rdonly, + bool cont) +{ + assertNames(inTypeName, propname); + + TYPES_MAP::iterator typeIter, typeIter2; + + //cout << "Adding property " << propname << "(" << propTypeUri << "#" << propTypeName + // << ") to type " << uri << "#" << inTypeName << endl; + + + SDOString fullTypeName; + getFullTypeName(fullTypeName, uri, inTypeName); + typeIter = types.find(fullTypeName); + + if(typeIter == types.end()) + { + string msg("Type not found: "); + if (uri != 0)msg += uri; + msg += " "; + if (inTypeName != 0)msg += inTypeName; + SDO_THROW_EXCEPTION("addPropertyToType", + SDOTypeNotFoundException, msg.c_str()); + + } + + if ((typeIter->second)->isDataType()) + { + string msg("Cannot add property "); + msg += propname; + msg += " of type "; + msg += propTypeUri; + msg += "#"; + msg += propTypeName; + msg += " to this data type "; + msg += uri; + msg += "#"; + msg += inTypeName; + SDO_THROW_EXCEPTION("addPropertyToType", + SDOIllegalArgumentException, msg.c_str()); + } + + getFullTypeName(fullTypeName, propTypeUri, propTypeName); + typeIter2 = types.find(fullTypeName); + + if (typeIter2 == types.end()) + { + string msg("Type not found: "); + if (propTypeUri != 0)msg += propTypeUri; + msg += " "; + if (propTypeName != 0)msg += propTypeName; + SDO_THROW_EXCEPTION("addPropertyToType", + SDOTypeNotFoundException, msg.c_str()); + } + + // Check if its a ChangeSummary + if (propTypeUri != 0 && !strcmp(propTypeUri,Type::SDOTypeNamespaceURI.c_str()) && + !strcmp(propTypeName,"ChangeSummary") ) + { + if (checkForValidChangeSummary(typeIter->second)) + { + // The change summary is allowable if we got to here - force the right params. + // we will not use this property - its just for compatibility. + // we have to use getChangeSummary to get the change summary, + // and isChangeSummaryType to see if this is a type which may have + // a change summary. + (typeIter->second)->addChangeSummary(); + // dont even show the property - its not needed + //((typeIter->second)->addProperty(propname, *(typeIter2->second),false,true, false)); + + } + return; + } + + + if ((typeIter->second)->isDataType()) + { + string msg("Cannot add property to a data type : "); + msg += (typeIter->second)->getName(); + SDO_THROW_EXCEPTION("addPropertyToType", + SDOIllegalArgumentException, msg.c_str()); + // cannot add a property to a primitive + } + + // @PGR@ containment should be ignored for DataType +/* if ((typeIter2->second)->isDataType() && cont == true) + { + string msg("Data types may not be containment : "); + msg += (typeIter2->second)->getName(); + SDO_THROW_EXCEPTION("addPropertyToType", + SDOIllegalArgumentException, msg.c_str()); + // cannot try to make a property containment on a data type + } +*/ + + if ((typeIter->second)->isResolved) + { + SDO_THROW_EXCEPTION("DataFactory::addPropertyToType", + SDOUnsupportedOperationException, "Adding Properties after type completed"); + } + + ((typeIter->second)->addProperty(propname, *(typeIter2->second),many,rdonly, cont)); + return; +} + +void DataFactoryImpl::addPropertyToType(const SDOString& uri, + const SDOString& inTypeName, + const SDOString& propname, + const SDOString& propTypeUri, + const SDOString& propTypeName, + bool many, + bool rdonly, + bool cont) +{ + addPropertyToType(uri.c_str(), + inTypeName.c_str(), + propname.c_str(), + propTypeUri.c_str(), + propTypeName.c_str(), + many, + rdonly, + cont); +} + +// =================================================================== +// addPropertyToType - adds a Property to an existing Type +// =================================================================== + +void DataFactoryImpl::addPropertyToType(const char* uri, + const char* inTypeName, + const char* propname, + const Type& tprop, + bool many) +{ + addPropertyToType(uri, + inTypeName, + propname, + tprop, + many, + false, + !tprop.isDataType()); +} + +void DataFactoryImpl::addPropertyToType(const SDOString& uri, + const SDOString& inTypeName, + const SDOString& propname, + const Type& tprop, + bool many) +{ + addPropertyToType(uri.c_str(), + inTypeName.c_str(), + propname.c_str(), + tprop, + many, + false, + !tprop.isDataType()); +} + +void DataFactoryImpl::addPropertyToType(const char* uri, + const char* inTypeName, + const char* propname, + const Type& tprop, + bool many, + bool rdonly, + bool cont) +{ + addPropertyToType(uri, + inTypeName, + propname, + tprop.getURI(), + tprop.getName(), + many, + rdonly, cont); +} + +void DataFactoryImpl::addPropertyToType(const SDOString& uri, + const SDOString& inTypeName, + const SDOString& propname, + const Type& tprop, + bool many, + bool rdonly, + bool cont) +{ + addPropertyToType(uri.c_str(), + inTypeName.c_str(), + propname.c_str(), + tprop.getURI(), + tprop.getName(), + many, + rdonly, + cont); +} + +// =================================================================== +// addPropertyToType - adds a Property to an existing Type +// =================================================================== +void DataFactoryImpl::addPropertyToType(const Type& cont, + const char* propname, + const char* propTypeUri, + const char* propTypeName, + bool many) +{ + addPropertyToType(cont.getURI(), + cont.getName(), + propname, + propTypeUri, + propTypeName, + many); +} + +void DataFactoryImpl::addPropertyToType(const Type& cont, + const SDOString& propname, + const SDOString& propTypeUri, + const SDOString& propTypeName, + bool many) +{ + addPropertyToType(cont.getURI(), + cont.getName(), + propname.c_str(), + propTypeUri.c_str(), + propTypeName.c_str(), + many); +} + +void DataFactoryImpl::addPropertyToType(const Type& cont, + const char* propname, + const char* propTypeUri, + const char* propTypeName, + bool many, + bool rdonly, + bool contain) +{ + addPropertyToType(cont.getURI(), + cont.getName(), + propname, + propTypeUri, + propTypeName, + many, + rdonly, + contain); +} + +void DataFactoryImpl::addPropertyToType(const Type& cont, + const SDOString& propname, + const SDOString& propTypeUri, + const SDOString& propTypeName, + bool many, + bool rdonly, + bool contain) +{ + addPropertyToType(cont.getURI(), + cont.getName(), + propname.c_str(), + propTypeUri.c_str(), + propTypeName.c_str(), + many, + rdonly, + contain); +} + +// =================================================================== +// addPropertyToType - adds a Property to an existing Type +// =================================================================== +void DataFactoryImpl::addPropertyToType(const Type& tp, + const char* propname, + const Type& tprop, + bool many) +{ + addPropertyToType(tp.getURI(), + tp.getName(), + propname, + tprop.getURI(), + tprop.getName(), + many); +} + +void DataFactoryImpl::addPropertyToType(const Type& tp, + const SDOString& propname, + const Type& tprop, + bool many) +{ + addPropertyToType(tp.getURI(), + tp.getName(), + propname.c_str(), + tprop.getURI(), + tprop.getName(), + many); +} + +void DataFactoryImpl::addPropertyToType(const Type& tp, + const char* propname, + const Type& tprop, + bool many, + bool rdonly, + bool cont) +{ + addPropertyToType(tp.getURI(), + tp.getName(), + propname, + tprop.getURI(), + tprop.getName(), + many, + rdonly, + cont); +} + +void DataFactoryImpl::addPropertyToType(const Type& tp, + const SDOString& propname, + const Type& tprop, + bool many, + bool rdonly, + bool cont) +{ + addPropertyToType(tp.getURI(), + tp.getName(), + propname.c_str(), + tprop.getURI(), + tprop.getName(), + many, + rdonly, + cont); +} + +// =================================================================== +// getFullTypeName - return the name used as a key in the types map +// =================================================================== +SDOString& DataFactoryImpl::getFullTypeName(SDOString& stringBuffer, const SDOString& uri, const SDOString& inTypeName) +{ + stringBuffer = uri; + stringBuffer += "#"; + stringBuffer += inTypeName; + return stringBuffer; +} + +// =================================================================== +// getAliasTypeName - return the name used as a key in the types map +// =================================================================== +SDOString& DataFactoryImpl::getAliasTypeName(SDOString& stringBuffer, const SDOString& uri, const SDOString& inTypeName) +{ + getFullTypeName(stringBuffer, uri, inTypeName); + stringBuffer.insert(0, "ALIAS::"); + return stringBuffer; +} + +// =================================================================== +// getType - return a pointer to the required Type +// =================================================================== +const Type& DataFactoryImpl::getType(const char* uri, const char* inTypeName) const +{ + + const Type* type = findType(uri, inTypeName); + + if (type == 0) + { + string msg("Type not found :"); + if (uri != 0) msg += uri; + msg += " "; + if (inTypeName != 0) msg += inTypeName; + SDO_THROW_EXCEPTION("getType" , + SDOTypeNotFoundException, msg.c_str()); + } + + return *type; +} + +const Type& DataFactoryImpl::getType(const SDOString& uri, const SDOString& inTypeName) const +{ + return getType(uri.c_str(), inTypeName.c_str()); +} + +// =================================================================== +// setBaseType - sets the type from which this type inherits properties +// =================================================================== + +void DataFactoryImpl::setBaseType( const Type& type, + const Type& base, bool isRestriction) +{ + setBaseType(type.getURI(),type.getName(),base.getURI(), base.getName(), + isRestriction); +} + +// =================================================================== +// setBaseType - sets the type from which this type inherits properties +// =================================================================== + +void DataFactoryImpl::setBaseType( const char* typeuri, + const char* typenam, + const char* baseuri, + const char* basename, + bool isRestriction ) +{ + const TypeImpl* base = findTypeImpl(baseuri, basename); + if (base == 0) + { + string msg("Type not found :"); + if (baseuri != 0) msg += baseuri; + msg += " "; + if (basename != 0) msg += basename; + SDO_THROW_EXCEPTION("setBaseType" , + SDOTypeNotFoundException, msg.c_str()); + } + + TYPES_MAP::const_iterator typeIter; + + SDOString fullTypeName; + getFullTypeName(fullTypeName, typeuri, typenam); + typeIter = types.find(fullTypeName); + + if(typeIter == types.end()) + { + string msg("Type not found :"); + if (typeuri != 0) msg += typeuri; + msg += " "; + if (typenam != 0) msg += typenam; + SDO_THROW_EXCEPTION("setBaseType" , + SDOTypeNotFoundException, msg.c_str()); + } + + (typeIter->second)->setBaseType(base, isRestriction); +} + +void DataFactoryImpl::setBaseType(const SDOString& typeuri, + const SDOString& typenam, + const SDOString& baseuri, + const SDOString& basename, + bool isRestriction) +{ + setBaseType(typeuri.c_str(), + typenam.c_str(), + baseuri.c_str(), + basename.c_str(), + isRestriction); +} + + +// =================================================================== +// setPropertySubstitute - additional type for a property +// =================================================================== + + void DataFactoryImpl::setPropertySubstitute( + const char* uri, + const char* inTypeName, + const char* propname, + const char* subname, + const char* subTypeUri, + const char* subTypeName) + { + const TypeImpl* cont = findTypeImpl(uri, inTypeName); + if (cont == 0) + { + string msg("Type not found :"); + if (uri != 0) msg += uri; + msg += " "; + if (inTypeName != 0) msg += inTypeName; + SDO_THROW_EXCEPTION("setPropertySubstitute" , + SDOTypeNotFoundException, msg.c_str()); + } + PropertyImpl* pi = cont->getPropertyImpl(propname); + const Type& tsub = getType(subTypeUri, + subTypeName); + if (pi != 0)pi->setSubstitution(this,subname,tsub); + } + + void DataFactoryImpl::setPropertySubstitute( + const SDOString& uri, + const SDOString& inTypeName, + const SDOString& propname, + const SDOString& subname, + const SDOString& subTypeUri, + const SDOString& subTypeName) + { + setPropertySubstitute(uri.c_str(), + inTypeName.c_str(), + propname.c_str(), + subname.c_str(), + subTypeUri.c_str(), + subTypeName.c_str()); + } + + void DataFactoryImpl::setPropertySubstitute( + const Type& containertype, + const char* propname, + const char* subname, + const Type& subtype) + { + setPropertySubstitute( + containertype.getURI(), + containertype.getName(), + propname,subname, + subtype.getURI(),subtype.getName()); + } + + void DataFactoryImpl::setPropertySubstitute( + const Type& containertype, + const SDOString& propname, + const SDOString& subname, + const Type& subtype) + { + setPropertySubstitute(containertype, propname.c_str(), subname.c_str(), subtype); + } +// =================================================================== +// setDefault - sets the default value for a property of a type +// =================================================================== + + void DataFactoryImpl::setDefault( + const Type& t, const char* propname, bool b ) + { + setDefault(t.getURI(), t.getName(), propname, b); + } + + void DataFactoryImpl::setDefault( + const Type& t, const SDOString& propname, bool b ) + { + setDefault(t.getURI(), t.getName(), propname.c_str(), b); + } + + void DataFactoryImpl::setDefault( + const Type& t, const char* propname , char c) + + { + setDefault(t.getURI(), t.getName(), propname, c); + } + + void DataFactoryImpl::setDefault( + const Type& t, const SDOString& propname , char c) + + { + setDefault(t.getURI(), t.getName(), propname.c_str(), c); + } + + void DataFactoryImpl::setDefault( + const Type& t, const char* propname , wchar_t c) + { + setDefault(t.getURI(), t.getName(), propname, c); + } + + void DataFactoryImpl::setDefault( + const Type& t, const SDOString& propname , wchar_t c) + { + setDefault(t.getURI(), t.getName(), propname.c_str(), c); + } + + void DataFactoryImpl::setDefault( + const Type& t, const char* propname , char* c) + { + setDefault(t.getURI(), t.getName(), propname, c); + } + + void DataFactoryImpl::setDefault( + const Type& t, const SDOString& propname , SDOString& outstr) + { + setDefault(t.getURI(), t.getName(), propname, outstr); + } + + void DataFactoryImpl::setDefault( + const Type& t, const char* propname , short s) + { + setDefault(t.getURI(), t.getName(), propname, s); + } + + void DataFactoryImpl::setDefault( + const Type& t, const SDOString& propname , short s) + { + setDefault(t.getURI(), t.getName(), propname.c_str(), s); + } + +#if __WORDSIZE !=64 + void DataFactoryImpl::setDefault( + const Type& t, const char* propname , long l) + { + setDefault(t.getURI(), t.getName(), propname, l); + } + + void DataFactoryImpl::setDefault( + const Type& t, const SDOString& propname , long l) + { + setDefault(t.getURI(), t.getName(), propname.c_str(), l); + } + +#endif + + void DataFactoryImpl::setDefault( + const Type& t, const char* propname , int64_t i) + { + setDefault(t.getURI(), t.getName(), propname, i); + } + + void DataFactoryImpl::setDefault( + const Type& t, const SDOString& propname , int64_t i) + { + setDefault(t.getURI(), t.getName(), propname.c_str(), i); + } + + void DataFactoryImpl::setDefault( + const Type& t, const char* propname , float f) + { + setDefault(t.getURI(), t.getName(), propname, f); + } + + void DataFactoryImpl::setDefault( + const Type& t, const SDOString& propname , float f) + { + setDefault(t.getURI(), t.getName(), propname.c_str(), f); + } + + void DataFactoryImpl::setDefault( + const Type& t, const char* propname , long double d) + { + setDefault(t.getURI(), t.getName(), propname, d); + } + + void DataFactoryImpl::setDefault( + const Type& t, const SDOString& propname , long double d) + { + setDefault(t.getURI(), t.getName(), propname.c_str(), d); + } + + void DataFactoryImpl::setDefault( + const Type& t, const char* propname , const SDODate d) + { + setDefault(t.getURI(), t.getName(), propname, d); + } + + void DataFactoryImpl::setDefault( + const Type& t, const SDOString& propname , const SDODate d) + { + setDefault(t.getURI(), t.getName(), propname.c_str(), d); + } + + void DataFactoryImpl::setDefault( + const Type& t, const char* propname , const wchar_t* c, unsigned int len) + { + setDefault(t.getURI(), t.getName(), propname, c, len); + } + + void DataFactoryImpl::setDefault( + const Type& t, const SDOString& propname , const wchar_t* c, unsigned int len) + { + setDefault(t.getURI(), t.getName(), propname.c_str(), c, len); + } + + void DataFactoryImpl::setDefault( + const Type& t, const char* propname , const char* c, unsigned int len) + { + setDefault(t.getURI(), t.getName(), propname, c, len); + } + + void DataFactoryImpl::setDefault( + const Type& t, const SDOString& propname , const SDOString& c, unsigned int len) + { + setDefault(t.getURI(), t.getName(), propname.c_str(), c.c_str(), len); + } + + void DataFactoryImpl::setDefault( + const char* typuri, const char* typnam, + const char* propname, bool b ) + { + const TypeImpl* ti = findTypeImpl(typuri,typnam); + PropertyImpl* pi = ti->getPropertyImpl(propname); + if (pi != 0)pi->setDefault(b); + } + + void DataFactoryImpl::setDefault( + const SDOString& typuri, const SDOString& typnam, + const SDOString& propname, bool b ) + { + setDefault(typuri.c_str(), typnam.c_str(), propname.c_str(), b); + } + + void DataFactoryImpl::setDefault( + const char* typuri, const char* typnam, + const char* propname , char c) + { + const TypeImpl* ti = findTypeImpl(typuri,typnam); + PropertyImpl* pi = ti->getPropertyImpl(propname); + if (pi != 0)pi->setDefault(c); + } + + void DataFactoryImpl::setDefault( + const SDOString& typuri, const SDOString& typnam, + const SDOString& propname , char c) + { + setDefault(typuri.c_str(), typnam.c_str(), propname.c_str(), c); + } + + void DataFactoryImpl::setDefault( + const char* typuri, const char* typnam, + const char* propname , wchar_t c) + { + const TypeImpl* ti = findTypeImpl(typuri,typnam); + PropertyImpl* pi = ti->getPropertyImpl(propname); + if (pi != 0)pi->setDefault(c); + } + + void DataFactoryImpl::setDefault( + const SDOString& typuri, const SDOString& typnam, + const SDOString& propname , wchar_t c) + { + setDefault(typuri.c_str(), typnam.c_str(), propname.c_str(), c); + } + + void DataFactoryImpl::setDefault( + const char* typuri, const char* typnam, + const char* propname , char* c) + { + const TypeImpl* ti = findTypeImpl(typuri,typnam); + PropertyImpl* pi = ti->getPropertyImpl(propname); + if (pi != 0)pi->setDefault(c); + } + + void DataFactoryImpl::setDefault( + const SDOString& typuri, const SDOString& typnam, + const SDOString& propname , SDOString& c) + { + const TypeImpl* ti = findTypeImpl(typuri, typnam); + PropertyImpl* pi = ti->getPropertyImpl(propname); + if (pi != 0)pi->setDefault(c); + } + + void DataFactoryImpl::setDefault( + const char* typuri, const char* typnam, + const char* propname , short s) + { + const TypeImpl* ti = findTypeImpl(typuri,typnam); + PropertyImpl* pi = ti->getPropertyImpl(propname); + if (pi != 0)pi->setDefault(s); + } + + void DataFactoryImpl::setDefault( + const SDOString& typuri, const SDOString& typnam, + const SDOString& propname , short s) + { + setDefault(typuri.c_str(), typnam.c_str(), propname.c_str(), s); + } + +#if __WORDSIZE !=64 + void DataFactoryImpl::setDefault( + const char* typuri, const char* typnam, + const char* propname , long l) + { + const TypeImpl* ti = findTypeImpl(typuri,typnam); + PropertyImpl* pi = ti->getPropertyImpl(propname); + if (pi != 0)pi->setDefault(l); + } + + void DataFactoryImpl::setDefault( + const SDOString& typuri, const SDOString& typnam, + const SDOString& propname , long l) + { + setDefault(typuri.c_str(), typnam.c_str(), propname.c_str(), l); + } + +#endif + + void DataFactoryImpl::setDefault( + const char* typuri, const char* typnam, + const char* propname , int64_t i) + { + const TypeImpl* ti = findTypeImpl(typuri,typnam); + PropertyImpl* pi = ti->getPropertyImpl(propname); + if (pi != 0)pi->setDefault(i); + } + + void DataFactoryImpl::setDefault( + const SDOString& typuri, const SDOString& typnam, + const SDOString& propname , int64_t i) + { + setDefault(typuri.c_str(), typnam.c_str(), propname.c_str(), i); + } + + void DataFactoryImpl::setDefault( + const char* typuri, const char* typnam, + const char* propname , float f) + { + const TypeImpl* ti = findTypeImpl(typuri,typnam); + PropertyImpl* pi = ti->getPropertyImpl(propname); + if (pi != 0)pi->setDefault(f); + } + + void DataFactoryImpl::setDefault( + const SDOString& typuri, const SDOString& typnam, + const SDOString& propname , float f) + { + setDefault(typuri.c_str(), typnam.c_str(), propname.c_str(), f); + } + + void DataFactoryImpl::setDefault( + const char* typuri, const char* typnam, + const char* propname , long double d) + { + const TypeImpl* ti = findTypeImpl(typuri,typnam); + PropertyImpl* pi = ti->getPropertyImpl(propname); + if (pi != 0)pi->setDefault(d); + } + + void DataFactoryImpl::setDefault( + const SDOString& typuri, const SDOString& typnam, + const SDOString& propname , long double d) + { + setDefault(typuri.c_str(), typnam.c_str(), propname.c_str(), d); + } + + void DataFactoryImpl::setDefault( + const char* typuri, const char* typnam, + const char* propname , const SDODate d) + { + const TypeImpl* ti = findTypeImpl(typuri,typnam); + PropertyImpl* pi = ti->getPropertyImpl(propname); + if (pi != 0)pi->setDefault(d); + } + + void DataFactoryImpl::setDefault( + const SDOString& typuri, const SDOString& typnam, + const SDOString& propname , const SDODate d) + { + setDefault(typuri.c_str(), typnam.c_str(), propname.c_str(), d); + } + + void DataFactoryImpl::setDefault( + const char* typuri, const char* typnam, + const char* propname , const wchar_t* c, unsigned int len) + { + const TypeImpl* ti = findTypeImpl(typuri,typnam); + PropertyImpl* pi = ti->getPropertyImpl(propname); + if (pi != 0)pi->setDefault(c,len); + } + + void DataFactoryImpl::setDefault( + const SDOString& typuri, const SDOString& typnam, + const SDOString& propname , const wchar_t* c, unsigned int len) + { + setDefault(typuri.c_str(), typnam.c_str(), propname.c_str(), c, len); + } + + void DataFactoryImpl::setDefault( + const char* typuri, const char* typnam, + const char* propname , const char* c, unsigned int len) + { + const TypeImpl* ti = findTypeImpl(typuri,typnam); + PropertyImpl* pi = ti->getPropertyImpl(propname); + if (pi != 0)pi->setDefault(c,len); + } + + void DataFactoryImpl::setDefault( + const SDOString& typuri, const SDOString& typnam, + const SDOString& propname , const SDOString& c, unsigned int len) + { + setDefault(typuri.c_str(), typnam.c_str(), propname.c_str(), c.c_str(), len); + } + + void DataFactoryImpl::setOpposite( + const Type& typ, + const char* propnam, + const Type& opptyp, + const char* opppropnam) + { + SDO_THROW_EXCEPTION("setOpposite" , + SDOUnsupportedOperationException, " Not implemented"); + } + + void DataFactoryImpl::setOpposite( + const Type& typ, + const SDOString& propnam, + const Type& opptyp, + const SDOString& opppropnam) + { + setOpposite(typ, propnam.c_str(), opptyp, opppropnam.c_str()); + } + +// =================================================================== +// getTypeImpl - return a pointer to the required TypeImpl +// =================================================================== +const TypeImpl& DataFactoryImpl::getTypeImpl(const SDOString& uri, const SDOString& inTypeName) const +{ + const TypeImpl* type = findTypeImpl(uri, inTypeName); + + if (type == 0) + { + string msg("Type not found :"); + msg += uri + " " + inTypeName; + SDO_THROW_EXCEPTION("getTypeImpl" , + SDOTypeNotFoundException, msg.c_str()); + } + + return *type;; +} + +// =================================================================== +// findType +// =================================================================== +const Type* DataFactoryImpl::findType(const SDOString uri, const SDOString inTypeName) const +{ + return (Type*) findTypeImpl(uri, inTypeName); +} + +// =================================================================== +// findTypeImpl +// =================================================================== + +const TypeImpl* DataFactoryImpl::findTypeImpl(const SDOString& uri, const SDOString& inTypeName) const +{ + SDOString fullTypeName; + getFullTypeName(fullTypeName, uri, inTypeName); + TYPES_MAP::const_iterator typeIter; + typeIter = types.find(fullTypeName); + if(typeIter != types.end()) + { + return typeIter->second; + } + else + { + // try alias names + getAliasTypeName(fullTypeName, uri, inTypeName); + typeIter = types.find(fullTypeName); + if(typeIter != types.end()) + { + return typeIter->second; + } + } + return 0; +} + +// =================================================================== +// setAlias - sets a new alias for this type +// =================================================================== + +void DataFactoryImpl::setAlias(const char* typeuri, + const char* typenam, + const char* alias) +{ + + SDOString fullTypeName; + getFullTypeName(fullTypeName, typeuri, typenam); + TYPES_MAP::iterator typeIter; + typeIter = types.find(fullTypeName); + if(typeIter != types.end()) + { + (typeIter->second)->setAlias(alias); + getAliasTypeName(fullTypeName, typeuri, alias); + types[fullTypeName] = typeIter->second; + } + +} + +void DataFactoryImpl::setAlias(const SDOString& typeuri, + const SDOString& typenam, + const SDOString& alias) +{ + setAlias(typeuri.c_str(), typenam.c_str(), alias.c_str()); +} + +// =================================================================== +// setAlias - sets a new alias for this type +// =================================================================== + +void DataFactoryImpl::setAlias(const char* typeuri, + const char* typenam, + const char* propname, + const char* alias) +{ + const TypeImpl& t = getTypeImpl(typeuri, typenam); + PropertyImpl* p = t.getPropertyImpl(propname); + if (p != 0)p->setAlias(alias); + +} + +void DataFactoryImpl::setAlias(const SDOString& typeuri, + const SDOString& typenam, + const SDOString& propname, + const SDOString& alias) +{ + setAlias(typeuri.c_str(), typenam.c_str(), propname.c_str(), alias.c_str()); +} + +// =================================================================== +// getTypes - gets the full list of types for this factory +// =================================================================== + +TypeList DataFactoryImpl::getTypes() const +{ + TYPES_MAP::const_iterator typeIter; + + + std::vector typeVector; + + for (typeIter = types.begin() ; typeIter != types.end(); + ++typeIter) { + if (strncmp((typeIter->first).c_str(),"ALIAS::", 7)) { + typeVector.insert(typeVector.end(),typeIter->second); + } + } + + + return typeVector; +} + + +// =================================================================== +// resolve - resolves the type and includes all the properties from +// the supertype. After this has been called, no further changes +// to the type hierarchy are allowed. +// =================================================================== + +void DataFactoryImpl::resolve() +{ + + TYPES_MAP::iterator typeIter; + for (typeIter = resolvePending.begin() ; typeIter != resolvePending.end(); + ++typeIter) + { + (typeIter->second)->initCompoundProperties(); + (typeIter->second)->validateChangeSummary(); + } + // Need to empty the resolvePending set. + resolvePending.clear(); + +} + +// =================================================================== +// create - creates a data object from the types available. +// This first resolves the type hierarchy, and thus no further changes +// to the type hierarchy are allowed. +// =================================================================== + + +RefCountingPointer DataFactoryImpl::create(const char* uri, const char* typeName) +{ + +// New types can always be added now, so if there are any that haven't been +// resolved, do them now. The isResolved boolean is superseded by the +// resolvePending set being non-empty. + + if (!resolvePending.empty()) + { + // Allow creation of types and properties before resolve. + if (uri != 0 && !strcmp(uri,Type::SDOTypeNamespaceURI.c_str())) { + if (!strcmp(typeName,"Type") || !strcmp(typeName,"Property")) + { + DataObject* dob = (DataObject*)(new DataObjectImpl(this, getTypeImpl(uri, typeName))); + return dob; + } + } + resolve(); + } + + const TypeImpl* ti = findTypeImpl(uri,typeName); + if (ti == 0) + { + string msg("Instantiation of unknown type :"); + if (uri != 0) msg += uri; + msg += " "; + if (typeName != 0)msg += typeName; + SDO_THROW_EXCEPTION("create" , + SDOTypeNotFoundException, msg.c_str()); + } + + if (ti->isAbstractType()) + { + string msg("Instantiation of abstract type :"); + if (uri != 0)msg += uri; + msg += " "; + if (typeName != 0)msg += typeName; + SDO_THROW_EXCEPTION("create" , + SDOUnsupportedOperationException, msg.c_str()); + } + + DataObject* dob = (DataObject*)(new DataObjectImpl(this, getTypeImpl(uri, typeName))); + return dob; +} + +// =================================================================== +// create - creates a data object from the types available. +// This first resolves the type hierarchy, and thus no further changes +// to the type hierarchy are allowed. +// =================================================================== + + +RefCountingPointer DataFactoryImpl::create(const SDOString& uri, const SDOString& typeName) +{ + return create(uri.c_str(), typeName.c_str()); +} + +// =================================================================== +// The openProperties map is a list of the curently present open +// properties as used by this factory. It will cause the +// open properties to be written out as attributes and elements +// of the root data object when a graph is serialized. +// =================================================================== + const propertyMap& DataFactoryImpl::getOpenProperties() + { + return openProperties; + } + + void DataFactoryImpl::addOpenProperty(const PropertyImpl& prop) + { + propertyMap::iterator i; + while ((i = openProperties.find(prop.getName())) != + openProperties.end()) + { + openProperties.erase(i); + } + openProperties.insert(make_pair(prop.getName(),prop)); + } + + void DataFactoryImpl::removeOpenProperty(const SDOString& name) + { + propertyMap::iterator i = + openProperties.find(name.c_str()); + if (i != openProperties.end()) + { + openProperties.erase(i); + } + } + + +// =================================================================== +// create - creates a data object from the types available. +// This first resolves the type hierarchy, and thus no further changes +// to the type hierarchy are allowed. +// =================================================================== + +RefCountingPointer DataFactoryImpl::create(const Type& type) +{ + return create( type.getURI(), type.getName()); +} + + +// =================================================================== +// setDASValue - Set a value on a Type +// =================================================================== +void DataFactoryImpl::setDASValue(const Type& type, + const char* name, + DASValue* value) +{ + setDASValue(type.getURI(), type.getName(), name, value); +} + +void DataFactoryImpl::setDASValue(const Type& type, + const SDOString& name, + DASValue* value) +{ + setDASValue(type.getURI(), type.getName(), name.c_str(), value); +} + +void DataFactoryImpl::setDASValue(const char* typeuri, + const char* typenam, + const char* name, + DASValue* value) +{ + TypeImpl* type = (TypeImpl*)findTypeImpl(typeuri, typenam); + if (type != NULL) + { + type->setDASValue(name, value); + } +} + +void DataFactoryImpl::setDASValue(const SDOString& typeuri, + const SDOString& typenam, + const SDOString& name, + DASValue* value) +{ + setDASValue(typeuri.c_str(), typenam.c_str(), name.c_str(), value); +} + +// =================================================================== +// getDASValue - retrieve a value from a Type +// =================================================================== + +DASValue* DataFactoryImpl::getDASValue(const Type& type, + const char* name) const +{ + return getDASValue(type.getURI(), type.getName(), name); +} + +DASValue* DataFactoryImpl::getDASValue(const Type& type, + const SDOString& name) const +{ + return getDASValue(type.getURI(), type.getName(), name.c_str()); +} + +DASValue* DataFactoryImpl::getDASValue(const char* typeuri, + const char* typenam, + const char* name) const +{ + TypeImpl* type = (TypeImpl*)findTypeImpl(typeuri, typenam); + if (type != NULL) + { + return type->getDASValue(name); + } + + return NULL; +} + +DASValue* DataFactoryImpl::getDASValue(const SDOString& typeuri, + const SDOString& typenam, + const SDOString& name) const +{ + return getDASValue(typeuri.c_str(), typenam.c_str(), name.c_str()); +} + +// =================================================================== +// setDASValue - Set a value on a Property +// =================================================================== +void DataFactoryImpl::setDASValue( + const Type& type, + const char* propertyName, + const char* name, + DASValue* value) +{ + setDASValue(type.getURI(), type.getName(), propertyName, name, value); +} + +void DataFactoryImpl::setDASValue( + const Type& type, + const SDOString& propertyName, + const SDOString& name, + DASValue* value) +{ + setDASValue(type.getURI(), type.getName(), propertyName.c_str(), name.c_str(), value); +} + +void DataFactoryImpl::setDASValue( + const char* typeuri, + const char* typenam, + const char* propertyName, + const char* name, + DASValue* value) +{ + const TypeImpl* type = findTypeImpl(typeuri, typenam); + if (type != NULL) + { + PropertyImpl* prop = type->getPropertyImplPure(propertyName); + if (prop != 0)prop->setDASValue(name, value); + } +} + +void DataFactoryImpl::setDASValue( + const SDOString& typeuri, + const SDOString& typenam, + const SDOString& propertyName, + const SDOString& name, + DASValue* value) +{ + setDASValue(typeuri.c_str(), typenam.c_str(), propertyName.c_str(), name.c_str(), value); +} + +// =================================================================== +// getDASValue - retrieve a value from a Property +// =================================================================== +DASValue* DataFactoryImpl::getDASValue( + const Type& type, + const char* propertyName, + const char* name) const +{ + return getDASValue(type.getURI(), type.getName(), propertyName, name); +} + +DASValue* DataFactoryImpl::getDASValue( + const Type& type, + const SDOString& propertyName, + const SDOString& name) const +{ + return getDASValue(type.getURI(), type.getName(), propertyName.c_str(), name.c_str()); +} + +DASValue* DataFactoryImpl::getDASValue( + const char* typeuri, + const char* typenam, + const char* propertyName, + const char* name) const +{ + const TypeImpl* type = findTypeImpl(typeuri, typenam); + if (type != NULL) + { + try + { + PropertyImpl* prop = type->getPropertyImpl(propertyName); + if (prop != 0)return prop->getDASValue(name); + } + catch (const SDOPropertyNotFoundException&) + { + // Ignore - return null + } + } + + return NULL; +} + +DASValue* DataFactoryImpl::getDASValue( + const SDOString& typeuri, + const SDOString& typenam, + const SDOString& propertyName, + const SDOString& name) const +{ + return getDASValue(typeuri.c_str(), typenam.c_str(), propertyName.c_str(), name.c_str()); +} + + +bool DataFactoryImpl::generateInterface(const char* fileroot, const char* factoryname) +{ + + FILE* header; + FILE* body; + + if ((fileroot == 0) || (strlen(fileroot) == 0)) return false; + + if (factoryname == 0 || (strlen(factoryname) == 0)) return false; + + + char *headername = new char[strlen(fileroot) + 5]; + char *bodyname = new char[strlen(fileroot) + 5]; + strcpy(headername,fileroot); + strcpy(bodyname,fileroot); + strcat(headername,".h"); + strcat(bodyname,".cpp"); + + // here we should check the files - and if they are present with + // contents we should read them, and merge the new generated code + // I think the way to do that is to allow sections in between comment + // pairs in three locations: + // a) outside any method in the CPP file. + // b) in the header file anywhere. + // c) inside method definitions in cpp, either before, or after the + // entire generated contents. + // + // + + header = fopen(headername,"w+"); + if (header == 0) return false; + + body = fopen(bodyname,"w+"); + if (body == 0) return false; + + + fprintf(header,"/*******************************************\n"); + fprintf(header," * Generated Typesafe Interface Header *\n"); + fprintf(header," *******************************************/\n\n\n"); + fprintf(header,"#include \"commonj/sdo/SDO.h\"\n"); + fprintf(header,"using namespace commonj::sdo;\n\n\n"); + + fprintf(body,"/*******************************************\n"); + fprintf(body," * Generated Typesafe Interface Body *\n"); + fprintf(body," *******************************************/\n\n\n"); + fprintf(body,"#include \"%s\"\n",headername); + fprintf(body,"using namespace commonj::sdo;\n\n\n"); + + delete headername; + delete bodyname; + + try { + + int nscount; + + TypeList tl = getTypes(); + + // forward declarations and smart pointers + + fprintf(header,"/*******************************************\n"); + fprintf(header," * Forward declarations and smart pointers *\n"); + fprintf(header," *******************************************/\n\n\n"); + + unsigned int i; + for (i=0;i %sPtr;\n", + name, name); + + for (int i=0;icreate(\"%s\",\"%s\");\n", + tl[i].getURI(),name); + fprintf(body," %s::%s* the_ob = new %s::%s(dob);\n",the_uri,name,the_uri,name); + fprintf(body," return the_ob;\n"); + fprintf(body,"}\n\n"); + + delete the_uri; + + } + + fprintf(header," DataFactory* getDataFactory()\n"); + fprintf(header," {\n"); + fprintf(header," return (DataFactory*)the_factory;\n"); + fprintf(header," }\n"); + fprintf(header," private:\n"); + fprintf(header," DataFactoryPtr the_factory;\n"); + fprintf(header,"};\n"); + + fprintf(header,"\n\n"); + + fprintf(body,"%sDataFactory* %sDataFactory::get%sDataFactory()\n", + factoryname,factoryname,factoryname); + fprintf(body,"{\n"); + fprintf(body," %sDataFactory* t = new %sDataFactory();\n", + factoryname, factoryname); + fprintf(body," t->the_factory = DataFactory::getDataFactory();\n"); + fprintf(body," return t;\n"); + fprintf(body,"}\n\n"); + + + fprintf(header,"/*******************************************\n"); + fprintf(header," * DataObject Type definitions *\n"); + fprintf(header," *******************************************/\n\n\n"); + + + for (i=0;isetUserData((void*)this);\n"); + fprintf(body,"}\n\n\n"); + + + + PropertyList pl = tl[i].getProperties(); + for (unsigned int j=0;jgetList(\"%s\");\n",pname); + fprintf(body, "}\n\n"); + } + else + { + if (pl[j].getType().isDataType()) + { + switch (pl[j].getTypeEnum()) + { + case Type::BooleanType: + fprintf(header," bool get%s();\n",pname); + fprintf(body, "bool %s::get%s\n(){\n",name, pname); + fprintf(body, " return the_object->getBoolean(\"%s\");\n",pname); + fprintf(body, "}\n\n"); + fprintf(header," void set%s(bool b);\n",pname); + fprintf(body, "void %s::set%s(bool b)\n{\n",name, pname); + fprintf(body, " the_object->setBoolean(\"%s\",b);\nreturn;\n",pname); + fprintf(body, "}\n\n"); + + break; + + case Type::ByteType: + + fprintf(header," char get%s();\n",pname); + fprintf(body, "char %s::get%s\n{\n",name, pname); + fprintf(body, " return the_object->getByte(\"%s\");\n",pname); + fprintf(body, "}\n\n"); + fprintf(header," void set%s(char c);\n",pname); + fprintf(body, "void %s::set%s(char c)\n{\n",name, pname); + fprintf(body, " the_object->setByte(\"%s\",c);\nreturn;\n",pname); + fprintf(body, "}\n\n"); + + break; + + case Type::BytesType: + + fprintf(header," unsigned int get%s(char *buf, unsigned int len);\n",pname); + fprintf(body, "unsigned int %s::get%s(char *buf, unsigned int len)\n{\n",name, + pname); + fprintf(body, " return the_object->getBytes(\"%s\", buf,len);\n",pname); + fprintf(body, "}\n\n"); + fprintf(header," void set%s(char *buf,unsigned int len);\n",pname); + fprintf(body, "void %s::set%s(char *buf, unsigned int len)\n{\n",name, + pname); + fprintf(body, " the_object->setBytes(\"%s\", buf,len);\nreturn;\n",pname); + fprintf(body, "}\n\n"); + + break; + + case Type::CharacterType: + + fprintf(header," wchar_t get%s();\n",pname); + fprintf(body, "wchar_t %s::get%s\n{\n",name, pname); + fprintf(body, " return the_object->getCharacter(\"%s\");\n",pname); + fprintf(body, "}\n\n"); + fprintf(header," void set%s(wchar_t c);\n",pname); + fprintf(body, "void %s::set%s(wchar_t c)\n{\n",name, pname); + fprintf(body, " the_object->setCharacter(\"%s\",c);\nreturn;\n",pname); + fprintf(body, "}\n\n"); + + break; + + case Type::DateType: + + fprintf(header," SDODate get%s();\n",pname); + fprintf(body, "SDODate %s::get%s\n{\n",name, pname); + fprintf(body, " return the_object->getDate(\"%s\");\n",pname); + fprintf(body, "}\n\n"); + fprintf(header," void set%s(const SDODate c);\n",pname); + fprintf(body, "void %s::set%s(const SDODate c)\n{\n",name, pname); + fprintf(body, " the_object->setDate(\"%s\",c);\nreturn;\n",pname); + fprintf(body, "}\n\n"); + + break; + + case Type::DoubleType: + + fprintf(header," long double get%s();\n",pname); + fprintf(body, "long double %s::get%s\n{\n",name, pname); + fprintf(body, " return the_object->getDouble(\"%s\");\n",pname); + fprintf(body, "}\n\n"); + fprintf(header," void set%s(long double c);\n",pname); + fprintf(body, "void %s::set%s(long double c)\n{\n",name, pname); + fprintf(body, " the_object->setDouble(\"%s\",c);\nreturn;\n",pname); + fprintf(body, "}\n\n"); + + break; + + case Type::FloatType: + + fprintf(header," float get%s();\n",pname); + fprintf(body, "float %s::get%s\n{\n",name, pname); + fprintf(body, " return the_object->getFloat(\"%s\");\n",pname); + fprintf(body, "}\n\n"); + fprintf(header," void set%s(float c);\n",pname); + fprintf(body, "void %s::set%s(float c)\n{\n",name, pname); + fprintf(body, " the_object->setFloat(\"%s\",c);\nreturn;\n",pname); + fprintf(body, "}\n\n"); + + break; + + case Type::IntegerType: + + fprintf(header," long get%s();\n",pname); + fprintf(body, "long %s::get%s\n{\n",name, pname); + fprintf(body, " return the_object->getInteger(\"%s\");\n",pname); + fprintf(body, "}\n\n"); + fprintf(header," void set%s(long c);\n",pname); + fprintf(body, "void %s::set%s(long c)\n{\n",name, pname); + fprintf(body, " the_object->setInteger(\"%s\",c);\nreturn;\n",pname); + fprintf(body, "}\n\n"); + + break; + + case Type::LongType: + + fprintf(header," int64_t get%s();\n",pname); + fprintf(body, "int64_t %s::get%s\n{\n",name, pname); + fprintf(body, " return the_object->getLong(\"%s\");\n",pname); + fprintf(body, "}\n\n"); + fprintf(header," void set%s(int64_t c);\n",pname); + fprintf(body, "void %s::set%s(int64_t c)\n{\n",name, pname); + fprintf(body, " the_object->setLong(\"%s\",c);\nreturn;\n",pname); + fprintf(body, "}\n\n"); + + break; + + case Type::ShortType: + + fprintf(header," short get%s();\n",pname); + fprintf(body, "short %s::get%s\n{\n",name, pname); + fprintf(body, " return the_object->getShort(\"%s\");\n",pname); + fprintf(body, "}\n\n"); + fprintf(header," void set%s(short c);\n",pname); + fprintf(body, "void %s::set%s(short c)\n{\n",name, pname); + fprintf(body, " the_object->setShort(\"%s\",c);\nreturn;\n",pname); + fprintf(body, "}\n\n"); + + break; + + case Type::StringType: + case Type::UriType: + + fprintf(header," unsigned int get%s(wchar_t *buf, unsigned int len);\n",pname); + fprintf(body, "unsigned int %s::get%s(wchar_t *buf, unsigned int len)\n{\n",name, + pname); + fprintf(body, " return the_object->getString(\"%s\", buf,len);\n",pname); + fprintf(body, "}\n\n"); + fprintf(header," void set%s(wchar_t *buf,unsigned int len);\n",pname); + fprintf(body, "void %s::set%s(wchar_t *buf, unsigned int len)\n{\n",name, + pname); + fprintf(body, " the_object->setString(\"%s\", buf,len);\nreturn;\n",pname); + fprintf(body, "}\n\n"); + + break; + + default: + fprintf(header,"/* unknown primitive:%s */\n",pname); + break; + } + } + else + + { + const char* ttname = pl[j].getType().getName(); + + fprintf(header," %sPtr get%s();\n",ttname, pname); + + fprintf(body, "%sPtr %s::get%s()\n{\n", + ttname, + name, + pname); + fprintf(body, "DataObjectPtr dob = the_object->getDataObject(\"%s\");\n",pname); + fprintf(body, "DataObject* d = (DataObject*)dob;\n"); + fprintf(body,"%s* value = (%s*)(d->getUserData());\n",ttname, ttname); + fprintf(body, " return (%s*)value;\n", ttname); + fprintf(body, "}\n\n"); + fprintf(header," void set%s(%sPtr dob);\n",pname, ttname); + fprintf(body, "void %s::set%s(%sPtr dob)\n{\n", + name,pname,ttname); + fprintf(body,"%s* ptr = dob;\n", ttname); + fprintf(body,"DataObject* the_obj = ptr->getDataObject();\n"); + fprintf(body,"the_object->setDataObject(\"%s\", the_obj);\nreturn;\n", + pname); + fprintf(body, "}\n\n"); + + } + } + } // for + + // now print the contained data object + + fprintf(header," DataObject* getDataObject()\n"); + fprintf(header," {\n"); + fprintf(header," return (DataObject*)the_object;\n"); + fprintf(header," }\n"); + fprintf(header," private:\n"); + fprintf(header," DataObjectPtr the_object;\n"); + + fprintf(header,"};\n"); + for (int i=0;i + + + +namespace commonj{ +namespace sdo{ + + typedef std::map propertyMap; + +/** + * DataFactoryImpl implements the abstract class DataFactory. + * DataFactoryImpl holds metadata and creates DataObjects. + * + * The DataFactory holds properties and types loaded from XSD, or + * created using the DataFactory API. + */ +class DataFactoryImpl : public DataFactory +{ +public: + DataFactoryImpl(); + virtual ~DataFactoryImpl(); + + DataFactoryImpl(const DataFactoryImpl& inmdg); + DataFactoryImpl& operator=(const DataFactoryImpl& inmdg); + + virtual void addType(const char* uri, const char* inTypeName, + bool isSeqenced = false, + bool isOpen = false, + bool isAbstract = false, + bool isDataType = false + ); + + virtual void addType(const SDOString& uri, const SDOString& inTypeName, + bool isSeqenced = false, + bool isOpen = false, + bool isAbstract = false, + bool isDataType = false + ); + + virtual void addType(const char* uri, const char* inTypeName, + bool isSeqenced , + bool isOpen , + bool isAbstract , + bool isDataType , + bool isFromList ); + + virtual void addType(const SDOString& uri, const SDOString& inTypeName, + bool isSeqenced , + bool isOpen , + bool isAbstract , + bool isDataType , + bool isFromList ); + + virtual void addPropertyToType(const char* uri, + const char* inTypeName, + const char* propname, + const char* propTypeUri, + const char* propTypeName, + bool isMany = false); + + virtual void addPropertyToType(const SDOString& uri, + const SDOString& inTypeName, + const SDOString& propname, + const SDOString& propTypeUri, + const SDOString& propTypeName, + bool isMany = false); + + virtual void addPropertyToType(const char* uri, + const char* inTypeName, + const char* propname, + const Type& propType, + bool isMany = false); + + virtual void addPropertyToType(const SDOString& uri, + const SDOString& inTypeName, + const SDOString& propname, + const Type& propType, + bool isMany = false); + + virtual void addPropertyToType(const Type& type, + const char* propname, + const Type& propType, + bool isMany = false); + + virtual void addPropertyToType(const Type& type, + const SDOString& propname, + const Type& propType, + bool isMany = false); + + virtual void addPropertyToType(const Type& type, + const char* propname, + const char* propTypeUri, + const char* propTypeName, + bool isMany = false); + + virtual void addPropertyToType(const Type& type, + const SDOString& propname, + const SDOString& propTypeUri, + const SDOString& propTypeName, + bool isMany = false); + + virtual void addPropertyToType(const char* uri, + const char* inTypeName, + const char* propname, + const char* propTypeUri, + const char* propTypeName, + bool isMany , + bool isReadOnly, + bool isContainment); + + virtual void addPropertyToType(const SDOString& uri, + const SDOString& inTypeName, + const SDOString& propname, + const SDOString& propTypeUri, + const SDOString& propTypeName, + bool isMany , + bool isReadOnly, + bool isContainment); + + virtual void addPropertyToType(const char* uri, + const char* inTypeName, + const char* propname, + const Type& propType, + bool isMany, + bool isReadOnly, + bool isContainment); + + virtual void addPropertyToType(const SDOString& uri, + const SDOString& inTypeName, + const SDOString& propname, + const Type& propType, + bool isMany, + bool isReadOnly, + bool isContainment); + + virtual void addPropertyToType(const Type& type, + const char* propname, + const Type& propType, + bool isMany, + bool isReadOnly, + bool isContainment); + + virtual void addPropertyToType(const Type& type, + const SDOString& propname, + const Type& propType, + bool isMany, + bool isReadOnly, + bool isContainment); + + virtual void addPropertyToType(const Type& type, + const char* propname, + const char* propTypeUri, + const char* propTypeName, + bool isMany, + bool isReadOnly, + bool isContainment); + + virtual void addPropertyToType(const Type& type, + const SDOString& propname, + const SDOString& propTypeUri, + const SDOString& propTypeName, + bool isMany, + bool isReadOnly, + bool isContainment); + + + virtual void setBaseType( const Type& type, + const Type& base, + bool isRestriction = false); + + virtual void setBaseType( const char* typeuri, + const char* typenam, + const char* baseuri, + const char* basename, + bool isRestriction = false); + + virtual void setBaseType( const SDOString& typeuri, + const SDOString& typenam, + const SDOString& baseuri, + const SDOString& basename, + bool isRestriction = false); + + virtual const Type& getType(const char* uri, const char* inTypeName) const; + + virtual const Type& getType(const SDOString& uri, const SDOString& inTypeName) const; + + virtual TypeList getTypes() const; + + virtual DataObjectPtr create(const char* uri, const char* typeName) ; + + virtual DataObjectPtr create(const SDOString& uri, const SDOString& typeName) ; + + virtual DataObjectPtr create(const Type& type) ; + + virtual void setAlias(const char* typeuri, + const char* typenam, + const char* alias) ; + + virtual void setAlias(const SDOString& typeuri, + const SDOString& typenam, + const SDOString& alias) ; + + virtual void setAlias(const char* typeuri, + const char* typname, + const char* propname, + const char* alias) ; + + virtual void setAlias(const SDOString& typeuri, + const SDOString& typname, + const SDOString& propname, + const SDOString& alias) ; + + virtual void setOpposite (const Type& type, + const char* propname, + const Type& opptype, + const char* opppropname) ; + + virtual void setOpposite (const Type& type, + const SDOString& propname, + const Type& opptype, + const SDOString& opppropname) ; + + + virtual void setPropertySubstitute( + const char* uri, + const char* inTypeName, + const char* propname, + const char* subname, + const char* subTypeUri, + const char* subTypeName); + + virtual void setPropertySubstitute( + const SDOString& uri, + const SDOString& inTypeName, + const SDOString& propname, + const SDOString& subname, + const SDOString& subTypeUri, + const SDOString& subTypeName); + + virtual void setPropertySubstitute( + const Type& containertype, + const char* propname, + const char* subname, + const Type& subtype); + + virtual void setPropertySubstitute( + const Type& containertype, + const SDOString& propname, + const SDOString& subname, + const Type& subtype); + + //////////////////////////////////////////////////////// + virtual void setDefault( + const Type& t, + const char* propname, + bool b ) ; + + virtual void setDefault( + const Type& t, + const SDOString& propname, + bool b ) ; + + virtual void setDefault( + const Type& t, + const char* propname , + char c) ; + + virtual void setDefault( + const Type& t, + const SDOString& propname , + char c) ; + + virtual void setDefault( + const Type& t, + const char* propname , + wchar_t c) ; + + virtual void setDefault( + const Type& t, + const SDOString& propname , + wchar_t c) ; + + virtual void setDefault( + const Type& t, + const char* propname , + char* c) ; + + virtual void setDefault( + const Type& t, + const SDOString& propname , + SDOString& outstr); + + virtual void setDefault( + const Type& t, + const char* propname , + short s) ; + + virtual void setDefault( + const Type& t, + const SDOString& propname , + short s) ; + + + +#if __WORDSIZE !=64 + virtual void setDefault( + const Type& t, + const char* propname , + long l) ; + + virtual void setDefault( + const Type& t, + const SDOString& propname , + long l) ; + +#endif + + virtual void setDefault( + const Type& t, + const char* propname , + int64_t i) ; + + virtual void setDefault( + const Type& t, + const SDOString& propname , + int64_t i) ; + + virtual void setDefault( + const Type& t, + const char* propname , + float f) ; + + virtual void setDefault( + const Type& t, + const SDOString& propname , + float f) ; + + virtual void setDefault( + const Type& t, + const char* propname , + long double d) ; + + virtual void setDefault( + const Type& t, + const SDOString& propname , + long double d) ; + + virtual void setDefault( + const Type& t, + const char* propname , + const SDODate d) ; + + virtual void setDefault( + const Type& t, + const SDOString& propname , + const SDODate d) ; + + virtual void setDefault( + const Type& t, + const char* propname , + const wchar_t* c, + unsigned int len) ; + + virtual void setDefault( + const Type& t, + const SDOString& propname , + const wchar_t* c, + unsigned int len) ; + + virtual void setDefault( + const Type& t, + const char* propname , + const char* c, + unsigned int len) ; + + virtual void setDefault( + const Type& t, + const SDOString& propname , + const SDOString& c, + unsigned int len) ; + + virtual void setDefault( + const char* typuri, + const char* typnam, + const char* propname, + bool b ) ; + + virtual void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname, + bool b ) ; + + virtual void setDefault( + const char* typuri, + const char* typnam, + const char* propname , + char c) ; + + virtual void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname , + char c) ; + + virtual void setDefault( + const char* typuri, + const char* typnam, + const char* propname , + wchar_t c) ; + + virtual void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname , + wchar_t c) ; + + virtual void setDefault( + const char* typuri, + const char* typnam, + const char* propname , + char* c) ; + + virtual void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname , + SDOString& c) ; + + virtual void setDefault( + const char* typuri, + const char* typnam, + const char* propname , + short s) ; + + virtual void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname , + short s) ; + +#if __WORDSIZE !=64 + virtual void setDefault( + const char* typuri, + const char* typnam, + const char* propname , + long l) ; + + virtual void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname , + long l) ; + +#endif + + virtual void setDefault( + const char* typuri, + const char* typnam, + const char* propname , + int64_t i) ; + + virtual void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname , + int64_t i) ; + + virtual void setDefault( + const char* typuri, + const char* typnam, + const char* propname , + float f) ; + + virtual void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname , + float f) ; + + virtual void setDefault( + const char* typuri, + const char* typnam, + const char* propname , + long double d) ; + + virtual void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname , + long double d) ; + + virtual void setDefault( + const char* typuri, + const char* typnam, + const char* propname , + const SDODate d) ; + + virtual void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname , + const SDODate d) ; + + virtual void setDefault( + const char* typuri, + const char* typnam, + const char* propname , + const wchar_t* c, + unsigned int len) ; + + virtual void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname , + const wchar_t* c, + unsigned int len) ; + + virtual void setDefault( + const char* typuri, + const char* typnam, + const char* propname , + const char* c, + unsigned int len) ; + + virtual void setDefault( + const SDOString& typuri, + const SDOString& typnam, + const SDOString& propname , + const SDOString& c, + unsigned int len) ; + + virtual void setDASValue( + const Type& type, + const char* name, + DASValue* value); + + virtual void setDASValue( + const Type& type, + const SDOString& name, + DASValue* value); + + virtual void setDASValue( + const char* typeuri, + const char* typenam, + const char* name, + DASValue* value); + + virtual void setDASValue( + const SDOString& typeuri, + const SDOString& typenam, + const SDOString& name, + DASValue* value); + + virtual DASValue* getDASValue( + const Type& type, + const char* name) const; + + virtual DASValue* getDASValue( + const Type& type, + const SDOString& name) const; + + virtual DASValue* getDASValue( + const char* typeuri, + const char* typenam, + const char* name) const; + + virtual DASValue* getDASValue( + const SDOString& typeuri, + const SDOString& typenam, + const SDOString& name) const; + + virtual void setDASValue( + const Type& type, + const char* propertyName, + const char* name, + DASValue* value); + + virtual void setDASValue( + const Type& type, + const SDOString& propertyName, + const SDOString& name, + DASValue* value); + + virtual void setDASValue( + const char* typeuri, + const char* typenam, + const char* propertyName, + const char* name, + DASValue* value); + + virtual void setDASValue( + const SDOString& typeuri, + const SDOString& typenam, + const SDOString& propertyName, + const SDOString& name, + DASValue* value); + + virtual DASValue* getDASValue( + const Type& type, + const char* propertyName, + const char* name) const; + + virtual DASValue* getDASValue( + const Type& type, + const SDOString& propertyName, + const SDOString& name) const; + + virtual DASValue* getDASValue( + const char* typeuri, + const char* typenam, + const char* propertyName, + const char* name) const; + + virtual DASValue* getDASValue( + const SDOString& typeuri, + const SDOString& typenam, + const SDOString& propertyName, + const SDOString& name) const; + + virtual void resolve(); + + const Type* findType(const SDOString uri, const SDOString inTypeName) const; + + const TypeImpl* findTypeImpl(const SDOString& uri, const SDOString& inTypeName) const; + + void addOpenProperty(const PropertyImpl& prop); + void removeOpenProperty(const SDOString& name); + const propertyMap& getOpenProperties(); + virtual const TypeImpl& getTypeImpl(const SDOString& uri, const SDOString& inTypeName) const; + + virtual bool generateInterface(const char* fileroot, const char* factoryname); + virtual bool generateInterface(const SDOString& fileroot, const SDOString& factoryname); + + virtual std::ostream& printSelf(std::ostream &os); + +private: + typedef std::map TYPES_MAP; + TYPES_MAP types; + TYPES_MAP resolvePending; // Set of types that have not yet been resolved. + + std::vector compatibleFactories; + + propertyMap openProperties; + + // Need to validate and 'lock' the data model for base types to + // work properly. + + bool isResolved; + + bool recursiveCheck(TypeImpl* cs, TypeImpl* t); + bool checkForValidChangeSummary(TypeImpl* t); + + typedef std::vector TYPES_VECTOR; + TYPES_VECTOR cstypes; + + static SDOString& getFullTypeName(SDOString& stringBuffer, const SDOString& uri, const SDOString& inTypeName); + static SDOString& getAliasTypeName(SDOString& stringBuffer, const SDOString& uri, const SDOString& inTypeName); + + void copyTypes(const DataFactoryImpl& inmdg); +}; +}; +}; +#endif // _DataFactoryIMPL_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataGraph.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataGraph.cpp new file mode 100644 index 0000000000..9f4fb02c6d --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataGraph.cpp @@ -0,0 +1,35 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/disable_warn.h" +#include "commonj/sdo/DataGraph.h" +#include "commonj/sdo/SDORuntimeException.h" + +namespace commonj{ + namespace sdo { + + DataGraph::~DataGraph() + { + } + + + }; +}; diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataGraph.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataGraph.h new file mode 100644 index 0000000000..eef42e393d --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataGraph.h @@ -0,0 +1,105 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _DATAGRAPH_H_ +#define _DATAGRAPH_H_ + +#include "commonj/sdo/RefCountingObject.h" +#include "commonj/sdo/Type.h" +#include "commonj/sdo/export.h" +#include "commonj/sdo/DataObject.h" + + +namespace commonj{ +namespace sdo{ + +/** + * DataGraph holds a whole graph of data objects, starting from + * a single root. This class is not currently used in the C++ + * implementation, but will be required by DAS implementations. + */ + +class DataGraph : public RefCountingObject +{ + public: + virtual ~DataGraph(); + + /** + * + * Gets the root data object of this graph. + */ + + + virtual SDO_API DataObjectPtr getRootObject() = 0; + + /** + * + * gets the name of the element from which the root + * object was loaded (The XML definition). + */ + virtual SDO_API const char* getRootElementName() = 0; + + /** + * Sets the Root data object. + * + */ + virtual SDO_API void setRootObject(DataObjectPtr dob) = 0; + + /** + * Creates a root data object - used by DAS implementations. + * + */ + + virtual SDO_API DataObjectPtr createRootObject(const char* uri, + const char* name) = 0; + virtual SDO_API DataObjectPtr createRootObject(const SDOString& uri, + const SDOString& name) = 0; + + /** + * Creates a root data object - used by DAS implementations. + * + */ + + virtual SDO_API DataObjectPtr createRootObject(const Type& t) = 0; + + /** + * Gets the change summary if there is one. + * + */ + + virtual SDO_API ChangeSummaryPtr getChangeSummary() = 0; + + /** + * Gets a type from the data factory. + * + */ + + virtual SDO_API const Type& getType(const char* uri, + const char* name) = 0; + virtual SDO_API const Type& getType(const SDOString& uri, + const SDOString& name) = 0; + + +}; +}; +}; + +#endif //_DATAGRAPH_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataGraphImpl.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataGraphImpl.cpp new file mode 100644 index 0000000000..3d4919767e --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataGraphImpl.cpp @@ -0,0 +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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/DataGraphImpl.h" +#include "commonj/sdo/DataObjectImpl.h" +#include "commonj/sdo/SDORuntimeException.h" + + + +namespace commonj{ + namespace sdo { + +/** + * DataGraphImpl implements DataGraph. + * DataGraph holds a whole graph of data objects, starting from + * a single root. This class is not currently used in the C++ + * implementation, but will be required by DAS implementations. + */ + DataGraphImpl::~DataGraphImpl() + { + } + + DataGraphImpl::DataGraphImpl(DataFactoryPtr fac) + { + factory = fac; + root = 0; + } + + + DataObjectPtr DataGraphImpl::getRootObject() + { + return root; + } + + const char* DataGraphImpl::getRootElementName() + { + if (root == 0) return 0; + return root->getInstanceProperties()[0].getName(); + } + + void DataGraphImpl::setRootObject(DataObjectPtr dob) + { + if (root != 0) + { + SDO_THROW_EXCEPTION("setRootObject",SDOUnsupportedOperationException, + "Root data object already exists"); + } + root = dob; + } + + +// DataObjectPtr DataGraphImpl::createRootObject(const char* uri, +// const char* name) +// { +// if (root != 0) +// { +// SDO_THROW_EXCEPTION("createRootObject",SDOUnsupportedOperationException, +// "Root data object already exists"); +// } +// root = factory->create(uri,name); +// if (root->getInstanceProperties()[0].getType().isDataType()) +// { +// SDO_THROW_EXCEPTION("createRootObject",SDOUnsupportedOperationException, +// "Root data object cannot have a datatype property at element 0"); +// } +// return root; +// } + + DataObjectPtr DataGraphImpl::createRootObject(const char* uri, + const char* name) + { + return createRootObject(SDOString(uri), SDOString(name)); + } + + DataObjectPtr DataGraphImpl::createRootObject(const SDOString& uri, + const SDOString& name) + { + if (root != 0) + { + SDO_THROW_EXCEPTION("createRootObject",SDOUnsupportedOperationException, + "Root data object already exists"); + } + root = factory->create(uri,name); + if (root->getInstanceProperties()[0].getType().isDataType()) + { + SDO_THROW_EXCEPTION("createRootObject",SDOUnsupportedOperationException, + "Root data object cannot have a datatype property at element 0"); + } + return root; + } + + + DataObjectPtr DataGraphImpl::createRootObject(const Type& t) + { + if (root != 0) + { + SDO_THROW_EXCEPTION("createRootObject",SDOUnsupportedOperationException, + "Root data object already exists"); + } + root = factory->create(t); + if (root->getInstanceProperties()[0].getType().isDataType()) + { + SDO_THROW_EXCEPTION("createRootObject",SDOUnsupportedOperationException, + "Root data object cannot have a datatype property at element 0"); + } + return root; + } + + + ChangeSummaryPtr DataGraphImpl::getChangeSummary() + { + if (!root) return 0; + return root->getChangeSummary(); + } + + + const Type& DataGraphImpl::getType(const char* uri, + const char* name) + { + return factory->getType(uri,name); + } + const Type& DataGraphImpl::getType(const SDOString& uri, + const SDOString& name) + { + return factory->getType(uri,name); + } + + }; +}; diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataGraphImpl.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataGraphImpl.h new file mode 100644 index 0000000000..6affa1cc46 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataGraphImpl.h @@ -0,0 +1,112 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _DATAGRAPHIMPL_H_ +#define _DATAGRAPHIMPL_H_ +#include "commonj/sdo/export.h" +#include "commonj/sdo/DataGraph.h" +#include "commonj/sdo/disable_warn.h" + + +namespace commonj{ +namespace sdo{ + +/** + * DataGraphImpl implements the abstract class DataGraph. + * DataGraph holds a whole graph of data objects, starting from + * a single root. This class is not currently used in the C++ + * implementation, but will be required by DAS implementations. + */ + +class DataGraphImpl : public DataGraph +{ + public: + virtual ~DataGraphImpl(); + + SDO_API DataGraphImpl(DataFactoryPtr fac); + + /** + * Sets the root data object. + * + */ + + virtual SDO_API void setRootObject(DataObjectPtr dob); + + /** + * Gets the root data object. + * + */ + + virtual DataObjectPtr getRootObject(); + + /** + * Gets the name of the root data element (from the XML + * description). + * + */ + + virtual const char* getRootElementName(); + + /** + * Creates the root data object - for use by DAS implementations + * + */ + + virtual DataObjectPtr createRootObject(const char* uri, + const char* name); + virtual DataObjectPtr createRootObject(const SDOString& uri, + const SDOString& name); + + /** + * Creates the root data object - for use by DAS implementations + * + */ + + + virtual DataObjectPtr createRootObject(const Type& t); + + /** + * + * Gets the change summary if there is one. + */ + + virtual ChangeSummaryPtr getChangeSummary(); + + /** + * + * Gets a type from the data factory. + */ + + virtual const Type& getType(const char* uri, + const char* name); + virtual const Type& getType(const SDOString& uri, + const SDOString& name); + + private: + + DataFactoryPtr factory; + DataObjectPtr root; + +}; +}; +}; + +#endif //_DATAGRAPHIMPL_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObject.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObject.cpp new file mode 100644 index 0000000000..a9415bc5f1 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObject.cpp @@ -0,0 +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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/DataObject.h" + +namespace commonj{ +namespace sdo{ + + + DataObject::~DataObject() + { + } +}; +}; + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObject.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObject.h new file mode 100644 index 0000000000..2b0ff2ad80 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObject.h @@ -0,0 +1,594 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _DATAOBJECT_H_ +#define _DATAOBJECT_H_ +#include "commonj/sdo/export.h" + + +#include "commonj/sdo/Property.h" +#include "commonj/sdo/Type.h" +#include "commonj/sdo/DataFactory.h" +#include "commonj/sdo/Sequence.h" +#include "commonj/sdo/DataObjectList.h" +#include "commonj/sdo/PropertyList.h" + + +namespace commonj{ +namespace sdo{ + +class DataGraph; +class DataObjectList; +class DataFactory; +class ChangeSummary; + + + /** + * DataObjects are the non-primitive members of a Data graph. + *

+ * A data object is a representation of some structured data. + * it is the fundamental component in the SDO (Service Data Objects) package. + * Data objects support reflection, path-based accesss, convenience creation + * and deletion methods,and the ability to be part of a data graph. + * Each data object holds its data as a series of properties. + * Properties can be accessed by name, property index, or using the property + * meta object itself. + *

+ * A data object can also contain references to other data objects, through + * reference-type properties. + *

+ * A data object has a series of convenience accessors for its properties. + * These methods either use a path (String), a property index, + * or the property's meta object itself, to identify the property. + * Some examples of the path-based accessors are as follows: + *

+ * DataObjectPtr company = ...;
+ * company->getString("name");
+ * company->setString("name", "acme");
+ * company->getString("department.0/name")
+ * company->getString("department[1]/name")
+ * (Note .n indexes from 0, whilst [] indexes from 1.
+ * company->getDataObject("department[number=123]") returns the department where number=123
+ * company->getDataObject("..") returns the containing data object
+ * company->getDataObject("/") returns the root containing data object
+ * There are specific accessors for the primitive types and commonly used + * data types like String. + */ + +class DataObject : public RefCountingObject +{ + public: + virtual ~DataObject(); + + /** + * + * Introspection - properties and types + */ + + /** getPropertyIndex gets the unique index of a property + * + * A property of a data object has a unique index associated with it. + * This method gets a property index for this object from the property, + * or throw SDOPropertyNotFoundException if the property is not part + * of this data object. + */ + + virtual unsigned int SDO_API getPropertyIndex(const Property& p) = 0; + + + /** getInstanceProperties gets the props of the current object. + * + * Returns a read-only List of the Properties currently used in this DataObject. + * This list will contain all of the properties in getType().getProperties() + * and any properties where isSet(property) is true. + * For example, properties resulting from the use of + * open or mixed XML content are present if allowed by the Type. + * The list does not contain duplicates. + * The order of the properties in the list begins with getType().getProperties() + * and the order of the remaining properties is determined by the implementation. + * The same list will be returned unless the DataObject is updated so that + * the contents of the list change + * Returns the list of Properties currently used in this DataObject. + */ + + virtual SDO_API PropertyList getInstanceProperties() = 0; + + /** + * See if the property currently exists + */ + + virtual SDO_API bool hasProperty(const char* name) = 0; + virtual SDO_API bool hasProperty(const SDOString& name) = 0; + /** + * These are just like getType().getProperty(), but may return + * values other than the property list for open types. + */ + + virtual const Property& getProperty(unsigned int index) = 0; + + virtual const Property& getProperty(const char* prop) = 0; + virtual const Property& getProperty(const SDOString& prop) = 0; + + + /** + * return the data factory which created this object + */ + + virtual SDO_API DataFactory* getDataFactory() = 0; + + /** getContainer get the containing object + * + * Returns the containing data object + * or 0 if there is no container. + */ + + virtual SDO_API DataObjectPtr getContainer() = 0; + + /** getContainmentProperty returns the property containing this object + * + * Return the Property of the data object containing this data object + * or throw an SDOPropertyNotFoundException if there is no container. + */ + + virtual SDO_API const Property& getContainmentProperty() = 0; + + /** getType returns the data object's type. + * + * getType returns the data object's type. + * The type defines the properties available for reflective access. + */ + + virtual SDO_API const Type& getType() = 0; + + /* getTypeEnum returns an enumerator for the type + * + * Returns an enumerator for the type for easy switching on basic types. + * The enumerator is part of the Type class + */ + + virtual SDO_API const Type::Types getTypeEnum() = 0; + + + + + + /** getDataObject returns a data object by path, index or property + * + * Returns the value of a property of either this object or an object + * reachable from it, as identified by the specified path. + */ + + virtual SDO_API DataObjectPtr getDataObject(const SDOString& path) = 0; + virtual SDO_API DataObjectPtr getDataObject(const char* path) = 0; + virtual SDO_API DataObjectPtr getDataObject(unsigned int propertyIndex) = 0; + virtual SDO_API DataObjectPtr getDataObject(const Property& property) = 0; + + /** setDataObject sets a value by path, index or property + * + * Sets a property of either this object or an object reachable from it, + * as identified by the specified path, + * to the specified value. + */ + + + virtual SDO_API void setDataObject(const char* path, DataObjectPtr value) = 0; + virtual SDO_API void setDataObject(const char* path, DataObjectPtr value, bool updateSequence) = 0; + virtual SDO_API void setDataObject(const SDOString& path, DataObjectPtr value) = 0; + virtual SDO_API void setDataObject(const SDOString& path, DataObjectPtr value, bool updateSequence) = 0; + virtual SDO_API void setDataObject(unsigned int propertyIndex, DataObjectPtr value) = 0; + virtual SDO_API void setDataObject(unsigned int propertyIndex, DataObjectPtr value, bool updateSequence) = 0; + virtual SDO_API void setDataObject(const Property& property, DataObjectPtr value) = 0; + + /** getBoolean returns a boolean by path, index or property + * + * Returns the value of a property of either this object or an object + * reachable from it, as identified by the specified path. + */ + + virtual SDO_API bool getBoolean(const char* path) = 0; + virtual SDO_API bool getBoolean(const SDOString& path) = 0; + virtual SDO_API bool getBoolean(unsigned int propindex) = 0; + virtual SDO_API bool getBoolean(const Property& p) = 0; + + virtual SDO_API void setBoolean(const char* path, bool b) = 0; + virtual SDO_API void setBoolean(const SDOString& path, bool b) = 0; + virtual SDO_API void setBoolean(unsigned int propindex, bool b) = 0; + virtual SDO_API void setBoolean(const Property& p, bool b) = 0; + + /** getByte returns a char by path, index or property + * + * Returns the value of a property of either this object or an object + * reachable from it, as identified by the specified path. + */ + + virtual SDO_API char getByte(const char* path) = 0; + virtual SDO_API char getByte(const SDOString& path) = 0; + virtual SDO_API char getByte(unsigned int propindex) = 0; + virtual SDO_API char getByte(const Property& p) = 0; + + virtual SDO_API void setByte(const char* path, char c) = 0; + virtual SDO_API void setByte(const SDOString& path, char c) = 0; + virtual SDO_API void setByte(unsigned int propindex, char c) = 0; + virtual SDO_API void setByte(const Property& p, char c) = 0; + + /** getCharacter returns a wchar_t by path, index or property + * + * Returns the value of a property of either this object or an object + * reachable from it, as identified by the specified path. + */ + + virtual SDO_API wchar_t getCharacter(const char* path) = 0; + virtual SDO_API wchar_t getCharacter(const SDOString& path) = 0; + virtual SDO_API wchar_t getCharacter(unsigned int propindex) = 0; + virtual SDO_API wchar_t getCharacter(const Property& p) = 0; + + virtual SDO_API void setCharacter(const char* path, wchar_t c) = 0; + virtual SDO_API void setCharacter(const SDOString& path, wchar_t c) = 0; + virtual SDO_API void setCharacter(unsigned int propindex, wchar_t c) = 0; + virtual SDO_API void setCharacter(const Property& p, wchar_t c) = 0; + + + /** getlength returns the length of a string + * + * Specific to Bytes and Characters data objects. This returns the + * length of the buffer required to hold the contents of the object. + * len = do->getLength("name"); + * buf = new char[len]; + * reallen = do->getBytes("name",buf,len); + */ + virtual SDO_API unsigned int getLength(const char* path) = 0; + virtual SDO_API unsigned int getLength(const SDOString& path) = 0; + virtual SDO_API unsigned int getLength(unsigned int propindex) = 0; + virtual SDO_API unsigned int getLength(const Property& p) = 0; + virtual SDO_API unsigned int getLength() = 0; + + + /** getBytes returns a byte buffer + * + * A DataObject of type Bytes holds an array of bytes as its value. These + * methods transfer the contents of that buffer into an array of chars allocated + * by the users program. The return value is the number of bytes actually + * copied. + * The byte array is not necessarily null terminated. If a null terminated + * C style string is required, then getCString is an alternative. + * The third paarameter is the length of the allocated buffer, which may be more + * than the length of the byte array. If the length specified is less than the + * length of the byte array, then only a portion of the + * byte array is returned. + */ + + + virtual SDO_API unsigned int getBytes(const char* path, char* buf, unsigned int max) = 0; + virtual SDO_API unsigned int getBytes(const SDOString& path, char* buf, unsigned int max) = 0; + virtual SDO_API unsigned int getBytes(unsigned int propindex, char* buf, unsigned int max) = 0; + virtual SDO_API unsigned int getBytes(const Property& p, char* buf, unsigned int max) = 0; + + virtual SDO_API void setBytes(const char* path, const char* c, unsigned int length) = 0; + virtual SDO_API void setBytes(const SDOString& path, const char* c, unsigned int length) = 0; + virtual SDO_API void setBytes(unsigned int propindex, const char* c, unsigned int length) = 0; + virtual SDO_API void setBytes(const Property& p, const char* c, unsigned int length) = 0; + + /** getString returns a wide char buffer + * + * A DataObject of type String holds an array of wide characters as its value. These + * methods transfer the contents of that buffer into an array of wchar_t allocated + * by the users program. The return value is the number of wchar_t actually + * copied. + * The array is not necessarily null terminated. + * The third paarameter is the length of the allocated buffer, which may be more + * than the length of the array. If the length specified is less than the + * length of the array, then only a portion of the array is returned. + */ + + virtual SDO_API unsigned int getString(const SDOString& path , wchar_t* c, unsigned int max) = 0; + virtual SDO_API unsigned int getString(const char* path , wchar_t* c, unsigned int max) = 0; + virtual SDO_API unsigned int getString(unsigned int propindex, wchar_t* c, unsigned int max) = 0; + virtual SDO_API unsigned int getString(const Property& p, wchar_t* c, unsigned int max) = 0; + + virtual SDO_API void setString(const char* path, const wchar_t* c, unsigned int length) = 0; + virtual SDO_API void setString(const SDOString& path, const wchar_t* c, unsigned int length) = 0; + virtual SDO_API void setString(unsigned int propindex, const wchar_t* c, unsigned int length) = 0; + virtual SDO_API void setString(const Property& p, const wchar_t* c, unsigned int length) = 0; + + /** getDate returns an SDODate by path, index or property + * + * Returns the value of a property of either this object or an object + * reachable from it, as identified by the specified path. + */ + virtual SDO_API const SDODate getDate(const char* path) = 0; + virtual SDO_API const SDODate getDate(const SDOString& path) = 0; + virtual SDO_API const SDODate getDate(unsigned int propindex) = 0; + virtual SDO_API const SDODate getDate(const Property& p) = 0; + + virtual SDO_API void setDate(const char* path, const SDODate d) = 0; + virtual SDO_API void setDate(const SDOString& path, const SDODate d) = 0; + virtual SDO_API void setDate(unsigned int propindex, const SDODate d) = 0; + virtual SDO_API void setDate(const Property& p, const SDODate d) = 0; + + /** getDouble returns a long double by path, index or property + * + * Returns the value of a property of either this object or an object + * reachable from it, as identified by the specified path. + */ + + virtual SDO_API long double getDouble(const SDOString& path) = 0; + virtual SDO_API long double getDouble(const char* path) = 0; + virtual SDO_API long double getDouble(unsigned int propindex) = 0; + virtual SDO_API long double getDouble(const Property& p) = 0; + + virtual SDO_API void setDouble(const SDOString& path, long double d) = 0; + virtual SDO_API void setDouble(const char* path, long double d) = 0; + virtual SDO_API void setDouble(unsigned int propindex, long double d) = 0; + virtual SDO_API void setDouble(const Property& p, long double d) = 0; + + /** getFloat returns a float by path, index or property + * + * Returns the value of a property of either this object or an object + * reachable from it, as identified by the specified path. + */ + + virtual SDO_API float getFloat(const SDOString& path) = 0; + virtual SDO_API float getFloat(const char* path) = 0; + virtual SDO_API float getFloat(unsigned int propindex) = 0; + virtual SDO_API float getFloat(const Property& p) = 0; + + virtual SDO_API void setFloat(const SDOString& path, float f) = 0; + virtual SDO_API void setFloat(const char* path, float f) = 0; + virtual SDO_API void setFloat(unsigned int propindex, float f) = 0; + virtual SDO_API void setFloat(const Property& p, float f) = 0; + + /** getInteger returns a long by path, index or property + * + * Returns the value of a property of either this object or an object + * reachable from it, as identified by the specified path. + */ + + virtual SDO_API long getInteger(const SDOString& path) = 0; + virtual SDO_API long getInteger(const char* path) = 0; + virtual SDO_API long getInteger(unsigned int propindex) = 0; + virtual SDO_API long getInteger(const Property& p) = 0; + + virtual SDO_API void setInteger(const SDOString& path, long i) = 0; + virtual SDO_API void setInteger(const char* path, long i) = 0; + virtual SDO_API void setInteger(unsigned int propindex, long i) = 0; + virtual SDO_API void setInteger(const Property& p, long i) = 0; + + /** getLong returns a int64_t by path, index or property + * + * Returns the value of a property of either this object or an object + * reachable from it, as identified by the specified path. + */ + + virtual SDO_API int64_t getLong(const SDOString& path) = 0; + virtual SDO_API int64_t getLong(const char* path) = 0; + virtual SDO_API int64_t getLong(unsigned int propindex) = 0; + virtual SDO_API int64_t getLong(const Property& p) = 0; + + virtual SDO_API void setLong(const SDOString& path, int64_t l) = 0; + virtual SDO_API void setLong(const char* path, int64_t l) = 0; + virtual SDO_API void setLong(unsigned int propindex, int64_t l) = 0; + virtual SDO_API void setLong(const Property& p, int64_t l) = 0; + + /** getShort returns a short by path, index or property + * + * Returns the value of a property of either this object or an object + * reachable from it, as identified by the specified path. + */ + + virtual SDO_API short getShort(const SDOString& path) = 0; + virtual SDO_API short getShort(const char* path) = 0; + virtual SDO_API short getShort(unsigned int propindex) = 0; + virtual SDO_API short getShort(const Property& p) = 0; + + virtual SDO_API void setShort(const SDOString& path, short s) = 0; + virtual SDO_API void setShort(const char* path, short s) = 0; + virtual SDO_API void setShort(unsigned int propindex, short s) = 0; + virtual SDO_API void setShort(const Property& p, short s) = 0; + + + /** getCString returns a null terminated string by path, index or property + * + * Returns the value of a property of either this object or an object + * reachable from it, as identified by the specified path. + */ + + virtual SDO_API const char* getCString(const char* path) = 0; + virtual SDO_API const char* getCString(const SDOString& path) = 0; + virtual SDO_API const char* getCString(unsigned int propertyIndex) = 0; + virtual SDO_API const char* getCString(const Property& prop) = 0; + + virtual SDO_API void setCString(const char* path, const char* value) = 0; + virtual SDO_API void setCString(unsigned int propertyIndex, const char* value) = 0; + virtual SDO_API void setCString (const Property& prop, const char* value) = 0; + + virtual SDO_API void setCString(const SDOString& path, const SDOString& value) = 0; + virtual SDO_API void setCString(unsigned int propertyIndex, const SDOString& value) = 0; + virtual SDO_API void setCString (const Property& prop, const SDOString& value) = 0; + + + /** setNull sets a data object value to null. + * + * A DataObjectType or DataType value may be set or unset. If it is set, then + * it may have a value, or it may be set to null. A distinction is drawn between + * being unset, having the default value, being set and being null. + * When the value of an integer (for example) is returned as zero, it could have + * been set to zero, or it could be null. Use isNull() to verify. + */ + + virtual SDO_API void setNull(const char* path) = 0; + virtual SDO_API void setNull(const SDOString& path) = 0; + virtual SDO_API void setNull(unsigned int propertyIndex) = 0; + virtual SDO_API void setNull(const Property& prop) = 0; + + virtual SDO_API bool isNull(const char* path) = 0; + virtual SDO_API bool isNull(const SDOString& path) = 0; + virtual SDO_API bool isNull(unsigned int propertyIndex) = 0; + virtual SDO_API bool isNull(const Property& prop) = 0; + + /** isSet test whether the value has been set + * + * Returns whether a property of either this object or an object reachable + * from it, as identified by the specified path, + * is considered to be set. + */ + + virtual SDO_API bool isSet(const char* path) = 0; + virtual SDO_API bool isSet(const SDOString& path) = 0; + virtual SDO_API bool isSet(unsigned int propertyIndex) = 0; + virtual SDO_API bool isSet(const Property& property) = 0; + + + /** isValid shows true if the value is set or defaulted. + * + * A property can be set, null, or have a default value - all + * of these are valid. It can also be unset, and have no default + * in which case this returns false. + */ + + virtual SDO_API bool isValid(const char* path) = 0; + virtual SDO_API bool isValid(const SDOString& path) = 0; + virtual SDO_API bool isValid(unsigned int propertyIndex) = 0; + virtual SDO_API bool isValid(const Property& property ) =0; + + /** unset unsets a value previously set. + * + * unsets a property of either this object or an object reachable + * from it, as identified by the specified path. + */ + + virtual SDO_API void unset(const char* path) = 0; + virtual SDO_API void unset(const SDOString& path) = 0; + virtual SDO_API void unset(unsigned int propertyIndex) = 0; + virtual SDO_API void unset(const Property& property) = 0; + + /** setUserData sets a reserved field in the data object. + * + * Each data object has precisely one 32 bit slot available to + * be used by applications. This is not part of the data, its + * just a place to store anything for later retrieval. + */ + + virtual SDO_API void setUserData(const char* path,void* value) = 0; + virtual SDO_API void setUserData(const SDOString& path, void* value) = 0; + virtual SDO_API void setUserData(unsigned int propertyIndex, void* value) = 0; + virtual SDO_API void setUserData(const Property& property, void* value) = 0; + virtual SDO_API void setUserData(void* value) = 0; + virtual SDO_API void* getUserData(const char* path) = 0; + virtual SDO_API void* getUserData(const SDOString& path) = 0; + virtual SDO_API void* getUserData(unsigned int propertyIndex) = 0; + virtual SDO_API void* getUserData(const Property& property) = 0; + virtual SDO_API void* getUserData() = 0; + + + /** getSequence returns the sequence for a data object + * + * Returns the value of a Sequence property identified by + * the specified path. See Sequence. + */ + + virtual SDO_API SequencePtr getSequence() = 0; + virtual SDO_API SequencePtr getSequence(const char* path) = 0; + virtual SDO_API SequencePtr getSequence(const SDOString& path) = 0; + virtual SDO_API SequencePtr getSequence(unsigned int propertyIndex) = 0; + virtual SDO_API SequencePtr getSequence(const Property& property) = 0; + + + + /** createDataObject creates a data object value + * + * Returns a new data object contained by this object using the + * specified property,which must be a containment property. + * The type of the created object is the declared type + * of the specified property. + * If the property is many valued, this method adds an element to the + * list, otherwise it sets the value, removing any old value. + */ + + + virtual SDO_API DataObjectPtr createDataObject(const char* propertyName) = 0; + virtual SDO_API DataObjectPtr createDataObject(const SDOString& propertyName) = 0; + virtual SDO_API DataObjectPtr createDataObject(unsigned int propertyIndex) = 0; + virtual SDO_API DataObjectPtr createDataObject(const Property& property) = 0; + + + + /** detach detaches an object from the graph + * + * This method removes the current data object from the graph, but does + * not destroy it. The DataObject can be re-attached to the graph later. + */ + + virtual SDO_API void detach() = 0; + + /** clear unsets all the properties + * + * This method unsets all the properties, and deletes all the data object + * propertiy values from this data object. + */ + + virtual SDO_API void clear() = 0; + + + /** getList gets the value of a many-valued property + * + * Many valued properties are returned as lists of DataObjects. + * These lists may contain primitives or data objects, but they behave + * like data objects. + * Getting a many valued integer consists of getting the list, then + * using the DataObjectList API to getInteger() for each list element. + */ + + virtual SDO_API DataObjectList& getList(const char* path) = 0; + virtual SDO_API DataObjectList& getList(const SDOString& path) = 0; + virtual SDO_API DataObjectList& getList(unsigned int propIndex) = 0; + virtual SDO_API DataObjectList& getList(const Property& p) = 0; + virtual DataObjectList& getList() = 0; + + + /** getChangeSummary get the applicable change summary + * + * This method gets the applicable change summary for a data object. + * The summary is not necessarily attached to the data object, it may be + * the summary for a parent data object. No object with a summary attached + * may be a child of another object with a summary attached. + * See the ChangeSummary API for details of using the change sumamry. + */ + + virtual SDO_SPI ChangeSummaryPtr getChangeSummary() = 0; + virtual SDO_SPI ChangeSummaryPtr getChangeSummary(const char* path) = 0; + virtual SDO_SPI ChangeSummaryPtr getChangeSummary(const SDOString& path) = 0; + virtual SDO_SPI ChangeSummaryPtr getChangeSummary(unsigned int propIndex) = 0; + virtual SDO_SPI ChangeSummaryPtr getChangeSummary(const Property& prop) = 0; + + /** objectToXPath - utility to find the xpath from the root. + * + * objectToXPath returns a string which could be used to locate this data + * object from the root data object of the graph. + */ + + virtual SDO_SPI const char* objectToXPath() = 0; + + +}; +}; +}; + +#endif //_DATAOBJECT_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectImpl.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectImpl.cpp new file mode 100644 index 0000000000..d05f747ec4 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectImpl.cpp @@ -0,0 +1,4910 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/disable_warn.h" +#include "commonj/sdo/DataObjectImpl.h" + +#include "commonj/sdo/SDORuntimeException.h" + +#include "commonj/sdo/Property.h" +#include "commonj/sdo/Type.h" +#include "commonj/sdo/TypeList.h" +#include "commonj/sdo/Sequence.h" +#include "commonj/sdo/SequenceImpl.h" + +#include "commonj/sdo/PropertyList.h" + +#include "commonj/sdo/Logging.h" + +#include "commonj/sdo/TypeImpl.h" + +#include "commonj/sdo/ChangeSummaryImpl.h" +#include "commonj/sdo/DataFactoryImpl.h" +#include "commonj/sdo/SDOUtils.h" + +#include +#include +#include +using std::string; + + + + +namespace commonj{ +namespace sdo { + + /** + * RDO is an internal class holding a property value + */ + + rdo::rdo(unsigned int infirst, DataObjectImpl* insecond) + : first(infirst), second(insecond) + { + } + + rdo::rdo() + { + first = 0; + second = 0; + } + + rdo::rdo (const rdo& inrdo) + { + first = inrdo.first; + second = inrdo.second; + } + + rdo::~rdo() + { + } + +#define ASSERT_SETTABLE(property,primval) ASSERT_WRITABLE(*property, set##primval) + + /** DataObject + * DataObjects are the non-primitive members of a Data graph. + * + * A data object is a representation of some structured data. + * it is the fundamental component in the SDO (Service Data Objects) package. + * Data objects support reflection, path-based accesss, convenience creation + * and deletion methods,and the ability to be part of a data graph. + * Each data object holds its data as a series of properties. + * Properties can be accessed by name, property index, or using the property + * meta object itself. + * A data object can also contain references to other data objects, through + * reference-type properties. + * A data object has a series of convenience accessors for its properties. + * These methods either use a path (String), a property index, + * or the property's meta object itself, to identify the property. + * Some examples of the path-based accessors are as follows: + * DataObjectPtr company = ...; + * company->getString("name"); + * company->setString("name", "acme"); + * company->getString("department.0/name") + * .n indexes from 0. + * company->getString("department[1]/name") [] indexes from 1. + * company->getDataObject("department[number=123]") returns the department where number=123 + * company->getDataObject("..") returns the containing data object + * company->getDataObject("/") returns the root containing data object + * There are specific accessors for the primitive types and commonly used + * data types like String. + */ + + unsigned int DataObjectImpl::getBytes(const char* path, char* valptr , unsigned int max) + { + const SDOString pathObject(path); + unsigned int result = getBytes(pathObject, valptr, max); + return result; + } + + unsigned int DataObjectImpl::getString(const char* path, wchar_t* buf, unsigned int max) + { + return getString(SDOString(path), buf, max); + } + + // Convenience methods for string/bytes length + + unsigned int DataObjectImpl::getLength(const Property& p) + { + switch (p.getType().getTypeEnum()) { + case Type::BooleanType: + return BOOL_SIZE; + case Type::CharacterType: + case Type::ByteType: + return BYTE_SIZE; + case Type::ShortType: + case Type::IntegerType: + case Type::LongType: + return MAX_LONG_SIZE; + case Type::FloatType: + return MAX_FLOAT_SIZE; + case Type::DoubleType: + return MAX_DOUBLE_SIZE; + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::UriType: + case Type::StringType: + return getString(p,0,0); + case Type::BytesType: + return getBytes(p,0,0); + default: + return 0; + } + } + + unsigned int DataObjectImpl::getLength() + { + switch (getType().getTypeEnum()) { + case Type::BooleanType: + return BOOL_SIZE; + case Type::CharacterType: + case Type::ByteType: + return BYTE_SIZE; + case Type::ShortType: + case Type::IntegerType: + case Type::LongType: + return MAX_LONG_SIZE; + case Type::FloatType: + return MAX_FLOAT_SIZE; + case Type::DoubleType: + return MAX_DOUBLE_SIZE; + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::UriType: + case Type::StringType: + return getString(0,0); + case Type::BytesType: + return getBytes(0,0); + default: + return 0; + } + } + + unsigned int DataObjectImpl::getLength(const char* path) + { + return getLength(SDOString(path)); + } + + unsigned int DataObjectImpl::getLength(const SDOString& path) + { + DataObjectImpl* d; + SDOString spath; + DataObjectImpl::stripPath(path, spath); + SDOString prop = findPropertyContainer(spath, &d); + if (d != 0) { + if (prop.length() == 0) { + return 0; + } + else + { + const Property& p = d->getProperty(prop); + return getLength(p); + } + } + else + { + if (prop.length()) + { + const Property& p = getProperty(prop); + return getLength(p); + } + else + { + return 0; + } + } + } + + unsigned int DataObjectImpl::getLength(unsigned int index) + { + return getLength(getProperty(index)); + } + + // +++ + // Provide implementations for the getXXX(const char* path) methods. + // These are implemented by delegating the call + // to the corresponding getXXX(const SDOString& path) method. + + // getPrimitiveFromPath(Boolean,bool,false); + bool DataObjectImpl::getBoolean(const char* path) + { + return getBoolean(SDOString(path)); + } + + // getPrimitiveFromPath(Short,short,0); + short DataObjectImpl::getShort(const char* path) + { + return getShort(SDOString(path)); + } + + // getPrimitiveFromPath(Byte,char,0); + char DataObjectImpl::getByte(const char* path) + { + return getByte(SDOString(path)); + } + + // getPrimitiveFromPath(Character,wchar_t,0); + wchar_t DataObjectImpl::getCharacter(const char* path) + { + return getCharacter(SDOString(path)); + } + + // getPrimitiveFromPath(Date,const SDODate,0); + const SDODate DataObjectImpl::getDate(const char* path) + { + return getDate(SDOString(path)); + } + + // getPrimitiveFromPath(Double,long double,0.0); + long double DataObjectImpl::getDouble(const char* path) + { + return getDouble(SDOString(path)); + } + + // getPrimitiveFromPath(Float,float,0.0); + float DataObjectImpl::getFloat(const char* path) + { + return getFloat(SDOString(path)); + } + + // getPrimitiveFromPath(Integer,long,0); + long DataObjectImpl::getInteger(const char* path) + { + return getInteger(SDOString(path)); + } + + // getPrimitiveFromPath(Long,int64_t,0L); + int64_t DataObjectImpl::getLong(const char* path) + { + return getLong(SDOString(path)); + } + + // End of implementations for the getXXX(const char* path) methods. + // --- + + + // +++ + // Provide implementations for the setXXX(const char* path, XXX) methods. + // These are implemented by delegating the call + // to the corresponding setXXX(const SDOString& path, XXX) method. + + void DataObjectImpl::setBoolean(const char* path, bool b) + { + setBoolean(SDOString(path), b); + } + + void DataObjectImpl::setShort(const char* path, short s) + { + setShort(SDOString(path), s); + } + + void DataObjectImpl::setByte(const char* path, char c) + { + setByte(SDOString(path), c); + } + + void DataObjectImpl::setCharacter(const char* path, wchar_t c) + { + setCharacter(SDOString(path), c); + } + + void DataObjectImpl::setDate(const char* path, const SDODate d) + { + setDate(SDOString(path), d); + } + + void DataObjectImpl::setDouble(const char* path, long double d) + { + setDouble(SDOString(path), d); + } + + void DataObjectImpl::setFloat(const char* path, float f) + { + setFloat(SDOString(path), f); + } + + void DataObjectImpl::setInteger(const char* path, long i) + { + setInteger(SDOString(path), i); + } + + // setPrimitiveFromPath(Long,int64_t, int64_t); + // setPrimitiveFromPath(Integer,long, long); + // Depends on wordsize, see SDOString& variant below. + void DataObjectImpl::setLong(const char* path, /*long long*/ int64_t l) + { + setLong(SDOString(path), l); + } + + // End of implementations for the setXXX(const char* path, XXX) methods. + // --- + + + // open type support + + const PropertyImpl* DataObjectImpl::defineProperty(const SDOString& propname, + const Type& t) + { + openProperties.insert(openProperties.end(), + PropertyImpl(getType(), + propname, + (TypeImpl&)t, + false, + false, + true)); + DataFactory* df = factory; + ((DataFactoryImpl*)df)->addOpenProperty(PropertyImpl(getType(), + propname, + (TypeImpl&)t, + false, + false, + true)); + + return getPropertyImpl(propname); + } + + void DataObjectImpl::undefineProperty(unsigned int index) + { + if (index < openBase) return; + unsigned int point = index - openBase; + if (point >= openProperties.size()) return; + + // downgrade all the property settings above this one + + PropertyValueMap::iterator pit; + for (pit = PropertyValues.begin(); pit != PropertyValues.end();++pit) + { + if ((*pit).first > index) + { + if (getPropertyImpl((*pit).first)->isMany()) + { + DataObjectListImpl* dl = (*pit).second->getListImpl(); + if (dl != 0) dl->decrementPindex(); + } + (*pit).first-=1; + } + } + + // then remove this property from the list + + std::list::iterator it = + openProperties.begin(); + for (unsigned int i=0;iremoveOpenProperty((*it).getName()); + + openProperties.erase(it); + + return; + } + + const PropertyImpl* DataObjectImpl::defineList(const char* propname) + { + const Type& t = factory->getType(Type::SDOTypeNamespaceURI, "OpenDataObject"); + openProperties.insert( + openProperties.end(), PropertyImpl(getType(),propname, + (TypeImpl&)t, true, false, true)); + + DataFactory* df = factory; + ((DataFactoryImpl*)df)->addOpenProperty(PropertyImpl(getType(),propname, + (TypeImpl&)t, true, false, true)); + + return getPropertyImpl(propname); + } + + const PropertyImpl* DataObjectImpl::defineSDOValue(const SDOString& propname, + const SDOValue& sval) + { + const Type& t = factory->getType(Type::SDOTypeNamespaceURI, + sval.convertTypeEnumToString()); + return defineProperty(propname, t); + } + + const PropertyImpl* DataObjectImpl::defineBoolean(const SDOString& propname) + { + const Type& t = factory->getType(Type::SDOTypeNamespaceURI, "Boolean"); + return defineProperty(propname,t); + } + + const PropertyImpl* DataObjectImpl::defineByte(const SDOString& propname) + { + const Type& t = factory->getType(Type::SDOTypeNamespaceURI, "Byte"); + return defineProperty(propname,t); + } + + const PropertyImpl* DataObjectImpl::defineCharacter(const SDOString& propname) + { + const Type& t = factory->getType(Type::SDOTypeNamespaceURI, "Character"); + return defineProperty(propname,t); + } + + const PropertyImpl* DataObjectImpl::defineString(const SDOString& propname) + { + const Type& t = factory->getType(Type::SDOTypeNamespaceURI, "String"); + return defineProperty(propname,t); + } + + const PropertyImpl* DataObjectImpl::defineBytes(const SDOString& propname) + { + const Type& t = factory->getType(Type::SDOTypeNamespaceURI, "Bytes"); + return defineProperty(propname,t); + } + + const PropertyImpl* DataObjectImpl::defineShort(const SDOString& propname) + { + const Type& t = factory->getType(Type::SDOTypeNamespaceURI, "Short"); + return defineProperty(propname,t); + } + + const PropertyImpl* DataObjectImpl::defineInteger(const SDOString& propname) + { + const Type& t = factory->getType(Type::SDOTypeNamespaceURI, "Integer"); + return defineProperty(propname,t); + } + + const PropertyImpl* DataObjectImpl::defineLong(const SDOString& propname) + { + const Type& t = factory->getType(Type::SDOTypeNamespaceURI, "Long"); + return defineProperty(propname,t); + } + + const PropertyImpl* DataObjectImpl::defineFloat(const SDOString& propname) + { + const Type& t = factory->getType(Type::SDOTypeNamespaceURI, "Float"); + return defineProperty(propname,t); + } + + const PropertyImpl* DataObjectImpl::defineDouble(const SDOString& propname) + { + const Type& t = factory->getType(Type::SDOTypeNamespaceURI, "Double"); + return defineProperty(propname,t); + } + + const PropertyImpl* DataObjectImpl::defineDate(const SDOString& propname) + { + const Type& t = factory->getType(Type::SDOTypeNamespaceURI, "Date"); + return defineProperty(propname,t); + } + + const PropertyImpl* DataObjectImpl::defineCString(const SDOString& propname) + { + const Type& t = factory->getType(Type::SDOTypeNamespaceURI, "String"); + return defineProperty(propname,t); + } + + const PropertyImpl* DataObjectImpl::defineDataObject(const SDOString& propname, + const Type& t) + { + return defineProperty(propname,t); + } + + const PropertyImpl* DataObjectImpl::defineDataObject(const char* propname, + const char* typeURI, const char* typeName) + { + const Type& t = factory->getType(typeURI, typeName); + return defineProperty(propname,t); + } + + void DataObjectImpl::setCString (unsigned int propertyIndex, const char* value) + { + setCString(propertyIndex, SDOString(value)); + } + + const char* DataObjectImpl::getCString (const char* path) + { + return getCString(SDOString(path)); + } + + void DataObjectImpl::setCString(const char* path, const char* value) + { + setCString(SDOString(path), SDOString(value)); + } + + void DataObjectImpl::setCString(const Property& property, const char* value) + { + setCString(property, SDOString(value)); + } + + // null support + + bool DataObjectImpl::isNull(const unsigned int propertyIndex) + { + validateIndex(propertyIndex); + if ((getProperty(propertyIndex).isMany())) + { + return false; + } + + PropertyValueMap::iterator i; + for (i = PropertyValues.begin(); i != PropertyValues.end();++i) + { + if ((*i).first == propertyIndex) + { + return (*i).second->isNull(); + } + } + return false; + } + + bool DataObjectImpl::isNull(const Property& property) + { + return isNull(getPropertyIndex(property)); + } + + bool DataObjectImpl::isNull(const char* path) + { + return isNull(SDOString(path)); + } + + bool DataObjectImpl::isNull(const SDOString& path) + { + DataObjectImpl *d = 0; + SDOString spath; + SDOString prop; + // char* spath = 0; + // char* prop = 0; + try { + DataObjectImpl::stripPath(path, spath); + prop = findPropertyContainer(spath, &d); + if (d != 0) { + if (prop.length() == 0) { + return d->isNull(); + } + else { + const Property& p = d->getProperty(prop); + return d->isNull(p); + } + } + return false; + } + catch (SDORuntimeException e) { + SDO_RETHROW_EXCEPTION("isNull",e); + } + } + + void DataObjectImpl::setNull(const unsigned int propertyIndex) + { + validateIndex(propertyIndex); + const Property& property = getProperty(propertyIndex); + if (property.isMany()) + { + string msg("Setting a list to null is not supported:"); + msg += property.getName(); + SDO_THROW_EXCEPTION("setNull", + SDOUnsupportedOperationException, + msg.c_str()); + } + + ASSERT_WRITABLE(property, setNull); + + PropertyValueMap::iterator i; + for (i = PropertyValues.begin(); i != PropertyValues.end(); ++i) + { + if ((*i).first == propertyIndex) + { + logChange(propertyIndex); + (*i).second->setNull(); + return; + } + } + // The property was not set yet... + logChange(propertyIndex); + DataFactory* df = getDataFactory(); + DataObjectImpl* b = + new DataObjectImpl(df, getProperty(propertyIndex).getType()); + b->setContainer(this); + PropertyValues.push_back(rdo(propertyIndex,b)); + b->setNull(); + } + + void DataObjectImpl::setNull(const Property& property) + { + setNull(getPropertyIndexInternal(property)); + } + + void DataObjectImpl::setNull(const char* path) + { + setNull(SDOString(path)); + } + + void DataObjectImpl::setNull(const SDOString& path) + { + DataObjectImpl *d = 0; + SDOString spath; + SDOString prop; + size_t pc; + + try { + DataObjectImpl::stripPath(path, spath); + prop = findPropertyContainer(spath, &d); + if (d != 0) { + if (prop.length() == 0) { + try { + DataObjectImpl* cont = d->getContainerImpl(); + if (cont != 0) + { + pc = path.rfind('/'); // Find the last '/' in the path + if (pc != string::npos) + pc++; // pc is the index of the first character following the / + } + const Property& pcont = cont->getProperty(path.substr(pc)); + ASSERT_WRITABLE(pcont, setNull) + cont->logChange(pcont); + } + catch (SDORuntimeException&) + { + } + d->setNull(); + } + else { + const PropertyImpl* p = d->getPropertyImpl(prop); + if (p == 0) + { + if(d->getType().isOpenType()) + { + string msg("Cannot set unassigned open property to null:"); + msg += prop; + SDO_THROW_EXCEPTION("setNull", SDOUnsupportedOperationException, + msg.c_str()); + } + else + { + string msg("Property Not Found:"); + msg += prop; + SDO_THROW_EXCEPTION("setNull", SDOPropertyNotFoundException, + msg.c_str()); + } + } + ASSERT_SETTABLE(p, Null) + d->setNull((Property&)*p); + return; + } + } + return; + } + catch (SDORuntimeException e) { + SDO_RETHROW_EXCEPTION("setNull",e); + } + + } + + // getters and setters for a List data object + + DataObjectList& DataObjectImpl::getList(const char* path) + { + // Can path really be a null pointer? + if (path == 0) + { + return(getList(SDOString())); + } + else + { + return(getList(SDOString(path))); + } + } + + DataObjectList& DataObjectImpl::getList(const SDOString& path) + { + DataObjectImpl *d; + SDOString spath; + + DataObjectImpl::stripPath(path, spath); + SDOString prop = findPropertyContainer(spath, &d); + + if (d != 0) { + if (prop.length() == 0) { + return d->getList(); + } + else { + const PropertyImpl* p = d->getPropertyImpl(prop); + if (p == 0 && d->getType().isOpenType()) + { + p = d->defineList(prop.c_str()); + } + if (p != 0) + { + return d->getList((Property&)*p); + } + } + } + + string msg("Invalid path:"); + msg += path; + SDO_THROW_EXCEPTION("getList",SDOPathNotFoundException, msg.c_str()); + } + + + DataObjectList& DataObjectImpl::getList(unsigned int propIndex) + { + return getList(getProperty(propIndex)); + } + + DataObjectList& DataObjectImpl::getList(const Property& p) + { + if (!p.isMany()) + { + PropertyImpl* pi = (PropertyImpl*)&p; + if (!pi->getTypeImpl()->isFromList()) + { + string msg("Get list not available on single valued property:"); + msg += p.getName(); + SDO_THROW_EXCEPTION("getList", SDOUnsupportedOperationException, + msg.c_str()); + } + } + + int propIndex = getPropertyIndexInternal(p); + DataObjectImpl* d = getDataObjectImpl(propIndex); + if (d == 0) { + // There is no list yet, so we need to create an + // empty data object to hold the list + DataFactory* df = getDataFactory(); + d = new DataObjectImpl(df, df->getType(Type::SDOTypeNamespaceURI,"DataObject")); + PropertyValues.push_back(rdo(propIndex, d)); + d->setContainer(this); + + DataObjectListImpl* list = new DataObjectListImpl(df,this, + propIndex,p.getType().getURI(),p.getType().getName()); + d->setList(list); + + } + return d->getList(); + } + + + + DataObjectList& DataObjectImpl::getList() + { + if (getTypeImpl().isFromList()) + { + return getList("values"); + } + return *listValue; + } + + DataObjectListImpl* DataObjectImpl::getListImpl() + { + if (getTypeImpl().isFromList()) + { + DataObjectList& dl = getList("values"); + return (DataObjectListImpl*)&dl; + } + return listValue; + } + + + + ///////////////////////////////////////////////////////////////////////////// + // Utilities + ///////////////////////////////////////////////////////////////////////////// + + + // get an index, or throw if the prop is not part of this DO + + unsigned int DataObjectImpl::getPropertyIndex(const Property& p) + { + const std::list props = getType().getPropertyListReference(); + + unsigned int i = 0; + for (std::list::const_iterator j = props.begin(); + j != props.end(); + j++, i++) + { + if (!strcmp((*j)->getName(), p.getName())) + { + return i; + } + } + if (getType().isOpenType()) + { + std::list::iterator j; + int count = 0; + for (j = openProperties.begin() ; + j != openProperties.end() ; ++j) + { + if (!strcmp((*j).getName(),p.getName())) + { + return count+openBase; + } + count++; + } + } + string msg("Cannot find property:"); + msg += p.getName(); + SDO_THROW_EXCEPTION("getPropertyIndex", SDOPropertyNotFoundException, + msg.c_str()); + } + + /** + * This method is used internally to find the index of a + * property. If differs from the public getPropertyIndex method + * in that if the type of the containing object is open a new + * index is created. In the public version and error is thrown + */ + unsigned int DataObjectImpl::getPropertyIndexInternal(const Property& p) + { + unsigned int index; + + try + { + index = getPropertyIndex(p); + } + catch ( SDOPropertyNotFoundException e ) + { + // this could mean that this data object has an open + // type. getPropertyIndex fails in this case because it + // tries to access the index of the property + // and it doesn't exist because it hasn't been created yet. + // This new method is used where properties are being set + // based on existing property objects. This is likely to + // occur when a data object is being copied. In this case + // we want properties that are open to be copied also + // so we need to create the property and provide the index + if ( this->getType().isOpenType() ) + { + const Property *prop = NULL; + + // need to treat many valued properties specially + // because the property is a list rather than + // a single value + if ( p.isMany() ) + { + prop = defineList(p.getName()); + } + else + { + prop = defineProperty(p.getName(), p.getType()); + } + + index = getPropertyIndex(p); + } + else + { + throw e; + } + } + + return index; + } + + + const Property& DataObjectImpl::getProperty(unsigned int index) + { + PropertyImpl* pi = getPropertyImpl(index); + if (pi == 0) + { + string msg("Index out of range"); + SDO_THROW_EXCEPTION("getProperty", SDOIndexOutOfRangeException, + msg.c_str()); + } + return (Property&)*pi; + } + + /** + * See if the property currently exists + */ + + bool DataObjectImpl::hasProperty(const char* name) + { + return hasProperty(SDOString(name)); + } + + bool DataObjectImpl::hasProperty(const SDOString& name) + { + PropertyImpl* pi = getPropertyImpl(name); + if (pi == 0) return false; + return true; + } + + + PropertyImpl* DataObjectImpl::getPropertyImpl(unsigned int index) + { + // Cannot use getPropertyListReference because we will return a + // writeable PropertyImpl. + PropertyList props = getType().getProperties(); + if (index < props.size()) + { + return (PropertyImpl*)&props[index]; + } + + if (getType().isOpenType()) + { + if (index >= openBase && index - openBase < openProperties.size()) + { + std::list::iterator j; + unsigned int val = 0; + j = openProperties.begin(); + while (val < index-openBase && j != openProperties.end()) + { + val++; + j++; + } + if (j != openProperties.end()) return &(*j); + } + } + return 0; + } + + + ////////////////////////////////////////////////////////////////////// + // TODO - this is rubbish, but gets us by until XPATH is done + // trip the path down to characters which I am going to + // recognise later (a-z, A-Z _ [ ] .) + ////////////////////////////////////////////////////////////////////// + + const char* DataObjectImpl::templateString = + " /abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890=[]._#-"; + + char* DataObjectImpl::stripPath(const char* path) + { + int pos = 0; + char* s = 0; + if (path == 0) return s; + + s = new char[strlen(path)+1]; + + for (unsigned int i=0;i < strlen(path); i++) + { + if (strchr(templateString,path[i]) != 0) { + s[pos++] = path[i]; + } + } + s[pos++] = 0; + return s; + } + + void DataObjectImpl::stripPath(const SDOString& path, SDOString& result) + { + result.erase(); + result.reserve(path.length()); + + size_t start = 0; + size_t position = path.find_first_not_of(templateString); + + while (position != string::npos) + { + result.append(path, start, (position - start)); + start = ++position; + position = path.find_first_not_of(templateString, position); + } + + result.append(path, start, string::npos); + + return; + } + + ////////////////////////////////////////////////////////////////////// + // Find a data object or return 0 if not found + ////////////////////////////////////////////////////////////////////// + DataObjectImpl* DataObjectImpl::findDataObject(const SDOString& token, long* index) + { + // name , name[int], name[x=y] name.int + size_t beginbrace = token.find('['); + size_t dot = token.find('.'); + size_t breaker = 0; + + if (dot != string::npos) + { + if (beginbrace != string::npos) + { + breaker = (beginbrace < dot) ? beginbrace : dot; + } + else + { + breaker = dot; + } + } + else + { + breaker = beginbrace; + } + + if (breaker == string::npos) + { + // its this object, and a property thereof + *index = -1; + const Property& p = getProperty(token); + return getDataObjectImpl(p); + } + + // We did find a breaker character. + const Property& p = getProperty(SDOString(token, 0, breaker)); + + breaker++; + + size_t endbrace = token.find(']'); + SDOString breakerStr = token.substr(breaker, (endbrace - breaker)); + // Search for the first occurence of an = sign starting at the previously + // identified "breaker" character and ending at the endbrace just found. We + // need to make a new SDOString to contain that substring. + + size_t eq = breakerStr.find('='); + + if (eq == string::npos) + { + // There is no "=" sign + unsigned int val = atoi(breakerStr.c_str()); + DataObjectList& list = getList(p); + + // The spec says that depts[1] is the first element, as is depts.0 + if (beginbrace != string::npos) val--; + + if (val >=0 && val < list.size()) + { + DataObject* dob = list[val]; + *index = val; + return (DataObjectImpl*)dob; + } + *index = -1; + return 0; + } + + // We did find an "=" sign. + SDOString PropertyName = breakerStr.substr(0, eq); + // breaker is now propname + eq++; + SDOString PropertyValue = breakerStr.substr(eq); + // eq is now propval + + DataObjectList& list = getList(p); + for (unsigned int li = 0 ; li < list.size() ; ++li) + { + // TODO comparison for double not ok + + const Type & t = list[li]->getType(); + const Property& p = list[li]->getProperty(PropertyName); + int ok = 0; + + switch (p.getTypeEnum()) + { + case Type::BooleanType: + { + // getCString will return "true" or "false" + if (!strcmp(PropertyValue.c_str(), list[li]->getCString(p))) ok = 1; + } + break; + + case Type::ByteType: + { + char cc = PropertyValue[0]; + // getByte return a char + if (cc == list[li]->getByte(p)) ok = 1; + } + break; + + case Type::CharacterType: + { + wchar_t wc = *((wchar_t*) PropertyValue.c_str()); + // wchar_t wc = (wchar_t)((wchar_t*)eq)[0]; + // TODO - this is not a very accesible way of storing a wchar + if (wc == list[li]->getCharacter(p)) ok = 1; + } + break; + + case Type::IntegerType: + { + long ic = atol(PropertyValue.c_str()); + if (ic == list[li]->getInteger(p)) ok = 1; + } + break; + + case Type::DateType: + { + long dc = atol(PropertyValue.c_str()); + if (dc == (long)(list[li]->getDate(p).getTime())) ok = 1; + } + break; + + case Type::DoubleType: + { + // TODO - double needs a bigger size than float + long double ldc = (long double)atof(PropertyValue.c_str()); + if (ldc == list[li]->getDouble(p)) ok = 1; + } + break; + + case Type::FloatType: + { + float fc = atof(PropertyValue.c_str()); + if (fc == list[li]->getFloat(p)) ok = 1; + } + break; + + case Type::LongType: + { +#if defined(WIN32) || defined (_WINDOWS) + int64_t lic = (int64_t)_atoi64(PropertyValue.c_str()); +#else + int64_t lic = (int64_t)strtoll(PropertyValue.c_str(), NULL, 0); +#endif + + if (lic == list[li]->getLong(p)) ok = 1; + } + break; + + case Type::ShortType: + { + short sic = atoi(PropertyValue.c_str()); + if (sic == list[li]->getShort(p)) ok = 1; + } + break; + + case Type::BytesType: + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::StringType: + case Type::UriType: + { + + if (!strcmp(PropertyValue.c_str(), list[li]->getCString(p))) ok = 1; + // try with quotes too + size_t firstquote = PropertyValue.find('"'); + size_t firstsingle = PropertyValue.find('\''); + + char searchchar = 0; + + if (firstsingle == string::npos) + { + if (firstquote != string::npos) + { + searchchar = '"'; + } + } + else + { + if (firstquote != string::npos && firstquote < firstsingle) + { + searchchar = '"'; + } + else + { + searchchar = '\''; + firstquote = firstsingle; + } + } + + if (searchchar != 0) + { + size_t ender = PropertyValue.find(searchchar, firstquote + 1); + if (ender != string::npos) + { + if (!strcmp(PropertyValue.substr(firstquote + 1, ender - (firstquote+1)).c_str(), list[li]->getCString(p))) + ok = 1; + } + } + } + break; + + case Type::DataObjectType: + break; + + default: + break; + } + + if (ok == 1) + { + DataObject* dob = list[li]; + *index = li; + return (DataObjectImpl*)dob; + } + + } + return 0; + } + + + ////////////////////////////////////////////////////////////////////// + // Find a data object and a property name within it. + ////////////////////////////////////////////////////////////////////// + SDOString DataObjectImpl::findPropertyContainer(const SDOString& path, DataObjectImpl** din) + { + // initially check for "#/" which indicates that we need to find the root object first + + if (path.length() <= 2) + { + if (path[0] == '#') + { + DataObjectImpl* root = this; + while (root->getContainerImpl() != 0) + { + root = root->getContainerImpl(); + } + *din = root; + return SDOString(); + } + } + + if (path[0] == '#' && path[1] == '/') + { + DataObjectImpl* root = this; + while (root->getContainerImpl() != 0) + { + root = root->getContainerImpl(); + } + return root->findPropertyContainer(SDOString(path, 2, string::npos), din); + } + + DataObjectImpl* d; + size_t slashPos = path.find('/'); // i is the subscript of the found character + SDOString remaining; + SDOString token; + + if (slashPos != string::npos) // If we found a slash character + { + if (slashPos > 0) // If there is something before the slash + { + token.assign(path, 0, slashPos); + } + if ((path.length() - slashPos) > 1) // If there is something after the slash + { + remaining.assign(path, slashPos + 1, string::npos); + } + } + else + { + remaining = path; + } + + if (token.empty()) + { + if (remaining == "..") + { + /* Its the container itself */ + *din = getContainerImpl(); + return SDOString(); + } + + /* Its this data object - property could be empty or + valid or invalid - user must check */ + *din = this; + return remaining; + } + + if (token == "..") { + /* Its derived from the container */ + d = getContainerImpl(); + /* carry on trying to find a property */ + if (d != 0) { + return d->findPropertyContainer(remaining, din); + } + /* Give up - no container */ + *din = 0; + return SDOString(); + } + + /* Try to find a property ....*/ + long l; + d = findDataObject(token, &l); + if (d != 0) { + return d->findPropertyContainer(remaining, din); + } + + /* Give up its not in the tree */ + *din = 0; + return SDOString(); + } + + + + + // Returns a read-only List of the Properties currently used in thIs DataObject. + // ThIs list will contain all of the properties in getType().getProperties() + // and any properties where isSet(property) is true. + // For example, properties resulting from the use of + // open or mixed XML content are present if allowed by the Type. + // The list does not contain duplicates. + // The order of the properties in the list begins with getType().getProperties() + // and the order of the remaining properties is determined by the implementation. + // The same list will be returned unless the DataObject is updated so that + // the contents of the list change + // @return the list of Properties currently used in thIs DataObject. + + PropertyList /* Property */ DataObjectImpl::getInstanceProperties() + { + std::vector theVec; + const std::list propList = getType().getPropertyListReference(); + + for (std::list::const_iterator i = propList.begin(); + i != propList.end(); + i++) + { + theVec.push_back((*i)); + } + std::list::iterator j; + for (j = openProperties.begin() ; + j != openProperties.end() ; ++j) + { + theVec.push_back(&(*j)); + } + return PropertyList(theVec); + } + + void DataObjectImpl::setInstancePropertyType(unsigned int index, + const Type* t) + { + if (index >= openBase && index - openBase < openProperties.size()) + { + std::list::iterator j; + unsigned int count = openBase; + for (j = openProperties.begin() ; + j != openProperties.end() ; ++j) + { + if (count == index) + { + openProperties.insert(j, + PropertyImpl(getType(), + (*j).getName(), + (TypeImpl&)*t, + (*j).isMany(), + (*j).isReadOnly(), + (*j).isContainment())); + + DataFactory* df = factory; + ((DataFactoryImpl*)df)->addOpenProperty( + PropertyImpl(getType(), + (*j).getName(), + (TypeImpl&)*t, + (*j).isMany(), + (*j).isReadOnly(), + (*j).isContainment())); + + openProperties.erase(j); + + return; + } + count++; + } + } + return; + } + + // Returns the Sequence for thIs DataObject. + // When Type.isSequencedType() == true, + // the Sequence of a DataObject corresponds to the + // XML elements representing the values of its properties. + // Updates through DataObject and the Lists or Sequences returned + // from DataObject operate on the same data. + // When Type.isSequencedType() == false, null is returned. + // @return the Sequence or null. + + SequenceImpl* DataObjectImpl::getSequenceImpl() + { + + return sequence; + } + + SequencePtr DataObjectImpl::getSequence() + { + return (SequencePtr)sequence; + } + + SequencePtr DataObjectImpl::getSequence(const char* path) + { + return getSequence(SDOString(path)); + } + + SequencePtr DataObjectImpl::getSequence(const SDOString& path) + { + DataObject* d = (DataObject*)getDataObject(path); + if (d) return d->getSequence(); + return 0; + } + + SequencePtr DataObjectImpl::getSequence(unsigned int propertyIndex) + { + DataObject* d = (DataObject*)getDataObject(propertyIndex); + if (d) return d->getSequence(); + return 0; + } + + SequencePtr DataObjectImpl::getSequence(const Property& property) + { + DataObject* d = (DataObject*)getDataObject(property); + if (d) return d->getSequence(); + return 0; + } + + + + ChangeSummaryPtr DataObjectImpl::getChangeSummary(const char* path) + { + // Can path really be a null pointer? + if (path == 0) + { + return(getChangeSummary(SDOString())); + } + else + { + return(getChangeSummary(SDOString(path))); + } + } + + ChangeSummaryPtr DataObjectImpl::getChangeSummary(const SDOString& path) + { + DataObjectImpl* d = getDataObjectImpl(path); + return d->getChangeSummary(); + } + + ChangeSummaryPtr DataObjectImpl::getChangeSummary(unsigned int propIndex) + { + DataObjectImpl* d = getDataObjectImpl(propIndex); + return d->getChangeSummary(); + } + + ChangeSummaryPtr DataObjectImpl::getChangeSummary(const Property& prop) + { + DataObjectImpl* d = getDataObjectImpl(prop); + return d->getChangeSummary(); + + } + + ChangeSummaryPtr DataObjectImpl::getChangeSummary() + { + if (getType().isChangeSummaryType()) + { + return (ChangeSummaryPtr)localCS; + } + + DataObjectImpl* dob = getContainerImpl(); + while (dob != 0) + { + if (dob->getType().isChangeSummaryType()) + { + return (ChangeSummaryPtr)dob->getSummary(); + } + dob = dob->getContainerImpl(); + } + return 0; + } + + + ChangeSummaryImpl* DataObjectImpl::getChangeSummaryImpl() + { + if (getType().isChangeSummaryType()) + { + return localCS; + } + + DataObjectImpl* dob = getContainerImpl(); + while (dob != 0) + { + if (dob->getType().isChangeSummaryType()) + { + return dob->getSummary(); + } + dob = dob->getContainerImpl(); + } + return 0; + } + + ChangeSummaryImpl* DataObjectImpl::getSummary() + { + return localCS; + } + + // sets a property of either this object or an object reachable from it, + // as identified by the specified path, + // to the specified value. + // @param path the path to a valid object and property. + // @param value the new value for the property. + + void DataObjectImpl::setDataObject(const char* path, DataObjectPtr value) + { + setDataObject(SDOString(path), value, true); + } + + void DataObjectImpl::setDataObject(const char* path, DataObjectPtr value, bool updateSequence) + { + setDataObject(SDOString(path), value, updateSequence); + } + + void DataObjectImpl::setDataObject(const SDOString& path, + DataObjectPtr value) + { + setDataObject(path, value, false); + } + + void DataObjectImpl::setDataObject(const SDOString& path, + DataObjectPtr value, + bool updateSequence) + { + DataObjectImpl* d; + + SDOString prop = findPropertyContainer(path, &d); + if (d != 0) + { + if (!prop.empty()) { + const PropertyImpl* p = d->getPropertyImpl(prop); + if ((p == 0) && (d->getType().isOpenType())) + { + if (value != 0) + { + p = d->defineDataObject(prop, value->getType()); + } + } + if (p != 0) + { + ASSERT_SETTABLE(p, DataObject); + if (p->isMany()) + { + DataObjectList& dol = d->getList((Property&)*p); + long idx; + DataObjectImpl* dx = d->findDataObject(prop,&idx); + // fix this. This is the only place the 2nd parm to findDataObject + // is used. Need a better way to do this + unsigned int index = (unsigned int) idx; + if (index >= 0) + { + if(index < dol.size()) + { + dol.setDataObject(index, value); + } + else + { + dol.append(value); + } + return; + } + string msg("Set of data object on many valued item"); + msg += path; + SDO_THROW_EXCEPTION("setDataObject", + SDOUnsupportedOperationException, + msg.c_str()); + } + else + { + d->setDataObject((Property&) *p, value, updateSequence); + return; + } + } + } + } + + string msg("Path not valid:"); + msg += path; + SDO_THROW_EXCEPTION("setDataObject", SDOPathNotFoundException, + msg.c_str()); + } + + void DataObjectImpl::validateIndex(unsigned int index) + { + const std::list pl = getType().getPropertyListReference(); + + if (index >= pl.size()) { + + // open type support + if (getType().isOpenType()) + { + if (index < openBase + openProperties.size()) + { + return; + } + } + + string msg("Index of property out of range:"); + msg += index; + SDO_THROW_EXCEPTION("Index Validation", SDOIndexOutOfRangeException, + msg.c_str()); + } + } + + + void DataObjectImpl::checkFactory(DataObjectPtr dob, + unsigned int propertyIndex) + { + + DataObjectImpl* d = (DataObjectImpl*)(DataObject*)dob; + + if (d->getDataFactory() == getDataFactory()) return; + + if (d->getContainer() != 0) + { + string msg("Insertion of object from another factory is only allowed if the parent is null: "); + const Type& t = d->getType(); + msg += t.getURI(); + msg += "#"; + msg += t.getName(); + msg += " into property "; + msg += getProperty(propertyIndex).getName(); + msg += " of "; + msg += getType().getURI(); + msg += "#"; + msg += getType().getName(); + SDO_THROW_EXCEPTION("checkFactory", SDOInvalidConversionException, + msg.c_str()); + } + + } + + + void DataObjectImpl::checkType( const Property& prop, + const Type& objectType) + { + const Type& propType = prop.getType(); + if (propType.equals(objectType)) return; + + DataFactory* df = (DataFactory*)factory; + + const TypeImpl* ti = ((DataFactoryImpl*)df)->findTypeImpl + (objectType.getURI(),objectType.getName()); + if (ti != 0) + { + do + { + ti = (const TypeImpl*)ti->getBaseType(); + if (ti == 0) break; + if (propType.equals(*ti)) return; + } while (ti != 0); + + // allow types of any substitutes + const PropertyImpl* pi = + getPropertyImpl(getPropertyIndex(prop)); + if (pi != 0) + { + unsigned int subcount = pi->getSubstitutionCount(); + for (unsigned int i=0;igetSubstitutionType(i); + if (tsub != 0 && tsub->equals(objectType)) return; + } + } + } + + // no match.. + string msg("Insertion of object of incompatible type "); + msg += objectType.getURI(); + msg += "#"; + msg += objectType.getName(); + msg += " into property of type "; + msg += propType.getURI(); + msg += "#"; + msg += propType.getName(); + SDO_THROW_EXCEPTION("TypeCheck", SDOInvalidConversionException, + msg.c_str()); + } + + void DataObjectImpl::setDataObject(unsigned int propertyIndex, DataObjectPtr value) + { + setDataObject(getProperty(propertyIndex), value, true); + } + + void DataObjectImpl::setDataObject(unsigned int propertyIndex, DataObjectPtr value, bool updateSequence) + { + setDataObject(getProperty(propertyIndex), value, updateSequence); + } + + void DataObjectImpl::setDataObject(const Property& prop, DataObjectPtr value) + { + setDataObject(prop, value, false); + } + +void DataObjectImpl::setDataObject(const Property& prop, + DataObjectPtr value, + bool updateSequence) +{ + unsigned int propertyIndex = getPropertyIndexInternal(prop); + + if (value != 0) + { + checkFactory(value, propertyIndex); + checkType(prop, value->getType()); + } + + validateIndex(propertyIndex); + + if (prop.isReference() && (value != 0)) + { + // just need to make sure that the object is already part of our tree. + DataObjectImpl* r1 = this; + while (r1->getContainerImpl() != 0) + { + r1 = r1->getContainerImpl(); + } + DataObjectImpl* r2 = (DataObjectImpl*) (DataObject*) value; + while (r2->getContainerImpl() != 0) + { + r2 = r2->getContainerImpl(); + } + if (r1 != r2) + { + string msg("Set of a reference to an object outside the graph"); + SDO_THROW_EXCEPTION("setDataObject", + SDOUnsupportedOperationException, + msg.c_str()); + } + } + + if ((prop.isMany())) + { + string msg("Set operation on a many valued property:"); + msg += prop.getName(); + SDO_THROW_EXCEPTION("setDataObject", + SDOUnsupportedOperationException, + msg.c_str()); + } + + ASSERT_WRITABLE(prop, setDataObject); + + if (value == 0) + { + // The new data object value is actually a null pointer. + PropertyValueMap::iterator j; + // Scan the property value map looking for this property. + for (j = PropertyValues.begin(); j != PropertyValues.end(); ++j) + { + if ((*j).first == propertyIndex) + { + if (prop.isReference()) + { + ((*j).second)->unsetReference(this, prop); + } + else + { + // log both deletion and change - change is not + // automatically recorded by deletion. + ((*j).second)->logDeletion(); + } + logChange(prop); + (*j).second = RefCountingPointer(0); + // We have just changed the value of this property, therefore + // if this is a sequenced data object, then we must update the + // sequence so that the new setting appears at the end (and + // the existing entry is removed). + if ((getType().isSequencedType()) && updateSequence) + { + SequenceImpl* mySequence = getSequenceImpl(); + mySequence->removeAll(prop); + mySequence->push(prop, 0); + } + + return; + } + } + // The property does not currently have a value. + logChange(prop); + PropertyValues.push_back(rdo(propertyIndex, (DataObjectImpl*) 0)); + // If this is a sequenced data object then update the + // sequence. We already know that a) the property was not previously + // set so it can't be in the sequence currently and b) it is not a + // multi-valued property. + if ((getType().isSequencedType()) && updateSequence) + { + getSequenceImpl()->push(prop, 0); + } + return; + } + + DataObject* dob = value; + PropertyValueMap::iterator i; + for (i = PropertyValues.begin(); i != PropertyValues.end(); ++i) + { + if ((*i).first == propertyIndex) + { + if (prop.isReference()) + { + ((*i).second)->unsetReference(this, prop); + } + else + { + // log both deletion and change - change is not + // automatically recorded by deletion. + ((*i).second)->logDeletion(); + } + logChange(prop); + + (*i).second = RefCountingPointer((DataObjectImpl*) dob); + + if (prop.isReference()) + { + ((DataObjectImpl*) dob)->setReference(this, prop); + } + else + { + logCreation((*i).second, this, prop); + } + return; + } + } + if (prop.isReference()) + { + ((DataObjectImpl*)dob)->setReference(this, prop); + } + else + { + ((DataObjectImpl*)dob)->setContainer(this); + // log creation before putting into property values. + // also log change - not done by logCreation + logCreation((DataObjectImpl*)dob, this, prop); + } + + logChange(prop); + + PropertyValues.push_back(rdo(propertyIndex, (DataObjectImpl*) dob)); + // If this is a sequenced data object then update the + // sequence. We already know that a) the property is not + // in the sequence currently and b) it is not a + // multi-valued property. + if ((getType().isSequencedType()) && updateSequence) + { + getSequenceImpl()->push(prop, 0); + } + + return; +} + + bool DataObjectImpl::isValid(const char* path) + { + // Can path really be a null pointer? + if (path == 0) + { + return(isValid(SDOString())); + } + else + { + return(isValid(SDOString(path))); + } + + } + + bool DataObjectImpl::isValid(const SDOString& path) + { + DataObjectImpl* d; + SDOString prop = findPropertyContainer(path, &d); + if (d != 0) { + if (!prop.empty()) { + const Property& p = d->getProperty(prop); + return d->isValid(p); + } + } + string msg("Invalid path:"); + msg += path; + SDO_THROW_EXCEPTION("isSet" ,SDOPathNotFoundException, + msg.c_str()); + } + + // Returns whether a property of either this object or an object reachable + // from it, as identified by the specified path, + // is considered to be set. + // @param path the path to a valid Object* and property. + + bool DataObjectImpl::isSet(const char* path) + { + // Can path really be a null pointer? + if (path == 0) + { + return(isSet(SDOString())); + } + else + { + return(isSet(SDOString(path))); + } + } + + bool DataObjectImpl::isSet(const SDOString& path) + { + DataObjectImpl* d; + SDOString prop = findPropertyContainer(path, &d); + if (d != 0) { + if (!prop.empty()) { + const Property& p = d->getProperty(prop); + return d->isSet(p); + } + } + string msg("Invalid path:"); + msg += path; + SDO_THROW_EXCEPTION("isSet" ,SDOPathNotFoundException, + msg.c_str()); + } + + bool DataObjectImpl::isValid(unsigned int propertyIndex) + { + return isValid(getProperty(propertyIndex)); + } + + bool DataObjectImpl::isValid(const Property& p) + { + if (p.isDefaulted()) return true; + if (isSet(p))return true; + return false; + } + + bool DataObjectImpl::isSet(unsigned int propertyIndex) + { + return isSet(getProperty(propertyIndex), propertyIndex); + } + + bool DataObjectImpl::isSet(const Property& property) + { + return isSet(property, getPropertyIndex(property)); + } + + bool DataObjectImpl::isSet(const Property& prop, unsigned int propertyIndex) + { + PropertyValueMap::iterator i; + for (i = PropertyValues.begin(); i != PropertyValues.end(); ++i) + { + if ((*i).first == propertyIndex) { + if (prop.isMany()) + { + DataObjectImpl* dol = (*i).second; + if (dol != 0 && dol->getList().size() == 0) + { + return false; + } + } + return true; + } + } + return false; + } + + + // unSets a property of either this Object or an Object reachable from it, + // as identified by the specified path. + // @param path the path to a valid Object and property. + // @see #unSet(Property) + + void DataObjectImpl::unset(const char* path) + { + // Can path really be a null pointer? + if (path == 0) + { + unset(SDOString()); + } + else + { + unset(SDOString(path)); + } + } + + void DataObjectImpl::unset(const SDOString& path) + { + DataObjectImpl* d; + SDOString prop = findPropertyContainer(path, &d); + if (d != 0) + { + if (!prop.empty()) + { + const Property& p = d->getProperty(prop); + ASSERT_WRITABLE(p, unset); + if (p.isMany()) + { + SDOString subscript; + size_t beginbrace = prop.find('['); + if (beginbrace != string::npos) + { + size_t endbrace = prop.find(']', ++beginbrace); + if (endbrace != string::npos) { + subscript = + prop.substr(beginbrace, (endbrace - beginbrace)); + } + unsigned int i = atoi(subscript.c_str()); + if (i > 0) { + i--; + DataObjectList& li = d->getList(p); + li.remove(i); + } + return; + } + size_t firstdot = prop.find('.'); + if (firstdot != string::npos) { + subscript = prop.substr(++firstdot); + unsigned int i = atoi(subscript.c_str()); + DataObjectList& li = d->getList(p); + li.remove(i); + return; + } + } + d->unset(p); + return; + } + } + + string msg("Invalid path:"); + msg += path; + SDO_THROW_EXCEPTION("unset", + SDOPathNotFoundException, + msg.c_str()); + } + + void DataObjectImpl::unset(unsigned int propertyIndex) + { + unset(getProperty(propertyIndex)); + } + + void DataObjectImpl::unset(const Property& p) + { + ASSERT_WRITABLE(p, unset) + + PropertyValueMap::iterator i; + unsigned int index = getPropertyIndex(p); + + if (getType().isSequencedType()) + { + Sequence* sq = getSequence(); + sq->removeAll(p); + } + + for (i = PropertyValues.begin(); i != PropertyValues.end(); ++i) + { + if ((*i).first == index) { + DataObjectImplPtr dol = (*i).second; + if (p.getType().isDataType()) + { + dol->clearReferences(); + logChange(index); + if (p.isMany()) { + DataObjectList& dl = dol->getList(); + while (dl.size() > 0) + { + RefCountingPointer dli = dl.remove(0); + } + } + else + { + PropertyValues.erase(i); + } + } + else { + // if its a reference, we dont want to delete anything + if (!p.isReference()) + { + if (dol) { + dol->clearReferences(); + if (p.isMany()) { + DataObjectList& dl = dol->getList(); + while (dl.size() > 0) + { + if (p.getType().isDataObjectType()) + { + DataObject* dob = dl[0]; + ((DataObjectImpl*)dob)->logDeletion(); + } + // the remove will record a change + // remove will also clear the container. + RefCountingPointer dli = dl.remove(0); + } + } + else + { + PropertyValues.erase(i); + dol->logDeletion(); + logChange(index); + dol->setContainer(0); + } + } + else + { + logChange(index); + PropertyValues.erase(i); + } + } + else { + if (dol) + { + dol->unsetReference(this, p); + } + logChange(index); + PropertyValues.erase(i); + } + } + if (getType().isOpenType() && index >= openBase) + { + if (p.isMany()) + { + PropertyValues.erase(i); + } + undefineProperty(index); + } + return; + } + } + return; + } + + + + // Returns the value of a DataObject property identified by + // the specified path. + // @param path the path to a valid object and property. + // @return the DataObject value of the specified property. + + RefCountingPointer DataObjectImpl::getDataObject(const char* path) + { + return getDataObject(SDOString(path)); + } + + RefCountingPointer DataObjectImpl::getDataObject(const SDOString& path) + { + DataObjectImpl* ptr = getDataObjectImpl(path); + return RefCountingPointer ((DataObject*)ptr); + } + + DataObjectImpl* DataObjectImpl::getDataObjectImpl(const SDOString& path) + { + + DataObjectImpl* d = 0; + SDOString prop = findPropertyContainer(path, &d); + if (d != 0) + { + if (!prop.empty()) + { + if (prop.find_first_of("[.") != string::npos) + { + /* Its a multi-valued property */ + long l; + DataObjectImpl* theob = d->findDataObject(prop, &l); + if (theob == 0) + { + string msg("Get DataObject - index out of range:"); + msg += path; + SDO_THROW_EXCEPTION("getDataObject", + SDOIndexOutOfRangeException, + msg.c_str()); + } + return theob; + } + else + { + if (prop.length() == 0) + { + return d; + } + const Property& p = d->getProperty(prop); + return d->getDataObjectImpl(p); + } + } + else + { + return d; + } + } + + string msg("Invalid path:"); + msg += path; + SDO_THROW_EXCEPTION("getDataObject", + SDOPathNotFoundException, + msg.c_str()); + } + + RefCountingPointer DataObjectImpl::getDataObject(unsigned int propertyIndex) + { + if ((getProperty(propertyIndex).isMany())) + { + string msg("get operation on a many valued property:"); + msg += getProperty(propertyIndex).getName(); + SDO_THROW_EXCEPTION("getDataObject", + SDOUnsupportedOperationException, + msg.c_str()); + } + DataObjectImpl* ptr = getDataObjectImpl(propertyIndex); + + return RefCountingPointer((DataObject*)ptr); + } + + DataObjectImpl* DataObjectImpl::getDataObjectImpl(unsigned int propertyIndex) + { + PropertyValueMap::iterator i; + for (i = PropertyValues.begin(); i != PropertyValues.end(); ++i) + { + if ((*i).first == propertyIndex) + { + DataObject* dob = (*i).second; + if ((dob == 0) || ((DataObjectImpl*) dob)->isNull()) + { + return 0; + } + return (DataObjectImpl*) dob; + } + } + return 0; + } + + + RefCountingPointer DataObjectImpl::getDataObject(const Property& property) + { + DataObjectImpl* ptr = getDataObjectImpl(property); + return RefCountingPointer((DataObject*) ptr); + } + + DataObjectImpl* DataObjectImpl::getDataObjectImpl(const Property& property) + { + return getDataObjectImpl(getPropertyIndex(property)); + } + + + + // Returns a new DataObject contained by this Object using the specified property, + // which must be a containment property. + // The type of the created Object is the declared type of the specified property. + + RefCountingPointer DataObjectImpl::createDataObject(const SDOString& propertyName) + { + // Throws runtime exception for type or property not found + + const Property& p = getProperty(propertyName); + return createDataObject(p); + } + + // Returns a new DataObject contained by this Object using the specified property, + // which must be a containment property. + // The type of the created Object is the declared type of the specified property. + + RefCountingPointer DataObjectImpl::createDataObject(const char* propertyName) + { + // Can propertyName really be a null pointer? + if (propertyName == 0) + { + return(createDataObject(SDOString())); + } + else + { + return(createDataObject(SDOString(propertyName))); + } + } + + // Returns a new DataObject contained by this Object using the specified property, + // which must be a containment property. + // The type of the created Object is the declared type of the specified property. + + RefCountingPointer DataObjectImpl::createDataObject(unsigned int propertyIndex) + { + const Property& p = getProperty(propertyIndex); + return createDataObject(p); + } + + // Returns a new DataObject contained by this Object using the specified property, + // which must be a containment property. + // The type of the created Object is the declared type of the specified property. + + RefCountingPointer DataObjectImpl::createDataObject(const Property& property) + { + const Type& tp = property.getType(); + return createDataObject(property,tp.getURI(), tp.getName()); + } + + + // Returns a new DataObject contained by this Object using the specified property, + // which must be a containment property. + // The type of the created Object is the declared type of the specified property. + + RefCountingPointer DataObjectImpl::createDataObject(const Property& property, const char* namespaceURI, + const char* typeName) + { + if (!property.isContainment()) + { + string msg("Create data object on non-containment property:"); + msg += property.getName(); + SDO_THROW_EXCEPTION("createDataObject", SDOUnsupportedOperationException, + msg.c_str()); + } + + DataFactory* df = getDataFactory(); + if (property.isMany()) { + /* add to the list */ + RefCountingPointer ptr = df->create(namespaceURI, typeName); + DataObject* dob = ptr; + ((DataObjectImpl*)dob)->setContainer(this); + + // log creation before adding to list - the change must record the old state + // of the list + logCreation(((DataObjectImpl*)dob), this, property); + //logChange(property); + + DataObjectImpl* theDO = getDataObjectImpl(property); + if ( theDO == 0) { /* No value set yet */ + unsigned int ind = getPropertyIndex(property); + RefCountingPointer listptr = + df->create(Type::SDOTypeNamespaceURI,"DataObject"); + + DataObject* doptr = listptr; + + PropertyValues.push_back(rdo(ind, (DataObjectImpl*) doptr)); + + ((DataObjectImpl*)doptr)->setContainer(this); + + DataObjectListImpl* list = new DataObjectListImpl(df, + this, ind, namespaceURI,typeName); + + ((DataObjectImpl*)doptr)->setList(list); + // the append will log a change to the property. + list->append(ptr); + + // now done by list append + //if (getType().isSequencedType()) + //{ + // SequenceImpl* sq = getSequenceImpl(); + // sq->push(property,0); + //} + } + else + { + DataObjectList& list = theDO->getList(); + // the append will log a change to the property, and update the + // sequence + list.append(ptr); + //if (getType().isSequencedType()) + //{ + // SequenceImpl* sq = getSequenceImpl(); + // sq->push(property,list.size()-1); + //} + + } + return ptr; + + } + else { + unset(property); + DataObjectImpl* ditem = + new DataObjectImpl(df, df->getType(namespaceURI, typeName)); + ditem->setContainer(this); + + // log both creation and change - creations no longer log + // changes automatically. + + logCreation(ditem, this, property); + logChange(property); + + PropertyValues.push_back(rdo(getPropertyIndex(property), ditem)); + + if (getType().isSequencedType()) + { + SequenceImpl* sq = getSequenceImpl(); + sq->push(property,0); + } + return RefCountingPointer((DataObject*)ditem); + } + return 0; + } + + void DataObjectImpl::setList( DataObjectList* theList) + { + listValue = (DataObjectListImpl*)theList; + } + + + bool DataObjectImpl::remove(DataObjectImpl* indol) + { + PropertyValueMap::iterator i; + for (i = PropertyValues.begin(); i != PropertyValues.end(); ++i) + { + const Property& prop = getProperty((*i).first); + if (prop.isMany()) + { + DataObjectList& dol = ((*i).second)->getList(); + for (unsigned int j=0;j< dol.size(); j++) + { + if (dol[j] == indol) + { + indol->logDeletion(); + logChange(prop); + indol->setContainer(0); + dol.remove(j); + return true; + } + } + } + DataObjectImpl* tmp = (*i).second; + if (tmp == indol) { + indol->logDeletion(); + logChange(prop); + indol->setContainer(0); + PropertyValues.erase(i); + return true; + } + } + return false; + } + + // remove this Object from its container and dont unSet all its properties. + + void DataObjectImpl::detach() + { + // remove this data object from its tree + clearReferences(); + if (container == 0) return; + container->remove(this); + return ; + } + + void DataObjectImpl::clear() + { + // clear this objects state + PropertyValueMap::iterator i = PropertyValues.begin(); + + while (i != PropertyValues.end()) + { + unset((*i).first); + i = PropertyValues.begin(); + } + return ; + } + + // Returns the containing Object + // or 0 if there is no container. + + RefCountingPointer DataObjectImpl::getContainer() + { + DataObject* dob = (DataObject*)container; + return RefCountingPointer (dob); + } + + DataObjectImpl* DataObjectImpl::getContainerImpl() + { + return container; + } + + void DataObjectImpl::setContainer(DataObjectImpl* d) + { + container = d; + } + + const Property* DataObjectImpl::findInProperties(DataObject* ob) + { + PropertyValueMap::iterator i; + for (i = PropertyValues.begin() ;i != PropertyValues.end() ; ++i) + { + if (getProperty((*i).first).isReference()) continue; + if (getProperty((*i).first).isMany()) + { + DataObjectList& dl = ((*i).second)->getList(); + for (unsigned int j = 0 ; j < dl.size(); j++) + { + if (dl[j] == ob) + { + return &(getProperty((*i).first)); + } + } + } + else + { + if ((*i).second == ob) + { + return &(getProperty((*i).first)); + } + } + } + return 0; // this can happen if the object has been detached + + //string msg("Object cannot find its containing property"); + //SDO_THROW_EXCEPTION("FindInProperties" ,SDOPropertyNotFoundException, + // msg.c_str()); + } + + // Return the Property of the data Object containing this data Object + // or 0 if there is no container. + + const Property& DataObjectImpl::getContainmentProperty() + { + if (container != 0) { + const Property* p = container->findInProperties(this); + if (p != 0)return *p; + } + SDO_THROW_EXCEPTION("getContainmentProperty" ,SDOPropertyNotFoundException, + "Object cannot find its containment property"); + } + + + // Returns the data Object's type. + // The type defines the properties available for reflective access. + + const Type& DataObjectImpl::getType() + { + return (const Type&)(*ObjectType); + } + + const Type::Types DataObjectImpl::getTypeEnum() + { + return ObjectType->getTypeEnum(); + } + + const TypeImpl& DataObjectImpl::getTypeImpl() + { + return (const TypeImpl&)*ObjectType; + } + + + // open type support + + const Property& DataObjectImpl::getProperty(const char* prop) + { + return getProperty(SDOString(prop)); + } + + const Property& DataObjectImpl::getProperty(const SDOString& prop) + { + PropertyImpl* pi = getPropertyImpl(prop); + if (pi == 0) + { + string msg("Cannot find property:"); + msg += prop; + SDO_THROW_EXCEPTION("getProperty", SDOPropertyNotFoundException, + msg.c_str()); + + } + return (Property&)*pi; + } + + PropertyImpl* DataObjectImpl::getPropertyImpl(const SDOString& prop) + { + PropertyImpl* pi = getTypeImpl().getPropertyImpl(prop); + if (pi != 0) return pi; + + if (getType().isOpenType()) + { + std::list::iterator j; + for (j=openProperties.begin(); + j != openProperties.end(); ++j) + { + if (!strcmp((*j).getName(), prop.c_str())) + { + return (PropertyImpl*)&(*j); + } + } + } + return 0; + } + + DataFactory* DataObjectImpl::getDataFactory() + { + return factory; + } + + void DataObjectImpl::setDataFactory(DataFactory* df) + { + ObjectType = (TypeImpl*)&(df->getType(ObjectType->getURI(), + ObjectType->getName())); + factory = df; + } + + /////////////////////////////////////////////////////////////////////////// + // These finally are the setters/getters for primitives given + // that the data object is a primitive type. + /////////////////////////////////////////////////////////////////////////// + + + bool DataObjectImpl::getBoolean() + { + return getTypeImpl().convertToBoolean(sdoValue); + } + + char DataObjectImpl::getByte() + { + return getTypeImpl().convertToByte(sdoValue); + } + + wchar_t DataObjectImpl::getCharacter() + { + return getTypeImpl().convertToCharacter(sdoValue); + } + + long DataObjectImpl::getInteger() + { + return getTypeImpl().convertToInteger(sdoValue); + } + + long double DataObjectImpl::getDouble() + { + return getTypeImpl().convertToDouble(sdoValue); + } + + float DataObjectImpl::getFloat() + { + return getTypeImpl().convertToFloat(sdoValue); + } + + int64_t DataObjectImpl::getLong() + { + return getTypeImpl().convertToLong(sdoValue); + } + + short DataObjectImpl::getShort() + { + return getTypeImpl().convertToShort(sdoValue); + } + + unsigned int DataObjectImpl::getString(wchar_t* outptr, unsigned int max) + { + return getTypeImpl().convertToString(sdoValue, outptr, max); + } + + unsigned int DataObjectImpl::getBytes( char* outptr, unsigned int max) + { + return getTypeImpl().convertToBytes(sdoValue, outptr, max); + } + + const char* DataObjectImpl::getCString() + { + return getTypeImpl().convertToCString(sdoValue); + } + + const SDODate DataObjectImpl::getDate() + { + return getTypeImpl().convertToDate(sdoValue); + } + + DataObjectImpl* DataObjectImpl::getDataObject() + { + // If the sdoValue is unset, then there is no primitive value. + // If doValue is non-null then that is the data object value. + switch (getTypeImpl().getTypeEnum()) + { + case Type::OtherTypes: + case Type::DataObjectType: + return doValue; + + case Type::BooleanType: + case Type::ByteType: + case Type::CharacterType: + case Type::IntegerType: + case Type::ShortType: + case Type::DoubleType: + case Type::FloatType: + case Type::LongType: + case Type::DateType: + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::StringType: + case Type::BytesType: + case Type::UriType: + default: + { + string msg("Cannot get Data Object from object of type:"); + msg += getTypeImpl().getName(); + SDO_THROW_EXCEPTION("DataObjectImpl::getDataObject", + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + return 0; + } + + void DataObjectImpl::setBoolean(bool invalue) + { + switch(getTypeEnum()) + { + + case Type::BooleanType: + case Type::ByteType: + case Type::CharacterType: + case Type::IntegerType: + case Type::ShortType: + case Type::LongType: + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::StringType: + case Type::UriType: + case Type::BytesType: + sdoValue = SDOValue(invalue); + break; + + case Type::DoubleType: + case Type::FloatType: + case Type::DateType: + case Type::OtherTypes: + case Type::DataObjectType: + case Type::ChangeSummaryType: + default: + { + string msg("Cannot set Boolean on object of type:"); + msg += getTypeImpl().getName(); + SDO_THROW_EXCEPTION("setBoolean" , + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + return; + } + + + void DataObjectImpl::setByte(char invalue) + { + switch (getTypeEnum()) + { + case Type::BooleanType: + case Type::ByteType: + case Type::CharacterType: + case Type::IntegerType: + case Type::ShortType: + case Type::DoubleType: + case Type::FloatType: + case Type::LongType: + case Type::DateType: + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::StringType: + case Type::UriType: + case Type::BytesType: + sdoValue = SDOValue(invalue); + break; + + case Type::OtherTypes: + case Type::DataObjectType: + case Type::ChangeSummaryType: + default: + { + string msg("Cannot set Byte on object of type:"); + msg += getTypeImpl().getName(); + SDO_THROW_EXCEPTION("DataObjectImpl::setByte" , + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + return; + } + + + void DataObjectImpl::setCharacter(wchar_t invalue) + { + switch (getTypeEnum()) + { + case Type::BooleanType: + case Type::ByteType: + case Type::CharacterType: + case Type::IntegerType: + case Type::ShortType: + case Type::DoubleType: + case Type::FloatType: + case Type::LongType: + case Type::DateType: + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::StringType: + case Type::UriType: + case Type::BytesType: + sdoValue = SDOValue(invalue); + break; + + case Type::OtherTypes: + case Type::DataObjectType: + case Type::ChangeSummaryType: + default: + { + string msg("Cannot set Character on object of type:"); + msg += getTypeImpl().getName(); + SDO_THROW_EXCEPTION("DataObjectImpl::setCharacter" , + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + return; + } + + void DataObjectImpl::setString(const wchar_t* invalue, unsigned int len) + { + switch (getTypeEnum()) + { + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::UriType: + case Type::StringType: + case Type::BytesType: + case Type::BooleanType: + case Type::CharacterType: + case Type::ByteType: + case Type::ShortType: + case Type::IntegerType: + case Type::LongType: + sdoValue = SDOValue(invalue, len); + break; + + case Type::DoubleType: + case Type::FloatType: + case Type::DateType: + case Type::OtherTypes: + case Type::DataObjectType: + case Type::ChangeSummaryType: + default: + { + string msg("Cannot set String on object of type:"); + msg += getTypeImpl().getName(); + SDO_THROW_EXCEPTION("DataObjectImpl::setString" , + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + return; + } + + void DataObjectImpl::setBytes(const char* invalue, unsigned int len) + { + switch (getTypeEnum()) + { + case Type::BytesType: + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::UriType: + case Type::StringType: + case Type::BooleanType: + case Type::ByteType: + case Type::CharacterType: + case Type::IntegerType: + case Type::ShortType: + case Type::LongType: + sdoValue = SDOValue(invalue, len); + break; + + case Type::DoubleType: + case Type::FloatType: + case Type::DateType: + case Type::OtherTypes: + case Type::DataObjectType: + case Type::ChangeSummaryType: + default: + { + string msg("Cannot set Bytes on object of type:"); + msg += getTypeImpl().getName(); + SDO_THROW_EXCEPTION("DataObjectImpl::setBytes" , + SDOInvalidConversionException, + msg.c_str()); + return; + } + } + return; + } + + void DataObjectImpl::setInteger(long invalue) + { + switch (getTypeEnum()) + { + case Type::BooleanType: + case Type::ByteType: + case Type::CharacterType: + case Type::IntegerType: + case Type::ShortType: + case Type::DoubleType: + case Type::FloatType: + case Type::LongType: + case Type::DateType: + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::StringType: + case Type::UriType: + case Type::BytesType: + sdoValue = SDOValue(invalue); + break; + + case Type::OtherTypes: + case Type::DataObjectType: + case Type::ChangeSummaryType: + default: + { + string msg("Cannot set LongLong on object of type:"); + msg += getTypeImpl().getName(); + SDO_THROW_EXCEPTION("DataObjectImpl::setInteger" , + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + return; + } + + + void DataObjectImpl::setDouble(long double invalue) + { + switch (getTypeEnum()) + { + case Type::BooleanType: + case Type::ByteType: + case Type::CharacterType: + case Type::IntegerType: + case Type::ShortType: + case Type::DoubleType: + case Type::FloatType: + case Type::LongType: + case Type::DateType: + sdoValue = SDOValue(invalue); + break; + + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::StringType: + case Type::UriType: + case Type::BytesType: + case Type::OtherTypes: + case Type::DataObjectType: + case Type::ChangeSummaryType: + default: + { + string msg("Cannot set Long Double on object of type:"); + msg += getTypeImpl().getName(); + SDO_THROW_EXCEPTION("setDouble" , + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + return; + } + + void DataObjectImpl::setFloat(float invalue) + { + switch (getTypeEnum()) + { + case Type::BooleanType: + case Type::ByteType: + case Type::CharacterType: + case Type::IntegerType: + case Type::ShortType: + case Type::DoubleType: + case Type::FloatType: + case Type::LongType: + case Type::DateType: + sdoValue = SDOValue(invalue); + break; + + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::StringType: + case Type::UriType: + case Type::BytesType: + case Type::OtherTypes: + case Type::DataObjectType: + case Type::ChangeSummaryType: + default: + { + string msg("Cannot set Float on object of type:"); + msg += getTypeImpl().getName(); + SDO_THROW_EXCEPTION("setFloat" , + SDOInvalidConversionException, + msg.c_str()); + break; + } + break; + } + return; + } + + + void DataObjectImpl::setLong(int64_t invalue) + { + switch (getTypeEnum()) + { + case Type::BooleanType: + case Type::ByteType: + case Type::CharacterType: + case Type::IntegerType: + case Type::ShortType: + case Type::DoubleType: + case Type::FloatType: + case Type::LongType: + case Type::DateType: + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::StringType: + case Type::UriType: + case Type::BytesType: + sdoValue = SDOValue(invalue); + break; + + case Type::OtherTypes: + case Type::DataObjectType: + case Type::ChangeSummaryType: + default: + { + string msg("Cannot set Long on object of type:"); + msg += getTypeImpl().getName(); + SDO_THROW_EXCEPTION("DataObjectImpl::setLong" , + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + return; + } + + + void DataObjectImpl::setShort(short invalue) + { + switch (getTypeEnum()) + { + case Type::BooleanType: + case Type::ByteType: + case Type::CharacterType: + case Type::IntegerType: + case Type::ShortType: + case Type::DoubleType: + case Type::FloatType: + case Type::LongType: + case Type::DateType: + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::StringType: + case Type::UriType: + case Type::BytesType: + sdoValue = SDOValue(invalue); + break; + + case Type::OtherTypes: + case Type::DataObjectType: + case Type::ChangeSummaryType: + default: + { + string msg("Cannot set short on object of type:"); + msg += getTypeImpl().getName(); + SDO_THROW_EXCEPTION("DataObjectImpl::setShort" , + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + return; + } + + void DataObjectImpl::setCString(const char* invalue) + { + setCString(SDOString(invalue)); + } + + void DataObjectImpl::setCString(const SDOString& invalue) + { + switch (getTypeEnum()) + { + case Type::BooleanType: + case Type::ByteType: + case Type::CharacterType: + case Type::IntegerType: + case Type::ShortType: + case Type::DoubleType: + case Type::FloatType: + case Type::LongType: + case Type::DateType: + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::StringType: + case Type::UriType: + case Type::BytesType: + sdoValue = SDOValue(invalue); + break; + + case Type::OtherTypes: + case Type::DataObjectType: + case Type::ChangeSummaryType: + default: + { + string msg("Cannot set CString on object of type:"); + msg += getTypeImpl().getName(); + SDO_THROW_EXCEPTION("DataObjectImpl::setCString" , + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + return; + } + + void DataObjectImpl::setDate(const SDODate invalue) + { + switch (getTypeEnum()) + { + case Type::ByteType: + case Type::CharacterType: + case Type::IntegerType: + case Type::ShortType: + case Type::DoubleType: + case Type::FloatType: + case Type::LongType: + case Type::DateType: + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::StringType: + case Type::UriType: + case Type::BytesType: + sdoValue = SDOValue(invalue); + break; + + case Type::OtherTypes: + case Type::BooleanType: + case Type::DataObjectType: + case Type::ChangeSummaryType: + default: + { + string msg("Cannot set LongLong on object of type:"); + msg += getTypeImpl().getName(); + SDO_THROW_EXCEPTION("DataObjectImpl::setDate" , + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + return; + } + + void DataObjectImpl::setDataObject(DataObject* inValue) + { + // If the sdoValue is unset, then there is no primitive value. + // If doValue is non-null then that is the data object value. + switch (getTypeImpl().getTypeEnum()) + { + case Type::OtherTypes: + case Type::DataObjectType: + doValue = (DataObjectImpl*) inValue; + break; + + case Type::BooleanType: + case Type::ByteType: + case Type::CharacterType: + case Type::IntegerType: + case Type::ShortType: + case Type::DoubleType: + case Type::FloatType: + case Type::LongType: + case Type::DateType: + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::StringType: + case Type::BytesType: + case Type::UriType: + default: + { + string msg("Cannot set Data Object for object of type:"); + msg += getTypeImpl().getName(); + SDO_THROW_EXCEPTION("DataObjectImpl::setDataObject", + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + return; + } + + void DataObjectImpl::setNull() + { + isnull = true; + } + + bool DataObjectImpl::isNull() + { + return isnull; + } + + void DataObjectImpl::unsetNull() + { + isnull = false; + } + + + DataObjectImpl::DataObjectImpl(const TypeImpl& t) : + ObjectType((TypeImpl*) &t), + container(0), + doValue(0), + isnull(false), + userdata((void*) 0xFFFFFFFF) + { + // open type support + openBase = t.getPropertiesSize() ; + + if (t.isChangeSummaryType()) + { + localCS = new ChangeSummaryImpl(); + } + else + { + localCS = 0; + } + + if (getType().isSequencedType()) + { + sequence = new SequenceImpl(this); + } + else + { + sequence = 0; + } + } + + + DataObjectImpl::DataObjectImpl(DataFactory* df, const Type& t) : + ObjectType((TypeImpl*) &t), + factory(df), + container(0), + isnull(false), + userdata((void*) 0xFFFFFFFF) + { + // open type support + openBase = ObjectType->getPropertiesSize() ; + + + if (ObjectType->isChangeSummaryType()) + { + localCS = new ChangeSummaryImpl(); + } + else + { + localCS = 0; + } + + if (getType().isSequencedType()) + { + sequence = new SequenceImpl(this); + } + else + { + sequence = 0; + } + } + + + DataObjectImpl::~DataObjectImpl() + { + // We do not want to log changes to our own deletion + // if this DO owns the ChangeSummary. Do not delete + // it here as contained DOs still have a reference to it. + + if (getTypeImpl().isChangeSummaryType()) + { + ChangeSummaryPtr c = getChangeSummary(); + if (c) { + if (c->isLogging()) + { + c->endLogging(); + } + } + } + + + clearReferences(); + PropertyValueMap::iterator i = PropertyValues.begin(); + while (i != PropertyValues.end()) + { + unsigned int pindx = (*i).first; + DataObjectImplPtr dol = (*i).second; + + unset(pindx); + i = PropertyValues.begin(); + if (i != PropertyValues.end() && (*i).first == pindx && (*i).second == dol) + { + // unset has not removed the item from the list - do it + // here instead + PropertyValues.erase(i); + i = PropertyValues.begin(); + } + } + + // Theory: A DO cant get here if its still attached to anything, + //so we dont need to detach.... + //detach(); + + if (sdoValue.isSet()) + { + sdoValue = SDOValue::unsetSDOValue; + } + + if (getType().isSequencedType()) + { + if (sequence != 0) delete sequence; + } + + + if (getTypeImpl().isChangeSummaryType() ) + { + if (getChangeSummary() != 0) + { + delete localCS; + localCS = 0; + } + } + } + + void DataObjectImpl::logCreation(DataObjectImpl* dol, DataObjectImpl* cont, + const Property& theprop) + { + if (getChangeSummaryImpl() != 0 && getChangeSummaryImpl()->isLogging()) + { + getChangeSummaryImpl()->logCreation(dol,cont,theprop); + } + } + + void DataObjectImpl::logDeletion() + { + // Only log if ChangeSummary is inherited from container + + if (getChangeSummaryImpl() != 0 && getChangeSummaryImpl()->isLogging() && !getType().isChangeSummaryType()) + { + DataObjectImpl* cont = getContainerImpl(); + if (cont != 0) // log if there is a container. If there is not, then + // this can only be the object with the CS, so logging + // would not make sense. + { + const Property* p = cont->findInProperties(this); + if ( p != 0) // if the object is not in the properties, then its been + // detached, and has already been logged as deleted + { + getChangeSummaryImpl()->logDeletion(this,cont,*p, + objectToXPath(), true); + } + } + } + } + + void DataObjectImpl::logChange(const Property& prop) + { + if (getChangeSummaryImpl() != 0 && getChangeSummaryImpl()->isLogging()) + { + getChangeSummaryImpl()->logChange(this,prop); + } + } + + void DataObjectImpl::logChange(unsigned int propIndex) + { + if (getChangeSummaryImpl() != 0 && getChangeSummaryImpl()->isLogging()) + { + getChangeSummaryImpl()->logChange(this,getProperty(propIndex)); + } + } + // reference support + + void DataObjectImpl::setReference(DataObject* dol, const Property& prop) + { + LOGINFO_1(INFO,"ChangeSummary:Setting a reference to %s",prop.getName()); + + refs.push_back(new Reference(dol,prop)); + } + void DataObjectImpl::unsetReference(DataObject* dol, const Property& prop) + { + LOGINFO_1(INFO,"ChangeSummary:Unsetting a reference to %s",prop.getName()); + + for (unsigned int i=0;i< refs.size();i++) + { + if (refs[i]->getDataObject() == dol) + { + if (!strcmp(refs[i]->getProperty().getName(), + prop.getName())) + { + delete refs[i]; + refs.erase(refs.begin() + i); + } + } + } + } + + + void DataObjectImpl::clearReferences() + { + for (unsigned int i=0;igetDataObject()->unset(refs[i]->getProperty()); + } + // separate loop because the unsets may modify the refs + for (unsigned int j=0;jgetContainmentProperty(); + if (asXPathBuffer != "") + { + asXPathBuffer = "/" + asXPathBuffer; + } + + if (p.isMany()) { + DataObjectList& dol = dob->getList(p); + for (unsigned int i=0;igetContainerImpl(); + } + + asXPathBuffer = "#/" + asXPathBuffer; + + return asXPathBuffer.c_str(); +/* + char* temp1; + char* temp2; + + if (asXPathBuffer == 0) + { + asXPathBuffer = new char[2]; + sprintf(asXPathBuffer,"#"); + } + + DataObjectImpl* dob = getContainerImpl(); + DataObject*thisob = this; + while (dob != 0){ + const Property& p = thisob->getContainmentProperty(); + const char* name = p.getName(); + temp1 = new char[strlen(name) + 34]; + temp1[0] = 0; + + + if (p.isMany()) { + DataObjectList& dol = dob->getList(p); + for (int i=0;igetContainerImpl(); + } + return asXPathBuffer; */ + } + + // user data support... + void* DataObjectImpl::getUserData(const char* path) + { + // Can path really be a null pointer? + if (path == 0) + { + return(getUserData(SDOString())); + } + else + { + return(getUserData(SDOString(path))); + } + } + + void* DataObjectImpl::getUserData(const SDOString& path) + { + DataObjectImpl *d; + void* v = 0; + SDOString spath; + SDOString prop; + try { + DataObjectImpl::stripPath(path, spath); + prop = findPropertyContainer(spath, &d); + if (d != 0) + { + if (!prop.empty()) + { + const Property& p = d->getProperty(prop); + if (p.getType().isDataType()) return 0; + if (p.isMany()) + { + DataObjectImpl* d2 = d->getDataObjectImpl(prop); + if (d2) v = d2->getUserData(); + return v; + } + v = d->getUserData(p); + return v; + } + return d->getUserData(); + } + return 0; + } + catch (SDORuntimeException e) + { + return 0; + } + } + + void* DataObjectImpl::getUserData(unsigned int propertyIndex) + { + if ((getProperty(propertyIndex).isMany())) + { + return 0; + } + if ((getProperty(propertyIndex).getType().isDataType())) + { + return 0; + } + DataObjectImpl* ptr = getDataObjectImpl(propertyIndex); + if (ptr) return ptr->getUserData(); + return 0; + } + + void* DataObjectImpl::getUserData(const Property& property) + { + if (property.isMany()) + { + return 0; + } + if (property.getType().isDataType()) + { + return 0; + } + DataObjectImpl* ptr = getDataObjectImpl(property); + if (ptr) return ptr->getUserData(); + return 0; + } + + void* DataObjectImpl::getUserData() + { + return userdata; + } + + void DataObjectImpl::setUserData(const char* path, void* value) + { + // Can path really be a null pointer? + if (path == 0) + { + setUserData(SDOString(), value); + } + else + { + setUserData(SDOString(path), value); + } + } + + void DataObjectImpl::setUserData(const SDOString& path, void* value) + { + SDOString spath; + SDOString prop; + DataObjectImpl *d; + try { + DataObjectImpl::stripPath(path, spath); + prop = findPropertyContainer(spath, &d); + if (d != 0) + { + if (!prop.empty()) + { + const Property& p = d->getProperty(prop); + if (p.getType().isDataType()) + return; + if (p.isMany()) + { + DataObjectImpl* d2 = d->getDataObjectImpl(prop); + if (d2) d2->setUserData(value); + return; + } + d->setUserData(p, value); + return; + } + d->setUserData(value); + return; + } + } + catch (SDORuntimeException e) + { + return; + } + + } + + void DataObjectImpl::setUserData(unsigned int propertyIndex, void* value) + { + if ((getProperty(propertyIndex).isMany())) + { + return; + } + if ((getProperty(propertyIndex).getType().isDataType())) + { + return; + } + DataObjectImpl* ptr = getDataObjectImpl(propertyIndex); + if (ptr) ptr->setUserData(value); + return; + } + + void DataObjectImpl::setUserData(const Property& property, void* value) + { + if (property.isMany()) + { + return; + } + if (property.getType().isDataType()) + { + return; + } + DataObjectImpl* ptr = getDataObjectImpl(property); + if (ptr) ptr->setUserData(value); + return; + } + + void DataObjectImpl::setUserData(void* value) + { + userdata = value; + } + + std::ostream& DataObjectImpl::printSelf(std::ostream &os) + { + SDOUtils::printDataObject(os, this); + return os; + } + + // +++ + // Extra methods to support SDOValue as an internal mechanism that + // simplifies dealing with the many interchangeable primitive data types. + + // set methods. + + void DataObjectImpl::setSDOValue(const SDOString& path, + const SDOValue& sval, + const SDOString& dataType) + { + DataObjectImpl *d = 0; + + SDOString spath; + SDOString prop; + try + { + DataObjectImpl::stripPath(path, spath); + prop = findPropertyContainer(spath, &d); + + if (d != 0) + { + if (prop.length() == 0) + { + d->setSDOValue(sval); + } + else + { + const PropertyImpl* p = d->getPropertyImpl(prop); + if ((p == 0) && (d->getType().isOpenType())) + { + // p = d->defineBytes(prop); + p = d->defineSDOValue(prop, sval); + } + + if (p == 0) + { + string msg("DataObjectImpl::setSDOValue - path not found: "); + SDO_THROW_EXCEPTION("setter", + SDOPathNotFoundException, + msg.c_str()); + } + + if (p->isReadOnly()) + { + SDOString stringBuffer = p->getName(); + stringBuffer += " is read-only."; + SDO_THROW_EXCEPTION("DataObjectImpl::setSDOValue", + SDOUnsupportedOperationException, + stringBuffer.c_str()); + } + + if ((p->isMany()) || (p->getTypeImpl()->isFromList())) + { + long l; + DataObjectList& dol = d->getList((Property&) *p); + DataObjectImpl* doi = d->findDataObject(prop, &l); + if (doi != 0) + { + doi->setSDOValue(sval); + } + else + { + dol.append(sval); + } + } + else + { + d->setSDOValue((Property&)*p, sval, dataType); + } + } + } + } + catch (SDORuntimeException e) + { + SDO_RETHROW_EXCEPTION("setSDOValue", e); + } + } + + void DataObjectImpl::setSDOValue(unsigned int propertyIndex, + const SDOValue& sval, + const SDOString& dataType) + { + setSDOValue(propertyIndex, sval, dataType, false); + } + + void DataObjectImpl::setSDOValue(unsigned int propertyIndex, + const SDOValue& sval, + const SDOString& dataType, + bool updateSequence) + { + validateIndex(propertyIndex); + + PropertyImpl *const p = getPropertyImpl(propertyIndex); + + if ((p->isMany()) || (p->getTypeImpl()->isFromList())) + { + string msg("Set value not available on many valued property: "); + msg += p->getName(); + SDO_THROW_EXCEPTION("DataObjectImpl::setSDOValue", + SDOUnsupportedOperationException, + msg.c_str()); + } + + if (p->isReadOnly()) + { + SDOString stringBuffer = p->getName(); + stringBuffer += "is read-only."; + SDO_THROW_EXCEPTION("DataObjectImpl::setSDOValue", + SDOUnsupportedOperationException, + stringBuffer.c_str()); + } + + // PropertyValues is a std::list of rdo objects. + PropertyValueMap::iterator i; + for (i = PropertyValues.begin(); i != PropertyValues.end(); ++i) + { + if ((*i).first == propertyIndex) + { + logChange(propertyIndex); + (*i).second->unsetNull(); + (*i).second->setSDOValue(sval); + + // If this is a sequenced data object then update the sequence. We + // already know that a) the property is already set and b) it + // is not a multi-valued property. + if ((getType().isSequencedType()) && updateSequence) + { + SequenceImpl* mySequence = getSequenceImpl(); + mySequence->removeAll(getProperty(propertyIndex)); + mySequence->push(getProperty(propertyIndex), 0); + } + return; + } + } + + // No existing property has the given index. + DataFactory* df = getDataFactory(); + // It is tempting to use the raw data type from the SDOValue object to + // set the type of the created DataObjectImpl but we can't because the + // SDOValue specifies a C++ type while we need an SDO type. + DataObjectImpl* b = + new DataObjectImpl(df, df->getType(Type::SDOTypeNamespaceURI, dataType.c_str())); + b->setContainer(this); + logChange(propertyIndex); + PropertyValues.push_back(rdo(propertyIndex, b)); + b->setSDOValue(sval); + + // If this is a sequenced data object then update the sequence. We + // already know that a) the property is not already set and b) it + // is not a multi-valued property. + if ((getType().isSequencedType()) && updateSequence) + { + SequenceImpl* mySequence = getSequenceImpl(); + mySequence->removeAll(getProperty(propertyIndex)); + mySequence->push(getProperty(propertyIndex), 0); + } + + return; + } + + void DataObjectImpl::setSDOValue(const Property& property, + const SDOValue& sval, + const SDOString& dataType) + { + setSDOValue(getPropertyIndexInternal(property), sval, dataType); + } + + void DataObjectImpl::setSDOValue(const Property& property, + const SDOValue& sval, + const SDOString& dataType, + bool updateSequence) + { + setSDOValue(getPropertyIndexInternal(property), sval, dataType, updateSequence); + } + + void DataObjectImpl::setSDOValue(const SDOValue& invalue) + { + sdoValue = invalue; + return; + } + + // get methods + + const SDOValue& DataObjectImpl::getSDOValue(const SDOString& path, + PropertyImpl** propertyForDefault) + { + *propertyForDefault = 0; + + DataObjectImpl* d = 0; + SDOString spath; + SDOString prop; + try + { + DataObjectImpl::stripPath(path, spath); + // It is possible for findPropertyContainer to return a 0 which caues an accvio. + prop = findPropertyContainer(spath, &d); + if (d != 0) + { + if (prop.length() == 0) + { + return d->getSDOValue(propertyForDefault); + } + else + { + PropertyImpl* p = d->getPropertyImpl(prop); + if (p != 0) + { + if ((p->isMany()) || p->getTypeImpl()->isFromList()) + { + long l; + DataObjectImpl* doi = d->findDataObject(prop, &l); + if (doi != 0) + { + return doi->getSDOValue(propertyForDefault); + } + string msg("DataObjectImpl::getSDOValue - index out of range"); + msg += path; + SDO_THROW_EXCEPTION("getter", + SDOIndexOutOfRangeException, + msg.c_str()); + } + else + { + if (!d->isSet(*p)) + { + *propertyForDefault = p; + return SDOValue::unsetSDOValue; + } + return d->getSDOValue(*p, propertyForDefault); + } + } + } + } + string msg("Object not found"); + SDO_THROW_EXCEPTION("DataObjectImpl::getSDOValue", + SDOPathNotFoundException, + msg.c_str()); + } + catch (SDORuntimeException e) { + SDO_RETHROW_EXCEPTION("getSDOValue", e); + } + } + + const SDOValue& DataObjectImpl::getSDOValue(const unsigned int propertyIndex, + PropertyImpl** propertyForDefault) + { + *propertyForDefault = 0; + + validateIndex(propertyIndex); + + // Since validateIndex didn't throw an exception, the following call + // will not return a null pointer. + PropertyImpl* targetProperty = getPropertyImpl(propertyIndex); + if ((targetProperty->isMany()) || + targetProperty->getTypeImpl()->isFromList()) + { + string msg("Get value not available on many valued property:"); + msg += targetProperty->getName(); + SDO_THROW_EXCEPTION("DataObjectImpl::getSDOValue", + SDOUnsupportedOperationException, + msg.c_str()); + } + + DataObjectImpl* d = getDataObjectImpl(propertyIndex); + if (d != 0) + { + if (!d->isNull()) + { + return d->getSDOValue(propertyForDefault); + } + else + { + return SDOValue::nullSDOValue; + } + } + + // To get here, the property does not have a value, but there are still 2 + // cases to consider: + // 1. The property has never had a value. In this case, we return + // "unset" for the value of the property. + // 2. The property did have a value at one time but since then has + // been explicitly set to null, causing the value to be discarded. In + // that case return an explicit null. + + if (isSet(propertyIndex)) + { + return SDOValue::nullSDOValue; + } + + *propertyForDefault = targetProperty; + return SDOValue::unsetSDOValue; + + } + + const SDOValue& DataObjectImpl::getSDOValue(const Property& property, + PropertyImpl** propertyForDefault) + { + return getSDOValue(getPropertyIndex(property), propertyForDefault); + } + + const SDOValue& DataObjectImpl::getSDOValue(PropertyImpl** propertyForDefault) + { + if (sdoValue.isSet()) + { + *propertyForDefault = 0; + } + else + { + *propertyForDefault = (PropertyImpl*) &(getContainmentProperty()); + } + return sdoValue; + } + + // End of SDOValue methods + // --- + + // +++ + // setBoolean using SDOValue methods + + void DataObjectImpl::setBoolean(unsigned int propertyIndex, + bool value) + { + setSDOValue(propertyIndex, SDOValue(value), "Boolean"); + } + + void DataObjectImpl::setBoolean(const Property& property, bool value) + { + setBoolean(getPropertyIndexInternal(property), value); + } + + void DataObjectImpl::setBoolean(const SDOString& path, + bool value) + { + setSDOValue(path, SDOValue(value), "Boolean"); + } + + // End of setBoolean using SDOValue methods + // --- + + // +++ + // getBoolean using SDOValue methods + + bool DataObjectImpl::getBoolean(const Property& property) + { + return getBoolean(getPropertyIndex(property)); + } + + bool DataObjectImpl::getBoolean(unsigned int propertyIndex) + { + + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(propertyIndex, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getBooleanDefault(); + } + else + { + if (result.isNull()) + { + return false; + } + else + { + return result.getBoolean(); + } + } + } + + bool DataObjectImpl::getBoolean(const SDOString& path) + { + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(path, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getBooleanDefault(); + } + else + { + if (result.isNull()) + { + return false; + } + else + { + return result.getBoolean(); + } + } + } + + // End of getBoolean using SDOValue methods + // --- + + // +++ + // setFloat using SDOValue methods + + void DataObjectImpl::setFloat(unsigned int propertyIndex, + float value) + { + setSDOValue(propertyIndex, SDOValue(value), "Float"); + } + + void DataObjectImpl::setFloat(const Property& property, float value) + { + setFloat(getPropertyIndexInternal(property), value); + } + + void DataObjectImpl::setFloat(const SDOString& path, + float value) + { + setSDOValue(path, SDOValue(value), "Float"); + } + + // End of setFloat using SDOValue methods + // --- + + // +++ + // getFloat using SDOValue methods + + float DataObjectImpl::getFloat(const Property& property) + { + return getFloat(getPropertyIndex(property)); + } + + float DataObjectImpl::getFloat(unsigned int propertyIndex) + { + + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(propertyIndex, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getFloatDefault(); + } + else + { + if (result.isNull()) + { + return 0.0F; // Default is 0 cast to return type + } + else + { + return result.getFloat(); + } + } + } + + float DataObjectImpl::getFloat(const SDOString& path) + { + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(path, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getFloatDefault(); + } + else + { + if (result.isNull()) + { + return 0.0F; // Default is 0 cast to return type + } + else + { + return result.getFloat(); + } + } + } + + // End of getFloat using SDOValue methods + // --- + + // +++ + // setDouble using SDOValue methods + + void DataObjectImpl::setDouble(unsigned int propertyIndex, + long double value) + { + setSDOValue(propertyIndex, SDOValue(value), "Double"); + } + + void DataObjectImpl::setDouble(const Property& property, long double value) + { + setDouble(getPropertyIndexInternal(property), value); + } + + void DataObjectImpl::setDouble(const SDOString& path, + long double value) + { + setSDOValue(path, SDOValue(value), "Double"); + } + + // End of setDouble using SDOValue methods + // --- + + // +++ + // getDouble using SDOValue methods + + long double DataObjectImpl::getDouble(const Property& property) + { + return getDouble(getPropertyIndex(property)); + } + + long double DataObjectImpl::getDouble(unsigned int propertyIndex) + { + + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(propertyIndex, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getDoubleDefault(); + } + else + { + if (result.isNull()) + { + return 0.0; // Default is 0 cast to return type + } + else + { + return result.getDouble(); + } + } + } + + long double DataObjectImpl::getDouble(const SDOString& path) + { + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(path, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getDoubleDefault(); + } + else + { + if (result.isNull()) + { + return 0.0; // Default is 0 cast to return type + } + else + { + return result.getDouble(); + } + } + } + + // End of getDouble using SDOValue methods + // --- + + // +++ + // setShort using SDOValue methods + + void DataObjectImpl::setShort(unsigned int propertyIndex, + short value) + { + setSDOValue(propertyIndex, SDOValue(value), "Short"); + } + + void DataObjectImpl::setShort(const Property& property, short value) + { + setShort(getPropertyIndexInternal(property), value); + } + + void DataObjectImpl::setShort(const SDOString& path, + short value) + { + setSDOValue(path, SDOValue(value), "Short"); + } + + // End of setShort using SDOValue methods + // --- + + // +++ + // getShort using SDOValue methods + + short DataObjectImpl::getShort(const Property& property) + { + return getShort(getPropertyIndex(property)); + } + + short DataObjectImpl::getShort(unsigned int propertyIndex) + { + + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(propertyIndex, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getShortDefault(); + } + else + { + if (result.isNull()) + { + return 0; // Default is 0 cast to return type + } + else + { + return result.getShort(); + } + } + } + + short DataObjectImpl::getShort(const SDOString& path) + { + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(path, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getShortDefault(); + } + else + { + if (result.isNull()) + { + return 0; // Default is 0 cast to return type + } + else + { + return result.getShort(); + } + } + } + + // End of getShort using SDOValue methods + // --- + + // +++ + // setByte using SDOValue methods + + void DataObjectImpl::setByte(unsigned int propertyIndex, + char value) + { + setSDOValue(propertyIndex, SDOValue(value), "Byte"); + } + + void DataObjectImpl::setByte(const Property& property, char value) + { + setByte(getPropertyIndexInternal(property), value); + } + + void DataObjectImpl::setByte(const SDOString& path, + char value) + { + setSDOValue(path, SDOValue(value), "Byte"); + } + + // End of setByte using SDOValue methods + // --- + + // +++ + // getByte using SDOValue methods + + char DataObjectImpl::getByte(const Property& property) + { + return getByte(getPropertyIndex(property)); + } + + char DataObjectImpl::getByte(unsigned int propertyIndex) + { + + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(propertyIndex, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getByteDefault(); + } + else + { + if (result.isNull()) + { + return 0; // Default is 0 cast to return type + } + else + { + return result.getByte(); + } + } + } + + char DataObjectImpl::getByte(const SDOString& path) + { + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(path, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getByteDefault(); + } + else + { + if (result.isNull()) + { + return 0; // Default is 0 cast to return type + } + else + { + return result.getByte(); + } + } + } + + // End of getByte using SDOValue methods + // --- + + // +++ + // setDate using SDOValue methods + + void DataObjectImpl::setDate(unsigned int propertyIndex, + const SDODate value) + { + setSDOValue(propertyIndex, SDOValue(value), "Date"); + } + + void DataObjectImpl::setDate(const Property& property, const SDODate value) + { + setDate(getPropertyIndexInternal(property), value); + } + + void DataObjectImpl::setDate(const SDOString& path, + const SDODate value) + { + setSDOValue(path, SDOValue(value), "Date"); + } + + // End of setDouble using SDOValue methods + // --- + + // +++ + // getDate using SDOValue methods + + const SDODate DataObjectImpl::getDate(const Property& property) + { + return getDate(getPropertyIndex(property)); + } + + const SDODate DataObjectImpl::getDate(unsigned int propertyIndex) + { + + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(propertyIndex, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getDateDefault(); + } + else + { + if (result.isNull()) + { + return SDODate(0); // Default is 0 cast to return type + } + else + { + return result.getDate(); + } + } + } + + const SDODate DataObjectImpl::getDate(const SDOString& path) + { + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(path, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getDateDefault(); + } + else + { + if (result.isNull()) + { + return SDODate(0); // Default is 0 cast to return type + } + else + { + return result.getDate(); + } + } + } + + // End of getDouble using SDOValue methods + // --- + + // +++ + // setInteger using SDOValue methods + + void DataObjectImpl::setInteger(unsigned int propertyIndex, + long value) + { + setSDOValue(propertyIndex, SDOValue(value), "Integer"); + } + + void DataObjectImpl::setInteger(const Property& property, long value) + { + setInteger(getPropertyIndexInternal(property), value); + } + + void DataObjectImpl::setInteger(const SDOString& path, + long value) + { + setSDOValue(path, SDOValue(value), "Integer"); + } + + // End of setInteger using SDOValue methods + // --- + + // +++ + // getInteger using SDOValue methods + + long DataObjectImpl::getInteger(const Property& property) + { + return getInteger(getPropertyIndex(property)); + } + + long DataObjectImpl::getInteger(unsigned int propertyIndex) + { + + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(propertyIndex, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getIntegerDefault(); + } + else + { + if (result.isNull()) + { + return 0; // Default is 0 cast to return type + } + else + { + return result.getInteger(); + } + } + } + + long DataObjectImpl::getInteger(const SDOString& path) + { + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(path, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getIntegerDefault(); + } + else + { + if (result.isNull()) + { + return 0; // Default is 0 cast to return type + } + else + { + return result.getInteger(); + } + } + } + + // End of getInteger using SDOValue methods + // --- + + // +++ + // setCString using SDOValue methods + + void DataObjectImpl::setCString(unsigned int propertyIndex, + const SDOString& value) + { + setSDOValue(propertyIndex, SDOValue(value), "String"); + } + + void DataObjectImpl::setCString(const Property& property, const SDOString& value) + { + setCString(getPropertyIndexInternal(property), value); + } + + void DataObjectImpl::setCString(const SDOString& path, + const SDOString& value) + { + setSDOValue(path, SDOValue(value), "String"); + } + + // End of setCString using SDOValue methods + // --- + + // +++ + // getCString using SDOValue methods + + const char* DataObjectImpl::getCString(const Property& property) + { + return getCString(getPropertyIndex(property)); + } + + const char* DataObjectImpl::getCString(unsigned int propertyIndex) + { + + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(propertyIndex, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getCStringDefault(); + } + else + { + if (result.isNull()) + { + return 0; // Default is 0 cast to return type + } + else + { + return result.getCString(); + } + } + } + + const char* DataObjectImpl::getCString(const SDOString& path) + { + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(path, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getCStringDefault(); + } + else + { + if (result.isNull()) + { + return 0; // Default is 0 cast to return type + } + else + { + return result.getCString(); + } + } + } + + // End of getCString using SDOValue methods + // --- + + // +++ + // setCharacter using SDOValue methods + + void DataObjectImpl::setCharacter(unsigned int propertyIndex, + wchar_t value) + { + setSDOValue(propertyIndex, SDOValue(value), "Character"); + } + + void DataObjectImpl::setCharacter(const Property& property, wchar_t value) + { + setCharacter(getPropertyIndexInternal(property), value); + } + + void DataObjectImpl::setCharacter(const SDOString& path, + wchar_t value) + { + setSDOValue(path, SDOValue(value), "Character"); + } + + // End of setByte using SDOValue methods + // --- + + // +++ + // getByte using SDOValue methods + + wchar_t DataObjectImpl::getCharacter(const Property& property) + { + return getCharacter(getPropertyIndex(property)); + } + + wchar_t DataObjectImpl::getCharacter(unsigned int propertyIndex) + { + + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(propertyIndex, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getCharacterDefault(); + } + else + { + if (result.isNull()) + { + return (wchar_t) 0; // Default is 0 cast to return type + } + else + { + return result.getCharacter(); + } + } + } + + wchar_t DataObjectImpl::getCharacter(const SDOString& path) + { + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(path, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getCharacterDefault(); + } + else + { + if (result.isNull()) + { + return (wchar_t) 0; // Default is 0 cast to return type + } + else + { + return result.getCharacter(); + } + } + } + + // End of getCharacter using SDOValue methods + // --- + + // +++ + // setLong using SDOValue methods + + void DataObjectImpl::setLong(unsigned int propertyIndex, + int64_t value) + { + setSDOValue(propertyIndex, SDOValue(value), "Long"); + } + + void DataObjectImpl::setLong(const Property& property, int64_t value) + { + setLong(getPropertyIndexInternal(property), value); + } + + void DataObjectImpl::setLong(const SDOString& path, + int64_t value) + { + setSDOValue(path, SDOValue(value), "Long"); + } + + // End of setLong using SDOValue methods + // --- + + // +++ + // getLong using SDOValue methods + + int64_t DataObjectImpl::getLong(const Property& property) + { + return getLong(getPropertyIndex(property)); + } + + int64_t DataObjectImpl::getLong(unsigned int propertyIndex) + { + + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(propertyIndex, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getLongDefault(); + } + else + { + if (result.isNull()) + { + return 0L; // Default is 0 cast to return type + } + else + { + return result.getLong(); + } + } + } + + int64_t DataObjectImpl::getLong(const SDOString& path) + { + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(path, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getLongDefault(); + } + else + { + if (result.isNull()) + { + return 0; // Default is 0 cast to return type + } + else + { + return result.getLong(); + } + } + } + + // End of getLong using SDOValue methods + // --- + + // The input value is a non-null terminated sequence of bytes. + void DataObjectImpl::setBytes(unsigned int propertyIndex, const char* value, unsigned int len) + { + setSDOValue(propertyIndex, SDOValue(value, len), "Bytes"); + } + + void DataObjectImpl::setString(unsigned int propertyIndex, const wchar_t* value, unsigned int len) + { + setSDOValue(propertyIndex, SDOValue(value, len), "String"); + } + + unsigned int DataObjectImpl::getBytes(unsigned int propertyIndex, char* valptr , unsigned int max) + { + + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(propertyIndex, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getBytesDefault(valptr, max); + } + else + { + if (result.isNull()) + { + return 0; + } + else + { + return result.getBytes(valptr, max); + } + } + } + + unsigned int DataObjectImpl::getString(unsigned int propertyIndex, wchar_t* valptr , unsigned int max) + { + + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(propertyIndex, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getStringDefault(valptr, max); + } + else + { + if (result.isNull()) + { + return 0; + } + else + { + return result.getString(valptr, max); + } + } + } + + unsigned int DataObjectImpl::getString(const SDOString& path, wchar_t* valptr , unsigned int max) + { + + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(path, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getStringDefault(valptr, max); + } + else + { + if (result.isNull()) + { + return 0; + } + else + { + return result.getString(valptr, max); + } + } + } + + unsigned int DataObjectImpl::getBytes(const SDOString& path, char* valptr , unsigned int max) + { + PropertyImpl* propertyForDefault = 0; + const SDOValue& result = getSDOValue(path, &propertyForDefault); + + if (!result.isSet()) + { + return propertyForDefault->getBytesDefault(valptr, max); + } + else + { + if (result.isNull()) + { + return 0; // Default is 0 cast to return type + } + else + { + return result.getBytes(valptr, max); + } + } + } + + void DataObjectImpl::setString(const char* path, const wchar_t* value, unsigned int len) + { + setString(SDOString(path), value, len); + } + + void DataObjectImpl::setBytes(const char* path, const char* value, unsigned int len) + { + setBytes(SDOString(path), value, len); + } + + void DataObjectImpl::setString(const SDOString& path, const wchar_t* value, unsigned int len) + { + setSDOValue(path, SDOValue(value, len), "String"); + } + + + void DataObjectImpl::setBytes(const SDOString& path, const char* value, unsigned int len) + { + setSDOValue(path, SDOValue(value, len), "Bytes"); + } + + unsigned int DataObjectImpl::getString(const Property& property, wchar_t* val, unsigned int max) + { + return getString(getPropertyIndex(property), val, max); + } + + unsigned int DataObjectImpl::getBytes(const Property& property, char* val, unsigned int max) + { + return getBytes(getPropertyIndex(property), val, max); + } + + void DataObjectImpl::setString(const Property& property, const wchar_t* value, unsigned int len) + { + setString(getPropertyIndexInternal(property),value, len); + } + + void DataObjectImpl::setBytes(const Property& property, const char* value, unsigned int len) + { + setBytes(getPropertyIndexInternal(property),value, len); + } + +}; +}; diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectImpl.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectImpl.h new file mode 100644 index 0000000000..9162b95a3b --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectImpl.h @@ -0,0 +1,729 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _DATAOBJECTIMPL_H_ +#define _DATAOBJECTIMPL_H_ +#include "commonj/sdo/DataObject.h" + +#include "commonj/sdo/disable_warn.h" + +#include +#include +#include + +#include + + +#include "commonj/sdo/Property.h" +#include "commonj/sdo/TypeImpl.h" +#include "commonj/sdo/DataFactory.h" +#include "commonj/sdo/SequenceImpl.h" +#include "commonj/sdo/DataObjectListImpl.h" +#include "commonj/sdo/PropertyList.h" + +#include "commonj/sdo/RefCountingPointer.h" +#include "commonj/sdo/ChangeSummaryImpl.h" +#include "commonj/sdo/SDODate.h" +#include "commonj/sdo/SDOValue.h" + +namespace commonj{ +namespace sdo{ + +class DataGraph; +class DataObjectImpl; +class DataObjectListImpl; +class DataFactory; + + +#define DataObjectImplPtr RefCountingPointer +#define ChangeSummaryImplPtr RefCountingPointer + +/** + * rdo is an internal class holding a property value in a data object. + */ + +class rdo { +public: + unsigned int first; + DataObjectImplPtr second; + rdo(unsigned int infirst, DataObjectImpl* insecond); + rdo(); + rdo (const rdo& inrdo); + virtual ~rdo(); +}; + +typedef std::list< rdo > PropertyValueMap; + + + /** + * DataObjectImpl implements the abstract class DataObject. + * + * A data object is a representation of some structured data. + * it is the fundamental component in the SDO (Service Data Objects) package. + * Data objects support reflection, path-based accesss, convenience creation + * and deletion methods,and the ability to be part of a data graph. + * Each data object holds its data as a series of properties. + * Properties can be accessed by name, property index, or using the property + * meta object itself. + * A data object can also contain references to other data objects, through + * reference-type properties. + * A data object has a series of convenience accessors for its properties. + * These methods either use a path (String), a property index, + * or the property's meta object itself, to identify the property. + * Some examples of the path-based accessors are as follows: + * DataObjectPtr company = ...; + * company->getString("name"); + * company->setString("name", "acme"); + * company->getString("department.0/name") + * .n indexes from 0. + * company->getString("department[1]/name") [] indexes from 1. + * company->getDataObject("department[number=123]") returns the department where number=123 + * company->getDataObject("..") returns the containing data object + * company->getDataObject("/") returns the root containing data object + * There are specific accessors for the primitive types and commonly used + * data types like String. + */ + +class DataObjectImpl : public DataObject +{ + public: + + DataObjectImpl(); + DataObjectImpl(const TypeImpl& t); + DataObjectImpl(DataFactory* dataFactory, const Type& t); + + // This one only needs the values, and the type/prop info. The rest + // is not copied and would be unsafe to do so. This is used to + // store the cloned info in a change summary. + + DataObjectImpl(DataObjectImplPtr indo); + + virtual ~DataObjectImpl(); + + ///////////////////////////////////////////////////////////////////////// + // Introspection + ///////////////////////////////////////////////////////////////////////// + + /** getPropertyIndex gets the unique index of a property + * + * A property of a data object has a unique index associated with it. + * This method gets a property index for this object from the property, + * or throw SDOPropertyNotFoundException if the property is not part + * of this data object. + */ + + virtual unsigned int getPropertyIndex(const Property& p); + + /** + * These are just like getType().getProperty(), but may return + * values other than the property list for open types. + */ + + virtual const Property& getProperty(unsigned int index); + + virtual const Property& getProperty(const char* prop); + virtual const Property& getProperty(const SDOString& prop); + + virtual PropertyImpl* getPropertyImpl(const SDOString& prop); + + virtual PropertyImpl* getPropertyImpl(unsigned int index); + + /** getInstanceProperties gets the props of the current object. + * + * Returns a read-only List of the Properties currently used in this DataObject. + * This list will contain all of the properties in getType().getProperties() + * and any properties where isSet(property) is true. + * For example, properties resulting from the use of + * open or mixed XML content are present if allowed by the Type. + * The list does not contain duplicates. + * The order of the properties in the list begins with getType().getProperties() + * and the order of the remaining properties is determined by the implementation. + * The same list will be returned unless the DataObject is updated so that + * the contents of the list change + * Returns the list of Properties currently used in this DataObject. + */ + + virtual PropertyList getInstanceProperties(); + + /** getContainer get the containing object + * + * Returns the containing data object + * or 0 if there is no container. + */ + + virtual DataObjectPtr getContainer(); + + /** getContainmentProperty returns the property containing this object + * + * Return the Property of the data object containing this data object + * or throw an SDOPropertyNotFoundException if there is no container. + */ + + virtual const Property& getContainmentProperty(); + + /** getType returns the data object's type. + * + * getType returns the data object's type. + * The type defines the properties available for reflective access. + */ + + virtual const Type& getType(); + + virtual const Type::Types getTypeEnum(); + + + + /////////////////////////////////////////////////////////////////////////// + // get/set + /////////////////////////////////////////////////////////////////////////// + + + /** getDataObject returns a data object by path, index or property + * + * Returns the value of a property of either this object or an object + * reachable from it, as identified by the specified path. + */ + + virtual DataObjectPtr getDataObject(const SDOString& path); + virtual DataObjectPtr getDataObject(const char* path); + virtual DataObjectPtr getDataObject(unsigned int propertyIndex); + virtual DataObjectPtr getDataObject(const Property& property); + + /** setDataObject sets a value by path, index or property + * + * Sets a property of either this object or an object reachable from it, + * as identified by the specified path, + * to the specified value. + */ + + virtual void setDataObject(const char* path, DataObjectPtr value); + virtual void setDataObject(const char* path, DataObjectPtr value, bool updateSequence); + virtual void setDataObject(const SDOString& path, DataObjectPtr value); + virtual void setDataObject(const SDOString& path, DataObjectPtr value, bool updateSequence); + virtual void setDataObject(unsigned int propertyIndex, DataObjectPtr value); + virtual void setDataObject(unsigned int propertyIndex, DataObjectPtr value, bool updateSequence); + virtual void setDataObject(const Property& property, DataObjectPtr value); + virtual void setDataObject(const Property& property, DataObjectPtr value, bool updateSequence); + + /** getBoolean returns a boolean by path, index or property + * + * Returns the value of a property of either this object or an object + * reachable from it, as identified by the specified path. + */ + + virtual bool getBoolean(const char* path); + virtual bool getBoolean(const SDOString& path); + virtual bool getBoolean(unsigned int propindex); + virtual bool getBoolean(const Property& p); + + virtual void setBoolean(const char* path, bool b); + virtual void setBoolean(const SDOString& path, bool b); + virtual void setBoolean(unsigned int propindex, bool b); + virtual void setBoolean(const Property& p, bool b); + + virtual char getByte(const char* path); + virtual char getByte(const SDOString& path); + virtual char getByte(unsigned int propindex); + virtual char getByte(const Property& p); + + virtual void setByte(const char* path, char c); + virtual void setByte(const SDOString& path, char c); + virtual void setByte(unsigned int propindex, char c); + virtual void setByte(const Property& p, char c); + + virtual wchar_t getCharacter(const char* path); + virtual wchar_t getCharacter(const SDOString& path); + virtual wchar_t getCharacter(unsigned int propindex); + virtual wchar_t getCharacter(const Property& p); + + virtual void setCharacter(const char* path, wchar_t c); + virtual void setCharacter(const SDOString& path, wchar_t c); + virtual void setCharacter(unsigned int propindex, wchar_t c); + virtual void setCharacter(const Property& p, wchar_t c); + + virtual unsigned int getLength(const SDOString& path) ; + virtual unsigned int getLength(const char* path) ; + virtual unsigned int getLength(unsigned int propindex) ; + virtual unsigned int getLength(const Property& p) ; + virtual unsigned int getLength() ; + + virtual unsigned int getBytes(const char* path, char* buf, unsigned int max) ; + virtual unsigned int getBytes(const SDOString& path, char* buf, unsigned int max) ; + virtual unsigned int getBytes(unsigned int propindex, char* buf, unsigned int max) ; + virtual unsigned int getBytes(const Property& p, char* buf, unsigned int max) ; + + virtual void setBytes(const char* path, const char* c, unsigned int len) ; + virtual void setBytes(const SDOString& path, const char* c, unsigned int len) ; + virtual void setBytes(unsigned int propindex, const char* c,unsigned int len) ; + virtual void setBytes(const Property& p, const char* c,unsigned int len) ; + + virtual unsigned int getString(const SDOString& path, wchar_t* buf, unsigned int max); + virtual unsigned int getString(const char* path, wchar_t* buf, unsigned int max) ; + virtual unsigned int getString(unsigned int propindex,wchar_t* buf, unsigned int max) ; + virtual unsigned int getString(const Property& p,wchar_t* buf, unsigned int max) ; + + virtual void setString(const SDOString& path, const wchar_t* c,unsigned int len); + virtual void setString(const char* path, const wchar_t* c,unsigned int len) ; + virtual void setString(unsigned int propindex, const wchar_t* c,unsigned int len) ; + virtual void setString(const Property& p, const wchar_t* c,unsigned int len) ; + + virtual const SDODate getDate(const SDOString& path); + virtual const SDODate getDate(const char* path); + virtual const SDODate getDate(unsigned int propindex); + virtual const SDODate getDate(const Property& p); + + virtual void setDate(const SDOString& path, const SDODate d); + virtual void setDate(const char* path, const SDODate d); + virtual void setDate(unsigned int propindex, const SDODate d); + virtual void setDate(const Property& p, const SDODate d); + + virtual long double getDouble(const SDOString& path); + virtual long double getDouble(const char* path); + virtual long double getDouble(unsigned int propindex); + virtual long double getDouble(const Property& p); + + virtual void setDouble(const SDOString& path, long double d); + virtual void setDouble(const char* path, long double d); + virtual void setDouble(unsigned int propindex, long double d); + virtual void setDouble(const Property& p, long double d); + + virtual float getFloat(const SDOString& path); + virtual float getFloat(const char* path); + virtual float getFloat(unsigned int propindex); + virtual float getFloat(const Property& p); + + virtual void setFloat(const SDOString& path, float f); + virtual void setFloat(const char* path, float f); + virtual void setFloat(unsigned int propindex, float f); + virtual void setFloat(const Property& p, float f); + + virtual long getInteger(const SDOString& path); + virtual long getInteger(const char* path); + virtual long getInteger(unsigned int propindex); + virtual long getInteger(const Property& p); + + virtual void setInteger(const SDOString& path, long i); + virtual void setInteger(const char* path, long i); + virtual void setInteger(unsigned int propindex, long i); + virtual void setInteger(const Property& p, long i); + + virtual /*long long*/ int64_t getLong(const SDOString& path); + virtual /*long long*/ int64_t getLong(const char* path); + virtual /*long long*/ int64_t getLong(unsigned int propindex); + virtual /*long long*/ int64_t getLong(const Property& p); + + virtual void setLong(const SDOString& path, /*long long*/ int64_t l); + virtual void setLong(const char* path, /*long long*/ int64_t l); + virtual void setLong(unsigned int propindex, /*long long*/ int64_t l); + virtual void setLong(const Property& p, /*long long*/ int64_t l); + + virtual short getShort(const SDOString& path); + virtual short getShort(const char* path); + virtual short getShort(unsigned int propindex); + virtual short getShort(const Property& p); + + virtual void setShort(const SDOString& path, short s); + virtual void setShort(const char* path, short s); + virtual void setShort(unsigned int propindex, short s); + virtual void setShort(const Property& p, short s); + + virtual const char* getCString(const char* path); + virtual const char* getCString(const SDOString& path); + virtual const char* getCString(unsigned int propertyIndex); + virtual const char* getCString(const Property& prop); + + virtual void setCString(const char* path, const char* value); + virtual void setCString(unsigned int propertyIndex, const char* value); + virtual void setCString (const Property& prop, const char* value); + + virtual void setCString(const SDOString& path, const SDOString& value); + virtual void setCString(unsigned int propertyIndex, const SDOString& value); + virtual void setCString (const Property& prop, const SDOString& value); + + /** setNull sets a data object value to null. + * + * A DataObjectType or DataType value may be set or unset. If it is set, then + * it may have a value, or it may be set to null. A distinction is drawn between + * being unset, having the default value, being set and being null. + * When the value of an integer (for example) is returned as zero, it could have + * been set to zero, or it could be null. Use isNull() to verify. + */ + + virtual void setNull(const SDOString& path); + virtual void setNull(const char* path); + virtual void setNull(unsigned int propertyIndex); + virtual void setNull(const Property& prop); + + virtual bool isNull(const SDOString& path); + virtual bool isNull(const char* path); + virtual bool isNull(unsigned int propertyIndex); + virtual bool isNull(const Property& prop); + + virtual bool isSet(const char* path); + virtual bool isSet(const SDOString& path); + virtual bool isSet(unsigned int propertyIndex); + virtual bool isSet(const Property& property); + + virtual bool isValid(const SDOString& path); + virtual bool isValid(const char* path); + virtual bool isValid(unsigned int propertyIndex); + virtual bool isValid(const Property& property); + + virtual void unset(const char* path); + virtual void unset(const SDOString& path); + virtual void unset(unsigned int propertyIndex); + virtual void unset(const Property& property); + + + /////////////////////////////////////////////////////////////////////////// + // Sequences + /////////////////////////////////////////////////////////////////////////// + + /** getSequence returns the sequence for a data object + * + * Returns the value of a Sequence property identified by + * the specified path. See Sequence. + */ + + virtual SequenceImpl* getSequenceImpl(); + virtual SequencePtr getSequence(); + virtual SequencePtr getSequence(const char* path); + virtual SequencePtr getSequence(const SDOString& path); + virtual SequencePtr getSequence(unsigned int propertyIndex); + virtual SequencePtr getSequence(const Property& property); + + + /////////////////////////////////////////////////////////////////////////// + // Creation of dataobjects + /////////////////////////////////////////////////////////////////////////// + + /** createDataObject creates a data object value + * + * Returns a new data object contained by this object using the + * specified property,which must be a containment property. + * The type of the created object is the declared type + * of the specified property. + * If the property is many valued, this method adds an element to the + * list, otherwise it sets the value, removing any old value. + */ + + virtual DataObjectPtr createDataObject(const char* propertyName); + virtual DataObjectPtr createDataObject(const SDOString& propertyName); + virtual DataObjectPtr createDataObject(unsigned int propertyIndex); + virtual DataObjectPtr createDataObject(const Property& property); + + + /** + * See if the property currently exists + */ + + virtual bool hasProperty(const char* name); + virtual bool hasProperty(const SDOString& name); + + + virtual void detach(); + + virtual void clear(); + + + /////////////////////////////////////////////////////////////////////////// + // Lists + /////////////////////////////////////////////////////////////////////////// + + /** getList gets the value of a many-valued property + * + * Many valued properties are returned as lists of DataObjects. + * These lists may contain primitives or data objects, but they behave + * like data objects. + * Getting a many valued integer consists of getting the list, then + * using the DataObjectList API to getInteger() for each list element. + */ + + virtual DataObjectList& getList(const char* path); + virtual DataObjectList& getList(const SDOString& path); + virtual DataObjectList& getList(unsigned int propIndex); + virtual DataObjectList& getList(const Property& p); + virtual DataObjectList& getList(); + virtual DataObjectListImpl* getListImpl(); + + void setList( DataObjectList* theList); + + /////////////////////////////////////////////////////////////////////////// + // Change Summary + /////////////////////////////////////////////////////////////////////////// + + /** getChangeSummary get the applicable change summary + * + * This method gets the applicable change summary for a data object. + * The summary is not necessarily attached to the data object, it may be + * the summary for a parent data object. No object with a summary attached + * may be a child of another object with a summary attached. + * See the ChangeSummary API for details of using the change sumamry. + */ + + virtual SDO_API ChangeSummaryPtr getChangeSummary(const char* path); + virtual SDO_API ChangeSummaryPtr getChangeSummary(const SDOString& path); + virtual SDO_API ChangeSummaryPtr getChangeSummary(unsigned int propIndex); + virtual SDO_API ChangeSummaryPtr getChangeSummary(const Property& prop); + virtual SDO_API ChangeSummaryPtr getChangeSummary(); + + + virtual bool getBoolean(); + virtual void setBoolean(bool b); + virtual char getByte(); + virtual void setByte(char c); + virtual wchar_t getCharacter(); + virtual void setCharacter(wchar_t c); + virtual unsigned int getString(wchar_t* buf, unsigned int max); + virtual unsigned int getBytes(char* buf, unsigned int max); + virtual void setString(const wchar_t* buf, unsigned int len); + virtual void setBytes(const char* c, unsigned int len); + virtual short getShort(); + virtual void setShort(short s); + virtual long getInteger(); + virtual void setInteger(long s); + virtual /* long long*/ int64_t getLong(); + virtual void setLong(/* long long */ int64_t i); + virtual float getFloat(); + virtual void setFloat(float b); + virtual long double getDouble(); + virtual void setDouble(long double d); + virtual const SDODate getDate(); + virtual void setDate(const SDODate d); + virtual const char* getCString(); + virtual void setCString(const char* s); + virtual void setCString(const SDOString& s); + virtual void setSDOValue(const SDOValue& s); + virtual DataObjectImpl* getDataObject(); + virtual void setDataObject(DataObject* d); + + // null support + virtual bool isNull(); + virtual void setNull(); + virtual void unsetNull(); + + // change logging is used by the dataobjectlistimpl + virtual void logChange(const Property& prop); + virtual void logChange(unsigned int propIndex); + virtual void logDeletion(); + virtual void logCreation(DataObjectImpl* dol, + DataObjectImpl* cont, const Property& prop); + + // reference support + virtual void setReference(DataObject* dob, const Property& prop); + virtual void unsetReference(DataObject* dob, const Property& prop); + virtual void clearReferences(); + + // user data support + virtual void setUserData(const char* path,void* value); + virtual void setUserData(const SDOString& path, void* value); + virtual void setUserData(unsigned int propertyIndex, void* value); + virtual void setUserData(const Property& property, void* value); + virtual void setUserData(void* value); + virtual void* getUserData(const char* path); + virtual void* getUserData(const SDOString& path); + virtual void* getUserData(unsigned int propertyIndex); + virtual void* getUserData(const Property& property); + virtual void* getUserData(); + + virtual void setContainer(DataObjectImpl* d); + DataObjectImpl* getContainerImpl(); + + // builds a temporary XPath for this object. + const char* objectToXPath(); + + // The data factory can be used to create new data objects within + // the Type system of this data object + // + + SDO_API DataFactory* getDataFactory(); + + // open type support + virtual void setInstancePropertyType(unsigned int index, + const Type* t); + + /** + * defineProperty is used by open type support. + * This method and its siblings define a new property on an + * open type when a setting is requested. + */ + virtual const PropertyImpl* defineProperty(const SDOString& propname, + const Type& t); + + virtual const PropertyImpl* defineSDOValue(const SDOString& propname, + const SDOValue& sval); + virtual const PropertyImpl* defineBoolean(const SDOString& propname); + virtual const PropertyImpl* defineByte(const SDOString& propname); + virtual const PropertyImpl* defineCharacter(const SDOString& propname); + virtual const PropertyImpl* defineString(const SDOString& propname); + virtual const PropertyImpl* defineBytes(const SDOString& propname); + virtual const PropertyImpl* defineShort(const SDOString& propname); + virtual const PropertyImpl* defineInteger(const SDOString& propname); + virtual const PropertyImpl* defineLong(const SDOString& propname); + virtual const PropertyImpl* defineFloat(const SDOString& propname); + virtual const PropertyImpl* defineDouble(const SDOString& propname); + virtual const PropertyImpl* defineDate(const SDOString& propname); + virtual const PropertyImpl* defineCString(const SDOString& propname); + virtual const PropertyImpl* defineDataObject(const SDOString& propname, + const Type&t ); + virtual const PropertyImpl* defineDataObject(const char* propname, + const char* typeURI, const char* typeName ); + virtual const PropertyImpl* defineList(const char* propname); + virtual void undefineProperty(unsigned int index); + virtual const TypeImpl& getTypeImpl(); + virtual void setDataFactory(DataFactory *df); + + virtual std::ostream& printSelf(std::ostream &os); + + virtual const SDOValue& getSDOValue(PropertyImpl** propertyForDefault); + virtual const SDOValue& getSDOValue(const unsigned int propertyIndex, + PropertyImpl** propertyForDefault); + virtual const SDOValue& getSDOValue(const Property& property, + PropertyImpl** propertyForDefault); + virtual const SDOValue& getSDOValue(const SDOString& path, + PropertyImpl** propertyForDefault); + virtual void setSDOValue(const SDOString& path, const SDOValue& sval, const SDOString& dataType); + virtual void setSDOValue(unsigned int propindex, const SDOValue& sval, const SDOString& dataType); + virtual void setSDOValue(unsigned int propindex, const SDOValue& sval, const SDOString& dataType, bool updateSequence); + virtual void setSDOValue(const Property& p, const SDOValue& sval, const SDOString& dataType); + virtual void setSDOValue(const Property& p, const SDOValue& sval, const SDOString& dataType, bool updateSequence); + + + +private: + /** + * This method is used internally to find the index of a + * property. If differs from the public getPropertyIndex method + * in that if the type of the containing object is open a new + * index is created. In the public version and error is thrown + */ + virtual unsigned int getPropertyIndexInternal(const Property& p); + + virtual void validateIndex(unsigned int index); + virtual void checkFactory(DataObjectPtr dob, unsigned int propertyIndex); + virtual void checkType( const Property& prop, + const Type& objectType); + + virtual bool remove(DataObjectImpl* indol); + virtual bool isSet(const Property& prop, unsigned int propertyIndex); + + + virtual DataObjectImpl* getDataObjectImpl(const SDOString& path); + virtual DataObjectImpl* getDataObjectImpl(unsigned int propertyIndex); + virtual DataObjectImpl* getDataObjectImpl(const Property& property); + + virtual DataObjectPtr + createDataObject(const Property& property, + const char* namespaceURI, + const char* typeName); + + DataObjectImpl* findDataObject(const SDOString& token, long* index); + const Property* findInProperties(DataObject* ob); + + SDOString findPropertyContainer(const SDOString& path, DataObjectImpl** din); + + char* stripPath(const char* path); + void stripPath(const SDOString& path, SDOString& result); + + + // Does not keep a reference counted pointer to the container. + DataObjectImpl* container; + + PropertyValueMap PropertyValues; + + TypeImpl* ObjectType; + + DataObjectListImpl* listValue; + + // Holds the value as an SDOValue object, if the value is a primitive data type. + SDOValue sdoValue; + + // If the value is a data object, it is recorded here. + DataObjectImpl* doValue; + + // holds the Xpath to this object if requested. + std::string asXPathBuffer; + + // The data object holds a counted reference to the data factory. + DataFactoryPtr factory; + + + // Support for open types + unsigned int openBase; + std::list openProperties; + + static const char* templateString; + + // Data may be set to null in any data object + bool isnull; + + // user supplied 32 bit value. + void* userdata; + + // + // The sequence, if this is a sequenced type - not + // reference counted by the data object + // + SequenceImpl* sequence; + + // + // The change summary if this is a summarised type + // not reference counted by the data object - only by + // clients + // + + ChangeSummaryImpl* getChangeSummaryImpl(); + ChangeSummaryImpl* getSummary(); + ChangeSummaryImpl* localCS; + + + // reference type support + + class Reference + { + public: + DataObject* getDataObject() + { + return referer; + } + const Property& getProperty() + { + return refprop; + } + Reference(DataObject* d, const Property& p) : refprop(p), referer(d) + { + } + private: + DataObject* referer; + const Property& refprop; + }; + + typedef std::vector REFERENCE_LIST; + + REFERENCE_LIST refs; + + + +}; +}; +}; + +#endif //_DATAOBJECTIMPL_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectInstance.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectInstance.cpp new file mode 100644 index 0000000000..c3a461b100 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectInstance.cpp @@ -0,0 +1,71 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/DataObjectInstance.h" +using commonj::sdo::CopyHelper; + + + +namespace commonj +{ + namespace sdo + { + // ============ + // Constructors + // ============ + DataObjectInstance::DataObjectInstance() + { + } + + DataObjectInstance::DataObjectInstance(const DataObjectPtr& theDO) + { + dataObject = CopyHelper::copy(theDO); + } + + // ========== + // Destructor + // ========== + DataObjectInstance::~DataObjectInstance() + { + } + + // =================================== + // Copy constructor: deep copy the DO + // =================================== + DataObjectInstance::DataObjectInstance(const DataObjectInstance& doi) + { + dataObject = CopyHelper::copy(doi.dataObject); + } + + // ============================= + // operator= : deep copy the DO + // ============================= + DataObjectInstance& DataObjectInstance::operator=(const DataObjectInstance& doi) + { + if (this != &doi) + { + dataObject = CopyHelper::copy(doi.dataObject); + } + return *this; + } + + } // End namespace sca +} // End namespace osoa diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectInstance.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectInstance.h new file mode 100644 index 0000000000..85a621194a --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectInstance.h @@ -0,0 +1,62 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef commonj_sdo_DataObjectInstance_h +#define commonj_sdo_DataObjectInstance_h + + +#include "commonj/sdo/export.h" +#include "commonj/sdo/SDO.h" + + +namespace commonj +{ + namespace sdo + { +/** + * DataObjectInstance is a class which allows DataObjects to be considered + * as instances rather than data object pointers. + */ + class DataObjectInstance + { + + public: + SDO_API DataObjectInstance(); + SDO_API virtual ~DataObjectInstance(); + + SDO_API DataObjectInstance(const DataObjectPtr& theDO); + SDO_API DataObjectInstance(const DataObjectInstance&); + + SDO_API DataObjectInstance& operator=(const DataObjectInstance&); + SDO_API bool operator!() {return (!dataObject);} + SDO_API operator bool() {return !!dataObject;} + + SDO_API DataObject* operator->() {return dataObject;} + + SDO_API DataObjectPtr getDataObject() {return dataObject;} + SDO_API operator DataObjectPtr() {return dataObject;} + private: + DataObjectPtr dataObject; + }; + } // End namespace sdo +} // End namespace commonj + +#endif // commonj_sdo_DataObjectInstance_h diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectList.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectList.cpp new file mode 100644 index 0000000000..0e60693c55 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectList.cpp @@ -0,0 +1,43 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/DataObjectList.h" + +namespace commonj{ +namespace sdo { + +/** + * + * List for retrieving many valued property values. + * + * DataObjectList provides an API for getting and setting values in + * many valued properties. The list deals with both DataType and + * DataObjectType properties. + */ + +DataObjectList::~DataObjectList() +{ + +} + +}; +}; + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectList.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectList.h new file mode 100644 index 0000000000..c5ad6c5e86 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectList.h @@ -0,0 +1,202 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _DATAOBJECTLIST_H_ +#define _DATAOBJECTLIST_H_ + + +#include "commonj/sdo/export.h" +#include "commonj/sdo/RefCountingPointer.h" +#include "commonj/sdo/DataObject.h" +#include "commonj/sdo/SDODate.h" +#include "commonj/sdo/SDOValue.h" +#include + + +namespace commonj{ +namespace sdo{ + +/** + * + * List for retrieving many valued property values, DataType or DataObjectType. + * + * DataObjectList provides an API for getting and setting values in + * many valued properties. The list deals with both DataType and + * DataObjectType properties. + */ + +class DataObjectList +{ +public: + virtual ~DataObjectList(); + + /** [] is a index operator, and returns a dataobject. + * + * The index operator returns a data object, even if the + * list is of a DataType. The data object can yield its true value using + * getInteger() etc. Alternatively, list elements can be accessed + * with their correct type using the list getInteger(index) api. + */ + + virtual SDO_API DataObjectPtr operator[] (unsigned int pos) = 0; + virtual SDO_API const DataObjectPtr operator[] (unsigned int pos) const = 0; + + /** size returns the number of elements. + * + * The size method returns the number of elements in the list + */ + + virtual SDO_API unsigned int size () const = 0; + + /** getBoolean returns a boolean at an index + * + * Each of the DataTypes has a corresponding getter and setter + * overload. getBoolean returns a bool, getByte returns a char + * etc + */ + + virtual SDO_API bool getBoolean(unsigned int index) const = 0; + virtual SDO_API char getByte(unsigned int index) const = 0; + virtual SDO_API wchar_t getCharacter(unsigned int index) const = 0; + virtual SDO_API unsigned int getString(unsigned int index, wchar_t* value, + unsigned int max) const = 0; + virtual SDO_API unsigned int getBytes(unsigned int index, char* value, + unsigned int max) const = 0; + virtual SDO_API short getShort(unsigned int index) const = 0; + virtual SDO_API long getInteger(unsigned int index) const = 0; + virtual SDO_API int64_t getLong(unsigned int index) const = 0; + virtual SDO_API float getFloat(unsigned int index) const = 0; + virtual SDO_API long double getDouble(unsigned int index) const = 0; + virtual SDO_API const SDODate getDate(unsigned int index) const = 0; + virtual SDO_API const char* getCString(unsigned int index) const = 0; + virtual SDO_API DataObjectPtr getDataObject(unsigned int index) const = 0; + + virtual SDO_API void setBoolean(unsigned int index, bool d) = 0; + virtual SDO_API void setByte(unsigned int index, char d) = 0; + virtual SDO_API void setCharacter(unsigned int index, wchar_t d) = 0; + virtual SDO_API void setString(unsigned int index, const wchar_t* d, unsigned int len) = 0; + virtual SDO_API void setBytes(unsigned int index, const char* d, unsigned int len) = 0; + virtual SDO_API void setShort(unsigned int index, short d) = 0; + virtual SDO_API void setInteger(unsigned int index, long d) = 0; + virtual SDO_API void setLong(unsigned int index, int64_t d) = 0; + virtual SDO_API void setFloat(unsigned int index, float d) = 0; + virtual SDO_API void setDouble(unsigned int index, long double d) = 0; + virtual SDO_API void setDate(unsigned int index, const SDODate d) = 0; + virtual SDO_API void setCString(unsigned int index, char* d) = 0; + virtual SDO_API void setCString(unsigned int index, const SDOString& d) = 0; + virtual SDO_API void setDataObject(unsigned int index, DataObjectPtr dob) = 0; + + /** getLength returns the length of a string element + * + * getLength behaves like DataObject::getlength. It returns the length + * of a bytes or string buffer such that space can be allocated for the + * values from getBytes() and getString() + */ + + virtual SDO_API unsigned int getLength(unsigned int index) const = 0; + + /** insert and append put items into the list + * + * insert and append have overrides for each of the DataTypes, and + * for DataObject. Insert inserts before the element number given. If the insertion + * point is off the end of the list, then an append is performed. + * Append puts the element on the end of the list. + */ + + + virtual SDO_API void insert (unsigned int index, DataObjectPtr d) = 0; + virtual SDO_API void append (DataObjectPtr d) = 0; + + virtual SDO_API void insert (unsigned int index, bool d) = 0; + virtual SDO_API void append (bool d) = 0; + + virtual SDO_API void insert (unsigned int index, char d) = 0; + virtual SDO_API void append (char d) = 0; + + virtual SDO_API void insert (unsigned int index, wchar_t d) = 0; + virtual SDO_API void append (wchar_t d) = 0; + + virtual SDO_API void insert (unsigned int index, const wchar_t* d, unsigned int len) = 0; + virtual SDO_API void append (const wchar_t* d, unsigned int len) = 0; + + virtual SDO_API void insert (unsigned int index, const char* d, unsigned int len) = 0; + virtual SDO_API void append (const char* d, unsigned int len) = 0; + + virtual SDO_API void insert (unsigned int index, const char* d) = 0; + virtual SDO_API void insert (unsigned int index, const SDOString& d) = 0; + virtual SDO_API void append (const char* d) = 0; + virtual SDO_API void append (const SDOString& d) = 0; + + virtual SDO_API void append (const SDOValue& sval) = 0; + + virtual SDO_API void insert (unsigned int index, short d) = 0; + virtual SDO_API void append (short d) = 0; + + virtual SDO_API void insert (unsigned int index, const SDODate d) = 0; + virtual SDO_API void append (const SDODate d) = 0; + +#if __WORDSIZE !=64 + virtual SDO_API void insert (unsigned int index, long d) = 0; + virtual SDO_API void append (long d) = 0; +#endif + + virtual SDO_API void insert (unsigned int index, int64_t d) = 0; + virtual SDO_API void append (int64_t d) = 0; + + virtual SDO_API void insert (unsigned int index, float d) = 0; + virtual SDO_API void append (float d) = 0; + + + virtual SDO_API void insert (unsigned int index, long double d) = 0; + virtual SDO_API void append (long double d) = 0; + + /** remove removes an element from the list. + * + * Remove removes the element from the list, and passes out a + * DataObjectPtr to the old value. This can be attached to the list + * somewhere else, or discarded. + */ + + virtual SDO_API DataObjectPtr remove (unsigned int index) = 0; + + /* getType returns type + * + * Returns the type. + * May throw SDOTYpeNotFoundException for unset open types + */ + + + virtual SDO_API const Type& getType() = 0; + + /* getTypeEnum returns an enumerator for the type + * + * Returns an enumerator for the type for easy switching on basic types. + * The enumerator is part of the Type class + * May throw SDOTypeNotFoundException for open types + */ + + virtual SDO_API const Type::Types getTypeEnum() = 0; + +}; +}; +}; + +#endif diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectListImpl.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectListImpl.cpp new file mode 100644 index 0000000000..9e58f0542e --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectListImpl.cpp @@ -0,0 +1,1129 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/DataObjectListImpl.h" + + +#include +#include "commonj/sdo/Property.h" +#include "commonj/sdo/Type.h" +#include "commonj/sdo/DataObject.h" +#include "commonj/sdo/Logger.h" +#include "commonj/sdo/SDORuntimeException.h" +#include "commonj/sdo/DataFactory.h" +#include "commonj/sdo/DataObjectImpl.h" +#include "commonj/sdo/DataFactoryImpl.h" + +#include + +namespace commonj{ +namespace sdo { + +/** + * DataObjectListImpl implements DataObjectList. + * List for retrieving many valued property values. + * + * DataObjectList provides an API for getting and setting values in + * many valued properties. The list deals with both DataType and + * DataObjectType properties. + */ +DataObjectListImpl::DataObjectListImpl(DATAOBJECT_VECTOR p) : plist (p) +{ + theFactory = 0; + container = 0; + pindex = 0; + isReference = false; +} + +DataObjectListImpl::DataObjectListImpl(const DataObjectListImpl &pin) +{ + plist = std::vector >(pin.getVec()); + theFactory = pin.theFactory; + container = pin.container; + pindex = pin.pindex; + typeUnset = pin.typeUnset; + isReference = pin.isReference; + if (pin.typeURI != 0) { + typeURI = new char[strlen(pin.typeURI) +1]; + strcpy(typeURI, pin.typeURI); + } + if (pin.typeName != 0) { + typeName = new char[strlen(pin.typeName) +1]; + strcpy(typeName, pin.typeName); + } +} + +DataObjectListImpl::DataObjectListImpl() +{ + theFactory = 0; + typeURI = 0; + typeName = 0; + theFactory = 0; + container = 0; + pindex = 0; + typeUnset = false; + isReference = false; +} + +DataObjectListImpl::DataObjectListImpl(DataFactory* df, + DataObjectImpl* cont, + unsigned int inpindex, + const char* intypeURI, + const char* intypeName) +{ + container = cont; + pindex = inpindex; + theFactory = df; + + + isReference = false; + if (container->getProperty(pindex).isReference()) + { + isReference = true; + } + typeUnset = false; + + if (container->getType().isOpenType()) + { + if (!strcmp(intypeURI,Type::SDOTypeNamespaceURI.c_str()) && + !strcmp(intypeName,"OpenDataObject")) + { + typeUnset = true; + } + } + + + if (intypeURI != 0) { + typeURI = new char[strlen(intypeURI) +1]; + strcpy(typeURI, intypeURI); + } + else { + typeURI = 0; + } + if (intypeName != 0) { + typeName = new char[strlen(intypeName) +1]; + strcpy(typeName, intypeName); + } + else { + typeName = 0; + theFactory = 0; + } +} + +DataObjectListImpl::~DataObjectListImpl() +{ + if (typeURI != 0) { + delete[] typeURI; + typeURI = 0; + } + if (typeName != 0) { + delete[] typeName; + typeName = 0; + } +} + +RefCountingPointer DataObjectListImpl::operator[] (unsigned int pos) +{ + validateIndex(pos); + return plist[pos]; +} + +const RefCountingPointer DataObjectListImpl::operator[] (unsigned int pos) const +{ + validateIndex(pos); + RefCountingPointer d = plist[pos]; + DataObjectImpl* dob = d; + return RefCountingPointer((DataObject*)dob); +} + + +unsigned int DataObjectListImpl::size () const +{ + return plist.size(); +} + +DATAOBJECT_VECTOR DataObjectListImpl::getVec() const +{ + return plist; +} + + + +const Type& DataObjectListImpl::getType() +{ + if (typeUnset) + { + std::string msg("The list property is open, and the type of the contents has not bee determined yet."); + SDO_THROW_EXCEPTION("Get Type", SDOTypeNotFoundException, + msg.c_str()); + } + return theFactory->getType(typeURI, typeName); +} + + +const Type::Types DataObjectListImpl::getTypeEnum() +{ + if (typeUnset) + { + return Type::OpenDataObjectType; + + } + return theFactory->getType(typeURI, typeName).getTypeEnum(); +} + + +void DataObjectListImpl::insert (unsigned int index, DataObjectPtr d) +{ + if (typeUnset)setType(d->getType().getURI(),d->getType().getName()); + + checkFactory(d); + + checkType(theFactory->getType(typeURI,typeName), + d->getType()); + + if (container != 0) + { + container->logChange(pindex); + } + for (unsigned int i=0;i < plist.size(); i++) + { + if (plist[i] == d) + { + std::string msg("Insertion of object which already exists in the list:"); + msg += typeURI; + msg += " "; + msg += typeName; + SDO_THROW_EXCEPTION("List insert", SDOUnsupportedOperationException, + msg.c_str()); + } + } + if (strcmp(typeURI,d->getType().getURI()) + || + strcmp(typeName,d->getType().getName())) + { + std::string msg("Insertion of object of the wrong type to a list:"); + msg += typeURI; + msg += " "; + msg += typeName; + msg += " not compatible with "; + msg += d->getType().getURI(); + msg += " "; + msg += d->getType().getName(); + SDO_THROW_EXCEPTION("List append", SDOInvalidConversionException, + msg.c_str()); + } + + const Property& property = container->getProperty(pindex); + ASSERT_WRITABLE(property,insert) + + DataObject* dob = d; // unwrap the data object ready for a downcasting hack. + DataObjectImpl* con = ((DataObjectImpl*)dob)->getContainerImpl(); + if (!isReference) + { + if (con != 0) + { + if (con != container) + { + /* this data object is already contained somewhere else */ + std::string msg("Insertion of object to list, object is already contained:"); + msg += d->getType().getURI(); + msg += " "; + msg += d->getType().getName(); + SDO_THROW_EXCEPTION("List append", SDOInvalidConversionException, + msg.c_str()); + } + } + else + { + ((DataObjectImpl*)dob)->setContainer(container); + ((DataObjectImpl*)dob)->logCreation((DataObjectImpl*)dob, + (DataObjectImpl*)container, + property); + } + } + + plist.insert(plist.begin()+index, RefCountingPointer((DataObjectImpl*)dob)); + + if (container != 0) + { + if (container->getType().isSequencedType()) + { + SequenceImpl* sq = container->getSequenceImpl(); + if (sq)sq->push(property,index); + } + } + +} + + + + void DataObjectListImpl::checkFactory(DataObjectPtr dob) + { + + DataObjectImpl* d = (DataObjectImpl*)(DataObject*)dob; + + if (d->getDataFactory() == theFactory) return; + + if (d->getContainer() != 0) + { + std::string msg("Insertion of object into list from another factory is only allowed if the parent is null: "); + + const Type& t = d->getType(); + msg += t.getURI(); + msg += "#"; + msg += t.getName(); + msg += " into property "; + msg += container->getProperty(pindex).getName(); + msg += " of type "; + msg += typeURI; + msg += "#"; + msg += typeName; + SDO_THROW_EXCEPTION("checkFactory", SDOInvalidConversionException, + msg.c_str()); + } + } + + +void DataObjectListImpl::checkType(const Type& listType, const Type& objectType) + { + if (listType.equals(objectType)) return; + + const TypeImpl* ti = ((DataFactoryImpl*)theFactory)->findTypeImpl + (objectType.getURI(),objectType.getName()); + if (ti != 0) + { + do + { + ti = (const TypeImpl*)ti->getBaseType(); + if (ti == 0) break; + if (listType.equals(*ti)) return; + } while (ti != 0); + + // allow types of any substitutes + if (container != 0) + { + PropertyImpl* pi = + container->getPropertyImpl(pindex); + if (pi != 0) + { + unsigned int subcount = pi->getSubstitutionCount(); + for (unsigned int i=0;igetSubstitutionType(i); + if (tsub != 0 && tsub->equals(objectType)) return; + } + } + } + } + + // no match.. + std::string msg("Insertion of object of incompatible type "); + msg += objectType.getURI(); + msg += "#"; + msg += objectType.getName(); + msg += " into list of type "; + msg += listType.getURI(); + msg += "#"; + msg += listType.getName(); + SDO_THROW_EXCEPTION("TypeCheck", SDOInvalidConversionException, + msg.c_str()); + } + +//TODO Modify parameters to SDOString +void DataObjectListImpl::setType(const char* uri, const char* name) +{ + // need to check for an opentype list which has not been set up yet + if (name == 0) return; + + const TypeImpl* t = ((DataFactoryImpl*)theFactory)->findTypeImpl(uri,name); + if (t == 0) return; // cannot set to a type which is not avilable + + // need to modify the instance property of the container + container->setInstancePropertyType(pindex,t); + + delete[] typeName; + typeName = new char[strlen(name)+1]; + strcpy(typeName, name); + delete[] typeURI; + if (uri == 0) + { + typeURI = new char[1]; + typeURI[0] = 0; + } + else + { + typeURI = new char[strlen(uri)+1]; + strcpy(typeURI, uri); + } + typeUnset = false; +} + +void DataObjectListImpl::setType(const SDOString& uri, const SDOString& name) +{ + // need to check for an opentype list which has not been set up yet + // if (name == 0) return; + + const TypeImpl* t = ((DataFactoryImpl*)theFactory)->findTypeImpl(uri.c_str(), name.c_str()); + if (t == 0) return; // cannot set to a type which is not avilable + + // need to modify the instance property of the container + container->setInstancePropertyType(pindex,t); + + delete[] typeName; + typeName = new char[name.length() + 1]; + strcpy(typeName, name.c_str()); + + delete[] typeURI; + typeURI = new char[uri.length() + 1]; + strcpy(typeURI, uri.c_str()); + + typeUnset = false; +} + +void DataObjectListImpl::append (DataObjectPtr d) +{ + + if (typeUnset) + { + setType(d->getType().getURI(), d->getType().getName()); + } + if (container != 0) + { + container->logChange(pindex); + } + + for (unsigned int i = 0; i < plist.size(); i++) + { + if (plist[i] == d) + { + std::string msg("Append of object which already exists in the list:"); + msg += typeURI; + msg += " "; + msg += typeName; + SDO_THROW_EXCEPTION("List append", + SDOUnsupportedOperationException, + msg.c_str()); + } + } + + checkFactory(d); + + checkType(theFactory->getType(typeURI, typeName), + d->getType()); + + const Property& property = container->getProperty(pindex); + ASSERT_WRITABLE(property, append); + + DataObject* dob = d; // unwrap the data object ready for a downcasting hack. + DataObjectImpl* con = ((DataObjectImpl*) dob)->getContainerImpl(); + + if (!isReference) + { + if (con != 0) + { + if (con != container) + { + /* this data object is already contained somewhere else */ + std::string msg("Append of object to list, object is already contained:"); + msg += d->getType().getURI(); + msg += " "; + msg += d->getType().getName(); + SDO_THROW_EXCEPTION("List append", + SDOInvalidConversionException, + msg.c_str()); + } + } + else + { + ((DataObjectImpl*) dob)->setContainer(container); + if (!container->getProperty(pindex).getType().isDataType()) + { + ((DataObjectImpl*) dob)->logCreation((DataObjectImpl*)dob, + container, + property); + } + } + } + plist.push_back(RefCountingPointer((DataObjectImpl*) dob)); + + if (container != 0) { + if (container->getType().isSequencedType()) + { + SequenceImpl* sq = container->getSequenceImpl(); + if (sq) + { + sq->push(property, (plist.size() - 1)); + } + } + } +} + +void DataObjectListImpl::insert (unsigned int index, bool d) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, BooleanLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setBoolean(d); + insert(index, dol); +} + +void DataObjectListImpl::append (bool d) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, BooleanLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setBoolean(d); + append( dol); +} + +void DataObjectListImpl::insert (unsigned int index, char d) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, ByteLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setByte(d); + insert(index, dol); +} + +void DataObjectListImpl::append (char d) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, ByteLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setByte(d); + append( dol); +} + +void DataObjectListImpl::insert (unsigned int index, wchar_t d) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, CharacterLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setCharacter(d); + insert(index, dol); +} + +void DataObjectListImpl::append (wchar_t d) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, CharacterLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setCharacter(d); + append( dol); +} + +void DataObjectListImpl::insert (unsigned int index, const wchar_t* d, unsigned int length) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, StringLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setString(d, length); + insert(index, dol); +} + +void DataObjectListImpl::append (const wchar_t* d, unsigned int length) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, StringLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setString(d, length); + append( dol); +} +void DataObjectListImpl::insert (unsigned int index, const char* d, unsigned int length) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, BytesLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setBytes(d, length); + insert(index, dol); +} + +void DataObjectListImpl::append (const char* d, unsigned int length) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, BytesLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setBytes(d, length); + append( dol); +} +void DataObjectListImpl::insert (unsigned int index, const char* d) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, StringLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setCString(d); + insert(index, dol); +} +void DataObjectListImpl::insert (unsigned int index, const SDOString& d) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, StringLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setCString(d); + insert(index, dol); +} + +void DataObjectListImpl::append (const char* d) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, StringLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setCString(d); + append( dol); +} + +void DataObjectListImpl::append (const SDOString& d) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, StringLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setCString(d); + append( dol); +} + +void DataObjectListImpl::append (const SDOValue& sval) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, StringLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setSDOValue(sval); + append(dol); +} + +void DataObjectListImpl::insert (unsigned int index, short d) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, ShortLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setShort(d); + insert(index, dol); +} + +void DataObjectListImpl::append (short d) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, ShortLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setShort(d); + append( dol); +} + + +#if __WORDSIZE !=64 +void DataObjectListImpl::insert (unsigned int index, long d) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, IntegerLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setInteger(d); + insert(index, dol); +} + +void DataObjectListImpl::append (long d) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, IntegerLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setInteger(d); + append( dol); +} +#endif + +void DataObjectListImpl::insert (unsigned int index, const SDODate d) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, DateLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setDate(d); + insert(index, dol); +} + +void DataObjectListImpl::append (const SDODate d) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, DateLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setDate(d); + append( dol); +} + +void DataObjectListImpl::insert (unsigned int index, int64_t d) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, LongLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setLong(d); + insert(index, dol); +} + +void DataObjectListImpl::append (int64_t d) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, LongLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setLong(d); + append( dol); +} + +void DataObjectListImpl::insert (unsigned int index, float d) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, FloatLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setFloat(d); + insert(index, dol); +} + +void DataObjectListImpl::append (float d) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, FloatLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setFloat(d); + append( dol); +} + +void DataObjectListImpl::insert (unsigned int index, long double d) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, DoubleLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setDouble(d); + insert(index, dol); +} + +void DataObjectListImpl::append (long double d) +{ + if (theFactory == 0) return; + + if (typeUnset)setType(Type::SDOTypeNamespaceURI, DoubleLiteral); + + RefCountingPointer dol = theFactory->create(typeURI, typeName); + DataObject* dob = dol; + ((DataObjectImpl*)dob)->setDouble(d); + append( dol); +} + + +void DataObjectListImpl::decrementPindex() +{ + pindex--; +} + + +RefCountingPointer DataObjectListImpl::remove(unsigned int index) +{ + validateIndex(index); + if (container != 0) + { + container->logChange(pindex); + } + RefCountingPointer d = (*this)[index]; + + // log deletion only if the list is of data objects. + if (theFactory != 0) + { + const Type& t = theFactory->getType(typeURI,typeName); + const Property& p = container->getProperty(pindex); + if (!t.isDataType() && !p.isReference()) + { + (getVec()[index])->logDeletion(); + } + } + plist.erase(plist.begin()+index); + DataObject* dob = d; + ((DataObjectImpl*)dob)->setContainer(0); + return d; +} + +void DataObjectListImpl::validateIndex(unsigned int index) const +{ + if ((index < 0) || (index >= size())) + { + char val[32]; + std::string msg("Index out of range:"); + sprintf(val,"%d",index); + msg += val; + SDO_THROW_EXCEPTION("validateIndex", SDOIndexOutOfRangeException, + msg.c_str()); + + } + +} + +bool DataObjectListImpl::getBoolean(unsigned int index) const +{ + validateIndex(index); + RefCountingPointer d = ((*this)[index]); + DataObject* dob = d; + return ((DataObjectImpl*)dob)->getBoolean(); +} +char DataObjectListImpl::getByte(unsigned int index) const +{ + validateIndex(index); + RefCountingPointer d = ((*this)[index]); + DataObject* dob = d; + return ((DataObjectImpl*)dob)->getByte(); +} +wchar_t DataObjectListImpl::getCharacter(unsigned int index) const +{ + validateIndex(index); + RefCountingPointer d = ((*this)[index]); + DataObject* dob = d; + return ((DataObjectImpl*)dob)->getCharacter(); +} +unsigned int DataObjectListImpl::getBytes(unsigned int index, char* value, unsigned int max) const +{ + validateIndex(index); + RefCountingPointer d = ((*this)[index]); + DataObject* dob = d; + return ((DataObjectImpl*)dob)->getBytes(value, max); +} +unsigned int DataObjectListImpl::getString(unsigned int index, wchar_t* value, unsigned int max) const +{ + validateIndex(index); + RefCountingPointer d = ((*this)[index]); + DataObject* dob = d; + return ((DataObjectImpl*)dob)->getString(value, max); +} +short DataObjectListImpl::getShort(unsigned int index) const +{ + validateIndex(index); + RefCountingPointer d = ((*this)[index]); + DataObject* dob = d; + return ((DataObjectImpl*)dob)->getShort(); +} +long DataObjectListImpl::getInteger(unsigned int index) const +{ + validateIndex(index); + RefCountingPointer d = ((*this)[index]); + DataObject* dob = d; + return ((DataObjectImpl*)dob)->getInteger(); +} +int64_t DataObjectListImpl::getLong(unsigned int index) const +{ + validateIndex(index); + RefCountingPointer d = ((*this)[index]); + DataObject* dob = d; + return ((DataObjectImpl*)dob)->getLong(); +} +float DataObjectListImpl::getFloat(unsigned int index) const +{ + validateIndex(index); + RefCountingPointer d = ((*this)[index]); + DataObject* dob = d; + return ((DataObjectImpl*)dob)->getFloat(); +} +long double DataObjectListImpl::getDouble(unsigned int index) const +{ + validateIndex(index); + RefCountingPointer d = ((*this)[index]); + DataObject* dob = d; + return ((DataObjectImpl*)dob)->getDouble(); +} +const SDODate DataObjectListImpl::getDate(unsigned int index) const +{ + validateIndex(index); + RefCountingPointer d = ((*this)[index]); + DataObject* dob = d; + return ((DataObjectImpl*)dob)->getDate(); +} +const char* DataObjectListImpl::getCString(unsigned int index) const +{ + validateIndex(index); + RefCountingPointer d = ((*this)[index]); + DataObject* dob = d; + return ((DataObjectImpl*)dob)->getCString(); +} + +DataObjectPtr DataObjectListImpl::getDataObject(unsigned int index) const +{ + validateIndex(index); + return (*this)[index]; +} + +void DataObjectListImpl::setBoolean(unsigned int index, bool d) +{ + validateIndex(index); + if (container != 0) + { + container->logChange(pindex); + } + RefCountingPointer dd = ((*this)[index]); + DataObject* dob = dd; + ((DataObjectImpl*)dob)->setBoolean(d); +} +void DataObjectListImpl::setByte(unsigned int index, char d) +{ + validateIndex(index); + if (container != 0) + { + container->logChange(pindex); + } + RefCountingPointer dd = ((*this)[index]); + DataObject* dob = dd; + ((DataObjectImpl*)dob)->setByte(d); +} +void DataObjectListImpl::setCharacter(unsigned int index, wchar_t d) +{ + validateIndex(index); + if (container != 0) + { + container->logChange(pindex); + } + RefCountingPointer dd = ((*this)[index]); + DataObject* dob = dd; + ((DataObjectImpl*)dob)->setCharacter(d); +} + +void DataObjectListImpl::setString(unsigned int index, const wchar_t* d, unsigned int len) +{ + validateIndex(index); + if (container != 0) + { + container->logChange(pindex); + } + RefCountingPointer dd = ((*this)[index]); + DataObject* dob = dd; + ((DataObjectImpl*)dob)->setString(d, len); +} +void DataObjectListImpl::setBytes(unsigned int index, const char* d, unsigned int len) +{ + validateIndex(index); + if (container != 0) + { + container->logChange(pindex); + } + RefCountingPointer dd = ((*this)[index]); + DataObject* dob = dd; + ((DataObjectImpl*)dob)->setBytes(d, len); +} + +void DataObjectListImpl::setShort(unsigned int index, short d) +{ + validateIndex(index); + if (container != 0) + { + container->logChange(pindex); + } + RefCountingPointer dd = ((*this)[index]); + DataObject* dob = dd; + ((DataObjectImpl*)dob)->setShort(d); +} +void DataObjectListImpl::setInteger(unsigned int index, long d) +{ + validateIndex(index); + if (container != 0) + { + container->logChange(pindex); + } + RefCountingPointer dd = ((*this)[index]); + DataObject* dob = dd; + ((DataObjectImpl*)dob)->setInteger(d); +} +void DataObjectListImpl::setLong(unsigned int index, int64_t d) +{ + validateIndex(index); + if (container != 0) + { + container->logChange(pindex); + } + RefCountingPointer dd = ((*this)[index]); + DataObject* dob = dd; + ((DataObjectImpl*)dob)->setLong(d); +} +void DataObjectListImpl::setFloat(unsigned int index, float d) +{ + validateIndex(index); + if (container != 0) + { + container->logChange(pindex); + } + RefCountingPointer dd = ((*this)[index]); + DataObject* dob = dd; + ((DataObjectImpl*)dob)->setFloat(d); +} +void DataObjectListImpl::setDouble(unsigned int index, long double d) +{ + validateIndex(index); + if (container != 0) + { + container->logChange(pindex); + } + RefCountingPointer dd = ((*this)[index]); + DataObject* dob = dd; + ((DataObjectImpl*)dob)->setDouble(d); +} +void DataObjectListImpl::setDate(unsigned int index, const SDODate d) +{ + validateIndex(index); + if (container != 0) + { + container->logChange(pindex); + } + RefCountingPointer dd = ((*this)[index]); + DataObject* dob = dd; + ((DataObjectImpl*)dob)->setDate(d); +} +void DataObjectListImpl::setCString(unsigned int index, char* d) +{ + validateIndex(index); + if (container != 0) + { + container->logChange(pindex); + } + RefCountingPointer dd = ((*this)[index]); + DataObject* dob = dd; + ((DataObjectImpl*)dob)->setCString(d); +} +void DataObjectListImpl::setCString(unsigned int index, const SDOString& d) +{ + validateIndex(index); + if (container != 0) + { + container->logChange(pindex); + } + RefCountingPointer dd = ((*this)[index]); + DataObject* dob = dd; + ((DataObjectImpl*)dob)->setCString(d); +} + +void DataObjectListImpl::setDataObject(unsigned int index, DataObjectPtr dob) +{ + + if (dob != 0) + { + checkFactory(dob); + + checkType(theFactory->getType(typeURI,typeName), + dob->getType()); + } + + validateIndex(index); + if (container != 0) + { + container->logChange(pindex); + } + + remove(index); + insert(index,dob); +} + +unsigned int DataObjectListImpl::getLength(unsigned int index) const +{ + validateIndex(index); + RefCountingPointer dd = ((*this)[index]); + DataObject* dob = dd; + return dob->getLength(); +} + + const SDOString DataObjectListImpl::BooleanLiteral = "Boolean"; + const SDOString DataObjectListImpl::ByteLiteral = "Byte"; + const SDOString DataObjectListImpl::CharacterLiteral = "Character"; + const SDOString DataObjectListImpl::BytesLiteral = "Bytes"; + const SDOString DataObjectListImpl::StringLiteral = "String"; + const SDOString DataObjectListImpl::IntegerLiteral = "Integer"; + const SDOString DataObjectListImpl::ShortLiteral = "Short"; + const SDOString DataObjectListImpl::DateLiteral = "Date"; + const SDOString DataObjectListImpl::LongLiteral = "Long"; + const SDOString DataObjectListImpl::FloatLiteral = "Float"; + const SDOString DataObjectListImpl::DoubleLiteral = "Double"; + +}; +}; diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectListImpl.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectListImpl.h new file mode 100644 index 0000000000..1181b0ad37 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataObjectListImpl.h @@ -0,0 +1,224 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _DATAOBJECTLISTIMPL_H_ +#define _DATAOBJECTLISTIMPL_H_ + +#include "commonj/sdo/DataObjectList.h" +#include "commonj/sdo/SDODate.h" +#include "commonj/sdo/SDOValue.h" + +#include "commonj/sdo/disable_warn.h" + +#include + + +namespace commonj{ +namespace sdo{ + +class DataObjectImpl; +class DataFactory; + +typedef std::vector< RefCountingPointer > DATAOBJECT_VECTOR; + +/** + * DataObjectListImpl implements the abstract class DataObjectList. + * List for retrieving many valued property values. + * + * DataObjectList provides an API for getting and setting values in + * many valued properties. The list deals with both DataType and + * DataObjectType properties. + */ + +class DataObjectListImpl : public DataObjectList +{ + +public: + DataObjectListImpl(DATAOBJECT_VECTOR p); + DataObjectListImpl(const DataObjectListImpl &pin); + DataObjectListImpl(); + DataObjectListImpl(DataFactory* df, DataObjectImpl* cont, unsigned int inpindex, + const char* tURI, const char* tName); + + virtual ~DataObjectListImpl(); + + // open type support + virtual void decrementPindex(); + + virtual DataObjectPtr operator[] (unsigned int pos); + virtual const DataObjectPtr operator[] (unsigned int pos) const; + + // set/get primitive values + virtual bool getBoolean(unsigned int index) const; + virtual char getByte(unsigned int index) const; + virtual wchar_t getCharacter(unsigned int index) const; + virtual unsigned int getString(unsigned int index, wchar_t* buf, + unsigned int max) const; + virtual unsigned int getBytes(unsigned int index, char* buf, + unsigned int max) const; + virtual short getShort(unsigned int index) const; + virtual long getInteger(unsigned int index) const; + virtual int64_t getLong(unsigned int index) const; + virtual float getFloat(unsigned int index) const; + virtual long double getDouble(unsigned int index) const; + virtual const SDODate getDate(unsigned int index) const; + virtual const char* getCString(unsigned int index) const; + virtual DataObjectPtr getDataObject(unsigned int index) const; + + virtual void setBoolean(unsigned int index, bool d); + virtual void setByte(unsigned int index, char d); + virtual void setCharacter(unsigned int index, wchar_t d); + virtual void setString(unsigned int index, const wchar_t* d, unsigned int len); + virtual void setBytes(unsigned int index, const char* d, unsigned int len); + virtual void setShort(unsigned int index, short d); + virtual void setInteger(unsigned int index, long d); + virtual void setLong(unsigned int index, int64_t d); + virtual void setFloat(unsigned int index, float d); + virtual void setDouble(unsigned int index, long double d); + virtual void setDate(unsigned int index, const SDODate d); + virtual void setCString(unsigned int index, char* d); + virtual void setCString(unsigned int index, const SDOString& d); + virtual void setDataObject(unsigned int index, DataObjectPtr dob); + + virtual unsigned int getLength(unsigned int index) const; + + virtual unsigned int size () const; + + virtual void insert (unsigned int index, DataObjectPtr d); + virtual void append (DataObjectPtr d); + + virtual void insert (unsigned int index, bool d) ; + virtual void append (bool d) ; + + virtual void insert (unsigned int index, char d) ; + virtual void append (char d) ; + + virtual void insert (unsigned int index, wchar_t d) ; + virtual void append (wchar_t d) ; + + virtual void insert (unsigned int index, const wchar_t* d, unsigned int len) ; + virtual void append (const wchar_t* d, unsigned int len) ; + + virtual void insert (unsigned int index, const char* d, unsigned int len) ; + virtual void append (const char* d, unsigned int len) ; + + virtual void insert (unsigned int index, const char* d) ; + virtual void insert (unsigned int index, const SDOString& d) ; + virtual void append (const char* d) ; + virtual void append (const SDOString& d) ; + + virtual void append (const SDOValue& sval); + + virtual void insert (unsigned int index, short d) ; + virtual void append (short d) ; + + virtual void insert (unsigned int index, const SDODate d) ; + virtual void append (const SDODate d) ; + +#if __WORDSIZE !=64 + virtual void insert (unsigned int index, long d) ; + virtual void append (long d) ; +#endif + + virtual void insert (unsigned int index, int64_t d) ; + virtual void append (int64_t d) ; + + virtual void insert (unsigned int index, float d) ; + virtual void append (float d) ; + + virtual void insert (unsigned int index, long double d) ; + virtual void append (long double d) ; + + + virtual DataObjectPtr remove (unsigned int index); + + virtual void checkFactory(DataObjectPtr dob); + virtual void checkType(const Type& listType, const Type& objectType); + virtual void setType(const char* uri, const char* name); + virtual void setType(const SDOString& uri, const SDOString& name); + + /* getType returns type + * + * Returns the type. + * May throw SDOTYpeNotFoundException for unset open types + */ + + + virtual const Type& getType(); + + /* getTypeEnum returns an enumerator for the type + * + * Returns an enumerator for the type for easy switching on basic types. + * The enumerator is part of the Type class + * May throw SDOTypeNotFoundException for open types + */ + + virtual const Type::Types getTypeEnum(); + + +private: + DATAOBJECT_VECTOR plist; + DATAOBJECT_VECTOR getVec() const; + + // For creation of items via the insert/append api. + char* typeURI; + char* typeName; + + // for open types, the list may not have a type until the + // first item is entered + + bool typeUnset; + + // No reference count held on the factory + DataFactory* theFactory; + + // For logging a change in the change summary when appending + DataObjectImpl* container; + unsigned int pindex; + bool isReference; + + void validateIndex(unsigned int index) const; + + static const SDOString BooleanLiteral; + static const SDOString ByteLiteral; + static const SDOString CharacterLiteral; + static const SDOString BytesLiteral; + static const SDOString StringLiteral; + static const SDOString IntegerLiteral; + static const SDOString ShortLiteral; + static const SDOString DateLiteral; + static const SDOString LongLiteral; + static const SDOString FloatLiteral; + static const SDOString DoubleLiteral; + +}; +}; +}; + +#define ASSERT_WRITABLE(property,method)\ + if ((property).isReadOnly())\ + {\ + SDOString stringBuffer = (property).getName();\ + stringBuffer += "is read-only.";\ + SDO_THROW_EXCEPTION(method, SDOUnsupportedOperationException, stringBuffer.c_str())\ + } + +#endif diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataTypeInfo.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataTypeInfo.cpp new file mode 100644 index 0000000000..30ccb2228f --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataTypeInfo.cpp @@ -0,0 +1,54 @@ +/* +* +* Copyright 2007 The Apache Software Foundation or its licensors, as applicable. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SDOString.h" +#include "commonj/sdo/DataTypeInfo.h" + +namespace commonj +{ + namespace sdo + { + + const SDOString& DataTypeInfo::convertTypeEnumToString(TrueDataType dataType) + { + if ((dataType < 0) || (dataType > TDTWideString)) + { + return rawTypeNames[TDTWideString + 1]; + } + else + { + return rawTypeNames[dataType]; + } + } + + const SDOString DataTypeInfo::rawTypeNames[] = {"Boolean", // 0 + "Byte", + "Character", + "Short", + "Integer", + "Long", // 5 + "Float", + "Double", + "Date", + "String", + "Bytes", // 10 + "String", + "No Such Type"}; + } +} diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataTypeInfo.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataTypeInfo.h new file mode 100644 index 0000000000..b85ce57389 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataTypeInfo.h @@ -0,0 +1,137 @@ +/* +* +* Copyright 2007 The Apache Software Foundation or its licensors, as applicable. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* $Rev$ $Date$ */ + +#ifndef _DATATYPEINFO_H_ +#define _DATATYPEINFO_H_ + +#include "commonj/sdo/SDODate.h" +#include "commonj/sdo/SDOString.h" + +namespace commonj +{ + namespace sdo + { + + // The DataTypeInfo class provides types that encapsulate the various + // primitive data types that SDO uses to represent the user level data + // types defined in the specification. The central artifact is a union + // of all the C++ data types that are used to represent SDO data + // types. This is augmented by enumerations that provide a convenient + // way to label a particular type, plus a method to retrieve a text + // representation of each enumeration value. + + // There are three different array-like primitive data types. + // 1. CString: An array of char, terminated by a 0 ie a C style string. + // 2. ByteArray: An array of bytes. Similar to 1. but without the null + // terminator. + // 3. String: An array of wchar_t, terminated by a 0. In the SDOValue + // class, the first two are stored in an SDOString (ie std::string), + // while the third is stored explicitly as a pointer to a buffer. + + class DataTypeInfo + { + public: + // The values of TrueDataType are used as subscripts for an array + // so they must a) start at zero and b) be contiguous. Elsewhere, + // TDTWideString is used as the definition of the largest + // TrueDatatype value, so if any constants are added beyond it the + // code that depends on it will have to be changed. + enum TrueDataType + { + TDTbool = 0, + TDTchar = 1, + TDTwchar_t = 2, + TDTshort = 3, + TDTlong = 4, + TDTint64_t = 5, + TDTfloat = 6, + TDTdouble = 7, + TDTSDODate = 8, + TDTCString = 9, + TDTByteArray = 10, + TDTWideString = 11 + }; + + enum PseudoDataType + { + PDTunset = -2, + PDTnull = -1 + }; + + // This enum identifies what C++ datatype is present in the union. + // It does not necessarily say what the SDO type is. Since it is + // possible for a value to be either unset or null there are + // enumerations for those cases too. This enum is effectively a + // union of the two previous enums where TrueDataType includes + // just those data types that can actually have values, while + // PseudoDataType includes just null and unset. This allows for + // methods that have to be told which type to create and for which + // unset and null are inappropriate. + enum RawDataType + { + SDOunset = PDTunset, + SDOnull = PDTnull, + SDObool = TDTbool, + SDOchar = TDTchar, + SDOwchar_t = TDTwchar_t, + SDOshort = TDTshort, + SDOlong = TDTlong, + SDOint64_t = TDTint64_t, + SDOfloat = TDTfloat, + SDOdouble = TDTdouble, + SDOSDODate = TDTSDODate, + SDOCString = TDTCString, + SDOByteArray = TDTByteArray, + SDOWideString = TDTWideString, + }; + + // Entities with copy constructors/destructors are not allowed in a union, + // since in general, the compiler doesn't know what type is + // actually in there so it can't know which constructor/destructor + // to call, hence the use of pointers for dates and strings + union SDODataTypeUnion + { + bool Boolean; + char Character; + wchar_t WideChar; + short Short; + long Integer; + int64_t Int64; + float Float; + long double Double; + SDODate* Date; + SDOString* TextString; + struct + { + wchar_t* data; + unsigned int length; + } WideString; + }; + + static const SDOString& convertTypeEnumToString(TrueDataType dataType); + + private: + // Array of text strings that correspond to TrueDataType enumeration values + static SDO_API const SDOString rawTypeNames[]; + + }; + } // End - namespace sdo +} // End - namespace commonj + +#endif // _DATATYPEINFO_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DefaultLogWriter.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DefaultLogWriter.cpp new file mode 100644 index 0000000000..cf9029afa9 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DefaultLogWriter.cpp @@ -0,0 +1,55 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/disable_warn.h" +#include "commonj/sdo/DefaultLogWriter.h" + +#include +using namespace std; + +namespace commonj +{ + namespace sdo + { + + DefaultLogWriter::DefaultLogWriter() + { + formatindent = 0; + } + + DefaultLogWriter::~DefaultLogWriter() + { + } + + void DefaultLogWriter::log(int indent, int level, const char* msg) + { + if (indent < 0) formatindent += indent; + for (int i=0; i < formatindent; i++) + { + cout << " "; + } + cout << msg < 0) formatindent += indent; + } + + } // End namespace sca +} // End namespace commonj + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DefaultLogWriter.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DefaultLogWriter.h new file mode 100644 index 0000000000..deab314ef7 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DefaultLogWriter.h @@ -0,0 +1,54 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef SDO_DefaultLOGWriter_H +#define SDO_DefaultLOGWriter_H + +#include "commonj/sdo/LogWriter.h" + + + +namespace commonj +{ + namespace sdo + { + +/** + * DefaultLogWriter is a basic log writer, part of the logger. + * The logging API holds a log writer , and uses it to send + * output whereever it is needed. The application writer would + * hook their own LogWriter in place of this simple one. + */ + class DefaultLogWriter : public LogWriter + { + public: + + DefaultLogWriter(); + virtual ~DefaultLogWriter(); + + virtual void log(int indent, int level, const char* msg); + private: + int formatindent; + }; + + } // End namespace sca +} // End namespace commonj +#endif // SDO_DefaultLOGWriter_H diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/EqualityHelper.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/EqualityHelper.cpp new file mode 100644 index 0000000000..bf47db4483 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/EqualityHelper.cpp @@ -0,0 +1,372 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/Property.h" +#include "commonj/sdo/Type.h" +#include "commonj/sdo/TypeList.h" +#include "commonj/sdo/Sequence.h" + +#include "commonj/sdo/DataObject.h" + + + +#include "commonj/sdo/EqualityHelper.h" + +namespace commonj{ +namespace sdo{ + + bool EqualityHelper::compareitem(DataObjectPtr to, DataObjectPtr from, const Property& p) + { + switch (p.getTypeEnum()) + { + case Type::BooleanType: + return (to->getBoolean(p) == from->getBoolean(p)); + case Type::ByteType: + return (to->getByte(p) == from->getByte(p)); + case Type::CharacterType: + return (to->getCharacter(p) == from->getCharacter(p)); + case Type::IntegerType: + return (to->getInteger(p) == from->getInteger(p)); + case Type::ShortType: + return (to->getShort(p) == from->getShort(p)); + case Type::DoubleType: + return (to->getDouble(p) == from->getDouble(p)); + case Type::FloatType: + return (to->getFloat(p) == from->getFloat(p)); + case Type::LongType: + return (to->getLong(p) == from->getLong(p)); + case Type::DateType: + return (to->getDate(p).getTime() == from->getDate(p).getTime()); + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::UriType: + case Type::StringType: + { + unsigned int siz = from->getLength(p); + if (siz != to->getLength(p)) return false; + + if (siz > 0) + { + wchar_t * buff = new wchar_t[siz]; + wchar_t * buft = new wchar_t[siz]; + from->getString(p, buff, siz); + to->getString(p, buft, siz); + for (unsigned int i=0;i< siz; i++) + { + if (buff[i] != buft[i]) + { + delete buff; + delete buft; + return false; + } + } + delete[] buff; + delete[] buft; + } + return true; + } + case Type::BytesType: + { + unsigned int siz = from->getLength(p); + if (siz != to->getLength(p)) return false; + + if (siz > 0) + { + char * buff = new char[siz]; + char * buft = new char[siz]; + from->getBytes(p, buff, siz); + to->getBytes(p, buft, siz); + for (unsigned int i=0;i< siz; i++) + { + if (buff[i] != buft[i]) + { + delete buff; + delete buft; + return false; + } + } + delete buff; + delete buft; + } + return true; + } + default: + return true; + } // switch + } + + bool EqualityHelper::comparelist(DataObjectList& to, DataObjectList& from, Type::Types t) + { + switch (t) + { + case Type::BooleanType: + { + for (unsigned int i=0;i< from.size(); i++) + { + if (to.getBoolean(i) != from.getBoolean(i)) + { + return false; + } + } + return true; + } + + case Type::ByteType: + { + for (unsigned int i=0;i< from.size(); i++) + { + if (to.getByte(i) != from.getByte(i)) + { + return false; + } + } + return true; + } + + case Type::CharacterType: + { + for (unsigned int i=0;i< from.size(); i++) + { + if (to.getCharacter(i) != from.getCharacter(i)) + { + return false; + } + } + return true; + } + + case Type::IntegerType: + { + for (unsigned int i=0;i< from.size(); i++) + { + if (to.getInteger(i) != from.getInteger(i)) + { + return false; + } + } + return true; + } + + case Type::ShortType: + { + for (unsigned int i=0;i< from.size(); i++) + { + if (to.getShort(i) != from.getShort(i)) + { + return false; + } + } + return true; + } + case Type::DoubleType: + { + for (unsigned int i=0;i< from.size(); i++) + { + if (to.getDouble(i) != from.getDouble(i)) + { + return false; + } + } + return true; + } + + case Type::FloatType: + { + for (unsigned int i=0;i< from.size(); i++) + { + if (to.getFloat(i) != from.getFloat(i)) + { + return false; + } + } + return true; + } + + case Type::LongType: + { + for (unsigned int i=0;i< from.size(); i++) + { + if (to.getLong(i) != from.getLong(i)) + { + return false; + } + } + return true; + } + + case Type::DateType: + { + for (unsigned int i=0;i< from.size(); i++) + { + if (to.getDate(i).getTime() != from.getDate(i).getTime()) + { + return false; + } + } + return true; + } + + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::UriType: + case Type::StringType: + { + for (unsigned int i=0;i< from.size(); i++) + { + unsigned int siz = from.getLength(i); + if (siz != to.getLength(i)) return false; + + if (siz > 0) + { + wchar_t * buff = new wchar_t[siz]; + wchar_t * buft = new wchar_t[siz]; + from.getString(i,buff,siz); + to.getString(i,buft,siz); + for (unsigned int j=0;j 0) + { + char * buff = new char[siz]; + char * buft = new char[siz]; + from.getBytes(i,buff,siz); + to.getBytes(i,buft,siz); + for (unsigned int j=0;jgetInstanceProperties(); + for (unsigned int i=0;i < pl.size(); i++) + { + // data objects are only compared the deep equality case + if (pl[i].getType().isDataObjectType()) + { + if (!fullEqual) + { + continue; + } + else + { + if (pl[i].isMany()) + { + DataObjectList& dolold = dataObject1->getList(pl[i]); + DataObjectList& dolnew = dataObject2->getList(pl[i]); + if (dolnew.size() != dolold.size()) return false; + + for (unsigned int i=0;i< dolold.size(); i++) + { + if (!internalEqual(dolold[i], dolnew[i], true)) + { + return false; + } + } + } + else + { + if (!internalEqual( + dataObject1->getDataObject(pl[i]), + dataObject2->getDataObject(pl[i]), true)) + { + return false; + } + } + } + } + else + { + if (pl[i].isMany()) + { + DataObjectList& dolold = dataObject1->getList(pl[i]); + DataObjectList& dolnew = dataObject2->getList(pl[i]); + if (dolold.size() != dolnew.size()) return false; + if (!comparelist(dolold, dolnew, pl[i].getTypeEnum())) return false; + } + else + { + if (!compareitem(dataObject1,dataObject2, pl[i])) + { + return false; + } + } // else + } + } + return true; + } + +} +}; + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/EqualityHelper.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/EqualityHelper.h new file mode 100644 index 0000000000..3058bd8f72 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/EqualityHelper.h @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef _EQUALITYHELPER_H_ +#define _EQUALITYHELPER_H_ + +#include "commonj/sdo/RefCountingPointer.h" + + + +namespace commonj{ +namespace sdo{ + +/** + * EqualityHelper provides static helper methods for equals. + * equalsShallow compares the DataType properties of the + * two data objects. + * equals performs a check on all the memebers and verifies that + * the same data objects are children. + */ + + class EqualityHelper +{ + public: + + /** + * Shallow compare of DataObjects + * + * Compares two DataObjects for each property where + * property.getType().isDataObjectType() is false. + * Compares dataObject1.get(property).equals(dataObject2.get(property)) + * Properties where property.getType().isDataObjectType() is true + * are not compared. + * DataObjects must have the same type + * dataObject1.getType() == dataObject2.getType() + * Returns true if all values of all compared properties are equal. + * @param dataObject1 DataObject to be compared + * @param dataObject2 DataObject to be compared + * @return true if equal + */ + static SDO_API bool equalShallow(DataObjectPtr dataObject1, DataObjectPtr dataObject2); + + /** + * Deep compare of DataObjects + * Compares dataObject1 and dataObject2 and all their contained + * DataObjects (property.isContainment() is true) recursively. + * Values of properties are comapred as in isEqualShallow, + * and values of properties where + * property.getType().isDataObjectType() is true + * are compared where each value copied must be a corresponding + * DataObject contained by the source dataObject. + * The dataObject trees must be closed. + * If any DataObject referenced in either tree is not part of the + * containment trees an IllegalArgumentException is thrown. + * If a ChangeSummary is part of the tree they must contain an + * identical summary for their respective trees. + * + * @param dataObject1 DataObject to be compared + * @param dataObject2 DataObject to be compared + * @return true if all compared aspects of all compared objects are equal + * @throws IllegalArgumentException if any referenced DataObject + * is not part of the containment trees. + */ + static SDO_API bool equal(DataObjectPtr dataObject1, DataObjectPtr dataObject2); + + private: + + static bool internalEqual(DataObjectPtr dataObject1, + DataObjectPtr dataObject2, + bool fullEqual); + + static bool comparelist(DataObjectList& to, DataObjectList& from, Type::Types t); + + static bool compareitem(DataObjectPtr to, DataObjectPtr from, const Property& p); + + + +}; +}; +}; +#endif //_EQUALITYHELPER_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/GroupDefinition.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/GroupDefinition.cpp new file mode 100644 index 0000000000..e0c275ede1 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/GroupDefinition.cpp @@ -0,0 +1,36 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/GroupDefinition.h" +namespace commonj +{ + namespace sdo + { + GroupDefinition::GroupDefinition() + { + } + + GroupDefinition::~GroupDefinition() + { + } + + } // End - namespace sdo +} // End - namespace commonj diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/GroupDefinition.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/GroupDefinition.h new file mode 100644 index 0000000000..de5e3bbb5d --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/GroupDefinition.h @@ -0,0 +1,59 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _GROUPDEFINITION_H_ +#define _GROUPDEFINITION_H_ + +#include "commonj/sdo/disable_warn.h" +#include "commonj/sdo/GroupEvent.h" + +#include "list" + + +namespace commonj +{ + namespace sdo + { + + +/** + * TypeDefinition holds information gathered from parsing the + * XSD and used for creating Types + */ + class GroupDefinition + { + + public: + GroupDefinition(); + virtual ~GroupDefinition(); + + + SDOXMLString name; + SDOXMLString uri; + bool isAttributeGroup; + std::vector events; + + }; + } // End - namespace sdo +} // End - namespace commonj + + +#endif //_TYPEDEFINITION_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/GroupEvent.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/GroupEvent.cpp new file mode 100644 index 0000000000..58c229ac0a --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/GroupEvent.cpp @@ -0,0 +1,65 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + + +#include "commonj/sdo/GroupEvent.h" +namespace commonj +{ + namespace sdo + { + GroupEvent::GroupEvent() + { + } + + GroupEvent::GroupEvent( + const SDOXMLString& inlocalname, + const SDOXMLString& inprefix, + const SDOXMLString& inURI, + const SAX2Namespaces& innamespaces, + const SAX2Attributes& inattributes + ) + { + localname = inlocalname; + prefix = inprefix; + URI = inURI; + namespaces = innamespaces; + attributes = inattributes; + isStartEvent = true; + } + + GroupEvent::GroupEvent( + const SDOXMLString& inlocalname, + const SDOXMLString& inprefix, + const SDOXMLString& inURI + ) + { + localname = inlocalname; + prefix = inprefix; + URI = inURI; + isStartEvent = false; + } + + GroupEvent::~GroupEvent() + { + } + + } // End - namespace sdo +} // End - namespace commonj diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/GroupEvent.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/GroupEvent.h new file mode 100644 index 0000000000..f6495687ba --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/GroupEvent.h @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef _GROUPEVENT_H_ +#define _GROUPEVENT_H_ + +#include "commonj/sdo/disable_warn.h" + + +#include "commonj/sdo/SAX2Parser.h" + +namespace commonj +{ + namespace sdo + { + + + class GroupEvent + { + + public: + GroupEvent(); + GroupEvent( + const SDOXMLString& inlocalname, + const SDOXMLString& inprefix, + const SDOXMLString& inURI, + const SAX2Namespaces& innamespaces, + const SAX2Attributes& inattributes + ); + + GroupEvent( + const SDOXMLString& inlocalname, + const SDOXMLString& inprefix, + const SDOXMLString& inURI + ); + + virtual ~GroupEvent(); + + bool isStartEvent; + SDOXMLString localname; + SDOXMLString prefix; + SDOXMLString URI; + SAX2Namespaces namespaces; + SAX2Attributes attributes; + + + }; + } // End - namespace sdo +} // End - namespace commonj + + +#endif //_TYPEDEFINITION_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/HelperProvider.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/HelperProvider.cpp new file mode 100644 index 0000000000..ec17d97b02 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/HelperProvider.cpp @@ -0,0 +1,49 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/HelperProvider.h" +#include "commonj/sdo/XSDHelperImpl.h" +#include "commonj/sdo/XMLHelperImpl.h" +#include "commonj/sdo/export.h" +#include "commonj/sdo/DataFactory.h" + +namespace commonj +{ + namespace sdo + { + + ////////////////////////////////////////////////////////////////////// + // Create an XSDHelper + ////////////////////////////////////////////////////////////////////// + XSDHelperPtr HelperProvider::getXSDHelper(DataFactoryPtr dataFactory) + { + return new XSDHelperImpl(dataFactory); + } + ////////////////////////////////////////////////////////////////////// + // Create an XMLHelper + ////////////////////////////////////////////////////////////////////// + XMLHelperPtr HelperProvider::getXMLHelper(DataFactoryPtr dataFactory) + { + return new XMLHelperImpl(dataFactory); + } + + } // End - namespace sdo +} // End - namespace commonj diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/HelperProvider.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/HelperProvider.h new file mode 100644 index 0000000000..426b069b56 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/HelperProvider.h @@ -0,0 +1,67 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _HELPERPROVIDER_H_ +#define _HELPERPROVIDER_H_ + + +#include "commonj/sdo/XSDHelper.h" +#include "commonj/sdo/XMLHelper.h" +#include "commonj/sdo/DataFactory.h" +#include "commonj/sdo/export.h" + + +namespace commonj +{ + namespace sdo + { + + +/** + * HelperProvider gives access to helpers (static methods). + * + * The helper provider gives back an XSD or XML helper associated + * with the given data factory + */ + class HelperProvider + { + public: + +/** + * + * The helper provider gives back an XSD helper associated + * with the given data factory + */ + SDO_API static XSDHelperPtr getXSDHelper(DataFactoryPtr dataFactory=0); + +/** + * + * The helper provider gives back an XML helper associated + * with the given data factory + */ + SDO_API static XMLHelperPtr getXMLHelper(DataFactoryPtr dataFactory=0); + + }; + + } // End - namespace sdo +} // End - namespace commonj + +#endif // _HELPERPROVIDER_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/LogWriter.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/LogWriter.cpp new file mode 100644 index 0000000000..d43b918a77 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/LogWriter.cpp @@ -0,0 +1,34 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/LogWriter.h" + +namespace commonj +{ + namespace sdo + { + LogWriter::~LogWriter() + { + } + + } // End namespace sdo +} // End namespace commonj + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/LogWriter.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/LogWriter.h new file mode 100644 index 0000000000..40954d9b25 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/LogWriter.h @@ -0,0 +1,46 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef SDO_LOGWriter_H +#define SDO_LOGWriter_H + +#include "commonj/sdo/export.h" + +namespace commonj +{ + namespace sdo + { + +/** + * LogWriter is an abstract class for implementers to inherit from. + * see DefaultLogWriter. + */ + class LogWriter + { + public: + virtual ~LogWriter(); + + SDO_API virtual void log(int indent, int level, const char* msg) = 0; + }; + + } // End namespace sdo +} // End namespace commonj +#endif // SDO_LOGWriter_H diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Logger.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Logger.cpp new file mode 100644 index 0000000000..47f7072c38 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Logger.cpp @@ -0,0 +1,102 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/Logger.h" +#include +#include +#include "commonj/sdo/DefaultLogWriter.h" +#include +#include +using namespace std; + +namespace commonj +{ + namespace sdo + { + LogWriter* Logger::logWriter = getLogWriter(); + + LogWriter* Logger::getLogWriter() + { + if (logWriter == 0) + { + setLogWriter(0); + } + return logWriter; + } + + void Logger::setLogWriter(LogWriter* writer) + { + if (logWriter != writer) + { + delete logWriter; + } + + if (writer == 0) + { + logWriter = new DefaultLogWriter; + } + else + { + logWriter = writer; + } + } + + int Logger::loggingLevel = setLogging(); + + int Logger::setLogging() + { + char* loggingVar = 0; + loggingVar = getenv("TUSCANY_SDOCPP_LOGGING"); + if (loggingVar == 0) + return 0; + else + return atoi(loggingVar); + } + + void Logger::setLogging(int level) + { + loggingLevel = level; + } + + void Logger::log(int indent, int level, const char* msg) + { + if (level <= loggingLevel) + { + logWriter->log(indent, level, msg); + } + } + + void Logger::logArgs(int indent, int level, const char* msg, ...) + { + if (level <= loggingLevel) + { + va_list variableArguments; + va_start(variableArguments, msg); + char messageBuffer[1024]; + vsprintf(messageBuffer, msg, variableArguments); + logWriter->log(indent, level, messageBuffer); + va_end(variableArguments); + } + } + + } // End namespace sdo +} // End namespace commonj + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Logger.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Logger.h new file mode 100644 index 0000000000..556d503154 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Logger.h @@ -0,0 +1,71 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef SDO_LOGGER_H +#define SDO_LOGGER_H + + + +#include "commonj/sdo/export.h" +#include "commonj/sdo/LogWriter.h" +namespace commonj +{ + namespace sdo + { + +/** + * Logger is used for debug style logging such as method trace. + * The logger can log at different levels, and can log entry, exit + * and events. The log entries can take arguments or be just + * strings. + */ + class Logger { + + public: +/** + * attach a log writer. + */ + SDO_API static void setLogWriter(LogWriter* writer); +/** + * switch logging to a level. + */ + SDO_API static void setLogging(int level); + +/** + * log a message. + */ + SDO_API static void log(int indent, int level, const char* msg); +/** + * log a message with parameters. + */ + SDO_API static void logArgs(int indent, int level, const char* msg, ...); + + static int loggingLevel; + + private: + static LogWriter* logWriter; + static LogWriter* getLogWriter(); + static int setLogging(); + }; + + } // End namespace sdo +} // End namespace commonj +#endif // SDO_LOGGER_H diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Logging.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Logging.h new file mode 100644 index 0000000000..2d72d6f42d --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Logging.h @@ -0,0 +1,171 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/Logger.h" +#include "commonj/sdo/SDORuntimeException.h" + +#ifndef SDO_LOGGING_H +#define SDO_LOGGING_H + +/** + * logging level for stuff you rarely want to see, like + * memory allocations. + */ + +#define HIGHVOLUME 40 +/** + * logging level for normal path information + */ +#define INFO 30 + + /** + * logging level for something which is unusual. + */ + +#define WARNING 20 +/** + * logging level for a major problem + */ + +#define ERROR 10 + +#define INDENT 1 +#define OUTDENT -1 +#define NODENT 0 + + +/** + * Macro for simplifying addition of trace points + */ + +#ifdef _DEBUG +#define LOGENTRY(level, methodName) \ +if (Logger::loggingLevel >= level) \ +Logger::logArgs(INDENT, level, "Entering: %s", methodName); + +/** + * Macro for simplifying addition of trace points + */ +#define LOGEXIT(level, methodName) \ +if (Logger::loggingLevel >= level) \ +Logger::logArgs(OUTDENT, level, "Exiting: %s" ,methodName); + +/** + * Macro for simplifying addition of trace points + */ +#define LOGINFO(level, message) \ +if (Logger::loggingLevel >= level) \ +Logger::log(NODENT, level, message); + +/** + * Macro for simplifying addition of trace points + */ +#define LOGINFO_1(level, message, arg1) \ +if (Logger::loggingLevel >= level) \ +Logger::logArgs(NODENT,level, message, arg1); + +/** + * Macro for simplifying addition of trace points + */ +#define LOGINFO_2(level, message, arg1, arg2) \ +if (Logger::loggingLevel >= level) \ +Logger::logArgs(NODENT,level, message, arg1, arg2); + +/** + * Macro for simplifying addition of trace points + */ +#define LOGERROR(level, message) \ +if (Logger::loggingLevel >= level) \ +Logger::log(NODENT,level, message); + +/** + * Macro for simplifying addition of trace points + */ +#define LOGERROR_1(level, message, arg1) \ +if (Logger::loggingLevel >= level) \ +Logger::logArgs(NODENT,level, message, arg1); + +/** + * Macro for simplifying addition of trace points + */ +#define LOGERROR_2(level, message, arg1, arg2) \ +if (Logger::loggingLevel >= level) \ +Logger::logArgs(NODENT,level, message, arg1, arg2); + +/** + * Macro for simplifying addition of trace points + */ +#define LOGSDOEXCEPTION(level, message, arg1) \ +if (Logger::loggingLevel >= level) \ +Logger::log(NODENT,level, message);\ +Logger::logArgs(NODENT,level, "%s:%s\nIn %s\nAt %s line %ld\n",\ + ((SDORuntimeException)arg1).getEClassName(),\ + ((SDORuntimeException)arg1).getMessageText(),\ + ((SDORuntimeException)arg1).getFunctionName(),\ + ((SDORuntimeException)arg1).getFileName(),\ + ((SDORuntimeException)arg1).getLineNumber()); + +#else // Not DEBUG + +/** + * Macro for simplifying addition of trace points + */ +#define LOGSDOEXCEPTION(level, message, arg1) + +/** + * Macro for simplifying addition of trace points + */ +#define LOGENTRY(level, methodName) + +/** + * Macro for simplifying addition of trace points + */ +#define LOGEXIT(level, methodName) + +/** + * Macro for simplifying addition of trace points + */ +#define LOGINFO(level, message) + +/** + * Macro for simplifying addition of trace points + */ +#define LOGINFO_1(level, message, arg1) + +/** + * Macro for simplifying addition of trace points + */ +#define LOGINFO_2(level, message, arg1, arg2) +/** + * Macro for simplifying addition of trace points + */ +#define LOGERROR(level, message) +/** + * Macro for simplifying addition of trace points + */ +#define LOGERROR_1(level, message, arg1) +/** + * Macro for simplifying addition of trace points + */ +#define LOGERROR_2(level, message, arg1, arg2) + +#endif +#endif // SDO_LOGGING_H diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Makefile.am b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Makefile.am new file mode 100644 index 0000000000..f38e1b27ab --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Makefile.am @@ -0,0 +1,106 @@ +# 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. + +lib_LTLIBRARIES = libtuscany_sdo.la +AM_CPPFLAGS = $(CPPFLAGS) + +libtuscany_sdo_la_SOURCES = \ + ChangedDataObjectListImpl.cpp \ + ChangeSummaryBuilder.cpp \ + ChangeSummary.cpp \ + ChangeSummaryImpl.cpp \ + CopyHelper.cpp \ + DASProperty.cpp \ + DASType.cpp \ + DASValue.cpp \ + DASValues.cpp \ + DataFactory.cpp \ + DataFactoryImpl.cpp \ + DataGraph.cpp \ + DataGraphImpl.cpp \ + DataObject.cpp \ + DataObjectImpl.cpp \ + DataObjectInstance.cpp \ + DataObjectList.cpp \ + DataObjectListImpl.cpp \ + DataTypeInfo.cpp \ + DefaultLogWriter.cpp \ + EqualityHelper.cpp \ + GroupDefinition.cpp \ + GroupEvent.cpp \ + HelperProvider.cpp \ + Logger.cpp \ + LogWriter.cpp \ + ParserErrorSetter.cpp \ + Property.cpp \ + PropertyDefinition.cpp \ + PropertyDefinitionImpl.cpp \ + PropertyImpl.cpp \ + PropertyList.cpp \ + PropertySetting.cpp \ + RefCountingObject.cpp \ + RefCountingPointer.cpp \ + SAX2Attribute.cpp \ + SAX2Attributes.cpp \ + SAX2Namespaces.cpp \ + SAX2Parser.cpp \ + SchemaInfo.cpp \ + SdoCheck.cpp \ + SDODataConverter.cpp \ + SDODate.cpp \ + SdoRuntime.cpp \ + SDORuntimeException.cpp \ + SDOSAX2Parser.cpp \ + SDOSchemaSAX2Parser.cpp \ + SDOUtils.cpp \ + SDOValue.cpp \ + SDOXMLBufferWriter.cpp \ + SDOXMLFileWriter.cpp \ + SDOXMLStreamWriter.cpp \ + SDOXMLString.cpp \ + SDOXMLWriter.cpp \ + SDOXSDBufferWriter.cpp \ + SDOXSDFileWriter.cpp \ + SDOXSDStreamWriter.cpp \ + SDOXSDWriter.cpp \ + Sequence.cpp \ + SequenceImpl.cpp \ + Setting.cpp \ + SettingList.cpp \ + Type.cpp \ + TypeDefinition.cpp \ + TypeDefinitions.cpp \ + TypeDefinitionImpl.cpp \ + TypeDefinitionsImpl.cpp \ + TypeImpl.cpp \ + TypeList.cpp \ + XMLDocument.cpp \ + XMLDocumentImpl.cpp \ + XMLHelper.cpp \ + XMLHelperImpl.cpp \ + XMLQName.cpp \ + XpathHelper.cpp \ + XSDHelper.cpp \ + XSDHelperImpl.cpp \ + XSDPropertyInfo.cpp \ + XSDTypeInfo.cpp + +libtuscany_sdo_la_LIBADD = -L${LIBXML2_LIB} -lxml2 + +INCLUDES = -I$(top_builddir)/runtime/core/src \ + -I${LIBXML2_INCLUDE} + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ParserErrorSetter.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ParserErrorSetter.cpp new file mode 100644 index 0000000000..14d5d7aa1b --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ParserErrorSetter.cpp @@ -0,0 +1,40 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +// ParserErrorSetter.cpp: class allowing parser to push errors back. +// +////////////////////////////////////////////////////////////////////// +#include "commonj/sdo/ParserErrorSetter.h" +namespace commonj +{ + namespace sdo + { + ////////////////////////////////////////////////////////////////////// + // Construction/Destruction + ////////////////////////////////////////////////////////////////////// + ParserErrorSetter::~ParserErrorSetter() + { + } + + } // End - namespace sdo +} // End - namespace commonj + + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ParserErrorSetter.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ParserErrorSetter.h new file mode 100644 index 0000000000..7156a3d297 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/ParserErrorSetter.h @@ -0,0 +1,51 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _PARSER_ERROR_SETTER_H_ +#define _PARSER_ERROR_SETTER_H_ + +#include "commonj/sdo/export.h" + +#include "commonj/sdo/disable_warn.h" + +namespace commonj{ +namespace sdo{ + +/** + * The ParserErrorSetter builds a list of all the errors which + * occurred during a parse, so they can be displayed for the + * user of an XSDHelper or XMLHelper + */ + +class ParserErrorSetter +{ +public: + virtual ~ParserErrorSetter(); + virtual void setError(const char* message) = 0; + virtual void clearErrors() = 0; + +protected: + +}; +}; +}; + +#endif diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Property.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Property.cpp new file mode 100644 index 0000000000..8e4a13ad9b --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Property.cpp @@ -0,0 +1,44 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include +using namespace std; + + +#ifndef SDO_EXPORTS +#define SDO_EXPORTS +#endif +#include "commonj/sdo/export.h" + +#include "commonj/sdo/Sequence.h" +#include "commonj/sdo/DataObject.h" +#include "commonj/sdo/TypeList.h" + +#include "commonj/sdo/Type.h" +#include "commonj/sdo/Property.h" +namespace commonj{ +namespace sdo{ + + // All delegated to the impl. + +}; +}; + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Property.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Property.h new file mode 100644 index 0000000000..74892ca832 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Property.h @@ -0,0 +1,207 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _PROPERTY_H_ +#define _PROPERTY_H_ + + +#include "commonj/sdo/export.h" + +#include "commonj/sdo/Type.h" +#include "commonj/sdo/SDODate.h" + +namespace commonj{ +namespace sdo{ + +class Type; +class TypeImpl; +class DataObject; + +/** + * + * A representation of a property in the type of a data object. + */ + +class Property +{ + public: + + /** getName gets the name of the property + * + * Returns the name of the property. + */ + + // TODO: We would like the returned value to be an SDOString but not until the internals are ready + virtual const SDO_API char* getName() const = 0; + // virtual const SDO_API SDOString& getName() const = 0; + + /** getAlias returns the n'th alias + * + * This method returns a const char* corresponding to the + * alias at index n of the list of aliases. Use getAliasCount to + * discover the size of the list. + */ + + // TODO: We would lke to convert the returned value to an SDOString but that means a rename for the method. + virtual SDO_API const char* getAlias(unsigned int index = 0) const = 0; + + // virtual SDO_API const SDOString& getAlias(unsigned int index = 0) const = 0; + + /** getAliasCount returns the number of aliases + * + * This method returns the number of aliases for this type + */ + + virtual SDO_API unsigned int getAliasCount() const = 0; + + /** getType returns the type of this property + * + * This method returns the type, which may be a DataType or a + * DataObjectType + */ + + virtual SDO_API const Type& getType() const = 0; + + /** getTypeEnum gets the enum for this type. + * + * Each DataType has a defined value in the list of Types. + */ + + virtual SDO_API const Type::Types getTypeEnum() const = 0; + + /** isMany is true if the property is a list + * + * IsMany returns true if this property represents a list of + * values, and should be accessed via the getList DataObjectAPI. + */ + + virtual bool SDO_API isMany() const = 0; + + /** isContainment is true if the property value is contained + * + * IsContainment returns true if this property represents a DataObjectType, + * and that DataObjectType is contained. I.E the property value is not a pointer + * to a DataObject somewhere else in the graph, it is an actual value. + */ + + virtual bool SDO_API isContainment() const = 0; + + /** isReference is true if the property value is not contained + * + * IsReference returns true if this property represents a DataObjectType, + * and that DataObjectType is not contained. I.E the property value is a pointer + * to a DataObject somewhere else in the graph not an actual value. + */ + + virtual bool SDO_API isReference() const = 0; + + /** getContainingType give the type which holds this property. + * + * Although many types may have a property of the same name, any given + * instance of a property belongs to only one type. + * This method returns the type which holds this proeprty. + */ + + virtual SDO_API const Type& getContainingType() const = 0; + + + + /** isReadOnly returns true if the property is unmodifiable. + * + * NOT IMPLEMENTED + * Returns true if values for this Property cannot be modified using the SDO APIs. + * When true, DataObject.set(Property property, Object value) throws an exception. + * Values may change due to other factors, such as services operating on DataObjects. + */ + + virtual bool SDO_API isReadOnly() const = 0; + + /** getOpposite returns the opposite property or zero. + * + * NOT IMPLEMENTED + */ + + virtual SDO_API const Property* getOpposite() const = 0; + + /** isDefaulted is true if a default has been set. + * + * A property value may be set or unset. If unset, requests to the + * data object for the value will return a default if there is one. + * If the property is not defaulted, an un specified value will be + * returned. (Thism value will probably be zero). + */ + + virtual SDO_API bool isDefaulted() const = 0 ; + + /** setDefault sets the right sort of default. + * + * The many overrides of this method allow the setting + * of a default value for any DataType property. + */ + + virtual SDO_API void setDefault(bool b ) = 0; + virtual SDO_API void setDefault(char c) = 0; + virtual SDO_API void setDefault(wchar_t c) = 0; + virtual SDO_API void setDefault(char* c) = 0; + virtual SDO_API void setDefault(const SDOString& c) = 0; + virtual SDO_API void setDefault(short s) = 0; +#if __WORDSIZE !=64 + virtual SDO_API void setDefault(long l) = 0; +#endif + virtual SDO_API void setDefault(int64_t i) = 0; + virtual SDO_API void setDefault(float f) = 0; + virtual SDO_API void setDefault(long double d) = 0; + virtual SDO_API void setDefault(const SDODate d) = 0; + virtual SDO_API void setDefault(const wchar_t* c, unsigned int len) = 0; + virtual SDO_API void setDefault(const char* c, unsigned int len) = 0; + virtual SDO_API void setDefault(const SDOString& c, unsigned int len) = 0; + + /** getDefault gets the right sort of default. + * + * The many overrides of this method allow the getting + * of a default value for any DataType property. + */ + + virtual SDO_API unsigned int getStringDefault(wchar_t* val, unsigned int max) const = 0; + virtual SDO_API unsigned int getBytesDefault(char* val, unsigned int max) const = 0; + virtual SDO_API unsigned int getBytesDefault(SDOString& val, unsigned int max) const = 0; + virtual SDO_API bool getBooleanDefault() const = 0; + virtual SDO_API char getByteDefault() const = 0; + virtual SDO_API wchar_t getCharacterDefault() const = 0; + virtual SDO_API short getShortDefault() const = 0; + virtual SDO_API long getIntegerDefault() const = 0; + virtual SDO_API int64_t getLongDefault() const = 0; + virtual SDO_API float getFloatDefault() const = 0; + virtual SDO_API long double getDoubleDefault() const = 0; + virtual SDO_API const SDODate getDateDefault() const = 0; + virtual SDO_API const char* getCStringDefault() const = 0; + // TODO: Can't overload return types. + // virtual SDO_API const SDOString& getSDOStringDefault() const = 0; + virtual SDO_API unsigned int getDefaultLength() const = 0; + + +}; + + +}; +}; + +#endif //_PROPERTY_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyDefinition.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyDefinition.cpp new file mode 100644 index 0000000000..6b3d802323 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyDefinition.cpp @@ -0,0 +1,323 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/PropertyDefinition.h" +#include "commonj/sdo/PropertyDefinitionImpl.h" + +namespace commonj +{ + namespace sdo + { + + PropertyDefinition::PropertyDefinition() + { + propertydefinition = new PropertyDefinitionImpl(); + } + + PropertyDefinition::~PropertyDefinition() + { + if (propertydefinition) delete propertydefinition; + } + + void PropertyDefinition::copy (const PropertyDefinition& pd) + { + if (propertydefinition != 0) delete propertydefinition; + propertydefinition = new PropertyDefinitionImpl(*(pd.propertydefinition)); + } + + PropertyDefinition::PropertyDefinition(const PropertyDefinition& pd) + { + copy(pd); + } + + PropertyDefinition& PropertyDefinition::operator=(const PropertyDefinition& pd) + { + if (this != &pd) + { + copy(pd); + } + return *this; + } + + PropertyDefinitionImpl* PropertyDefinition::getPropertyDefinition() + { + return propertydefinition; + } + + // where this property is to be substituted for another + void PropertyDefinition::setSubstituteName(const char * name) + { + propertydefinition->substituteName = name; + } + void PropertyDefinition::setSubstituteName(const SDOString& name) + { + propertydefinition->substituteName = name.c_str(); + } + + const char* PropertyDefinition::getSubstituteName() const + { + return (const char *)propertydefinition->substituteName; + } + + + void PropertyDefinition::setSubstituteUri(const char* name) + { + propertydefinition->substituteUri = name; + } + void PropertyDefinition::setSubstituteUri(const SDOString& name) + { + propertydefinition->substituteUri = name.c_str(); + } + + const char* PropertyDefinition::getSubstituteUri() const + { + return (const char*)propertydefinition->substituteUri; + } + + // where there are substitute names for this property. + void PropertyDefinition::addSubstitute(const SDOString& name, + const SDOString& localname) + { + propertydefinition->substituteNames.push_back(name.c_str()); + propertydefinition->substituteLocalNames.push_back(localname.c_str()); + } + + int PropertyDefinition::getSubstituteCount() const + { + return propertydefinition->substituteNames.size(); + } + + const char* PropertyDefinition::getSubstituteNames(unsigned int index) const + { + if (index >= 0 && index < propertydefinition->substituteNames.size()) + { + return propertydefinition->substituteNames[index];; + } + return 0; + } + + const char* PropertyDefinition::getSubstituteLocalNames(unsigned int index) const + { + if (index >= 0 && index < propertydefinition->substituteLocalNames.size()) + { + return propertydefinition->substituteLocalNames[index];; + } + return 0; + } + + + void PropertyDefinition::setAliases(const char* aliases) + { + propertydefinition->aliases = aliases; + } + void PropertyDefinition::setAliases(const SDOString& aliases) + { + propertydefinition->aliases = aliases.c_str(); + } + + const char* PropertyDefinition::getAliases() const + { + return (const char *)propertydefinition->aliases; + } + + void PropertyDefinition::setName(const char* name) + { + propertydefinition->name = name; + } + void PropertyDefinition::setName(const SDOString& name) + { + propertydefinition->name = name.c_str(); + } + + const char* PropertyDefinition::getName() const + { + return (const char *)propertydefinition->name; + } + + void PropertyDefinition::setLocalName(const char* name) + { + propertydefinition->localname = name; + } + void PropertyDefinition::setLocalName(const SDOString& name) + { + propertydefinition->localname = name.c_str(); + } + + const char* PropertyDefinition::getLocalName() const + { + return (const char*)propertydefinition->localname; + } + + void PropertyDefinition::setType(const char* uri, const char* name) + { + propertydefinition->typeUri = uri; + propertydefinition->typeName = name; + propertydefinition->fullTypeName = uri; + propertydefinition->fullTypeName += "#"; + propertydefinition->fullTypeName += name; + } + void PropertyDefinition::setType(const SDOString& uri, const SDOString& name) + { + propertydefinition->typeUri = uri.c_str(); + propertydefinition->typeName = name.c_str(); + propertydefinition->fullTypeName = uri.c_str(); + propertydefinition->fullTypeName += "#"; + propertydefinition->fullTypeName += name.c_str(); + } + + const char * PropertyDefinition::getTypeName() const + { + return propertydefinition->typeName; + } + + const char * PropertyDefinition::getTypeUri() const + { + return propertydefinition->typeUri; + } + + const char * PropertyDefinition::getTypeFullName() const + { + return propertydefinition->fullTypeName; + } + + const char * PropertyDefinition::getTypeFullLocalName() const + { + return propertydefinition->fullLocalTypeName; + } + + void PropertyDefinition::setTypeFullLocalName(const char* name) + { + propertydefinition->fullLocalTypeName = name; + } + void PropertyDefinition::setTypeFullLocalName(const SDOString& name) + { + propertydefinition->fullLocalTypeName = name.c_str(); + } + + + void PropertyDefinition::setDefaultValue(const char* value) + { + propertydefinition->defaultValue = value; + } + void PropertyDefinition::setDefaultValue(const SDOString& value) + { + propertydefinition->defaultValue = value.c_str(); + } + + const char* PropertyDefinition::getDefaultValue() const + { + return propertydefinition->defaultValue; + } + + bool PropertyDefinition::getIsMany() const + { + return propertydefinition->isMany; + } + + bool PropertyDefinition::getIsContainment() const + { + return propertydefinition->isContainment; + } + + bool PropertyDefinition::getIsReadOnly() const + { + return propertydefinition->isReadOnly; + } + + bool PropertyDefinition::getIsID() const + { + return propertydefinition->isID; + } + + bool PropertyDefinition::getIsIDREF() const + { + return propertydefinition->isIDREF; + } + + bool PropertyDefinition::getIsReference() const + { + return propertydefinition->isReference; + } + + bool PropertyDefinition::getIsElement() const + { + return propertydefinition->isElement; + } + + bool PropertyDefinition::getIsQName() const + { + return propertydefinition->isQName; + } + + bool PropertyDefinition::getIsSubstitute() const + { + return propertydefinition->isSubstitute; + } + + + void PropertyDefinition::setIsMany(bool value) + { + propertydefinition->isMany = value; + } + + void PropertyDefinition::setIsContainment(bool value) + { + propertydefinition->isContainment = value; + } + + void PropertyDefinition::setIsReadOnly(bool value) + { + propertydefinition->isReadOnly = value; + } + + void PropertyDefinition::setIsID(bool value) + { + propertydefinition->isID = value; + } + + void PropertyDefinition::setIsIDREF(bool value) + { + propertydefinition->isIDREF = value; + } + + void PropertyDefinition::setIsReference(bool value) + { + propertydefinition->isReference = value; + } + + void PropertyDefinition::setIsElement(bool value) + { + propertydefinition->isElement = value; + } + + void PropertyDefinition::setIsQName(bool value) + { + propertydefinition->isQName = value; + } + + void PropertyDefinition::setIsSubstitute(bool value) + { + propertydefinition->isSubstitute = value; + } + + + } // End - namespace sdo +} // End - namespace commonj diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyDefinition.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyDefinition.h new file mode 100644 index 0000000000..0f6bb6be97 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyDefinition.h @@ -0,0 +1,135 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _PROPERTYDefinition_H_ +#define _PROPERTYDefinition_H_ + +#include "export.h" + +#include +#include "commonj/sdo/SDOString.h" + + + +namespace commonj +{ + namespace sdo + { + + class PropertyDefinitionImpl; + +/** + * PropertyDefinitionImpl holds a property as defined by an XSD. + * The XSD holds more information than does the SDO Property. + * This class holds the extra information found as the XSD is + * parsed. + */ + class SDO_API PropertyDefinition + { + + public: + + + /*SDO_API*/ PropertyDefinition(); + PropertyDefinition(const PropertyDefinition& pd); + PropertyDefinition& operator=(const PropertyDefinition& pd); + + /*SDO_API*/ virtual ~PropertyDefinition(); + + PropertyDefinitionImpl* getPropertyDefinition(); + + + + // where this property is to be substituted for another + /*SDO_API*/ void setSubstituteName(const char * name); + /*SDO_API*/ void setSubstituteName(const SDOString& name); + /*SDO_API*/ const char* getSubstituteName() const; + + /*SDO_API*/ void setSubstituteUri(const char* name); + /*SDO_API*/ void setSubstituteUri(const SDOString& name); + /*SDO_API*/ const char* getSubstituteUri() const; + + // where there are substitute names for this property. + /*SDO_API*/ void addSubstitute(const char* name, + const char* localname); + /*SDO_API*/ void addSubstitute(const SDOString& name, + const SDOString& localname); + /*SDO_API*/ int getSubstituteCount() const; + /*SDO_API*/ const char* getSubstituteNames(unsigned int index) const; + /*SDO_API*/ const char* getSubstituteLocalNames(unsigned int index) const; + + + /*SDO_API*/ void setAliases(const char* aliases); + /*SDO_API*/ void setAliases(const SDOString& aliases); + /*SDO_API*/ const char* getAliases() const; + + /*SDO_API*/ void setName(const char* name); + /*SDO_API*/ void setName(const SDOString& name); + /*SDO_API*/ const char* getName() const; + + /*SDO_API*/ void setLocalName(const char* name); + /*SDO_API*/ void setLocalName(const SDOString& name); + /*SDO_API*/ const char* getLocalName() const; + + /*SDO_API*/ void setType(const char* uri, const char* name); + /*SDO_API*/ void setType(const SDOString& uri, const SDOString& name); + /*SDO_API*/ const char * getTypeName() const; + /*SDO_API*/ const char * getTypeUri() const; + /*SDO_API*/ const char * getTypeFullName() const; + /*SDO_API*/ const char * getTypeFullLocalName() const ; + + /*SDO_API*/ void setTypeFullLocalName(const char* name); + /*SDO_API*/ void setTypeFullLocalName(const SDOString& name); + + /*SDO_API*/ void setDefaultValue(const char* value); + /*SDO_API*/ void setDefaultValue(const SDOString& value); + /*SDO_API*/ const char* getDefaultValue() const; + + /*SDO_API*/ bool getIsMany() const; + /*SDO_API*/ bool getIsContainment() const; + /*SDO_API*/ bool getIsReadOnly() const; + /*SDO_API*/ bool getIsID() const; + /*SDO_API*/ bool getIsIDREF() const; + /*SDO_API*/ bool getIsReference() const; + /*SDO_API*/ bool getIsElement() const; + /*SDO_API*/ bool getIsQName() const; + /*SDO_API*/ bool getIsSubstitute() const; + + /*SDO_API*/ void setIsMany(bool value); + /*SDO_API*/ void setIsContainment(bool value); + /*SDO_API*/ void setIsReadOnly(bool value); + /*SDO_API*/ void setIsID(bool value); + /*SDO_API*/ void setIsIDREF(bool value); + /*SDO_API*/ void setIsReference(bool value); + /*SDO_API*/ void setIsElement(bool value); + /*SDO_API*/ void setIsQName(bool value); + /*SDO_API*/ void setIsSubstitute(bool value); + + + private: + PropertyDefinitionImpl* propertydefinition; + void copy(const PropertyDefinition& pd); + }; + } // End - namespace sdo +} // End - namespace commonj + + +#endif //_PROPERTYDefinitionImpl_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyDefinitionImpl.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyDefinitionImpl.cpp new file mode 100644 index 0000000000..c9ac38a90c --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyDefinitionImpl.cpp @@ -0,0 +1,46 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/PropertyDefinitionImpl.h" +namespace commonj +{ + namespace sdo + { + PropertyDefinitionImpl::PropertyDefinitionImpl() + : isMany(false), + isContainment(true), + isReadOnly(false), + isElement(false), + isReference(false), + isQName(false), + isID(false), + isIDREF(false), + isSubstitute(false) + + { + } + + PropertyDefinitionImpl::~PropertyDefinitionImpl() + { + } + + } // End - namespace sdo +} // End - namespace commonj diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyDefinitionImpl.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyDefinitionImpl.h new file mode 100644 index 0000000000..46764261d4 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyDefinitionImpl.h @@ -0,0 +1,90 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _PROPERTYDefinitionImpl_H_ +#define _PROPERTYDefinitionImpl_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/SDOXMLString.h" +#include + + + +namespace commonj +{ + namespace sdo + { + + +/** + * PropertyDefinitionImpl holds a property as defined by an XSD. + * The XSD holds more information than does the SDO Property. + * This class holds the extra information found as the XSD is + * parsed. + */ + class PropertyDefinitionImpl + { + + public: + PropertyDefinitionImpl(); + virtual ~PropertyDefinitionImpl(); + + // where this property is to be substituted for another + SDOXMLString substituteName; + SDOXMLString substituteUri; + + // where there are substitute names for this property. + std::vector substituteNames; + std::vector substituteLocalNames; + + SDOXMLString aliases; + + SDOXMLString name; + SDOXMLString localname; + SDOXMLString namespaceURI; + + SDOXMLString typeUri; + SDOXMLString typeName; + SDOXMLString fullTypeName; + + SDOXMLString fullLocalTypeName; + + SDOXMLString defaultValue; + + bool isMany; + bool isContainment; + bool isReadOnly; + + bool isID; + bool isIDREF; + bool isReference; + bool isElement; + + bool isQName; + + bool isSubstitute; + }; + } // End - namespace sdo +} // End - namespace commonj + + +#endif //_PROPERTYDefinitionImpl_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyImpl.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyImpl.cpp new file mode 100644 index 0000000000..38997e421e --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyImpl.cpp @@ -0,0 +1,594 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/export.h" + +#include +using namespace std; + + +#include "commonj/sdo/Sequence.h" +#include "commonj/sdo/DataObject.h" +#include "commonj/sdo/TypeList.h" + +#include "commonj/sdo/Type.h" +#include "commonj/sdo/TypeImpl.h" +#include "commonj/sdo/Property.h" +#include "commonj/sdo/PropertyImpl.h" +#include "commonj/sdo/DataFactoryImpl.h" +#include "commonj/sdo/SDORuntimeException.h" + +namespace commonj{ + namespace sdo{ + + + Substitution::Substitution() : name(), type(0) + { + } + + // Standard Constructor + Substitution::Substitution(DataFactoryPtr mdg, + const SDOString& inname, + const Type& intype) : name(inname) + { + DataFactory* f = (DataFactory*)mdg; + + type = ((DataFactoryImpl*)f)->findType(intype.getURI(),intype.getName()); + } + + // Copy constructor + Substitution::Substitution(const Substitution& s) : name(s.name), type(s.type) + { + } + + Substitution::~Substitution() + { + } + + + /////////////////////////////////////////////////////////////////////////// + // construction by DAS + /////////////////////////////////////////////////////////////////////////// + + PropertyImpl::PropertyImpl(const Type& cont, + const char* inname, + const TypeImpl& intype, + bool many , + bool ro , + bool contain) : + containertype(cont), + type(intype), + defvalue(0), + defvaluelength(0), + opposite(0), + stringdef(0), + bisMany(many), + bisArray(false), + bisReadOnly(ro), + bisContainer(contain), + bDefaulted(false), + bisReference(false) + { + if (inname != 0) + { + name = inname; + } + else + { + name.erase(); + } + if (contain == false && intype.isDataObjectType()) + { + bisReference = true; + } + } + + PropertyImpl::PropertyImpl(const Type& cont, + const SDOString& inname, + const TypeImpl& intype, + bool many, + bool ro, + bool contain) : + containertype(cont), + name(inname), + type(intype), + bisMany(many), + bisArray(false), + bisReadOnly(ro), + bisContainer(contain), + bDefaulted(false), + opposite(0), + stringdef(0), + defvalue(0), + defvaluelength(0), + bisReference(false) + { + if (contain == false && intype.isDataObjectType()) + { + bisReference = true; + } + } + + PropertyImpl::PropertyImpl(const PropertyImpl& p) : + type((*(p.getTypeImpl()))), + containertype(p.getContainingType()), + name(p.name), + bisMany(p.bisMany), + bisArray(false), + bisReadOnly(p.bisReadOnly), + bisContainer(p.bisContainer), + bDefaulted(false), + opposite(0), + defvalue(0), + defvaluelength(0), + stringdef(0), + bisReference(false) + { + if (bisContainer == false && type.isDataObjectType()) + { + bisReference = true; + } + } + + PropertyImpl::~PropertyImpl() + { + // If the default value is an array type then we must use delete[] + // otherwise delete + if (defvalue != 0) + { + if (bisArray) + { + delete[] defvalue; + } + else + { + delete defvalue; + } + } + if (stringdef != 0) + { + delete[] stringdef; + } + } + + /////////////////////////////////////////////////////////////////////////// + // Setting of attributes by DAS + /////////////////////////////////////////////////////////////////////////// + + void PropertyImpl::setMany(bool many) + { + bisMany = many; + } + + void PropertyImpl::setReadOnly(bool readonly) + { + bisReadOnly = readonly; + } + + void PropertyImpl::setContainment(bool contains) + { + if (contains == true && type.isDataType()) + { + return; + } + bisContainer = contains; + if (bisContainer == false && type.isDataObjectType()) + { + bisReference = true; + } + else + { + bisReference = false; + } + } + + + /////////////////////////////////////////////////////////////////////////// + // Setting of defaults by DAS + /////////////////////////////////////////////////////////////////////////// + + void PropertyImpl::setDefault(bool b ) + { + setDefaultBoolean(b); + } + + void PropertyImpl::setDefault(char c ) + { + setDefaultByte(c); + } + + void PropertyImpl::setDefault(wchar_t c ) + { + setDefaultCharacter(c); + } + void PropertyImpl::setDefault(char* c ) + { + setDefaultCString(c); + } + void PropertyImpl::setDefault(const SDOString& c) + { + setDefaultCString(c); + } + void PropertyImpl::setDefault(short s ) + { + setDefaultShort(s); + } +#if __WORDSIZE !=64 + void PropertyImpl::setDefault(long i ) + { + setDefaultInteger(i); + } +#endif + void PropertyImpl::setDefault(int64_t i ) + { + setDefaultLong(i); + } + void PropertyImpl::setDefault(float f ) + { + setDefaultFloat(f); + } + void PropertyImpl::setDefault(long double d ) + { + setDefaultDouble(d); + } + void PropertyImpl::setDefault(const SDODate d ) + { + setDefaultDate(d); + } + void PropertyImpl::setDefault(const char* c , unsigned int len) + { + setDefaultBytes(c, len); + } + void PropertyImpl::setDefault(const SDOString& c , unsigned int len) + { + setDefaultBytes(c, len); + } + + void PropertyImpl::setDefault(const wchar_t* c, unsigned int len ) + { + setDefaultString(c, len); + } + + /////////////////////////////////////////////////////////////////////////// + // Substitution groups. + /////////////////////////////////////////////////////////////////////////// + const Type* PropertyImpl::getSubstitutionType(const char* inname) const + { + for (unsigned int i=0;iisFromList())return true; + return bisMany; + } + + /////////////////////////////////////////////////////////////////////////// + // Returns whether the property is containment. + /////////////////////////////////////////////////////////////////////////// + bool PropertyImpl::isContainment() const + { + return bisContainer; + } + + /////////////////////////////////////////////////////////////////////////// + // Returns whether the property is containment. + /////////////////////////////////////////////////////////////////////////// + bool PropertyImpl::isReference() const + { + return bisReference; + } + + /////////////////////////////////////////////////////////////////////////// + // Returns the containing type of this property. + /////////////////////////////////////////////////////////////////////////// + const Type& PropertyImpl::getContainingType() const + { + return containertype; + } + + /////////////////////////////////////////////////////////////////////////// + // Returns the opposite. + /////////////////////////////////////////////////////////////////////////// + const Property* PropertyImpl::getOpposite() const + { + return opposite; + } + + void PropertyImpl::setOpposite(const Property* opp) + { + opposite = opp; + } + /////////////////////////////////////////////////////////////////////////// + // Returns the default value this property will have in a + // data object where the property hasn't been set. + /////////////////////////////////////////////////////////////////////////// + + // check whether the property has a default first + bool PropertyImpl::isDefaulted() const + { + return bDefaulted; + } + + const char* PropertyImpl::getCStringDefault() const + { + PropertyImpl* p = (PropertyImpl*)this; + return getTypeImpl()->convertToCString(defvalue, &(p->stringdef), defvaluelength); + } + bool PropertyImpl::getBooleanDefault() const + { + return getTypeImpl()->convertToBoolean(defvalue,defvaluelength); + } + char PropertyImpl::getByteDefault() const + { + return getTypeImpl()->convertToByte(defvalue,defvaluelength); + } + wchar_t PropertyImpl::getCharacterDefault() const + { + return getTypeImpl()->convertToCharacter(defvalue,defvaluelength); + } + short PropertyImpl::getShortDefault() const + { + return getTypeImpl()->convertToShort(defvalue,defvaluelength); + } + long PropertyImpl::getIntegerDefault() const + { + return getTypeImpl()->convertToInteger(defvalue,defvaluelength); + } + int64_t PropertyImpl::getLongDefault() const + { + return getTypeImpl()->convertToLong(defvalue,defvaluelength); + } + float PropertyImpl::getFloatDefault() const + { + return getTypeImpl()->convertToFloat(defvalue,defvaluelength); + } + long double PropertyImpl::getDoubleDefault() const + { + return getTypeImpl()->convertToDouble(defvalue,defvaluelength); + } + const SDODate PropertyImpl::getDateDefault() const + { + return getTypeImpl()->convertToDate(defvalue,defvaluelength); + } + unsigned int PropertyImpl::getStringDefault(wchar_t* val, unsigned int max) const + { + if (val == 0 || max == 0) return defvaluelength; + return getTypeImpl()->convertToString(defvalue, val, defvaluelength, max); + + } + unsigned int PropertyImpl::getBytesDefault(char* val, unsigned int max) const + { + if (val == 0 || max == 0) return defvaluelength; + return getTypeImpl()->convertToBytes(defvalue, val, defvaluelength, max); + } + + unsigned int PropertyImpl::getBytesDefault(SDOString& val, unsigned int max) const + { + if (max == 0) return defvaluelength; + return getTypeImpl()->convertToBytes(defvalue, val, defvaluelength, max); + } + + unsigned int PropertyImpl::getDefaultLength() const + { + return defvaluelength; + } + + /////////////////////////////////////////////////////////////////////////// + // sets the default value by type + /////////////////////////////////////////////////////////////////////////// + + void PropertyImpl::setDefaultCString(const char* s) + { + bDefaulted=true; + bisArray = true; + defvaluelength = getTypeImpl()->convert(&defvalue,s); + } + void PropertyImpl::setDefaultCString(const SDOString& s) + { + bDefaulted=true; + bisArray = true; + defvaluelength = getTypeImpl()->convert(&defvalue, s); + } + void PropertyImpl::setDefaultString( const wchar_t* c , unsigned int len ) + { + bDefaulted=true; + bisArray = true; + defvaluelength = getTypeImpl()->convert(&defvalue,c, len); + } + void PropertyImpl::setDefaultBytes( const char* c , unsigned int len ) + { + bDefaulted=true; + bisArray = true; + defvaluelength = getTypeImpl()->convert(&defvalue,c, len); + } + void PropertyImpl::setDefaultBytes(const SDOString& c , unsigned int len) + { + bDefaulted=true; + bisArray = true; + defvaluelength = getTypeImpl()->convert(&defvalue,c, len); + } + void PropertyImpl::setDefaultBoolean( const bool b ) + { + bDefaulted=true; + defvaluelength = getTypeImpl()->convert(&defvalue,b); + } + void PropertyImpl::setDefaultByte( const char c ) + { + bDefaulted=true; + defvaluelength = getTypeImpl()->convert(&defvalue,c); + } + void PropertyImpl::setDefaultCharacter( const wchar_t c) + { + bDefaulted=true; + defvaluelength = getTypeImpl()->convert(&defvalue,c); + } + void PropertyImpl::setDefaultShort( const short s ) + { + bDefaulted=true; + defvaluelength = getTypeImpl()->convert(&defvalue,s); + } + void PropertyImpl::setDefaultInteger( const long i ) + { + bDefaulted=true; +#if __WORDSIZE ==64 + defvaluelength = getTypeImpl()->convert(&defvalue,(int64_t)i); +#else + defvaluelength = getTypeImpl()->convert(&defvalue,i); +#endif + } + void PropertyImpl::setDefaultLong(const int64_t l) + { + bDefaulted=true; + defvaluelength = getTypeImpl()->convert(&defvalue,l); + } + void PropertyImpl::setDefaultFloat( const float f ) + { + bDefaulted=true; + defvaluelength = getTypeImpl()->convert(&defvalue,f); + } + void PropertyImpl::setDefaultDouble( const long double d ) + { + bDefaulted=true; + defvaluelength = getTypeImpl()->convert(&defvalue,d); + } + void PropertyImpl::setDefaultDate( const SDODate d ) + { + bDefaulted=true; + defvaluelength = getTypeImpl()->convertDate(&defvalue,d); + } + + /////////////////////////////////////////////////////////////////////////// + // Returns true if values for this Property cannot be modified using the SDO APIs. + // When true, DataObject.set(Property property, Object value) throws an exception. + // Values may change due to other factors, such as services operating on DataObjects. + /////////////////////////////////////////////////////////////////////////// + bool PropertyImpl::isReadOnly() const + { + return bisReadOnly; + } + +}; +}; + + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyImpl.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyImpl.h new file mode 100644 index 0000000000..760bde2215 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyImpl.h @@ -0,0 +1,294 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _PROPERTYIMPL_H_ +#define _PROPERTYIMPL_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/DASProperty.h" +#include "commonj/sdo/SDODate.h" +#include "commonj/sdo/DataFactory.h" + +namespace commonj{ +namespace sdo{ + +class Type; +class TypeImpl; +class DataObject; + +/** + * A substitution is a class which permits a property to be a substitute for + * another one. + * A substitution is a definition of a type which is allowed to be placed in the + * data object in place of a property of another type. + */ + +class Substitution +{ +public: + Substitution(); + Substitution(DataFactoryPtr mdg, const SDOString& inname, + const Type& intype); + Substitution(const Substitution& s); + virtual ~Substitution(); + const Type* type; + SDOString name; +}; + + + +/** PropertyImpl implements the abstract class Property. + * + * A representation of a property in the type of a data object. + */ + +class PropertyImpl :public DASProperty +{ + public: + + + /////////////////////////////////////////////////////////////////////////// + // Construction for the DAS + /////////////////////////////////////////////////////////////////////////// + + SDO_API PropertyImpl( + const Type& cont, + const char* name, + const TypeImpl& type, + bool many = false, + bool ro = false, + bool contain = false); + + SDO_API PropertyImpl(const Type& cont, + const SDOString& name, + const TypeImpl& type, + bool many = false, + bool ro = false, + bool contain = false); + + + + virtual SDO_API ~PropertyImpl(); + + /** + * A Data access service may set the features of this property instead of + * passing them as construction parameters. + */ + + virtual SDO_API void setMany(bool many ); + + /** + * A Data access service may set the features of this property instead of + * passing them as construction parameters. + */ + virtual SDO_API void setReadOnly(bool rdonly); + + /** + * A Data access service may set the features of this property instead of + * passing them as construction parameters. + */ + virtual SDO_API void setContainment(bool contains); + + /** + * A Data access service may set the features of this property instead of + * passing them as construction parameters. + */ + + virtual SDO_API bool isDefaulted() const; + + /** + * A Data access service sets the default value. + */ + + virtual SDO_API void setDefault(bool b ); + virtual SDO_API void setDefault(char c); + virtual SDO_API void setDefault(wchar_t c); + virtual SDO_API void setDefault(char* c); + virtual SDO_API void setDefault(const SDOString& c); + virtual SDO_API void setDefault(short s); +#if __WORDSIZE !=64 + virtual SDO_API void setDefault(long l); +#endif + virtual SDO_API void setDefault(int64_t i); + virtual SDO_API void setDefault(float f); + virtual SDO_API void setDefault(long double d); + virtual SDO_API void setDefault(const SDODate d); + virtual SDO_API void setDefault(const wchar_t* c, unsigned int len); + virtual SDO_API void setDefault(const char* c, unsigned int len); + virtual SDO_API void setDefault(const SDOString& c, unsigned int len); + + + + + + /** + * Returns the name of the property. + */ + + virtual const SDO_API char* getName() const; + + /** getAlias returns the n'th alias + * + * This method returns a const char* corresponding to the + * alias at index n of the list of aliases. Use getAliasCount to + * discover the size of the list. + */ + + virtual const char* getAlias(unsigned int index = 0) const ; + virtual unsigned int getAliasCount() const ; + virtual void setAlias(const char* alias) ; + virtual void setAlias(const SDOString& alias) ; + + /** + * + * SubstitutionGroup support. + */ + + virtual const Type* getSubstitutionType(const char* name) const ; + virtual unsigned int getSubstitutionCount(void) const ; + virtual const Type* getSubstitutionType(unsigned int index) const ; + virtual const char* getSubstitutionName(unsigned int index) const ; + virtual void setSubstitution(DataFactoryPtr mdg, const char* alias, + const Type& substype) ; + + + /** getType returns the type of this property + * + * This method returns the type, which may be a DataType or a + * DataObjectType + */ + + virtual SDO_API const Type& getType() const; + + virtual SDO_API const Type::Types getTypeEnum() const; + + virtual SDO_API const TypeImpl* getTypeImpl() const; + + /** + * Returns whether the property is many-valued. + */ + virtual bool SDO_API isMany() const; + + /** + * Returns whether the property is containment. + */ + virtual bool SDO_API isContainment() const; + + /** + * Returns whether the property is a reference. + */ + virtual bool SDO_API isReference() const; + + /** + * Returns the containing type of this property. + */ + virtual SDO_API const Type& getContainingType() const; + + /** + * returns the opposite property, or zero if there is none + */ + virtual SDO_API const Property* getOpposite() const; + + virtual void setOpposite(const Property* opp); + + + /** + * setters for type primitive types and 'an object' + */ + + SDO_API void setDefaultCString( const char* s); + SDO_API void setDefaultCString(const SDOString& s); + SDO_API void setDefaultString( const wchar_t* c , unsigned int len ); + SDO_API void setDefaultBytes( const char* c , unsigned int len ); + SDO_API void setDefaultBytes(const SDOString& c , unsigned int len); + SDO_API void setDefaultBoolean( const bool b ); + SDO_API void setDefaultByte( const char c ); + SDO_API void setDefaultCharacter( const wchar_t c); + SDO_API void setDefaultShort( const short s ); + SDO_API void setDefaultInteger( const long i ); + SDO_API void setDefaultLong(const int64_t l); + SDO_API void setDefaultFloat( const float f ); + SDO_API void setDefaultDouble( const long double d ); + SDO_API void setDefaultDate( const SDODate d ); + + SDO_API const char* getCStringDefault() const; + SDO_API unsigned int getStringDefault(wchar_t* val, unsigned int max) const; + SDO_API unsigned int getBytesDefault(char* val, unsigned int max) const; + SDO_API unsigned int getBytesDefault(SDOString& val, unsigned int max) const; + SDO_API bool getBooleanDefault() const; + SDO_API char getByteDefault() const; + SDO_API wchar_t getCharacterDefault() const; + SDO_API short getShortDefault() const; + SDO_API long getIntegerDefault() const; + SDO_API int64_t getLongDefault() const; + SDO_API float getFloatDefault() const; + SDO_API long double getDoubleDefault() const; + SDO_API const SDODate getDateDefault() const; + SDO_API unsigned int getDefaultLength() const; + + /** + * Returns true if values for this Property cannot be modified using the SDO APIs. + * When true, DataObject.set(Property property, Object value) throws an exception. + * Values may change due to other factors, such as services operating on DataObjects. + */ + virtual bool SDO_API isReadOnly() const; + + SDO_API PropertyImpl(const PropertyImpl& p); + + private: + + // clear the default value + void deleteValue(); + + bool bisReadOnly; + bool bisContainer; + bool bisReference; + bool bisMany; + bool bisArray; + + bool bDefaulted; + + const TypeImpl& type; + const Type& containertype; + const Property* opposite; + SDOString name; + char* stringdef; + + void* defvalue; + // in the event of a bytes and string, this holds the length + unsigned int defvaluelength; + + // alias support + // std::vector aliases; + std::vector aliases; + + std::vector substitutions; + + typedef std::list REFEREE_LIST; + REFEREE_LIST references; + + +}; +}; +}; + +#endif //_PROPERTYIMPL_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyList.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyList.cpp new file mode 100644 index 0000000000..7fff72c291 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyList.cpp @@ -0,0 +1,95 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef SDO_EXPORTS + #define SDO_EXPORTS +#endif + +#include "commonj/sdo/export.h" +#include +#include "commonj/sdo/Property.h" +#include "commonj/sdo/PropertyImpl.h" +#include "commonj/sdo/Type.h" +#include "commonj/sdo/PropertyList.h" + +#include "commonj/sdo/Logger.h" + +namespace commonj{ +namespace sdo { + +class Property; + +SDO_API PropertyList::PropertyList(PROPERTY_LIST p) +{ + PROPERTY_LIST::iterator i; + for (i = p.begin(); i != p.end(); ++i) + { + plist.push_back((PropertyImpl*) (*i)); + } +} + +SDO_API PropertyList::PropertyList(PROPERTY_VECTOR p) +{ + plist = PROPERTY_VECTOR(p); +} + +SDO_API PropertyList::PropertyList(const PropertyList &pin) +{ + plist = PROPERTY_VECTOR(pin.getVec()); +} + +SDO_API PropertyList::PropertyList() +{ +} + +SDO_API PropertyList::~PropertyList() +{ +} + +SDO_API Property& PropertyList::operator[] (int pos) +{ + return *(plist[pos]); +} + +SDO_API const Property& PropertyList::operator[] (int pos) const +{ + return *(plist[pos]); +} + +SDO_API unsigned int PropertyList::size () +{ + return plist.size(); +} + +SDO_API void PropertyList::insert(const Property& p) +{ + PropertyImpl* pi = (PropertyImpl*) &p; + plist.push_back(new PropertyImpl(*pi)); +} + +PROPERTY_VECTOR PropertyList::getVec() const +{ + return plist; +} + +}; +}; + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyList.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyList.h new file mode 100644 index 0000000000..70b1f5403e --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertyList.h @@ -0,0 +1,89 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _PROPERTYLIST_H_ +#define _PROPERTYLIST_H_ + + +#include "commonj/sdo/export.h" + +#include +#include + + + + +namespace commonj{ +namespace sdo{ + + class PropertyImpl; + class Property; + typedef std::vector PROPERTY_VECTOR; +#ifndef PROPERTY_LIST + typedef std::list PROPERTY_LIST; +#endif + +/** + * This class provides for iteration over a collection of Properties + */ + +class PropertyList +{ +private: + PROPERTY_VECTOR plist; + PROPERTY_VECTOR getVec() const; +public: + SDO_API PropertyList(PROPERTY_VECTOR p); + SDO_API PropertyList(PROPERTY_LIST p); + SDO_API PropertyList(const PropertyList &pin); + SDO_API PropertyList(); + virtual SDO_API ~PropertyList(); + + /** [] + * + * Operator to allow reference to an element of the list. + * There are separate versions for const and variable lists + */ + + SDO_API Property& operator[] (int pos); + SDO_API const Property& operator[] (int pos) const; + + /** size gives the number of elements. + * + * size() returns the number of elements in the list. + */ + + SDO_API unsigned int size (); + + /** insert adds an element to the list + * + * insert appends an item to the list. This is not + * of any use to a client application, as these lists + * are always supplied by the library, and are const. + */ + + SDO_API void insert (const Property& p); +}; +}; +}; + + +#endif diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertySetting.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertySetting.cpp new file mode 100644 index 0000000000..1fe3f78e5b --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertySetting.cpp @@ -0,0 +1,68 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/PropertySetting.h" +#include "SDOString.h" +#include "SDOUtils.h" + +namespace commonj +{ + namespace sdo + { + + + PropertySetting::PropertySetting() + : dataObject(NULL), isNULL(false), isIDREF(false), pendingUnknownType(false) + + { + } + + PropertySetting::PropertySetting(DataObjectPtr dataObj, const SDOXMLString& propertyName, + bool isNull, bool IDREF) + : dataObject(dataObj), name(propertyName), isNULL(isNull),isIDREF(IDREF),pendingUnknownType(false) + { + } + + PropertySetting::~PropertySetting() + { + } + + + /* + * The value that PropertySetting uses to hold values passing from + * an input XML stream to data object properties is currently an SDOXMLString + * SDOXMLString use libxml2 functions to do it's thing and in the process messes + * up CDATA markers. To avoid this we use our own version of CDATA makers and + * use this method to replace them with the real ones just before the PropertSetting + * gets committed to the SDO proper in SDOSAX2Parser + */ + SDOString PropertySetting::getStringWithCDataMarkers() + { + SDOString valueString((const char*)value); + + SDOString returnString = SDOUtils::replace(valueString, SDOUtils::CDataStartMarker, SDOUtils::XMLCDataStartMarker); + returnString = SDOUtils::replace(returnString, SDOUtils::CDataEndMarker, SDOUtils::XMLCDataEndMarker); + + return returnString; + } + + } // End - namespace sdo +} // End - namespace commonj diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertySetting.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertySetting.h new file mode 100644 index 0000000000..3133c83c1e --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/PropertySetting.h @@ -0,0 +1,65 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _PROPERTYSETTING_H_ +#define _PROPERTYSETTING_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/SDOXMLString.h" +#include "commonj/sdo/DataObject.h" + + +namespace commonj +{ + namespace sdo + { + +/** + * PropertySetting holds some information about properties as + * they are read by the parser, for subsequent creation + */ + class PropertySetting + { + + public: + PropertySetting(); + PropertySetting(DataObjectPtr dataObj, + const SDOXMLString& propertyName, + bool isNull=false, + bool isIDREF=false); + virtual ~PropertySetting(); + + SDOString getStringWithCDataMarkers(); + + SDOXMLString name; + SDOXMLString value; + DataObjectPtr dataObject; + bool isIDREF; + bool isNULL; + bool pendingUnknownType; + + }; + } // End - namespace sdo +} // End - namespace commonj + + +#endif //_PROPERTYSETTING_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/RefCountingObject.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/RefCountingObject.cpp new file mode 100644 index 0000000000..e125f58a85 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/RefCountingObject.cpp @@ -0,0 +1,83 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/RefCountingObject.h" +#include "commonj/sdo/Logging.h" + +#include +using namespace std; + +namespace commonj{ +namespace sdo{ + +long RefCountingObject::allObs = 0; + +RefCountingObject::RefCountingObject() +: refCount(0) +{ + LOGINFO_2(HIGHVOLUME,"RCO:CREATE:%p Count:%ld",this, ++allObs); +} + +RefCountingObject::RefCountingObject(const RefCountingObject& rc) +: refCount(0) +{ + LOGINFO_2(HIGHVOLUME,"RCO:COPCON:%p Count:%ld",this,++allObs); +} + +RefCountingObject& RefCountingObject::operator=(const RefCountingObject& rc) +{ + return *this; +} + +RefCountingObject::~RefCountingObject() +{ + LOGINFO_2(HIGHVOLUME,"RCO:DELETE:%p Count:%ld",this, --allObs); + // + //if (allObs < 0) + // LOGINFO(HIGHVOLUME,"RCO:More objects deleted than created"); + //if (allObs == 0) + // LOGINFO(HIGHVOLUME,"RCO: All data objects deleted");; +} + +void RefCountingObject::addRef() + +{ + + ++refCount; + LOGINFO_2(HIGHVOLUME,"RCO:ADDREF:%p:%ld",this,refCount); +} + +void RefCountingObject::releaseRef() +{ + LOGINFO_2(HIGHVOLUME,"RCO:DECREF:%p:%ld",this,refCount-1); + if (--refCount == 0) delete this; +} + + +SDO_API std::ostream& RefCountingObject::printSelf(std::ostream &os) +{ + os << "RefCountingObject: reference count = " << refCount < + +namespace commonj { + namespace sdo { + +/** + * RefcountingObject is the base class for all objects in SDO + * These objects keep a count of references to themselves, then + * free themselves when they are unused. + */ + class RefCountingObject + { + public: + SDO_API RefCountingObject(); + SDO_API RefCountingObject(const RefCountingObject& rc); + SDO_API RefCountingObject& operator=(const RefCountingObject& rc); + SDO_API virtual ~RefCountingObject() = 0; +/** + * Add to the reference count - a new pointer has been created. + */ + SDO_API void addRef(); +/** + * Subtract from the the reference count - a reference has dropped. + */ + SDO_API void releaseRef(); + +/** + * Print contents to stream + */ + SDO_API virtual std::ostream& printSelf(std::ostream &os); + + + private: + unsigned int refCount; + static long allObs; + }; + + }; +}; + +#endif diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/RefCountingPointer.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/RefCountingPointer.cpp new file mode 100644 index 0000000000..07d4834574 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/RefCountingPointer.cpp @@ -0,0 +1,155 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/RefCountingPointer.h" +#include "commonj/sdo/DataFactory.h" +#include "commonj/sdo/DataObject.h" +#include "commonj/sdo/DataGraph.h" +#include "commonj/sdo/ChangeSummary.h" +#include "commonj/sdo/XMLDocument.h" +#include "commonj/sdo/XSDHelper.h" +#include "commonj/sdo/XMLHelper.h" + +namespace commonj{ + namespace sdo{ + + // officially, there is nothing here- but if I dont use the overrides in + // the templates, then they dont get generated. + void Test () + { + +#if defined(WIN32) || defined (_WINDOWS) + /* 1) construct */ + DataFactoryPtr fptr = DataFactory::getDataFactory(); + + /* 2) use the & operator= */ + fptr = DataFactory::getDataFactory(); + + /* 3) copy */ + DataFactoryPtr fptr2 = fptr; + + /* 4) use the == and ! */ + if (fptr2 == fptr || !fptr){} + + /* 5) Use the T* and * */ + DataFactory* dmsf = fptr; + DataFactory& dmsr = *fptr; + + /* 1) construct */ + DataFactoryPtr dfptr(fptr); + + /* 3) copy */ + DataFactoryPtr dfptr2 = dfptr; + + /* 2) use the & operator= */ + dfptr = dfptr2; + + /* 4) use the == and ! */ + if (dfptr2 == dfptr || !dfptr){} + + /* 5) Use the T* and * */ + DataFactory* ddmsf = dfptr; + DataFactory& ddmsr = *dfptr; + + /* 6) Use the -> */ + DataObjectPtr dptr = dfptr->create("nothing","nowhere"); + + /* and agin to catch the = */ + dptr = fptr->create("nothing","nowhere"); + + DataObjectPtr dptr2 = dptr; + + /* Use the T* and * */ + DataObject* dof = dptr; + DataObject& dor = *dptr; + + if (dptr2 == dptr || !dptr){} + + + ChangeSummaryPtr cptr = dptr->getChangeSummary(); + cptr = dptr->getChangeSummary(); + ChangeSummaryPtr cptr2 = cptr; + + ChangeSummary* cof = cptr; + ChangeSummary& cop = *cptr; + + + if (cptr2 == cptr || !cptr){} + + cptr->endLogging(); + + SequencePtr sptr = dptr->getSequence(); + sptr = dptr->getSequence(); + SequencePtr sptr2 = sptr; + + Sequence* sof = sptr; + Sequence& sop = *sptr; + + + if (sptr2 == sptr || !sptr){} + + sptr->getBooleanValue(0); + + + // Generate code for XMLDocumentPtr + XMLDocumentPtr xmldocptr1 = 0; + XMLDocumentPtr xmldocptr2 = xmldocptr1; + xmldocptr1 = xmldocptr2; + if (xmldocptr2 == xmldocptr1 || !xmldocptr1){} + XMLDocument* xmldocp = xmldocptr1; + XMLDocument& xmldocref = *xmldocptr2; + xmldocptr1->getEncoding(); + + // Generate code for XSDHelperPtr + XSDHelperPtr xsdhptr1 = 0; + XSDHelperPtr xsdhptr2 = xsdhptr1; + xsdhptr1 = xsdhptr2; + if (xsdhptr2 == xsdhptr1 || !xsdhptr1){} + XSDHelper* xsdhp = xsdhptr1; + XSDHelper& xsdhref = *xsdhptr2; + xsdhptr1->define("dummy"); + + // Generate code for XMLHelperPtr + XMLHelperPtr xmlhptr1 = 0; + XMLHelperPtr xmlhptr2 = xmlhptr1; + xmlhptr1 = xmlhptr2; + if (xmlhptr2 == xmlhptr1 || !xmlhptr1){} + XMLHelper* xmlhp = xmlhptr1; + XMLHelper& xmlhref = *xmlhptr2; + xmlhptr1->load("dummy"); + + // Generate code for DataGraphPtr + DataGraphPtr dgptr1 = 0; + DataGraphPtr dgptr2 = dgptr1; + dgptr1 = dgptr2; + if (dgptr2 == dgptr1 || !dgptr1){} + DataGraph* dghp = dgptr1; + DataGraph& dgref = *dgptr2; + dgptr1->getRootObject(); + +#endif + + } + }; +}; + + + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/RefCountingPointer.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/RefCountingPointer.h new file mode 100644 index 0000000000..dec13f2937 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/RefCountingPointer.h @@ -0,0 +1,198 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _REFCOUNTINGPOINTER_H +#define _REFCOUNTINGPOINTER_H + + +#include "commonj/sdo/export.h" +#include "commonj/sdo/SDORuntimeException.h" + +#include + +namespace commonj{ +namespace sdo{ + +/** + * RefcountingPointer is a template for all SDO pointers. + * The ref count increases with each use, and drops when one of these + * goes out of scope. + * Refcounting pointers are a lot like smart pointers, however in this + * implementation there is a cast method to a void*, so unlike real + * smart pointers, a user might call "delete mypointer", which would + * compile, but cause a crash. + * RefCountingPointers do not need to be deleted. + */ + +template +class RefCountingPointer { + public: + /*SDO_API*/ RefCountingPointer(T* realPtr = 0); + /*SDO_API*/ RefCountingPointer(const RefCountingPointer& rhs); + /*SDO_API*/ ~RefCountingPointer(); + /*SDO_API*/ RefCountingPointer& operator=(const RefCountingPointer& rhs); + /*SDO_API*/ bool operator==(RefCountingPointer& test) const; + /*SDO_API*/ T* operator->() const; + /*SDO_API*/ T& operator*() const; + /*SDO_API*/ bool operator!() const; + +#ifdef MFT + // MFT == member function templates + // Notes on the items below. + // In our code, we use subclasses to expose the API, and super + // classes to implement. E,g DataObject and DataObjectImpl. + // In some cases, we know that the DataObject given to us is a + // DataObjectImpl, and cast it. With RefCountingPointers, however, + // the cast cannot work, as the RefCountingPointer to the superclass + // is not related to the RCP to the subclass. Recent changes in the + // C++ language allow this to work by defining an operator which + // causes a pointer of the other type to be returned, as long as pointee + // is acceptable as a parameter to the cosntructor of the other type + // of pointer. This works in C++.NET, but not in C++6: + operator RefCountingPointer() + { + return RefCountingPointer(pointee); + } + + // Since we are using C6, a possible workround is to provide a method + // which returns the dumb pointer, then construct a pointer to the + // base class from the pointer returned. This is that the operator T* does. + // The code in DataObject could be simpler if we used C7,and we should + // discusss changing. +#else + operator T*() {return pointee;} +#endif + + template + operator RefCountingPointer() + { + return RefCountingPointer(pointee); + } + + friend std::ostream& operator<< (std::ostream &os, const RefCountingPointer& ptr) + { + if (!ptr) + { + os << "RefCountingPointer is NULL" << std::endl; + } + else + { + ptr->printSelf(os); + } + + return os; + } + + private: + T *pointee; + void init(); +}; + + + +template +void RefCountingPointer::init() +{ + if (pointee == 0) return; + pointee->addRef(); +} + +template +/*SDO_API*/ RefCountingPointer::RefCountingPointer(T* realPtr) +:pointee(realPtr) +{ + init(); +} + +template +/*SDO_API*/ RefCountingPointer::RefCountingPointer(const RefCountingPointer& rhs) +: pointee(rhs.pointee) +{ + init(); +} + +template +/*SDO_API*/ RefCountingPointer::~RefCountingPointer() +{ + if (pointee)pointee->releaseRef(); +} + +template +/*SDO_API*/ RefCountingPointer& RefCountingPointer::operator=(const RefCountingPointer& rhs) +{ + if (pointee != rhs.pointee) + { + T *oldP = pointee; + pointee = rhs.pointee; + init(); + if (oldP) oldP->releaseRef(); + } + return *this; +} + +template +/*SDO_API*/ bool RefCountingPointer::operator!() const +{ + return (pointee == 0); +} + +template +/*SDO_API*/ bool RefCountingPointer::operator==(RefCountingPointer& test) const +{ + return (pointee == test.pointee); +} + +template +/*SDO_API*/ T* RefCountingPointer::operator->() const +{ + if (pointee == 0) + SDO_THROW_EXCEPTION("Pointer",SDONullPointerException, ""); + return pointee; +} + +template +/*SDO_API*/ T& RefCountingPointer::operator*() const +{ + return *pointee; +} + + +class DataObject; +typedef RefCountingPointer DataObjectPtr; +class DataGraph; +typedef RefCountingPointer DataGraphPtr; +class DataFactory; +typedef RefCountingPointer DataFactoryPtr; +class Sequence; +typedef Sequence* SequencePtr; +class ChangeSummary; +typedef ChangeSummary* ChangeSummaryPtr; +class XMLDocument; +typedef RefCountingPointer XMLDocumentPtr; +class XSDHelper; +typedef RefCountingPointer XSDHelperPtr; +class XMLHelper; +typedef RefCountingPointer XMLHelperPtr; + +}; +}; + +#endif diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Attribute.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Attribute.cpp new file mode 100644 index 0000000000..925ce3d372 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Attribute.cpp @@ -0,0 +1,51 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SAX2Attribute.h" + + +namespace commonj +{ + namespace sdo + { + +/** + * SAX2Attribute holds an attribute supplied by the SAX2 parser. + */ + SAX2Attribute::SAX2Attribute() + { + } + + SAX2Attribute::SAX2Attribute(const xmlChar **attribute) // localname/prefix/URI/value/end + { + name = attribute[0]; + prefix = attribute[1]; + uri = attribute[2]; + value = SDOXMLString(attribute[3],0, (int)(attribute[4] - attribute[3])); + } + + SAX2Attribute::~SAX2Attribute() + { + } + + + } // End - namespace sdo +} // End - namespace commonj diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Attribute.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Attribute.h new file mode 100644 index 0000000000..37a3469a94 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Attribute.h @@ -0,0 +1,66 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _SAX2ATTRIBUTE_H_ +#define _SAX2ATTRIBUTE_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/SDOXMLString.h" + +namespace commonj +{ + namespace sdo + { + +/** + * SAX2Attribute holds an attribute supplied by the SAX2 parser. + */ + + class SAX2Attribute + { + + public: + + SAX2Attribute(); + SAX2Attribute(const xmlChar **attribute); + + virtual ~SAX2Attribute(); + + const SDOXMLString& getName() const {return name;} + const SDOXMLString& getPrefix() const {return prefix;} + const SDOXMLString& getUri() const {return uri;} + const SDOXMLString& getValue() const {return value;} + + + private: + SDOXMLString name; + SDOXMLString prefix; + SDOXMLString uri; + SDOXMLString value; + + + + }; + } // End - namespace sdo +} // End - namespace commonj + +#endif //_SAX2ATTRIBUTE_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Attributes.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Attributes.cpp new file mode 100644 index 0000000000..3ae7dc061e --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Attributes.cpp @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SAX2Attributes.h" + +namespace commonj +{ + namespace sdo + { + +/** + * SAX2Attributes holds a list of attributes supplied by the SAX2 parser. + */ + SAX2Attributes::SAX2Attributes( + int nb_attributes, + int nb_defaulted, + const xmlChar **attrs) // localname/prefix/URI/value/end + { + for (int i=0; i < nb_attributes*5; i+=5) + { + // attributes.insert(attributes.end(), SAX2Attribute(&attrs[i])); + attributes.push_back(SAX2Attribute(&attrs[i])); + } + } + + SAX2Attributes::SAX2Attributes() + { + } + + SAX2Attributes::~SAX2Attributes() + { + } + + const SAX2Attribute& SAX2Attributes::operator[] (int pos) const + { + return attributes[pos]; + } + + int SAX2Attributes::size () const + { + return attributes.size(); + } + + + const SAX2Attribute* SAX2Attributes::getAttribute(const SDOXMLString& attributeName) const + { + for (unsigned int i=0; i < attributes.size(); i++) + { + if (attributes[i].getName().equalsIgnoreCase(attributeName)) + { + return &attributes[i]; + } + } + return NULL; + } + + void SAX2Attributes::addAttribute(const SAX2Attribute& attr) + { + for (unsigned int i=0; i < attributes.size(); i++) + { + if (attributes[i].getUri().equals(attr.getUri())) + { + if (attributes[i].getName().equals(attr.getName())) + { + // oeverwrite this attribute + attributes[i] = attr; + return; + } + } + } + attributes.push_back(attr); + } + + + const SDOXMLString SAX2Attributes::nullValue; + + const SDOXMLString& SAX2Attributes::getValue( + const SDOXMLString& attributeUri, + const SDOXMLString& attributeName) const + { + for (unsigned int i=0; i < attributes.size(); i++) + { + if (attributes[i].getUri().equalsIgnoreCase(attributeUri)) + { + if (attributes[i].getName().equalsIgnoreCase(attributeName)) + { + return attributes[i].getValue(); + } + } + } + + return nullValue; + } + + const SDOXMLString& SAX2Attributes::getValue( + const SDOXMLString& attributeName) const + { + for (unsigned int i=0; i < attributes.size(); i++) + { + if (attributes[i].getName().equalsIgnoreCase(attributeName)) + { + return attributes[i].getValue(); + } + } + + return nullValue; + } + + + } // End - namespace sdo +} // End - namespace commonj diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Attributes.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Attributes.h new file mode 100644 index 0000000000..7c832214e3 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Attributes.h @@ -0,0 +1,80 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _SAX2ATTRIBUTES_H_ +#define _SAX2ATTRIBUTES_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/SAX2Attribute.h" + +#include "vector" + + +namespace commonj +{ + namespace sdo + { + +/** + * SAX2Attributes holds a list of attributes supplied by the SAX2 parser. + */ + class SAX2Attributes + { + + public: + + SAX2Attributes(); + + SAX2Attributes( + int nb_attributes, + int nb_defaulted, + const xmlChar **attributes); + + virtual ~SAX2Attributes(); + + const SAX2Attribute& operator[] (int pos) const; + int size() const; + + const SDOXMLString& getValue( + const SDOXMLString& attributeUri, + const SDOXMLString& attributeName) const; + + const SDOXMLString& getValue( + const SDOXMLString& attributeName) const; + + const SAX2Attribute* getAttribute( + const SDOXMLString& attributeName) const; + + void addAttribute(const SAX2Attribute& attr); + private: + typedef std::vector ATTRIBUTE_LIST; + ATTRIBUTE_LIST attributes; + + static const SDOXMLString nullValue; + + + + }; + } // End - namespace sdo +} // End - namespace commonj + +#endif //_SAX2ATTRIBUTES_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Namespaces.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Namespaces.cpp new file mode 100644 index 0000000000..ab16b9cc5b --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Namespaces.cpp @@ -0,0 +1,95 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SAX2Namespaces.h" + + +namespace commonj +{ + namespace sdo + { + + SAX2Namespaces::SAX2Namespaces() + { + } + + SAX2Namespaces::SAX2Namespaces(int nb_namespaces, const xmlChar** namespaces) + { + for (int i=0; isecond); + + } + + const SDOXMLString* SAX2Namespaces::findPrefix(const SDOXMLString& uri) const + { + NAMESPACE_MAP::const_iterator nsIter; + for (nsIter = namespaceMap.begin(); nsIter != namespaceMap.end(); nsIter++) + { + if (nsIter->second.equals(uri)) + return &(nsIter->first); + } + return 0; + } + + void SAX2Namespaces::merge(const SAX2Namespaces& inspaces) + { + NAMESPACE_MAP::const_iterator nsIter; + for (nsIter = inspaces.namespaceMap.begin(); + nsIter != inspaces.namespaceMap.end(); nsIter++) + { + // add will not overwrite if it already exists + namespaceMap[nsIter->first] = nsIter->second; + } + return; + } + + + + void SAX2Namespaces::add(const SDOXMLString& prefix, const SDOXMLString& uri) + { + namespaceMap[prefix] = uri; + } + + void SAX2Namespaces::empty() + { + namespaceMap.clear(); + } + + } // End - namespace sdo +} // End - namespace commonj diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Namespaces.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Namespaces.h new file mode 100644 index 0000000000..525ad73945 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Namespaces.h @@ -0,0 +1,69 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _SAX2NAMESPACES_H_ +#define _SAX2NAMESPACES_H_ +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/SDOXMLString.h" +#include "map" + + +namespace commonj +{ + namespace sdo + { + +/** + * SAX2Namespaces holds a list of namespaces supplied by the SAX2 parser. + */ + + class SAX2Namespaces + { + + public: + + SAX2Namespaces(); + + SAX2Namespaces(int nb_namespaces, const xmlChar** namespaces); + + virtual ~SAX2Namespaces(); + + void add(const SDOXMLString& prefix, const SDOXMLString& uri); + + void merge(const SAX2Namespaces& inspaces); + + const SDOXMLString* find(const SDOXMLString& prefix) const; + const SDOXMLString* findPrefix(const SDOXMLString& uri) const; + + void empty(); + + private: + typedef std::map NAMESPACE_MAP; + NAMESPACE_MAP namespaceMap; + + + + }; + } // End - namespace sdo +} // End - namespace commonj + +#endif //_SAX2NAMESPACES_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Parser.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Parser.cpp new file mode 100644 index 0000000000..368c3b6f15 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Parser.cpp @@ -0,0 +1,531 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SAX2Parser.h" +#include "libxml/SAX2.h" +#include "commonj/sdo/SDORuntimeException.h" +#include "commonj/sdo/SDOUtils.h" +using namespace commonj::sdo; + +/** + * SAX2Parser holds the methods which will be called back. + * The implementation uses libxml, which provides callbacks for + * errors, warnings , elements etc. These methods correspond to thos + * callbacks. + * Callbacks from libxml to these C methods are converted into calls + * to the C++ equivalent (with some parameter manipulation + * In the callback methods the void* ctx is a pointer to 'this' SAX2Parser + */ + + + +int sdo_isStandalone(void *ctx) +{ + return 0; +} + + +int sdo_hasInternalSubset(void *ctx) +{ + return(0); +} + +int sdo_hasExternalSubset(void *ctx) +{ + return(0); +} + +void sdo_internalSubset(void *ctx, const xmlChar *name, + const xmlChar *ExternalID, const xmlChar *SystemID) +{ +} + + +void sdo_externalSubset(void *ctx, const xmlChar *name, + const xmlChar *ExternalID, const xmlChar *SystemID) +{ +} + +xmlParserInputPtr sdo_resolveEntity(void *ctx, const xmlChar *publicId, const xmlChar *systemId) +{ + return(NULL); +} + + +xmlEntityPtr sdo_getEntity(void *ctx, const xmlChar *name) +{ + return(NULL); +} + + +xmlEntityPtr sdo_getParameterEntity(void *ctx, const xmlChar *name) +{ + return(NULL); +} + + +void sdo_entityDecl(void *ctx, const xmlChar *name, int type, + const xmlChar *publicId, const xmlChar *systemId, xmlChar *content) +{ +} + + +void sdo_attributeDecl(void *ctx, const xmlChar * elem, + const xmlChar * name, int type, int def, + const xmlChar * defaultValue, xmlEnumerationPtr tree) +{ +} + +void sdo_elementDecl(void *ctx, const xmlChar *name, int type, + xmlElementContentPtr content) +{ +} + + +void sdo_notationDecl(void *ctx, const xmlChar *name, + const xmlChar *publicId, const xmlChar *systemId) +{ +} + +void sdo_unparsedEntityDecl(void *ctx, const xmlChar *name, + const xmlChar *publicId, const xmlChar *systemId, + const xmlChar *notationName) +{ +} + + +void sdo_setDocumentLocator(void *ctx, xmlSAXLocatorPtr loc) +{ +} + + +void sdo_startDocument(void *ctx) +{ + if (!((SAX2Parser*)ctx)->parserError) + ((SAX2Parser*)ctx)->startDocument(); +} + + +void sdo_endDocument(void *ctx) +{ + if (!((SAX2Parser*)ctx)->parserError) + ((SAX2Parser*)ctx)->endDocument(); +} + + +void sdo_startElement(void *ctx, const xmlChar *name, const xmlChar **atts) +{ + // ((SAX2Parser*)ctx)->startElement(name, atts); +} + + +void sdo_endElement(void *ctx, const xmlChar *name) +{ + // ((SAX2Parser*)ctx)->endElement(name); +} + + +void sdo_characters(void *ctx, const xmlChar *ch, int len) +{ + if (!((SAX2Parser*)ctx)->parserError) + ((SAX2Parser*)ctx)->characters(SDOXMLString(ch, 0, len)); +} + + +void sdo_reference(void *ctx, const xmlChar *name) +{ +} + + +void sdo_ignorableWhitespace(void *ctx, const xmlChar *ch, int len) +{ +} + + +void sdo_processingInstruction(void *ctx, const xmlChar *target, + const xmlChar *data) +{ +} + + +void sdo_cdataBlock(void *ctx, const xmlChar *value, int len) +{ + if (!((SAX2Parser*)ctx)->parserError) + { + SDOXMLString valueAsString(value, 0, len); + + SDOXMLString cdata(SDOUtils::CDataStartMarker); + cdata = cdata + valueAsString; + cdata = cdata + SDOUtils::CDataEndMarker; + + ((SAX2Parser*)ctx)->characters(cdata); + } +} + +void sdo_comment(void *ctx, const xmlChar *value) +{ +} + + +void sdo_warning(void *ctx, const char *msg, ...) +{ + va_list args; + va_start(args, msg); + ((SAX2Parser*)ctx)->warning(msg, args); + va_end(args); +} + +void sdo_error(void *ctx, const char *msg, ...) +{ + va_list args; + va_start(args, msg); + ((SAX2Parser*)ctx)->error(msg, args); + va_end(args); + + +} + +void sdo_fatalError(void *ctx, const char *msg, ...) +{ + va_list args; + va_start(args, msg); + ((SAX2Parser*)ctx)->fatalError(msg, args); + va_end(args); +} + + + +// =============== +// SAX2 callbacks +// =============== +void sdo_startElementNs(void *ctx, + const xmlChar *localname, + const xmlChar *prefix, + const xmlChar *URI, + int nb_namespaces, + const xmlChar **namespaces, + int nb_attributes, + int nb_defaulted, + const xmlChar **attributes) +{ + if (!((SAX2Parser*)ctx)->parserError) + ((SAX2Parser*)ctx)->startElementNs( + localname, + prefix, + URI, + SAX2Namespaces(nb_namespaces, namespaces), + SAX2Attributes(nb_attributes, nb_defaulted, attributes)); +} + + +void sdo_endElementNs(void *ctx, + const xmlChar *localname, + const xmlChar *prefix, + const xmlChar *URI) +{ + if (!((SAX2Parser*)ctx)->parserError) + ((SAX2Parser*)ctx)->endElementNs(localname, prefix, URI); +} + + +// The callback method structure +xmlSAXHandler SDOSAX2HandlerStruct = { + sdo_internalSubset, + sdo_isStandalone, + sdo_hasInternalSubset, + sdo_hasExternalSubset, + sdo_resolveEntity, + sdo_getEntity, + sdo_entityDecl, + sdo_notationDecl, + sdo_attributeDecl, + sdo_elementDecl, + sdo_unparsedEntityDecl, + sdo_setDocumentLocator, + sdo_startDocument, + sdo_endDocument, + sdo_startElement, + sdo_endElement, + sdo_reference, + sdo_characters, + sdo_ignorableWhitespace, + sdo_processingInstruction, + sdo_comment, + sdo_warning, + sdo_error, + sdo_fatalError, + sdo_getParameterEntity, + sdo_cdataBlock, + sdo_externalSubset, + XML_SAX2_MAGIC, + NULL, + sdo_startElementNs, + sdo_endElementNs, + NULL +}; + + +namespace commonj +{ + namespace sdo + { + + + + + SAX2Parser::SAX2Parser() + { + setter = 0; + parserError = false; + currentFile = 0; + } + + SAX2Parser::SAX2Parser(ParserErrorSetter* insetter) + { + setter = insetter; + parserError = false; + currentFile = 0; + } + + SAX2Parser::~SAX2Parser() + { + // xmlCleanupParser(); + if (currentFile != 0) + { + delete[] currentFile; + } + } + + const char* SAX2Parser::getCurrentFile() const + { + return currentFile; + } + + + void SAX2Parser::setCurrentFile(const char* filename) + { + if (currentFile != 0) + { + delete[] currentFile; + } + currentFile = new char[strlen(filename)+1]; + strcpy(currentFile,filename); + } + + int SAX2Parser::parse(const char* filename) + { + + parserError = false; + xmlSAXHandlerPtr handler = &SDOSAX2HandlerStruct; + + if (currentFile != 0) + { + delete[] currentFile; + } + currentFile = new char[strlen(filename)+1]; + strcpy(currentFile,filename); + + + int rc = xmlSAXUserParseFile(handler, this, filename); + if (rc == -1) + { + sdo_error(this, "xmlSAXUserParseFile returned an error %d", rc); + SDO_THROW_EXCEPTION("parse", SDOFileNotFoundException,messageBuffer); + } + return rc; + } + + void SAX2Parser::startDocument() + { + } + + void SAX2Parser::endDocument() + { + } + + void SAX2Parser::startElementNs( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes) + { + } + + void SAX2Parser::endElementNs( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI) + { + } + + void SAX2Parser::characters(const SDOXMLString& chars) + { + } + + + void SAX2Parser::warning(const char* msg, va_list args) + { + // warnings are perhaps too frequent + // vsprintf(messageBuffer, msg, args); + // if (setter != 0)setter->setError(messageBuffer); + } + + void SAX2Parser::fatalError(const char* msg, va_list args) + { + parserError = true; + vsprintf(messageBuffer, msg, args); + if (setter != 0)setter->setError(messageBuffer); + } + + void SAX2Parser::error(const char* msg, va_list args) + { + vsprintf(messageBuffer, msg, args); + if (setter != 0)setter->setError(messageBuffer); + } + + + void SAX2Parser::stream(std::istream& input) + { + char buffer[100]; + xmlSAXHandlerPtr handler = &SDOSAX2HandlerStruct; + parserError = false; + xmlParserCtxtPtr ctxt; + + input.read(buffer,4); + ctxt = xmlCreatePushParserCtxt(handler, this, + buffer, input.gcount(), NULL); + + while (input.read(buffer,100)) + { + xmlParseChunk(ctxt, buffer, input.gcount(), 0); + + } + + xmlParseChunk(ctxt, buffer, input.gcount(), 1); + xmlFreeParserCtxt(ctxt); + + if (parserError) + { + SDO_THROW_EXCEPTION("stream", SDOXMLParserException,messageBuffer); + } + + } + + int SAX2Parser::parse_twice(const char* filename) + { + parserError = false; + xmlSAXHandlerPtr handler = &SDOSAX2HandlerStruct; + + setCurrentFile(filename); + + int rc = xmlSAXUserParseFile(handler, this, filename); + if (rc == -1) + { + sdo_error(this, "xmlSAXUserParseFile returned an error %d", rc); + SDO_THROW_EXCEPTION("parse", SDOFileNotFoundException,messageBuffer); + } + + // parse twice - first was for groups + + if (setter)setter->clearErrors(); + + rc = xmlSAXUserParseFile(handler, this, filename); + if (rc == -1) + { + sdo_error(this, "xmlSAXUserParseFile returned an error %d", rc); + SDO_THROW_EXCEPTION("parse", SDOFileNotFoundException,messageBuffer); + } + return rc; + } + + void SAX2Parser::stream_twice(std::istream& input) + { + + std::vector buffer_vec; + int count = 0; + parserError = false; + + xmlSAXHandlerPtr handler = &SDOSAX2HandlerStruct; + xmlParserCtxtPtr ctxt; + + char bctx[5]; + input.read(bctx,4); + int bcount = input.gcount(); + + + ctxt = xmlCreatePushParserCtxt(handler, this, + bctx, bcount, NULL); + + buffer_vec.push_back(parse_buf_element()); + + while (input.read(buffer_vec[count].buf,1000)) + { + buffer_vec[count].len = input.gcount(); + xmlParseChunk(ctxt, buffer_vec[count].buf, + buffer_vec[count].len, 0); + buffer_vec.push_back(parse_buf_element()); + count++; + + } + + buffer_vec[count].len = input.gcount(); + xmlParseChunk(ctxt, buffer_vec[count].buf, + buffer_vec[count].len, 1); + xmlFreeParserCtxt(ctxt); + + if (parserError) + { + SDO_THROW_EXCEPTION("stream", SDOXMLParserException,messageBuffer); + } + + if (setter)setter->clearErrors(); + + ctxt = xmlCreatePushParserCtxt(handler, this, + bctx, bcount, NULL); + + for (unsigned int i=0;i 0) + { + xmlParseChunk(ctxt, buffer_vec[i].buf, + buffer_vec[i].len, 0); + } + } + + if (parserError) + { + SDO_THROW_EXCEPTION("stream", SDOXMLParserException,messageBuffer); + } + + } + + + std::istream& operator>>(std::istream& input, SAX2Parser& parser) + { + parser.stream(input); + return input; + } + + + } // End - namespace sdo +} // End - namespace commonj + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Parser.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Parser.h new file mode 100644 index 0000000000..fd11d98fde --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SAX2Parser.h @@ -0,0 +1,117 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _SAX2PARSER_H_ +#define _SAX2PARSER_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/SDOXMLString.h" +#include "commonj/sdo/SAX2Namespaces.h" +#include "commonj/sdo/SAX2Attributes.h" +#include "commonj/sdo/ParserErrorSetter.h" + + + +#include "sstream" +namespace commonj +{ + namespace sdo + { + + class parse_buf_element + { + + public: + char buf[1000]; + int len; + }; + +/** + * SAX2Parser holds the methods which will be called back. + * The implementation uses libxml, which provides callbacks for + * errors, warnings , elements etc. These methods correspond to thos + * callbacks. + * Callbacks from libxml to these C methods are converted into calls + * to the C++ equivalent (with some parameter manipulation + * In the callback methods the void* ctx is a pointer to 'this' SAX2Parser + */ + class SAX2Parser + { + + public: + + SAX2Parser(); + + SAX2Parser(ParserErrorSetter* insetter); + + virtual ~SAX2Parser(); + + virtual int parse (const char* filename); + virtual int parse_twice (const char* filename); + + virtual void startDocument(); + virtual void endDocument(); + + virtual void startElementNs( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes); + + virtual void endElementNs( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI); + + virtual void characters(const SDOXMLString& chars); + + virtual void warning(const char* msg, va_list args); + + virtual void fatalError(const char* msg, va_list args); + + virtual void error(const char* msg, va_list args); + + virtual void stream(std::istream& input); + virtual void stream_twice(std::istream& input); + + friend std::istream& operator>>(std::istream& input, SAX2Parser& parser); + + ParserErrorSetter* setter; + bool parserError; + + char messageBuffer[1024]; + + virtual const char* getCurrentFile() const; + virtual void setCurrentFile(const char* filename); + + private: + + char* currentFile; + + + }; + } // End - namespace sdo +} // End - namespace commonj + + +#endif //_SAX2PARSER_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDO.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDO.h new file mode 100644 index 0000000000..cc4fc6cf7b --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDO.h @@ -0,0 +1,62 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/Property.h" +#include "commonj/sdo/Type.h" +#include "commonj/sdo/SDORuntimeException.h" +#include "commonj/sdo/PropertyList.h" +#include "commonj/sdo/Sequence.h" +#include "commonj/sdo/TypeList.h" +#include "commonj/sdo/DataObject.h" +#include "commonj/sdo/DataObjectList.h" +#include "commonj/sdo/XSDHelper.h" +#include "commonj/sdo/XMLHelper.h" +#include "commonj/sdo/EqualityHelper.h" +#include "commonj/sdo/CopyHelper.h" +#include "commonj/sdo/SdoRuntime.h" +#include "commonj/sdo/HelperProvider.h" +#include "commonj/sdo/SDODate.h" +#include "commonj/sdo/DataGraph.h" +#include "commonj/sdo/ChangeSummary.h" +#include "commonj/sdo/export.h" +#include "commonj/sdo/SDOUtils.h" +#include "commonj/sdo/ChangedDataObjectList.h" +#include "commonj/sdo/DataFactory.h" +#include "commonj/sdo/DataObjectInstance.h" +#include "commonj/sdo/DefaultLogWriter.h" +#include "commonj/sdo/Logger.h" +#include "commonj/sdo/LogWriter.h" +#include "commonj/sdo/RefCountingPointer.h" +#include "commonj/sdo/RefCountingObject.h" +#include "commonj/sdo/SdoCheck.h" +#include "commonj/sdo/Setting.h" +#include "commonj/sdo/SettingList.h" +#include "commonj/sdo/XMLDocument.h" +#include "commonj/sdo/DASValue.h" +#include "commonj/sdo/XpathHelper.h" +#include "commonj/sdo/TypeDefinition.h" +#include "commonj/sdo/TypeDefinitions.h" +#include "commonj/sdo/PropertyDefinition.h" + + + + + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODataConverter.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODataConverter.cpp new file mode 100644 index 0000000000..579fbb77e0 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODataConverter.cpp @@ -0,0 +1,1130 @@ +/* + * + * Copyright 2007 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Rev$ $Date$ */ + +#include +#include "commonj/sdo/SDODataConverter.h" +#include "commonj/sdo/SDORuntimeException.h" + + +// Data type conversion code is currently spread across this class and +// TypeImpl. This is necessary while the widespread use of C macros is +// eradicated, however, the long term aim should be to have all the conversion +// code here and anything else that needs to perform conversions (eg TypeImpl) +// should invoke these methods. + + +namespace commonj +{ + namespace sdo + { + + const int SDODataConverter::MAX_TRANSIENT_SIZE = 48; + + const bool SDODataConverter::convertToBoolean(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType) + { + switch (dataType) + { + case DataTypeInfo::TDTbool: + return sourceValue.Boolean; + + case DataTypeInfo::TDTchar: + return (sourceValue.Character != 0) ? true : false; + + case DataTypeInfo::TDTwchar_t: + return (sourceValue.WideChar != 0) ? true : false; + + case DataTypeInfo::TDTshort: + return (sourceValue.Short != 0) ? true : false; + + case DataTypeInfo::TDTlong: + return (sourceValue.Integer != 0) ? true : false; + + case DataTypeInfo::TDTint64_t: + return (sourceValue.Int64 != 0) ? true : false; + + case DataTypeInfo::TDTfloat: + return (sourceValue.Float != 0) ? true : false; + + case DataTypeInfo::TDTdouble: + return (sourceValue.Double != 0) ? true : false; + + case DataTypeInfo::TDTSDODate: + return ((sourceValue.Date)->getTime() != 0) ? true : false; + + case DataTypeInfo::TDTCString: + case DataTypeInfo::TDTByteArray: + return (*(sourceValue.TextString) == "true") ? true : false; + + case DataTypeInfo::TDTWideString: + if (sourceValue.WideString.length < 4) + { + return false; + } + + if ((sourceValue.WideString.data[0] == (wchar_t) 't') && + (sourceValue.WideString.data[1] == (wchar_t) 'r') && + (sourceValue.WideString.data[2] == (wchar_t) 'u') && + (sourceValue.WideString.data[3] == (wchar_t) 'e')) + { + return true; + } + + return false; + + default: + { + std::string msg("Invalid conversion to boolean from SDOValue of type: "); + msg += DataTypeInfo::convertTypeEnumToString(dataType); + SDO_THROW_EXCEPTION("SDODataConverter::convertToBoolean", + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + } + + + const char SDODataConverter::convertToByte(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType) + { + switch (dataType) + { + case DataTypeInfo::TDTbool: + return (sourceValue.Boolean) ? 1 : 0; + + case DataTypeInfo::TDTchar: + return sourceValue.Character; + + case DataTypeInfo::TDTwchar_t: + return (char) sourceValue.WideChar; + + case DataTypeInfo::TDTshort: + return (char) sourceValue.Short; + + case DataTypeInfo::TDTlong: + return (char) sourceValue.Integer; + + case DataTypeInfo::TDTint64_t: + return (char) sourceValue.Int64; + + case DataTypeInfo::TDTfloat: + return (char) sourceValue.Float; + + case DataTypeInfo::TDTdouble: + return (char) sourceValue.Double; + + case DataTypeInfo::TDTSDODate: + return (char) (sourceValue.Date)->getTime(); + + case DataTypeInfo::TDTCString: + case DataTypeInfo::TDTByteArray: + return (char) atoi((sourceValue.TextString)->c_str()); + + case DataTypeInfo::TDTWideString: + { + // char tmpstr[SDODataConverter::MAX_TRANSIENT_SIZE]; + char* tmpstr = new char[sourceValue.WideString.length + 1]; + for (unsigned int j = 0; j < sourceValue.WideString.length; j++) + { + tmpstr[j] = (char) sourceValue.WideString.data[j]; + } + tmpstr[sourceValue.WideString.length] = 0; + char result = (char) atoi(tmpstr); + delete[] tmpstr; + return result; + } + default: + { + std::string msg("Invalid conversion to byte from SDOValue of type: "); + msg += DataTypeInfo::convertTypeEnumToString(dataType); + SDO_THROW_EXCEPTION("SDODataConverter::convertToByte", + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + return 0; + } + + const wchar_t SDODataConverter::convertToCharacter(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType) + { + switch (dataType) + { + case DataTypeInfo::TDTbool: + return (sourceValue.Boolean == false) ? (wchar_t) 0 : (wchar_t) 1; + + case DataTypeInfo::TDTchar: + return (wchar_t) sourceValue.Character; + + case DataTypeInfo::TDTwchar_t: + return sourceValue.WideChar; + + case DataTypeInfo::TDTshort: + return (wchar_t) sourceValue.Short; + + case DataTypeInfo::TDTlong: + return (wchar_t) sourceValue.Integer; + + case DataTypeInfo::TDTint64_t: + return (wchar_t) sourceValue.Int64; + + case DataTypeInfo::TDTfloat: + return (wchar_t) sourceValue.Float; + + case DataTypeInfo::TDTdouble: + return (wchar_t) sourceValue.Double; + + case DataTypeInfo::TDTSDODate: + return (wchar_t) (sourceValue.Date)->getTime(); + + case DataTypeInfo::TDTCString: + case DataTypeInfo::TDTByteArray: + if ((sourceValue.TextString)->length() == 0) + { + return (wchar_t) 0; + } + return (wchar_t) (*sourceValue.TextString)[0]; + + case DataTypeInfo::TDTWideString: + if (sourceValue.WideString.length == 0) + { + return (wchar_t) 0; + } + return sourceValue.WideString.data[0]; + + default: + { + std::string msg("Invalid conversion to character from SDOValue of type: "); + msg += DataTypeInfo::convertTypeEnumToString(dataType); + SDO_THROW_EXCEPTION("SDODataConverter::convertToCharacter", + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + return 0; + } + + const short SDODataConverter::convertToShort(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType) + { + switch (dataType) + { + case DataTypeInfo::TDTbool: + return (sourceValue.Boolean == false) ? 0 : 1; + + case DataTypeInfo::TDTchar: + return (short) sourceValue.Character; + + case DataTypeInfo::TDTwchar_t: + return (short) sourceValue.WideChar; + + case DataTypeInfo::TDTshort: + return sourceValue.Short; + + case DataTypeInfo::TDTlong: + return (short) sourceValue.Integer; + + case DataTypeInfo::TDTint64_t: + return (short) sourceValue.Int64; + + case DataTypeInfo::TDTfloat: + return (short) sourceValue.Float; + + case DataTypeInfo::TDTdouble: + return (short) sourceValue.Double; + + case DataTypeInfo::TDTSDODate: + return (short) (sourceValue.Date)->getTime(); + + case DataTypeInfo::TDTCString: + case DataTypeInfo::TDTByteArray: + return (short) atoi((sourceValue.TextString)->c_str()); + + case DataTypeInfo::TDTWideString: + { + char* tmpstr = new char[sourceValue.WideString.length + 1]; + for (unsigned int j = 0; j < sourceValue.WideString.length; j++) + { + tmpstr[j] = (char) sourceValue.WideString.data[j]; + } + tmpstr[sourceValue.WideString.length] = 0; + short result = (short) atoi(tmpstr); + delete[] tmpstr; + return result; + } + + default: + { + std::string msg("Invalid conversion to short from SDOValue of type: "); + msg += DataTypeInfo::convertTypeEnumToString(dataType); + SDO_THROW_EXCEPTION("SDODataConverter::convertToShort", + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + return 0; + } + + const long SDODataConverter::convertToInteger(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType) + { + switch (dataType) + { + case DataTypeInfo::TDTbool: + return (sourceValue.Boolean == false) ? 0 : 1; + + case DataTypeInfo::TDTchar: + return (long) sourceValue.Character; + + case DataTypeInfo::TDTwchar_t: + return (long) sourceValue.WideChar; + + case DataTypeInfo::TDTshort: + return (long) sourceValue.Short; + + case DataTypeInfo::TDTlong: + return sourceValue.Integer; + + case DataTypeInfo::TDTint64_t: + return (long) sourceValue.Int64; + + case DataTypeInfo::TDTfloat: + return (long) sourceValue.Float; + + case DataTypeInfo::TDTdouble: + return (long) sourceValue.Double; + + case DataTypeInfo::TDTSDODate: + return (long) (sourceValue.Date)->getTime(); + + case DataTypeInfo::TDTCString: + case DataTypeInfo::TDTByteArray: + return (long) atoi((sourceValue.TextString)->c_str()); + + case DataTypeInfo::TDTWideString: + { + char* tmpstr = new char[sourceValue.WideString.length + 1]; + for (unsigned int j = 0; j < sourceValue.WideString.length; j++) + { + tmpstr[j] = (char) sourceValue.WideString.data[j]; + } + tmpstr[sourceValue.WideString.length] = 0; + long result = (long) atoi(tmpstr); + delete[] tmpstr; + return result; + } + + default: + { + std::string msg("Invalid conversion to long from SDOValue of type: "); + msg += DataTypeInfo::convertTypeEnumToString(dataType); + SDO_THROW_EXCEPTION("SDODataConverter::convertToInteger", + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + return 0; + } + + + const int64_t SDODataConverter::convertToLong(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType) + { + switch (dataType) + { + case DataTypeInfo::TDTbool: + return (sourceValue.Boolean == false) ? 0 : 1; + + case DataTypeInfo::TDTchar: + return (int64_t) sourceValue.Character; + + case DataTypeInfo::TDTwchar_t: + return (int64_t) sourceValue.WideChar; + + case DataTypeInfo::TDTshort: + return (int64_t) sourceValue.Short; + + case DataTypeInfo::TDTlong: + return (int64_t) sourceValue.Integer; + + case DataTypeInfo::TDTint64_t: + return sourceValue.Int64; + + case DataTypeInfo::TDTfloat: + return (int64_t) sourceValue.Float; + + case DataTypeInfo::TDTdouble: + return (int64_t) sourceValue.Double; + + case DataTypeInfo::TDTSDODate: + return (int64_t) (sourceValue.Date)->getTime(); + + case DataTypeInfo::TDTCString: + case DataTypeInfo::TDTByteArray: +#if defined(WIN32) || defined (_WINDOWS) + return _atoi64((sourceValue.TextString)->c_str()); +#else + return strtoll((sourceValue.TextString)->c_str(), NULL, 0); +#endif + + case DataTypeInfo::TDTWideString: + { + char* tmpstr = new char[sourceValue.WideString.length + 1]; + for (unsigned int j = 0; j < sourceValue.WideString.length; j++) + { + tmpstr[j] = (char) sourceValue.WideString.data[j]; + } + tmpstr[sourceValue.WideString.length] = 0; +#if defined(WIN32) || defined (_WINDOWS) + int64_t result = _atoi64(tmpstr); +#else + int64_t result = strtoll(tmpstr, NULL, 0); +#endif + delete[] tmpstr; + return result; + } + + default: + { + std::string msg("Invalid conversion to int64_t from SDOValue of type: "); + msg += DataTypeInfo::convertTypeEnumToString(dataType); + SDO_THROW_EXCEPTION("SDODataConverter::convertToLong", + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + return 0; + } + + + const float SDODataConverter::convertToFloat(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType) + { + switch (dataType) + { + case DataTypeInfo::TDTbool: + return (sourceValue.Boolean == false) ? (float) 0 : (float) 1; + + case DataTypeInfo::TDTchar: + return (float) sourceValue.Character; + + case DataTypeInfo::TDTwchar_t: + return (float) sourceValue.WideChar; + + case DataTypeInfo::TDTshort: + return (float) sourceValue.Short; + + case DataTypeInfo::TDTlong: + return (float) sourceValue.Integer; + + case DataTypeInfo::TDTint64_t: + return (float) sourceValue.Int64; + + case DataTypeInfo::TDTfloat: + return sourceValue.Float; + + case DataTypeInfo::TDTdouble: + return (float) sourceValue.Double; + + case DataTypeInfo::TDTSDODate: + return (float) (sourceValue.Date)->getTime(); + + case DataTypeInfo::TDTCString: + case DataTypeInfo::TDTByteArray: + return (float) atof(sourceValue.TextString->c_str()); + + case DataTypeInfo::TDTWideString: + { + char* tmpstr = new char[sourceValue.WideString.length + 1]; + for (unsigned int j = 0; j < sourceValue.WideString.length; j++) + { + tmpstr[j] = (char) sourceValue.WideString.data[j]; + } + tmpstr[sourceValue.WideString.length] = 0; + float result = (float) atof(tmpstr); + delete[] tmpstr; + return result; + } + + default: + { + std::string msg("Invalid conversion to float from SDOValue of type: "); + msg += DataTypeInfo::convertTypeEnumToString(dataType); + SDO_THROW_EXCEPTION("SDODataConverter::convertToFloat", + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + return 0; + } + + + const double SDODataConverter::convertToDouble(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType) + { + switch (dataType) + { + case DataTypeInfo::TDTbool: + return (sourceValue.Boolean == false) ? (double) 0 : (double) 1; + + case DataTypeInfo::TDTchar: + return (double) sourceValue.Character; + + case DataTypeInfo::TDTwchar_t: + return (double) sourceValue.WideChar; + + case DataTypeInfo::TDTshort: + return (double) sourceValue.Short; + + case DataTypeInfo::TDTlong: + return (double) sourceValue.Integer; + + case DataTypeInfo::TDTint64_t: + return (double) sourceValue.Int64; + + case DataTypeInfo::TDTfloat: + return (double) sourceValue.Float; + + case DataTypeInfo::TDTdouble: + return sourceValue.Double; + + case DataTypeInfo::TDTSDODate: + return (double) (sourceValue.Date)->getTime(); + + case DataTypeInfo::TDTCString: + case DataTypeInfo::TDTByteArray: + return atof(sourceValue.TextString->c_str()); + + case DataTypeInfo::TDTWideString: + { + char* tmpstr = new char[sourceValue.WideString.length + 1]; + for (unsigned int j = 0; j < sourceValue.WideString.length; j++) + { + tmpstr[j] = (char) sourceValue.WideString.data[j]; + } + tmpstr[sourceValue.WideString.length] = 0; + double result = atof(tmpstr); + delete[] tmpstr; + return result; + } + + default: + { + std::string msg("Invalid conversion to double from SDOValue of type: "); + msg += DataTypeInfo::convertTypeEnumToString(dataType); + SDO_THROW_EXCEPTION("SDODataConverter::convertToDouble", + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + return 0; + } + + + const SDODate SDODataConverter::convertToDate(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType) + { + switch (dataType) + { + case DataTypeInfo::TDTbool: + case DataTypeInfo::TDTCString: + case DataTypeInfo::TDTByteArray: + case DataTypeInfo::TDTWideString: + { + std::string msg("Cannot get Date from object of type:"); + msg += DataTypeInfo::convertTypeEnumToString(dataType); + SDO_THROW_EXCEPTION("SDODataConverter::convertToDate" , + SDOInvalidConversionException, + msg.c_str()); + break; + } + case DataTypeInfo::TDTchar: + return SDODate((time_t) sourceValue.Character); + + case DataTypeInfo::TDTwchar_t: + return SDODate((time_t) sourceValue.WideChar); + + case DataTypeInfo::TDTshort: + return SDODate((time_t) sourceValue.Short); + + case DataTypeInfo::TDTlong: + return SDODate((time_t) sourceValue.Integer); + + case DataTypeInfo::TDTint64_t: + return SDODate((time_t) sourceValue.Int64); + + case DataTypeInfo::TDTfloat: + return SDODate((time_t) sourceValue.Float); + + case DataTypeInfo::TDTdouble: + return SDODate((time_t) sourceValue.Double); + + case DataTypeInfo::TDTSDODate: + return *(sourceValue.Date); + + default: + { + std::string msg("Invalid conversion to SDODate from SDOValue of type: "); + msg += DataTypeInfo::convertTypeEnumToString(dataType); + SDO_THROW_EXCEPTION("SDODataConverter::convertToDate", + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + return 0; + } + + + SDOString* SDODataConverter::convertToSDOString(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType) + { + char buffer[SDODataConverter::MAX_TRANSIENT_SIZE]; + buffer[0] = 0; + + switch (dataType) + { + case DataTypeInfo::TDTbool: + if (sourceValue.Boolean == false) + { + return new SDOString("false"); + } + return new SDOString("true"); + case DataTypeInfo::TDTchar: + { + sprintf(buffer , "%ld", (long) sourceValue.Character); + break; + } + case DataTypeInfo::TDTwchar_t: + { + sprintf(buffer , "%ld", (long) sourceValue.WideChar); + break; + } + case DataTypeInfo::TDTshort: + { + sprintf(buffer , "%ld", (long) sourceValue.Short); + break; + } + case DataTypeInfo::TDTlong: + { + sprintf(buffer , "%ld", sourceValue.Integer); + break; + } + case DataTypeInfo::TDTint64_t: + sprintf(buffer , "%lld", sourceValue.Int64); + break; + + case DataTypeInfo::TDTfloat: + { + sprintf(buffer , "%.3e", sourceValue.Float); + break; + } + case DataTypeInfo::TDTdouble: + { + sprintf(buffer , "%.3Le", sourceValue.Double); + break; + } + case DataTypeInfo::TDTSDODate: + { + sprintf(buffer , "%ld", (sourceValue.Date)->getTime()); + break; + } + case DataTypeInfo::TDTByteArray: + case DataTypeInfo::TDTCString: + return new SDOString(*sourceValue.TextString); + case DataTypeInfo::TDTWideString: + { + char* tmpbuf = new char[sourceValue.WideString.length + 1]; + for (unsigned int i = 0; i < sourceValue.WideString.length; i++) + { + tmpbuf[i] = (char) (sourceValue.WideString.data)[i]; + } + + tmpbuf[sourceValue.WideString.length] = 0; + SDOString* result = new SDOString(tmpbuf); + delete[] tmpbuf; + return result; + } + + default: + { + std::string msg("Invalid conversion to String from SDOValue of type: "); + msg += DataTypeInfo::convertTypeEnumToString(dataType); + SDO_THROW_EXCEPTION("SDODataConverter::convertToSDOString", + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + return new SDOString(buffer); + } + + + unsigned int SDODataConverter::convertToBytes(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType, + char* outptr, + unsigned int max_length) + { + // max_length and outptr are allowed to be zero for some data types, + // to request that the length required to hold this value be returned + // rather than the actual data. This is a now obselete alternative to + // the getLength method. It creates a confusing situation because + // some datatypes respond to this and some return 0. + // if ((outptr == 0) || (max_length == 0)) + + switch (dataType) + { + case DataTypeInfo::TDTbool: + if (outptr == 0) + { + return 0; + } + + if (sourceValue.Boolean) + { + if (max_length < 4) + { + return 0; + } + else + { + outptr[0] = 't'; + outptr[1] = 'r'; + outptr[2] = 'u'; + outptr[3] = 'e'; + return 4; + } + } + else + { + if (max_length < 5) + { + return 0; + } + else + { + outptr[0] = 'f'; + outptr[1] = 'a'; + outptr[2] = 'l'; + outptr[3] = 's'; + outptr[4] = 'e'; + return 5; + } + } + + case DataTypeInfo::TDTchar: + if (outptr == 0) + { + return 0; + } + outptr[0] = sourceValue.Character; + return 1; + + case DataTypeInfo::TDTwchar_t: + if (outptr == 0) + { + return 0; + } + outptr[0] = (char) sourceValue.WideChar; + return 1; + + case DataTypeInfo::TDTshort: + { + char tmpstr[SDODataConverter::MAX_TRANSIENT_SIZE]; + unsigned int j = 0; + + sprintf(tmpstr, "%ld", sourceValue.Short); + size_t tmplen = strlen(tmpstr); + if ((tmplen > max_length) || (outptr == 0)) + { + return 0; + } + for (j = 0; j < tmplen; j++) + { + outptr[j] = tmpstr[j]; + } + return j; + + } + case DataTypeInfo::TDTlong: + { + char tmpstr[SDODataConverter::MAX_TRANSIENT_SIZE]; + unsigned int j = 0; + + sprintf(tmpstr, "%ld", sourceValue.Integer); + size_t tmplen = strlen(tmpstr); + if ((tmplen > max_length) || (outptr == 0)) + { + return 0; + } + for (j = 0; j < tmplen; j++) + { + outptr[j] = tmpstr[j]; + } + return j; + + } + case DataTypeInfo::TDTint64_t: + { + char tmpstr[SDODataConverter::MAX_TRANSIENT_SIZE]; + unsigned int j = 0; + + sprintf(tmpstr, "%lld", sourceValue.Int64); + size_t tmplen = strlen(tmpstr); + if ((tmplen > max_length) || (outptr == 0)) + { + return 0; + } + for (j = 0; j < tmplen; j++) + { + outptr[j] = tmpstr[j]; + } + return j; + + } + case DataTypeInfo::TDTfloat: + { + char tmpstr[SDODataConverter::MAX_TRANSIENT_SIZE]; + unsigned int j = 0; + + sprintf(tmpstr, "%.3e", sourceValue.Float); + size_t tmplen = strlen(tmpstr); + if ((tmplen > max_length) || (outptr == 0)) + { + return 0; + } + for (j = 0; j < tmplen; j++) + { + outptr[j] = tmpstr[j]; + } + return j; + + } + case DataTypeInfo::TDTdouble: + { + char tmpstr[SDODataConverter::MAX_TRANSIENT_SIZE]; + unsigned int j = 0; + + sprintf(tmpstr, "%.3Le", sourceValue.Double); + size_t tmplen = strlen(tmpstr); + if ((tmplen > max_length) || (outptr == 0)) + { + return 0; + } + for (j = 0; j < tmplen; j++) + { + outptr[j] = tmpstr[j]; + } + return j; + + } + case DataTypeInfo::TDTSDODate: + { + std::string msg("Conversion to bytes not implemented from type: SDODate"); + SDO_THROW_EXCEPTION("getString", + SDOInvalidConversionException, + msg.c_str()); + break; + } + + case DataTypeInfo::TDTByteArray: + case DataTypeInfo::TDTCString: + { + if (max_length == 0) + { + return (sourceValue.TextString)->length(); + } + else + { + unsigned int copy_count = (sourceValue.TextString)->length(); + if (max_length < copy_count) + { + copy_count = max_length; + } + for (unsigned int i = 0; (i < copy_count); i++) + { + outptr[i] = (*sourceValue.TextString)[i]; + } + return copy_count; + } + } + + case DataTypeInfo::TDTWideString: + { + if (max_length == 0) + { + return sourceValue.WideString.length; + } + else + { + unsigned int copy_count = sourceValue.WideString.length; + if (max_length < copy_count) + { + copy_count = max_length; + } + for (unsigned int i = 0; i < copy_count; i++) + { + outptr[i] = (char) (sourceValue.WideString.data)[i]; + } + return copy_count; + } + } + + default: + { + std::string msg("Invalid conversion to bytes from SDOValue of type: "); + msg += DataTypeInfo::convertTypeEnumToString(dataType); + SDO_THROW_EXCEPTION("SDODataConverter::convertToBytes", + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + } + + unsigned int SDODataConverter::convertToString(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType, + wchar_t* outptr, + unsigned int max_length) + { + // max_length and outptr are allowed to be zero for some data types, + // to request that the length required to hold this value be returned + // rather than the actual data. This is a now obselete alternative to + // the getLength method. It creates a confusing situation because + // some datatypes respond to this and some return 0. + // if ((outptr == 0) || (max_length == 0)) + + switch (dataType) + { + case DataTypeInfo::TDTbool: + if (outptr == 0) + { + return 0; + } + + if (sourceValue.Boolean) + { + if (max_length < 4) + { + return 0; + } + else + { + outptr[0] = (wchar_t) 't'; + outptr[1] = (wchar_t) 'r'; + outptr[2] = (wchar_t) 'u'; + outptr[3] = (wchar_t) 'e'; + return 4; + } + } + else + { + if (max_length < 5) + { + return 0; + } + else + { + outptr[0] = (wchar_t) 'f'; + outptr[1] = (wchar_t) 'a'; + outptr[2] = (wchar_t) 'l'; + outptr[3] = (wchar_t) 's'; + outptr[4] = (wchar_t) 'e'; + return 5; + } + } + case DataTypeInfo::TDTchar: + if (outptr == 0) + { + return 0; + } + outptr[0] = (wchar_t) sourceValue.Character; + return 1; + + case DataTypeInfo::TDTwchar_t: + if (outptr == 0) + { + return 0; + } + outptr[0] = sourceValue.WideChar; + return 1; + + case DataTypeInfo::TDTshort: + { + char tmpstr[SDODataConverter::MAX_TRANSIENT_SIZE]; + unsigned int j = 0; + + sprintf(tmpstr, "%ld", sourceValue.Short); + size_t tmplen = strlen(tmpstr); + if ((tmplen > max_length) || (outptr == 0)) + { + return 0; + } + for (j = 0; j < tmplen; j++) + { + outptr[j] = (wchar_t) tmpstr[j]; + } + return j; + } + + case DataTypeInfo::TDTlong: + { + char tmpstr[SDODataConverter::MAX_TRANSIENT_SIZE]; + unsigned int j = 0; + + sprintf(tmpstr, "%ld", sourceValue.Integer); + size_t tmplen = strlen(tmpstr); + if ((tmplen > max_length) || (outptr == 0)) + { + return 0; + } + for (j = 0; j < tmplen; j++) + { + outptr[j] = (wchar_t) tmpstr[j]; + } + return j; + } + + case DataTypeInfo::TDTint64_t: + { + char tmpstr[SDODataConverter::MAX_TRANSIENT_SIZE]; + unsigned int j = 0; + + sprintf(tmpstr, "%lld", sourceValue.Integer); + size_t tmplen = strlen(tmpstr); + if ((tmplen > max_length) || (outptr == 0)) + { + return 0; + } + for (j = 0; j < tmplen; j++) + { + outptr[j] = (wchar_t) tmpstr[j]; + } + return j; + } + + case DataTypeInfo::TDTfloat: + { + char tmpstr[SDODataConverter::MAX_TRANSIENT_SIZE]; + unsigned int j = 0; + + sprintf(tmpstr, "%.3e", sourceValue.Float); + size_t tmplen = strlen(tmpstr); + if ((tmplen > max_length) || (outptr == 0)) + { + return 0; + } + for (j = 0; j < tmplen; j++) + { + outptr[j] = (wchar_t) tmpstr[j]; + } + return j; + } + + case DataTypeInfo::TDTdouble: + { + char tmpstr[SDODataConverter::MAX_TRANSIENT_SIZE]; + unsigned int j = 0; + + sprintf(tmpstr, "%.3Le", sourceValue.Double); + size_t tmplen = strlen(tmpstr); + if ((tmplen > max_length) || (outptr == 0)) + { + return 0; + } + for (j = 0; j < tmplen; j++) + { + outptr[j] = (wchar_t) tmpstr[j]; + } + return j; + } + + case DataTypeInfo::TDTSDODate: + { + std::string msg("Conversion to string not implemented from type: SDODate"); + SDO_THROW_EXCEPTION("getString", + SDOInvalidConversionException, + msg.c_str()); + break; + } + + case DataTypeInfo::TDTByteArray: + case DataTypeInfo::TDTCString: + { + if (max_length == 0) + { + return (sourceValue.TextString)->length(); + } + else + { + unsigned int copy_count = (sourceValue.TextString)->length(); + if (max_length < copy_count) + { + copy_count = max_length; + } + for (unsigned int i = 0; (i < copy_count); i++) + { + outptr[i] = (wchar_t) (*sourceValue.TextString)[i]; + } + return copy_count; + } + } + + case DataTypeInfo::TDTWideString: + { + if (max_length == 0) + { + return sourceValue.WideString.length; + } + else + { + unsigned int copy_count = sourceValue.WideString.length; + if (max_length < copy_count) + { + copy_count = max_length; + } + for (unsigned int i = 0; i < copy_count; i++) + { + outptr[i] = (sourceValue.WideString.data)[i]; + } + return copy_count; + } + } + + default: + { + std::string msg("Invalid conversion to String from SDOValue of type: "); + msg += DataTypeInfo::convertTypeEnumToString(dataType); + SDO_THROW_EXCEPTION("SDODataConverter::convertToString", + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + } + } +} diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODataConverter.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODataConverter.h new file mode 100644 index 0000000000..1cbf92f2aa --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODataConverter.h @@ -0,0 +1,83 @@ +/* +* +* Copyright 2007 The Apache Software Foundation or its licensors, as applicable. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* $Rev$ $Date$ */ + +#ifndef _SDODATACONVERTER_H_ +#define _SDODATACONVERTOR_H_ + +#include "commonj/sdo/DataTypeInfo.h" +#include "commonj/sdo/SDODate.h" + +namespace commonj +{ + namespace sdo + { + // The SDODataConverter class provides methods that convert between the + // many primitive data types that SDO must support. In general, the + // inputs to a method are a DataTypeInfo::SDODataTypeUnion that gives + // the source value that is to be converted and a + // DataTypeInfo::TrueDataType that says which member of the union is + // actually set. The target of the conversion is determined by the + // method name. + + class SDODataConverter + { + + public: + static const bool convertToBoolean(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType); + static const char convertToByte(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType); + static const wchar_t convertToCharacter(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType); + static const short convertToShort(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType); + static const long convertToInteger(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType); + static const int64_t convertToLong(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType); + static const float convertToFloat(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType); + static const double convertToDouble(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType); + static const SDODate convertToDate(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType); + + static SDOString* convertToSDOString(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType); + + static unsigned int convertToBytes(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType, + char* outptr, + unsigned int max_length); + static unsigned int convertToString(const DataTypeInfo::SDODataTypeUnion& sourceValue, + const DataTypeInfo::TrueDataType& dataType, + wchar_t* outptr, + unsigned int max_length); + private: + // We sometimes need to convert primitive data types into an + // equivalent string representation and for that we need a + // temporary buffer. Rather than fret too much about how big each + // one can be we choose a size that should be adequate for any of them + + static const int MAX_TRANSIENT_SIZE; + }; + } +} + +#endif // _SDODATACONVERTER_H diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODate.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODate.cpp new file mode 100644 index 0000000000..6ccbe4c2ee --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODate.cpp @@ -0,0 +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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SDODate.h" + +// According to Linux, localtime_r is defined as +// struct tm *localtime_r(const time_t *timep, struct tm *result); +// However, Windows doesn't have localtime_r, and actually varies what it does +// have across dfferent versions. To accommodate this we use a macro that +// resolves to the correct settings on linux and MS VC8. For other platforms +// it will be necessary to modify this file or override the macro for which we +// provide the SDOUserMacros.h file so that any required macro definition can +// supply other includes if they are needed. + +#include "commonj/sdo/SDOUserMacros.h" +#ifndef tuscany_localtime_r +#if defined(WIN32) || defined (_WINDOWS) + #define tuscany_localtime_r(value, tmp_tm) localtime_s(&tmp_tm, &value); +#else + #define tuscany_localtime_r(value, tmp_tm) localtime_r(&value, &tmp_tm); +#endif +#endif // tuscany_localtime_r + +namespace commonj{ +namespace sdo{ + + + SDODate::~SDODate() + { + } + + SDODate::SDODate(time_t inval) + { + value = inval; + } + + /////////////////////////////////////////////////////////////////////////// + // + /////////////////////////////////////////////////////////////////////////// + + const time_t SDODate::getTime(void) const + { + return value; + } + + const char* SDODate::ascTime(void) const + { + struct tm tmp_tm; + + tuscany_localtime_r(value, tmp_tm); + + return asctime(&tmp_tm); + } + +}; +}; +// end - namespace sdo + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODate.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODate.h new file mode 100644 index 0000000000..59306462e5 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODate.h @@ -0,0 +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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _SDO_SDODATE_H_ +#define _SDO_SDODATE_H_ + + +#include "commonj/sdo/export.h" +#include "time.h" + + + + +namespace commonj{ +namespace sdo{ + + + /////////////////////////////////////////////////////////////////////////// + // A representation of the type of a date. + /////////////////////////////////////////////////////////////////////////// + +/** + * SDODate - a means of hiding the time_t. + * The SDO API in several places uses method overloads to allow the + * same method to set many types of data. As time_t and long are + * sometimes synonymous, it was not possible to have a time_t and a + * long method, so SDODate simply wraps the time_t. + * SDODate also allows modifcation of the implementation, as time_t is + * only a short-term solution - better date/time handling is required. + */ + +class SDODate +{ + +public: + + + virtual SDO_API ~SDODate(); + + SDO_API SDODate(time_t inval); + + /** + * Hand out the date as a time_t + */ + virtual SDO_API const time_t getTime() const; + + /** + * Format the date as a string + */ + + virtual const char* ascTime(void) const; + + +private: + time_t value; +}; + +}; +}; +#endif //_SDO_SDODATE_H_ + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDORuntimeException.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDORuntimeException.cpp new file mode 100644 index 0000000000..d285e5b83e --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDORuntimeException.cpp @@ -0,0 +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. + */ + +/* $Rev$ $Date$ */ + + +#include "commonj/sdo/SDORuntimeException.h" + +#include + +// ======================================================================== +// Constructor +// ======================================================================== +SDORuntimeException :: SDORuntimeException(const char* name, + severity_level sev, + const char* msg_text) + : severity(sev),location_set(0) +{ + class_name = new char[strlen(name) + 1]; + strcpy(class_name,name); + message_text = new char[strlen(msg_text)+1]; + strcpy(message_text,msg_text); + + locations[0].file = 0; + locations[0].line = 0; + locations[0].function = 0; + +} // end SDORuntimeException constuctor + +// ======================================================================== +// Constructor +// ======================================================================== +SDORuntimeException :: SDORuntimeException(const SDORuntimeException& c) + : + severity(c.getSeverity()), location_set(c.location_set) + +{ + class_name = new char[strlen(c.getEClassName()) + 1]; + strcpy(class_name, c.getEClassName()); + message_text = new char[strlen(c.getMessageText())+1]; + strcpy(message_text,c.getMessageText()); + if (c.location_set) + { + for (int i=0;i +#include + + + +/** SDORuntimeException - Exception base class. + * + * + * Description : + * ------------- + * SDO exception class definition + * + * This is intended as a base class. + * + * Parent Classes : + * ---------------- + * none + * + * Public Member functions: + * ------------------------ + * + * Constructors : + * SDORuntimeExceptionm(severity_level sev=severe, + * const string &msg_text=""); + * + * creates the exception object. Parameters are: + * sev: the severity of the exception (Error, Severe) + * msg_text: descriptive message_text + * + * copy constructor not necessary + * + * Destructor : + * virtual ~SDORuntimeException(); + * + * Assignment operator: + * not necessary + * + * void setSeverity(severity_level sev); + * set the exception severity + * + * void setMessageText(const char* msg_text); + * set the message text associated with the exception. (This text should + * come from a message catalog as it may be written to stdout/stderr at + * some point) + * + * void setExceptionLocation(const char* file, + * unsigned long line, + * const char* function=""); + * + * adds the location of the exception. Parameters + * file: the filename from where the exception is being created + * (from __FILE__) + * line: the line number from where the exception is being created + * (from __LINE__) + * function: The function name from where the exception is being created + * + * severity_level getSeverity() const; + * returns the severity of the exception + * + * const char* getMessageText() const; + * returns the message text that describes this exception. + * + * const tring& getFileName() const; + * returns the file name from the location information in the exception + * + * unsigned long getLineNumber() const; + * returns the line number from the location information in the exception + * + * const char* getFunctionName() const; + * returns the function name from the location information in the exception + * + * Private Data Members : + * ---------------------- + * severity_level severity; * Severity of exception + * string message_text; * Message associated with exception + * string file_name; * File name (from __FILE__) + * unsigned long line_number; * Line number (from __LINE__) + * string function_name; * Function name + * + */ + +class SDORuntimeException +{ + public: + // Constructor + enum severity_level + { + Normal, + Warning, + Error, + Severe + }; + + SDO_API SDORuntimeException(const char *name="SDORuntimeException", + severity_level sev=Severe, + const char* msg_text=""); + + SDO_API SDORuntimeException(const SDORuntimeException& c); + + // Destructor + virtual SDO_API ~SDORuntimeException(); + + /** getEClassName() get the exception class + * + * returns the name of the exception class, which will be + * a subclass of SDORuntimeException + */ + + SDO_API const char* getEClassName() const; + + /** getSeverity returns a level from severity_levels + * + * Return severity + * from the enumerator severity_levels, which is: + * + * Normal,Warning, Error,Severe + */ + + SDO_API severity_level getSeverity() const; + + /** + * Return message text associated with exception + */ + + SDO_API const char* getMessageText() const; + + /** getFileName() the file where the exception occurred + * + * Return file name where exception was raised + */ + + SDO_API const char* getFileName() const; + + /** getLineNumber gives the line where the excepion occurred + * + * Return line number where exception was raised + */ + + SDO_API unsigned long getLineNumber() const; + + /** getFunctionName give the name of the raising function + * + * Return function name where exception was raised + */ + + SDO_API const char* getFunctionName() const; + + + /** setSeverity + * + * sets an exception severity + */ + + SDO_API void setSeverity(severity_level sev); + + /** setMessageText + * + * set the message text associated with exception + */ + + SDO_API void setMessageText(const char* msg_text); + + + /** setExceptionLocation + * + * set exception location + */ + + SDO_API void setExceptionLocation(const char* file, + unsigned long line, + const char* function=""); + + SDO_API void setLocation(const char* file, + unsigned long line, + const char* function=""); + + SDO_API void trace(const char* text="%1:\n %3 %4 %2"); + + SDO_API virtual std::ostream& PrintSelf(std::ostream &os) const; + + /** operator << to write the exception + * + * ostream operator << + */ + + SDO_API friend std::ostream& operator<< (std::ostream &os, const SDORuntimeException &except); + + protected: + + private: + + char* class_name; + + severity_level severity; // Severity of exception + + char* message_text; // Description of exception + + //* Location where the exception was last thrown*handled + + class location + { + public: + char* file; //* File name (from __FILE__) + unsigned long line; //* Line number (from __LINE__) + char* function; //* Function name + }; + + // Array of locations + enum {num_locations=5}; + location locations[num_locations]; + + // Index into locations array + int location_set; + + +}; // End SDORuntimeException class definition + +/** + *************************************************************************** + * + * SDOOutOfMemoryException - Exception for no-storage + * + * *************************************************************************** + */ + +class SDOOutOfMemoryException: public SDORuntimeException +{ + public: + SDOOutOfMemoryException(unsigned long size) + : SDORuntimeException("SDOOutOfMemoryException", Severe, + "Unable to obtain storage of length " + size) + { + } + private: +}; // End SDOOutOfMemory class definition + +/** + *************************************************************************** + * + * SDONullPointerException - Exception for no-storage + * + * *************************************************************************** + */ + +class SDONullPointerException: public SDORuntimeException +{ + public: + SDONullPointerException(const char* param) + : SDORuntimeException("SDONullPointerException", Warning, + "The referenced object is null ") + { + } + private: +}; // End SDOOutOfMemory class definition +/** +*************************************************************************** +* +* SDOPathNotFoundException - Exception for bad path +* +**************************************************************************** +*/ +class SDOPathNotFoundException: public SDORuntimeException +{ + public: + SDOPathNotFoundException(const char* path) + : SDORuntimeException("SDOPathNotFoundException", Warning, + path) + { + } + private: +}; // End SDOPathNotFoundException class definition + +/** +*************************************************************************** +* +* SDOPropertyNotFoundException - Exception for property not found +* +**************************************************************************** +*/ + +class SDOPropertyNotFoundException: public SDORuntimeException +{ + public: + SDOPropertyNotFoundException(const char* name) + : SDORuntimeException("SDOPropertyNotFoundException", Warning, + name) + { + } + private: +}; // End SDOPropertyNotFoundException class definition + +/** +*************************************************************************** +* +* SDOTypeNotFoundException - Exception for type not found. +* +**************************************************************************** +*/ +class SDOTypeNotFoundException: public SDORuntimeException +{ + public: + SDOTypeNotFoundException(const char* name) + : SDORuntimeException("SDOTypeNotFoundException", Warning, + name) + { + } + private: +}; // End SDOTypeNotFoundException class definition + +/** +*************************************************************************** +* +* SDOFileNotFoundException - Exception for file not found +* +**************************************************************************** +*/ + +class SDOFileNotFoundException: public SDORuntimeException +{ + public: + SDOFileNotFoundException(const char* name) + : SDORuntimeException("SDOFileNotFoundException", Warning, + name) + { + } + private: +}; // End SDOFileNotFoundException class definition +/** +*************************************************************************** +* +* SDOPropertyNotSetException - Exception for asking for the value of an +* unset/undefaulted prop +* +**************************************************************************** +*/ +class SDOPropertyNotSetException: public SDORuntimeException +{ + public: + SDOPropertyNotSetException(const char* name) + : SDORuntimeException("SDOPropertyNotSetException", Warning, + name) + { + } + private: +}; // End SDOPropertyNotSetException class definition +/** +*************************************************************************** +* +* SDOUnsupportedOperationException - Invalid action or unimplemented method. +* +**************************************************************************** +*/ +class SDOUnsupportedOperationException: public SDORuntimeException +{ + public: + SDOUnsupportedOperationException(const char* name) + : SDORuntimeException("SDOUnsupportedOperationException", Warning, + name) + { + } + private: +}; // End SDOTypeNotFoundException class definition + +/** +*************************************************************************** +* +* SDOInvalidConversionException - Invalid conversion - cannot convert to type. +* +**************************************************************************** +*/ +class SDOInvalidConversionException: public SDORuntimeException +{ + public: + SDOInvalidConversionException(const char* name) + : SDORuntimeException("SDOInvalidConversionException", Warning, + name) + { + } + private: +}; // End SDOTypeNotFoundException class definition +/** +*************************************************************************** +* +* SDOIllegalArgumentException - Invalid argument passed (null name?). +* +**************************************************************************** +*/ +class SDOIllegalArgumentException: public SDORuntimeException +{ + public: + SDOIllegalArgumentException(const char* name) + : SDORuntimeException("SDOIllegalArgumentException", Warning, + name) + { + } + private: +}; // End SDOTypeNotFoundException class definition +/** +**************************************************************************** +* +* SDOIndexOutOfRangeException - element index not in a list. +* +**************************************************************************** +*/ +class SDOIndexOutOfRangeException: public SDORuntimeException +{ + public: + SDOIndexOutOfRangeException(const char* name) + : SDORuntimeException("SDOIndexOutOfRangeException", Warning, + name) + { + } + private: +}; // End SDOTypeNotFoundException class definition + +/** +*************************************************************************** +* +* SDOXMLParserException - XMLParser error +* +**************************************************************************** +*/ +class SDOXMLParserException: public SDORuntimeException +{ + public: + SDOXMLParserException(const char* name) + : SDORuntimeException("SDOXMLParserException", Warning, + name) + { + } + private: +}; // End SDOTypeNotFoundException class definition + +/* +*************************************************************************** +* +* Macro definitions +* +**************************************************************************** +*/ +/** + * ========================================================================= + * Macro - SDO_THROW_EXCEPTION + * + * adds the current file name, line number and function name to the exception. + * then throws the exception. + * The parameter 'function_name' should be the name of the function throwing + * this exception. + * The parameter 'type' is the class of exception to throw and must be a + * SDORuntimeException or a class derived from SDORuntimeException. + * The parameter 'parameter' is the construction parameter for the exception + * ========================================================================= +*/ + + #define SDO_THROW_EXCEPTION(function_name, type, parameter ) \ + {\ + type ex(parameter); \ + ex.setExceptionLocation(__FILE__,__LINE__,#function_name); \ + throw ex;\ + } + +/** + ========================================================================= + * Macro - SDO_RETHROW_EXCEPTION + * + * adds the current file name, line number and function name to the exception. + * then re-throws the exception. + * The parameter 'function_name' should be the name of the function throwing + * this exception. + * ========================================================================= +*/ + #define SDO_RETHROW_EXCEPTION(function_name, exception) \ + (exception).setLocation(__FILE__,__LINE__,#function_name); \ + throw; + +/** + * ========================================================================= + * Macro - SDO_HANDLE_EXCEPTION + * + * adds the current file name, line number and function name to the exception. + * Writes an exception trace entry then continues. + * The parameter 'function_name' should be the name of the function handling + * this exception. + * ========================================================================= +*/ + #define SDO_HANDLE_EXCEPTION(function_name, exception) \ + {\ + (exception).setLocation(__FILE__,__LINE__,#function_name); \ + (exception).Trace("Exception handled by %1: \n %3 %4 %2");\ + } + +#endif diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOSAX2Parser.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOSAX2Parser.cpp new file mode 100644 index 0000000000..c2cf70bcd8 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOSAX2Parser.cpp @@ -0,0 +1,1547 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SDOSAX2Parser.h" + +#include "commonj/sdo/SDORuntimeException.h" +#include "commonj/sdo/ChangeSummary.h" +#include "commonj/sdo/XSDPropertyInfo.h" +#include "commonj/sdo/XMLQName.h" +#include "commonj/sdo/DASProperty.h" +#include "commonj/sdo/Logging.h" +#include "commonj/sdo/DASType.h" +#include "commonj/sdo/XSDTypeInfo.h" +#include "commonj/sdo/TypeImpl.h" +#include "commonj/sdo/DataObjectImpl.h" +#include "commonj/sdo/DataFactoryImpl.h" +#include "commonj/sdo/SDOUtils.h" +#include +using namespace std; + +namespace commonj +{ + namespace sdo + { + + SDOSAX2Parser::SDOSAX2Parser( + DataFactoryPtr df, + const SDOXMLString& targetNamespace, + DataObjectPtr& rootDO, + ParserErrorSetter* insetter + ) + + : dataFactory(df), + targetNamespaceURI(targetNamespace), + rootDataObject(rootDO), + currentDataObject(0), + isDataGraph(false), + ignoreEvents(false), + dealingWithChangeSummary(false), + csbuilder(0), + SAX2Parser(insetter), + rootElementName(""), + rootElementURI("") + + + { + reset(); + if (targetNamespace.isNull()) + { + targetNamespaceURI = ""; + } + rootDataObject = 0; + newSequence = true; + } + + SDOSAX2Parser::~SDOSAX2Parser() + { + } + + void SDOSAX2Parser::reset() + { + rootDataObject = 0; + currentDataObject = 0; + isDataGraph = false; + ignoreEvents = false; + changeSummary = false; + IDMap.empty(); + IDRefs.empty(); + rootElementURI = ""; + rootElementName = ""; + } + + void SDOSAX2Parser::setRootElementName(const SDOXMLString& name) + { + rootElementName = name; + } + + void SDOSAX2Parser::setRootElementURI(const SDOXMLString& uri) + { + rootElementURI = uri; + } + + void SDOSAX2Parser::startDocument() + { + LOGINFO(INFO,"SDOSAX2Parser: startDocument"); + setNamespaces = true; + reset(); + } + + void SDOSAX2Parser::endDocument() + { + LOGENTRY(INFO,"SDOSAX2Parser: endDocument"); + // Iterate over IDREFs list and set references + ID_REFS::iterator refsIter; + for (refsIter = IDRefs.begin(); refsIter != IDRefs.end(); refsIter++) + { + try + { + const Type& type = refsIter->dataObject->getType(); + const Property& prop = refsIter->dataObject->getProperty((const char*)refsIter->property); + const Type& propType = ((TypeImpl&)type).getRealPropertyType(refsIter->property); + + // Allowing referenes to DataObjects only + if (!propType.isDataType()) + { + DataObjectPtr reffedDO; + ID_MAP::iterator idIter = IDMap.find(refsIter->value); + if (idIter != IDMap.end()) + { + reffedDO = idIter->second; + } + else + { + // assume it is an XPath? + + // Remove #/ from front of XPATH as getDataObject doeesnt + // support this yet - it does now + //SDOXMLString xpath(refsIter->value); + //if (xpath.firstIndexOf('#') == 0) + // xpath = xpath.substring(1); + //if (xpath.firstIndexOf('/') == 0) + // xpath = xpath.substring(1); + + reffedDO = rootDataObject->getDataObject((const char*)refsIter->value); + } + + if (!reffedDO) + { + continue; + } + + if (prop.isMany()) + { + DataObjectList& dol = refsIter->dataObject->getList(prop); + dol.append(reffedDO); + } + else + { + refsIter->dataObject->setDataObject(prop, reffedDO); + } + } + + } + catch (const SDORuntimeException&) + { + } + } + try { + // Now rebuild the changeSummary + if (csbuilder != 0) + { + csbuilder->buildChangeSummary(changeSummaryDO); + delete csbuilder; + csbuilder = 0; + } + } + catch (SDORuntimeException&) + { + } + + LOGEXIT(INFO,"SDOSAX2Parser: endDocument"); + } + + + bool SDOSAX2Parser::setDO(DataObjectPtr newDO, + SDOXMLString& propertyName) + { + LOGENTRY(INFO,"SDOSAX2Parser: setDO"); + + if (currentDataObject) + { + const Type& type = currentDataObject->getType(); + // go lower level so we can find open properties w/o exception + DataObject* dob = currentDataObject; + const PropertyImpl* pprop = ((DataObjectImpl*)dob)->getPropertyImpl((const char*)propertyName); + if (pprop == 0) + { + + LOGEXIT(INFO,"SDOSAX2Parser: setDO - exit1"); + return false; + } + + const Property& property = (Property&)*pprop; + //const Type& propertyType = ((TypeImpl&)type).getRealPropertyType(propertyName); + if (currentDataObject->getType().isSequencedType()) + { + SequencePtr seq = currentDataObject->getSequence(); + seq->addDataObject(property, newDO); + } + else + { + if (!property.isMany()) + { + currentDataObject->setDataObject((const char*)propertyName, newDO); + } + else + { + DataObjectList& dol = currentDataObject->getList((const char*)propertyName); + dol.append(newDO); + } + } + } + + setCurrentDataObject(newDO); + + LOGEXIT(INFO,"SDOSAX2Parser: setDO - exit2"); + return true; + } + + void SDOSAX2Parser::handleOpenAttribute( + SDOXMLString& tns, + const SDOXMLString& propuri, + const SDOXMLString& propname, + const SDOXMLString& value) + { + // first, see if there is a global element or attribute corresponding... + try + { + DataFactory* df = dataFactory; + const PropertyImpl* prop = 0; + const TypeImpl* ti = + ((DataFactoryImpl*)df)->findTypeImpl(propuri,"RootType"); + + if (ti != 0) + { + prop = (const PropertyImpl*)ti->getPropertyImpl(propname); + } + else + { + ti = ((DataFactoryImpl*)df)->findTypeImpl(tns,"RootType"); + } + + if (ti != 0) + { + prop = (const PropertyImpl*)ti->getPropertyImpl(propname); + } + + if (prop == 0) + { + // need to use the sequence interface if it exists + if (currentDataObject->getType().isSequencedType()) + { + SequencePtr seq = currentDataObject->getSequence(); + seq->addCString(propname, value); + } + else + { + currentDataObject->setCString((const char*)propname,value); + } + return; + } + + DataObject* dob = currentDataObject; + + switch (prop->getTypeEnum()) + { + case Type::BooleanType: + ((DataObjectImpl*)dob)->defineBoolean(propname); + break; + case Type::ByteType: + ((DataObjectImpl*)dob)->defineByte(propname); + break; + case Type::CharacterType: + ((DataObjectImpl*)dob)->defineCharacter(propname); + break; + case Type::BytesType: + ((DataObjectImpl*)dob)->defineBytes(propname); + break; + case Type::StringType: + ((DataObjectImpl*)dob)->defineString(propname); + break; + case Type::ShortType: + ((DataObjectImpl*)dob)->defineShort(propname); + break; + case Type::IntegerType: + ((DataObjectImpl*)dob)->defineInteger(propname); + break; + case Type::LongType: + ((DataObjectImpl*)dob)->defineLong(propname); + break; + case Type::DoubleType: + ((DataObjectImpl*)dob)->defineDouble(propname); + break; + case Type::FloatType: + ((DataObjectImpl*)dob)->defineFloat(propname); + break; + case Type::DateType: + ((DataObjectImpl*)dob)->defineDate(propname); + break; + } // switch + + // regardless of what type the property now is, we can set CString , and the + // right conversion will happen + + // need to use the sequence interface if it exists. + if (currentDataObject->getType().isSequencedType()) + { + SequencePtr seq = currentDataObject->getSequence(); + seq->addCString(propname, value); + } + else + { + currentDataObject->setCString((const char*)propname,value); + } + } + catch (SDORuntimeException) + { + } + return; + } + + + void SDOSAX2Parser::setAttributes( + SDOXMLString& tns, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes) + { + + LOGENTRY(INFO,"SDOSAX2Parser::setAttributes"); + + ////////////////////////////////////////////// + // The attributes are properties on the new DO + // Handle attributes + ////////////////////////////////////////////// + for (int i=0; i < attributes.size(); i++) + { + // Should ignore attributes like xsi:type + if (!(attributes[i].getUri().equalsIgnoreCase("http://www.w3.org/2001/XMLSchema-instance"))) + { + try + { + const SDOXMLString& propertyName = getSDOName(*currentDataObjectType, attributes[i].getName()); + DataObject* dob = currentDataObject; + const PropertyImpl* pprop = ((DataObjectImpl*)dob)->getPropertyImpl(propertyName); + if (pprop == 0 ) + { + if (currentDataObject->getType().isOpenType()) + { + // if its an open type, then attributes will be allowed to have + // an invalid name, and setCString will create them all as bytes + handleOpenAttribute(tns, attributes[i].getUri(), + attributes[i].getName(), + attributes[i].getValue()); + + } + else + { + LOGERROR_1(WARNING,"SDOSAX2Parser: Property not found on closed type (ignored):%s", + (const char*)(attributes[i].getName())); + } + } + else + { + const Property& prop = (Property&)*pprop; + SDOXMLString propValue; + + XSDPropertyInfo* pi = (XSDPropertyInfo*)((DASProperty*)&prop)->getDASValue("XMLDAS::PropertyInfo"); + if (pi && pi->getPropertyDefinition().isElement) + { + // xml instance is trying to set an attribute when schema defines property as element + LOGERROR_1(WARNING,"SDOSAX2Parser: Attribute %s should be an element. Attribute ignored", + (const char*)(attributes[i].getName())); + continue; + } + + if (pi && pi->getPropertyDefinition().isQName) + { + XMLQName qname(attributes[i].getValue(), + documentNamespaces, namespaces); + propValue = qname.getSDOName(); + } + else + { + propValue = attributes[i].getValue(); + } + + if ((pi && pi->getPropertyDefinition().isIDREF) + || prop.isReference()) + { + // remember this value to resolve later + IDRef ref(currentDataObject, attributes[i].getName(), propValue); + IDRefs.push_back(ref); + } + else + { + if (pi && pi->getPropertyDefinition().isID) + { + // add this ID to the map + IDMap[propValue] = currentDataObject; + } + // Always set the property as a String. SDO will do the conversion + currentDataObject->setCString((const char*)attributes[i].getName(), propValue); + } + } + } + catch (const SDOPropertyNotFoundException&) + { + LOGERROR_1(WARNING,"SDOSAX2Parser: Error processing attribute (ignored):%s", + (const char*)(attributes[i].getName())); + } + } + } // End iterate over attributes + + LOGEXIT(INFO,"SDOSAX2Parser:setAttributes"); + + } + + + const PropertyImpl* SDOSAX2Parser::handleOpenType( + SDOXMLString& tns, + const SDOXMLString& localname, + DataObjectImpl* dob, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes, + SDOXMLString& xsitypeURI, + SDOXMLString& xsitypeName, + bool bToBeNull) + { + // first, see if there is a global element or attribute corresponding... + const PropertyImpl* pprop; + DataObjectPtr newDO = 0; + try + { + DataFactory* df = dataFactory; + const TypeImpl* ti = 0; + const PropertyImpl* prop = 0; + SDOXMLString propertyName; + + ti = ((DataFactoryImpl*)df)->findTypeImpl(tns,"RootType"); + if (ti != 0) + { + propertyName = getSDOName((Type&)*ti, localname); + prop = ti->getPropertyImpl(propertyName); + } + else + { + propertyName = localname; + } + + if (prop != 0) + { + if (prop->isMany()) + { + pprop = ((DataObjectImpl*)dob)->defineList(propertyName); + + // the type of the list needs to be set, as chars sets a CString + try + { + DataObjectList& dl = ((DataObjectImpl*)dob)->getList((const char*)propertyName); + ((DataObjectListImpl*)&dl)->setType(prop->getType().getURI(), + prop->getType().getName()); + } + catch (SDORuntimeException) + { + // let it pass - the type will be Bytes + } + + if (prop->getType().isDataType()) + { + currentPropertySetting = PropertySetting(currentDataObject, propertyName, + bToBeNull); + } + else + { + newDO = dataFactory->create( + prop->getType().getURI(), + prop->getType().getName()); + // here we need to use the sequence interface if it exists. + if (dob->getType().isSequencedType()) + { + SequencePtr seq = currentPropertySetting.dataObject->getSequence(); + seq->addDataObject(propertyName,newDO); + } + else + { + DataObjectList& dol = dob->getList((const char*)propertyName); + dol.append(newDO); + } + setCurrentDataObject(newDO); + setAttributes(tns, namespaces,attributes); + } + return pprop; + } + else + { + switch (prop->getTypeEnum()) + { + case Type::BooleanType: + pprop = ((DataObjectImpl*)dob)->defineBoolean((const char*)propertyName); + currentPropertySetting = PropertySetting(currentDataObject, propertyName, + bToBeNull); + break; + case Type::ByteType: + pprop = ((DataObjectImpl*)dob)->defineByte((const char*)propertyName); + currentPropertySetting = PropertySetting(currentDataObject, propertyName, + bToBeNull); + break; + case Type::CharacterType: + pprop = ((DataObjectImpl*)dob)->defineCharacter(propertyName); + currentPropertySetting = PropertySetting(currentDataObject, propertyName, + bToBeNull); + break; + case Type::BytesType: + pprop = ((DataObjectImpl*)dob)->defineBytes(propertyName); + currentPropertySetting = PropertySetting(currentDataObject, propertyName, + bToBeNull); + break; + case Type::StringType: + pprop = ((DataObjectImpl*)dob)->defineString(propertyName); + currentPropertySetting = PropertySetting(currentDataObject, propertyName, + bToBeNull); + break; + case Type::ShortType: + pprop = ((DataObjectImpl*)dob)->defineShort(propertyName); + currentPropertySetting = PropertySetting(currentDataObject, propertyName, + bToBeNull); + break; + case Type::IntegerType: + pprop = ((DataObjectImpl*)dob)->defineInteger(propertyName); + currentPropertySetting = PropertySetting(currentDataObject, propertyName, + bToBeNull); + break; + case Type::LongType: + pprop = ((DataObjectImpl*)dob)->defineLong(propertyName); + currentPropertySetting = PropertySetting(currentDataObject, propertyName, + bToBeNull); + break; + case Type::DoubleType: + pprop = ((DataObjectImpl*)dob)->defineDouble(propertyName); + currentPropertySetting = PropertySetting(currentDataObject, propertyName, + bToBeNull); + break; + case Type::FloatType: + pprop = ((DataObjectImpl*)dob)->defineFloat(propertyName); + currentPropertySetting = PropertySetting(currentDataObject, propertyName, + bToBeNull); + break; + case Type::DateType: + pprop = ((DataObjectImpl*)dob)->defineDate(propertyName); + currentPropertySetting = PropertySetting(currentDataObject, propertyName, + bToBeNull); + break; + case Type::DataObjectType: + pprop = ((DataObjectImpl*)dob)->defineDataObject(propertyName, + prop->getType().getURI(), prop->getType().getName()); + newDO = dataFactory->create( + prop->getType().getURI(), + prop->getType().getName()); + // here we need to use the sequence interface if it exists. + if (dob->getType().isSequencedType()) + { + SequencePtr seq = dob->getSequence(); + seq->addDataObject(propertyName, newDO); + } + else + { + dob->setDataObject((const char*)propertyName, newDO); + } + setCurrentDataObject(newDO); + setAttributes(tns,namespaces,attributes); + break; + } + } // else + } // if prop != 0 + else + { + // The type is open, and the property doesnt exist, so we are creating + // a property, and need to find out the type to create. + // As I cannot tell if its a single value or many valued, I create all + // as many valued + // could be data object or primitive. All primitives will appear + // as bytes. + // UPDATE: Spec says that all elements will appear as DataObjects which + // are sequenced - the text will come out as text elements in the sequence + + if (!xsitypeName.isNull()) + { + // it has a type from xsi:type + newDO = dataFactory->create((const char*)xsitypeURI, (const char*)xsitypeName); + } + else + { + newDO = dataFactory->create(Type::SDOTypeNamespaceURI, "OpenDataObject"); + } + pprop = ((DataObjectImpl*)dob)->defineList(propertyName); + // here we need to use the sequence interface if it exists. + if (dob->getType().isSequencedType()) + { + SequencePtr seq = dob->getSequence(); + seq->addDataObject(propertyName, newDO); + } + else + { + DataObjectList& dol = dob->getList((const char*)propertyName); + dol.append(newDO); + } + setCurrentDataObject(newDO); + setAttributes(tns,namespaces,attributes); + } + return pprop; + } + catch (SDORuntimeException) + { + // fail to find the property or create a dummy + return 0; + } + } + + void SDOSAX2Parser::startElementNs( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes) + + { + LOGENTRY(INFO,"SDOSAX2Parser: startElementNs"); + + LOGINFO_1(INFO,"SDOSAX2Parser: startElementNs:%s", + (const char*)localname); + + newSequence = true; + + bool bToBeNull = false; + // Save the namespace information from the first element + if (setNamespaces) + { + documentNamespaces = namespaces; + setNamespaces = false; + } + else + { + documentNamespaces.merge(namespaces); + } + + if (ignoreEvents) + { + // Check for the tag we are waiting for + if ( (ignoreTag.localname.equals(localname)) + && (ignoreTag.uri.equals(URI)) + && (ignoreTag.prefix.equals(prefix)) ) + { + ignoreTag.tagCount++; + } + LOGEXIT(INFO,"SDOSAX2Parser: startElementNs - exit1"); + return; + } + + if (URI.equalsIgnoreCase("http://www.w3.org/2001/XMLSchema")) + { + // ignore anything within a schema + LOGINFO_1(INFO,"SDOSAX2Parser ignores schema element:%s", + (const char *)localname); + + // We need to ignore all events until the end tag for this element + ignoreEvents = true; + ignoreTag.localname = localname; + ignoreTag.uri = URI; + ignoreTag.prefix = prefix; + ignoreTag.tagCount = 0; + return; + } + + + + if (dealingWithChangeSummary) + { + if (csbuilder == 0) + { + LOGERROR(ERROR,"SDOSAX2Parser:Parser builds summary with no builder"); + LOGEXIT(INFO,"SDOSAX2Parser: startElementNs - exit2"); + return; + } + csbuilder->processStart( + localname, + prefix, + URI, + namespaces, + attributes); + LOGEXIT(INFO,"SDOSAX2Parser: startElementNs - exit3"); + return; + } + + + if (URI.equalsIgnoreCase(Type::SDOTypeNamespaceURI.c_str())) + { + /////////////////////////////////////////////////////////////////////// + // Handle datagraph + /////////////////////////////////////////////////////////////////////// + if (localname.equalsIgnoreCase("datagraph")) + { + // Remember this is a datagraph. The root DO will be created + // later when we can have a better guess at the namespaceURI + isDataGraph = true; + } // end handling sdo:datagraph + + //////////////////////////////////// + // Handle ChangeSummary on datagraph + //////////////////////////////////// + if (localname.equals("changeSummary")) + { + changeSummary = true; + changeSummaryDO = currentDataObject; + + csbuilder = new ChangeSummaryBuilder( + dataFactory, rootDataObject ); + + changeSummaryLogging = true; + + + SDOXMLString logging = attributes.getValue("logging"); + if (!logging.isNull()) + { + if (logging.equals("false")) + { + changeSummaryLogging = false; + } + } + + LOGINFO(INFO,"SDOSAX2Parser:Start change summary"); + dealingWithChangeSummary = true; + LOGEXIT(INFO,"SDOSAX2Parser: startElementNs - exit4"); + return; + + } + + } + else + { + /////////////////////////////////////////////////////////////////////// + // Each element is a DataObject or a Property on the current DO + /////////////////////////////////////////////////////////////////////// + DataObjectPtr newDO = 0; + + SDOXMLString typeURI, typeName, propertyName; + + /////////////////////////////////////////////////////////////////////// + // Determine the type. It is either specified by the xsi:type attribute + // or the localname is the name of a property on "RootType" + /////////////////////////////////////////////////////////////////////// + int i; + for (i=0; i < attributes.size(); i++) + { + if (attributes[i].getUri().equalsIgnoreCase("http://www.w3.org/2001/XMLSchema-instance")) + { + if (attributes[i].getName().equalsIgnoreCase("type")) + { + SDOXMLString fullTypeName = attributes[i].getValue(); + SDOXMLString pref; + + int index = fullTypeName.firstIndexOf(':'); + if (index < 0) + { + typeName = fullTypeName; + } + else + { + // Is the namespace prefix defined? + typeName = fullTypeName.substring(index+1); + pref = fullTypeName.substring(0, index); + } + + // Convert the prefix to a namespace URI + const SDOXMLString* namespaceURI = namespaces.find(pref); + if (namespaceURI == 0) + { + namespaceURI = documentNamespaces.find(pref); + } + if (namespaceURI != 0) + { + typeURI = *namespaceURI; + } + } + else if (attributes[i].getName().equalsIgnoreCase("nil")) + { + if (attributes[i].getValue().equalsIgnoreCase("true")) + { + // the current setting needs to be setNull + bToBeNull = true; + } + } + } + } // End - attribute loop + + if (typeURI.isNull()) + { + typeURI = ""; + } + + SDOXMLString tns = URI; + + if (tns.isNull()) + tns = ""; + + try + { + if (currentDataObject == 0) + { + // This element should become the root data object + + // Target namespace will be: + // the targetNamespaceURI if specified + // or the URI of xsi:type if specified + // or the URI of this element + if (!typeURI.equals("")) + { + tns = typeURI; + } + + if (!targetNamespaceURI.isNull() && !targetNamespaceURI.equals("")) + { + tns = targetNamespaceURI; + rootElementURI = tns; + } + else + { + rootElementURI = URI; + } + + // Check for localname as a property of the RootType + // if we do not already know the type + if (typeName.isNull()) + { + try { + const Type& rootType = dataFactory->getType(tns, "RootType"); + propertyName = getSDOName(rootType, localname); + const Type& newType = + ((TypeImpl&)(rootType)).getRealPropertyType(propertyName); + + typeURI = newType.getURI(); + typeName = newType.getName(); + } + catch (const SDOTypeNotFoundException&) + { + typeURI = Type::SDOTypeNamespaceURI.c_str(); + typeName = "OpenDataObject"; + } + } + + // Create the root DataObject + if (isDataGraph) + { + DataObjectPtr rootdo = dataFactory->create(tns, "RootType"); + setCurrentDataObject(rootdo); + changeSummaryDO = currentDataObject; + } + else + { + DataFactory* df = dataFactory; + rootElementName = localname; + } + + // NOTE: always creating DO doesn't cater for DataType as top element + + const Type& tp = dataFactory->getType((const char*)typeURI,typeName); + if (tp.isDataType()) + { + newDO = dataFactory->create(tns, "RootType"); + currentPropertySetting = PropertySetting(newDO, localname, + bToBeNull); + + // TODO - need instead to record the fact that its a primitive, not + // a real DO - and then present it as the root. + // newDO = dataFactory->create(tns, "RootType"); + // const Type& tpr = dataFactory->getType(tns,"RootType"); + // XSDTypeInfo* typeInfo = (XSDTypeInfo*) + // ((DASType*)&tpr)->getDASValue("XMLDAS::TypeInfo"); + // if (typeInfo) + // { + // TypeDefinitionImpl* td; + // td = (TypeDefinitionImpl*)&(typeInfo->getTypeDefinition()); + // if (td)td->isExtendedPrimitive = true; + // currentPropertySetting = PropertySetting(newDO, "value" /*localname*/, + // bToBeNull); + + // } + // else + // { + // currentPropertySetting = PropertySetting(newDO, localname, + // bToBeNull); + // } + + } + else + { + + newDO = dataFactory->create((const char*)typeURI, (const char*)typeName); + + // get the type definition, and see if its an extended primitive. + + XSDTypeInfo* typeInfo = (XSDTypeInfo*) + ((DASType*)&tp)->getDASValue("XMLDAS::TypeInfo"); + if (typeInfo) + { + const TypeDefinitionImpl& typeDefinition = typeInfo->getTypeDefinition(); + if (typeDefinition.isExtendedPrimitive) + { + // The name of this element is the name of a property on the current DO + currentPropertySetting = PropertySetting(newDO, localname, + bToBeNull); + } + } + } + + } // End - currentDataObject == 0 + + else + { // currentDataObject != 0 + + // Get the Property from the dataObject + propertyName = getSDOName(*currentDataObjectType, localname); + const Type& type = currentDataObject->getType(); + + + // go lower level so we can find open properties w/o exception + DataObject* dob = currentDataObject; + const PropertyImpl* pprop = ((DataObjectImpl*)dob)->getPropertyImpl(propertyName); + if (pprop == 0) + { + if (type.isOpenType()) + { + pprop = handleOpenType( + tns, + localname, + (DataObjectImpl*)dob, + namespaces, + attributes, + typeURI, + typeName, + bToBeNull); + } + if (pprop == 0) + { + // this is an open property , we will need to create it + LOGERROR_1(WARNING,"SDOSAX2Parser Unknown element:%s", + (const char *)localname); + + // We need to ignore all events until the end tag for this element + ignoreEvents = true; + ignoreTag.localname = localname; + ignoreTag.uri = URI; + ignoreTag.prefix = prefix; + ignoreTag.tagCount = 0; + if (setter != 0) + { + char *msg = new char[strlen((const char*)localname) + 32]; + if (msg) { + sprintf(msg,"Parser found unknown element %s", + (const char*)localname); + setter->setError( msg ); + delete[] msg; + } + } + } + LOGEXIT(INFO,"SDOSAX2Parser: startElementNs - exit5"); + return; + } + else + { + + const Property& prop = (Property&)*pprop; + const TypeImpl* propType = ((TypeImpl&)type).getRealPropertyTypeImpl(propertyName); + if (propType == 0) + { + // could be a previously created open type property + propType = (const TypeImpl*)pprop->getTypeImpl(); + } + if (propType != 0) + { + XSDPropertyInfo* pi = (XSDPropertyInfo*)((DASProperty*)&prop)->getDASValue("XMLDAS::PropertyInfo"); + if ((pi && pi->getPropertyDefinition().isIDREF) + || prop.isReference()) + { + // The name of this element is the name of a property on the current DO + currentPropertySetting = PropertySetting(currentDataObject, propertyName, bToBeNull, + true); + } + + // If it is a DataType then we need set the value + else if (propType->isDataType() ) + { + // The name of this element is the name of a property on the current DO + currentPropertySetting = PropertySetting(currentDataObject, propertyName, + bToBeNull); + } + else + { + + // If typeName is not set then create object of Type of Property + // otherwise use the typeURI and typeName specified by e.g. xsi:type + if (typeName.isNull()) + { + newDO = dataFactory->create(propType->getURI(), propType->getName()); + } + else + { + newDO = dataFactory->create((const char*)typeURI, (const char*)typeName); + } + + XSDTypeInfo* typeInfo = (XSDTypeInfo*) + ((DASType*)propType)->getDASValue("XMLDAS::TypeInfo"); + if (typeInfo && typeInfo->getTypeDefinition().isExtendedPrimitive) + { + // The name of this element is the name of a property on the current DO + currentPropertySetting = PropertySetting(newDO, "value", bToBeNull); + } + + } + } + } // End // currentDataObject != 0 + } // end prop != 0 + if (newDO) + { + if (!setDO(newDO, propertyName)) + { + LOGERROR_1(WARNING,"SDOSAX2Parser Unknown element:%s", + (const char *)localname); + + // We need to ignore all events until the end tag for this element + ignoreEvents = true; + ignoreTag.localname = localname; + ignoreTag.uri = URI; + ignoreTag.prefix = prefix; + ignoreTag.tagCount = 0; + if (setter != 0) + { + char *msg = new char[strlen((const char*)localname) + 32]; + if (msg) { + sprintf(msg,"Parser found unknown element %s", + (const char*)localname); + setter->setError( msg ); + delete msg; + } + } + LOGEXIT(INFO,"SDOSAX2Parser: startElementNs - exit6"); + return; + } + } + } // end try + + catch (const SDOTypeNotFoundException& ) + { + + LOGERROR_1(WARNING,"SDOSAX2Parser Unknown element:%s", + (const char *)localname); + + // We need to ignore all events until the end tag for this element + ignoreEvents = true; + ignoreTag.localname = localname; + ignoreTag.uri = URI; + ignoreTag.prefix = prefix; + ignoreTag.tagCount = 0; + if (setter != 0) + { + char *msg = new char[strlen((const char*)localname) + 32]; + if (msg) { + sprintf(msg,"Parser found unknown element %s", + (const char*)localname); + setter->setError( msg ); + delete[] msg; + } + } + LOGEXIT(INFO,"SDOSAX2Parser: startElementNs - exit7"); + return; + } + +#ifdef _DEBUG + catch (const SDOPropertyNotFoundException& e ) +#else + catch (const SDOPropertyNotFoundException& ) +#endif + { + LOGERROR_1(WARNING,"SDOSAX2Parser Unknown element exception:%s", + (const char *)localname); + LOGSDOEXCEPTION(WARNING,"Exception:",e); + + // We need to ignore all events until the end tag for this element + ignoreEvents = true; + ignoreTag.localname = localname; + ignoreTag.uri = URI; + ignoreTag.prefix = prefix; + ignoreTag.tagCount = 0; + if (setter != 0) + { + char *msg = new char[strlen((const char*)localname) + 32]; + if (msg) + { + sprintf(msg,"Parser found unknown element %s", + (const char*)localname); + setter->setError( msg ); + delete msg; + } + } + LOGEXIT(INFO,"SDOSAX2Parser: startElementNs - exit8"); + return; + } + + setAttributes(tns,namespaces, attributes); + + } + LOGEXIT(INFO,"SDOSAX2Parser: startElementNs - exit9"); + } + + + void SDOSAX2Parser::endElementNs( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI) + { + + LOGENTRY(INFO,"SDOSAX2Parser: endElementNs"); + + newSequence = true; + + if (localname.equals("changeSummary")) + { + // end of change summary + dealingWithChangeSummary = false; + LOGINFO(INFO,"SDOSAX2Parser: Finished change summary"); + LOGEXIT(INFO,"SDOSAX2Parser: endElementNs - exit1"); + return; + } + + if (dealingWithChangeSummary) + + { + if (csbuilder == 0) + { + LOGERROR(WARNING,"SDOSAX2Parser: End change summary with no builder"); + LOGEXIT(INFO,"SDOSAX2Parser: endElementNs - exit2"); + return; + } + csbuilder->processEnd(localname, + prefix, + URI); + LOGEXIT(INFO,"SDOSAX2Parser: endElementNs - exit3"); + return; + } + + + if (ignoreEvents) + { + // Check for the tag we are waiting for + if ( (ignoreTag.localname.equals(localname)) + && (ignoreTag.uri.equals(URI)) + && (ignoreTag.prefix.equals(prefix)) ) + { + if (ignoreTag.tagCount == 0) + { + ignoreEvents = false; + } + ignoreTag.tagCount--; + } + LOGEXIT(INFO,"SDOSAX2Parser: endElementNs - exit4"); + return; + } + + bool popDO = false; // Indicate if we need to pop DO from stack + + // If currentPropertySetting is set (name is not null) + // then we need to set the property now + if (!currentPropertySetting.name.isNull()) + { + // Determine if this is an extended primitive + bool isExtendedPrimitive = false; + const Type& tp = currentPropertySetting.dataObject->getType(); + XSDTypeInfo* typeInfo = (XSDTypeInfo*) + ((DASType*)&tp)->getDASValue("XMLDAS::TypeInfo"); + if (typeInfo && typeInfo->getTypeDefinition().isExtendedPrimitive) + { + isExtendedPrimitive = true; + // If this setting was for an extended primitive we need to remove the + // DO from the stack + popDO = true; + } + + if (currentPropertySetting.isNULL) + { + currentPropertySetting.dataObject-> + setNull((const char*)currentPropertySetting.name); + } + else + { + if (currentPropertySetting.value.isNull()) + { + currentPropertySetting.value = SDOXMLString(""); + } + try + { + if (isExtendedPrimitive) + { + const Property& p = currentPropertySetting.dataObject->getProperty( + "value"); + if (p.isMany()) + { + // use the sequence interface if it exists. + if (currentPropertySetting.dataObject->getType().isSequencedType()) + { + SequencePtr seq = currentPropertySetting.dataObject->getSequence(); + seq->addCString("value", currentPropertySetting.getStringWithCDataMarkers().c_str()); + } + else + { + DataObjectList& dl = currentPropertySetting.dataObject-> + getList((const char*)"value"); + dl.append((const char*)currentPropertySetting.getStringWithCDataMarkers().c_str()); + } + + } + else + { + // use the sequence interface if it exists + if (currentPropertySetting.dataObject->getType().isSequencedType()) + { + SequencePtr seq = currentPropertySetting.dataObject->getSequence(); + seq->addCString("value", currentPropertySetting.getStringWithCDataMarkers().c_str()); + } + else + { + currentPropertySetting.dataObject-> +// setCString((const char*)"value", currentPropertySetting.value ); + setCString((const char*)"value", currentPropertySetting.getStringWithCDataMarkers().c_str() ); + } + } + popDO = true; + } + else + { + if (currentPropertySetting.isIDREF) + { + // remember this value to resolve later + IDRef ref(currentPropertySetting.dataObject, + currentPropertySetting.name, + currentPropertySetting.value ); + IDRefs.push_back(ref); + } + else + { + if (currentPropertySetting.dataObject->getType().isSequencedType()) + { + SequencePtr seq = currentPropertySetting.dataObject->getSequence(); + seq->addCString(currentPropertySetting.name, currentPropertySetting.getStringWithCDataMarkers().c_str()); + } + // Always set the property as a String. SDO will do the conversion + + // It might be a single setting for a many-valued property. + // may throw SDOPropertyNotFoundException + else { + const Property& p = currentPropertySetting.dataObject->getProperty( + (const char*)currentPropertySetting.name); + if (p.isMany()) + { + DataObjectList& dl = currentPropertySetting.dataObject-> + getList((const char*)currentPropertySetting.name); + dl.append((const char*)currentPropertySetting.getStringWithCDataMarkers().c_str()); + } + else + { + currentPropertySetting.dataObject-> +// setCString((const char*)currentPropertySetting.name, currentPropertySetting.value ); + setCString((const char*)currentPropertySetting.name, currentPropertySetting.getStringWithCDataMarkers().c_str() ); + } + } + } + } + } +#ifdef _DEBUG + catch (const SDOPropertyNotFoundException& e) +#else + catch (const SDOPropertyNotFoundException&) +#endif + { + LOGSDOEXCEPTION(WARNING,"SDOSAX2Parser error attribute (ignored)",e); + } + } + currentPropertySetting = PropertySetting(); + + } + else + { + if (changeSummary + && changeSummaryLogging + && changeSummaryDO == currentDataObject) + { + // Set logging on for this DO before it is popped from stack + ChangeSummary* cs = currentDataObject->getChangeSummary(); + if (cs) + { + cs->beginLogging(); + } + changeSummary = false; + } + + popDO = true; + } + + if (popDO) + { + if (dataObjectStack.size() == 0 || rootDataObject == dataObjectStack.top()) + { + currentDataObject = 0; + currentDataObjectType = 0; + } + else + { + dataObjectStack.pop(); + currentDataObject = dataObjectStack.top(); + currentDataObjectType = &(currentDataObject->getType()); + } + } + + LOGEXIT(INFO,"SDOSAX2Parser: endElementNs - exit4"); + } + + + + void SDOSAX2Parser::characters(const SDOXMLString& chars) + { + if (chars.isNull()) return; + + if (!strcmp((const char*)chars,"\r") || + !strcmp((const char*)chars,"\n")) + { + newSequence = true; + return; + } + + if (dealingWithChangeSummary) + { + if (csbuilder == 0) + { + LOGERROR(WARNING,"SDOSAX2Parser: no builder"); + return; + } + csbuilder->processChars(chars); + return; + } + + if (ignoreEvents) + return; + + if (!currentPropertySetting.name.isNull()) + { + currentPropertySetting.value = currentPropertySetting.value + chars; + return; + } + DataObject* dob = currentDataObject; + if ((dob != 0) && ((DataObjectImpl*)dob)->getTypeImpl().isFromList()) + { + // this is a list,so we need to split it up + DataObjectList& dl = currentDataObject->getList( + (const char *)"values"); + + const char* str = (const char*)chars; + + // Convert any synthetic CDATA markers back to the real thing + SDOString valueString(str); + SDOString tmpString = SDOUtils::replace(valueString, SDOUtils::CDataStartMarker, SDOUtils::XMLCDataStartMarker); + tmpString = SDOUtils::replace(tmpString, SDOUtils::CDataEndMarker, SDOUtils::XMLCDataEndMarker); + str = (const char*)tmpString.c_str(); + + char* buf = new char[strlen(str)+1]; + if (!buf) return; + + strcpy(buf,str); + + int start_point = 0; + int end_point; + int final = strlen(buf); + + do { + if (start_point >= final)break; + while (buf[start_point] == (char)0x20 || buf[start_point] == (char)0x09 + || buf[start_point] == (char)0x0A || buf[start_point] == (char)0x0D )start_point++; + end_point = start_point; + while (buf[end_point] != (char)0x20 && buf[end_point] != (char)0x09 && + buf[end_point] != (char)0x0A && buf[end_point] != (char)0x0D && + buf[end_point] != 0x0)end_point++; + if (end_point == start_point)break; + *(buf+end_point) = 0; + dl.append((const char*)(buf+start_point)); + start_point = end_point + 1; + } while(1); + + delete[] buf; + return; + } + + + // If the current DataObject is a sequenced Type + // then add this as text to the sequence + if (currentDataObject && currentDataObjectType->isSequencedType()) + { + // Convert any synthetic CDATA markers back to the real thing + const char* str = (const char*)chars; + + SDOString valueString(str); + SDOString tmpString = SDOUtils::replace(valueString, SDOUtils::CDataStartMarker, SDOUtils::XMLCDataStartMarker); + tmpString = SDOUtils::replace(tmpString, SDOUtils::CDataEndMarker, SDOUtils::XMLCDataEndMarker); + str = tmpString.c_str(); + + SequencePtr seq = currentDataObject->getSequence(); + if (seq) + { + if (newSequence == true) + { + seq->addText(str); + newSequence = false; + } + else + { + for (int k= (int)(seq->size())-1; k>=0 ; k --) + { + if (seq->isText(k)) + { + const char * s = seq->getCStringValue(k); + + if (s) + { + char *combi = + new char[strlen(s)+strlen(str) + 2]; + strcpy(combi,s); + strcat(combi,str); + seq->setText(k,(const char*)combi); + delete[] combi; + } + else + { + seq->setText(k,str); + } + return; + } + } + seq->addText(str); + } + return; + } + } + + } + + + void SDOSAX2Parser::setCurrentDataObject(DataObjectPtr currentDO) + { + currentDataObject = currentDO; + dataObjectStack.push(currentDataObject); + currentDataObjectType = &(currentDataObject->getType()); + if (rootDataObject == 0) + { + rootDataObject = currentDataObject; + } + } + + const SDOXMLString& SDOSAX2Parser::getSDOName(const Type& type, const SDOXMLString& localName) + { + +/* XSDTypeInfo* typeInfo = (XSDTypeInfo*)((DASType*)&type)->getDASValue("XMLDAS::TypeInfo"); + if (typeInfo) + { + const TypeDefinitionImpl& typeDefinition = typeInfo->getTypeDefinition(); + XmlDasPropertyDefs::const_iterator propsIter; + for (propsIter = typeDefinition.properties.begin(); propsIter != typeDefinition.properties.end(); propsIter++) + { + const PropertyDefinitionImpl& prop = *propsIter; + if (prop.localname.equals(localName)) + { + return prop.name; + } + for (int i=0;i< prop.substituteNames.size();i++) + { + if (prop.substituteLocalNames[i].equals(localName)) + { + return prop.substituteNames[i]; + // possibly should be return prop.name; + } + } + } + } + */ + + const std::list pl = type.getPropertyListReference(); + + for (std::list::const_iterator i = pl.begin(); + i != pl.end(); + i++) + { + XSDPropertyInfo* pi = (XSDPropertyInfo*) + ((DASProperty*) (*i))->getDASValue("XMLDAS::PropertyInfo"); + + if (pi) + { + const PropertyDefinitionImpl& propdef = pi->getPropertyDefinition(); + if (localName .equals(propdef.localname)) + return propdef.name; + + for (unsigned int j=0;j< propdef.substituteNames.size();j++) + { + if (propdef.substituteLocalNames[j].equals(localName)) + { + return propdef.substituteNames[j]; + // possibly should be return propdef.name; + } + } + } + } + + + + return localName; + } + + + std::istream& operator>>(std::istream& input, SDOSAX2Parser& parser) + { + parser.stream(input); + + return input; + } + + std::istringstream& operator>>(std::istringstream& input, SDOSAX2Parser& parser) + { + parser.stream(input); + + return input; + } + + } // End - namespace sdo +} // End - namespace commonj + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOSAX2Parser.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOSAX2Parser.h new file mode 100644 index 0000000000..8e06b5c82e --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOSAX2Parser.h @@ -0,0 +1,179 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _SDOSAX2PARSER_H_ +#define _SDOSAX2PARSER_H_ +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/SAX2Parser.h" + +#include "commonj/sdo/DataFactory.h" +#include "commonj/sdo/DataObject.h" +#include "commonj/sdo/SAX2Namespaces.h" +#include "commonj/sdo/PropertySetting.h" +#include "commonj/sdo/ChangeSummaryImpl.h" +#include "commonj/sdo/ChangeSummaryBuilder.h" + + +#include + +namespace commonj +{ + namespace sdo + { + + +/** + * SDOSAX2Parser implements SAX2Parser. + * This class gets called back by the libxml library, and + * deals with the creation of data objects from XML. + */ + + class SDOSAX2Parser : public SAX2Parser + { + + + public: + + + SDOSAX2Parser( + DataFactoryPtr df, + const SDOXMLString& targetNamespaceURI, + DataObjectPtr& rootDO, + ParserErrorSetter* insetter); + + virtual ~SDOSAX2Parser(); + + virtual void startDocument(); + virtual void endDocument(); + + virtual bool setDO(DataObjectPtr newDO, + SDOXMLString& propertyName); + + virtual void setAttributes( + SDOXMLString& tns, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes); + + virtual void handleOpenAttribute( + SDOXMLString& tns, + const SDOXMLString& propuri, + const SDOXMLString& propname, + const SDOXMLString& value); + + virtual const PropertyImpl* handleOpenType( + SDOXMLString& tns, + const SDOXMLString& localname, + DataObjectImpl* dob, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes, + SDOXMLString& xsitypeURI, + SDOXMLString& xsitypeName, + bool bToBeNull); + + virtual void startElementNs( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes); + + virtual void endElementNs( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI); + + virtual void characters(const SDOXMLString& chars); + + friend std::istream& operator>>(std::istream& input, SDOSAX2Parser& parser); + friend std::istringstream& operator>>(std::istringstream& input, SDOSAX2Parser& parser); + + void setRootElementName(const SDOXMLString& name); + const SDOXMLString& getRootElementName() const {return rootElementName;} + void setRootElementURI(const SDOXMLString& uri); + const SDOXMLString& getRootElementURI() const {return rootElementURI;} + + + private: + SDOXMLString targetNamespaceURI; + SDOXMLString rootElementName; + SDOXMLString rootElementURI; + DataFactoryPtr dataFactory; + DataObjectPtr& rootDataObject; + + + std::stack dataObjectStack; + + DataObjectPtr currentDataObject; + bool isDataGraph; + bool newSequence; + + void setCurrentDataObject(DataObjectPtr currentDO); + const Type* currentDataObjectType; + const SDOXMLString& getSDOName(const Type& type, const SDOXMLString& localName); + + PropertySetting currentPropertySetting; + + void reset(); + + bool setNamespaces; + SAX2Namespaces documentNamespaces; + + bool changeSummary; + DataObjectPtr changeSummaryDO; + bool changeSummaryLogging; + bool dealingWithChangeSummary; + ChangeSummaryBuilder* csbuilder; + + bool ignoreEvents; + struct ignoretag + { + SDOXMLString localname; + SDOXMLString uri; + SDOXMLString prefix; + int tagCount; + } ignoreTag; + + + typedef std::map ID_MAP; + ID_MAP IDMap; + + class IDRef + { + public: + IDRef(DataObjectPtr dataobj, + const SDOXMLString& prop, + const SDOXMLString& val) + : dataObject(dataobj), property(prop), value(val) + {} + + DataObjectPtr dataObject; + SDOXMLString property; + SDOXMLString value; + }; + + typedef std::list ID_REFS; + ID_REFS IDRefs; + }; + } // End - namespace sdo +} // End - namespace commonj + +#endif //_SDOSAX2PARSER_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOSPI.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOSPI.h new file mode 100644 index 0000000000..011d112d2f --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOSPI.h @@ -0,0 +1,27 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/DataFactory.h" +#include "commonj/sdo/ChangeSummary.h" +#include "commonj/sdo/DataObject.h" +#include "commonj/sdo/SDO.h" + +#include "commonj/sdo/DASValues.h" diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOSchemaSAX2Parser.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOSchemaSAX2Parser.cpp new file mode 100644 index 0000000000..cf0e3f775d --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOSchemaSAX2Parser.cpp @@ -0,0 +1,1421 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "libxml/uri.h" +#include "commonj/sdo/SDOSchemaSAX2Parser.h" +#include "commonj/sdo/XSDPropertyInfo.h" +#include "commonj/sdo/XSDTypeInfo.h" +#include "commonj/sdo/SDORuntimeException.h" +#include "commonj/sdo/Logging.h" +#include "commonj/sdo/SDOUtils.h" + + +#include + +extern "C" { + void sdo_error(void *ctx, const char *msg, ...); +} + +namespace commonj +{ + namespace sdo + { + + SDOSchemaSAX2Parser::SDOSchemaSAX2Parser(SchemaInfo& schemaInf, + ParserErrorSetter* insetter, + PARSED_LOCATIONS& parsedLocs, + DEFINED_NAMESPACES& definedNSs) + : schemaInfo(schemaInf), + SAX2Parser(insetter), + parsedLocations(parsedLocs), + definedNamespaces(definedNSs) + { + bInSchema = false; + bInvalidElement = false; + bInInvalidContent = false; + bInvalidList = false; + inGroup = 0; + preParsing = true; + } + + SDOSchemaSAX2Parser::~SDOSchemaSAX2Parser() + { + } + + + void SDOSchemaSAX2Parser::storeStartElementEvent( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes) + { + // copy the event to as list for replay. + if (currentGroup) + { + currentGroup->events.push_back(GroupEvent(localname, + prefix, + URI, + namespaces, + attributes)); + } + + } + + void SDOSchemaSAX2Parser::storeEndElementEvent( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI) + { + // copy the event to as list for replay. + if (currentGroup) + { + currentGroup->events.push_back(GroupEvent(localname, prefix, URI)); + } + + } + + void SDOSchemaSAX2Parser::replayEvents( + const SDOXMLString& uri, + const SDOXMLString& name, + bool isGroup, + const SAX2Attributes& groupAttributes) + { + for (unsigned int i=0;i< groupList.size(); i++) + { + if (groupList[i].isAttributeGroup != isGroup) + { + if ( + (!name.isNull() && name.equals(groupList[i].name)) + && + ( + (uri.isNull() && groupList[i].uri.isNull()) + || uri.equals(groupList[i].uri)) + ) + { + // Determine the maxOccurs value from the getValue().equalsIgnoreCase("1")) + { + isMany = true; + } + + int level = 0; + + for (unsigned int j=0;j< groupList[i].events.size();j++) + { + if (groupList[i].events[j].isStartEvent) + { + // For top level or we need to add the maxOccurrs + // attribute from the group definition if it was "many" + if ((level == 0) && isMany) + { + if (groupList[i].events[j].localname.equalsIgnoreCase("choice") + || groupList[i].events[j].localname.equalsIgnoreCase("sequence")) + { + // Add maxOccurs attribute to list + groupList[i].events[j].attributes.addAttribute(*groupMaxOccurrs); + } + } + + startElementNs( + (const SDOXMLString&) + groupList[i].events[j].localname, + (const SDOXMLString&) + groupList[i].events[j].prefix, + (const SDOXMLString&) + groupList[i].events[j].URI, + (const SAX2Namespaces&) + groupList[i].events[j].namespaces, + (const SAX2Attributes&) + groupList[i].events[j].attributes); + + level++; + } + else + { + endElementNs( + (const SDOXMLString&) + groupList[i].events[j].localname, + (const SDOXMLString&) + groupList[i].events[j].prefix, + (const SDOXMLString&) + groupList[i].events[j].URI); + + level--; + } + } + return; + } + } + } + // no group found + if (setter) + { + char *msg = new char[strlen((const char*)name) + 32]; + if (msg) + { + sprintf(msg,"Use of undefined group %s", + (const char*)name); + setter->setError( msg ); + delete[] msg; + } + } + } + + // ============================================================================ + // endDocument + // ============================================================================ + void SDOSchemaSAX2Parser::endDocument() + { + preParsing=!preParsing; + schemaInfo.getSchemaNamespaces().empty(); + } + + + // ============================================================================ + // startElementNS + // ============================================================================ + void SDOSchemaSAX2Parser::startElementNs( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes) + { + LOGINFO_1( INFO,"SchemaParser:startElementNs:%s",(const char*)localname); + + if (URI.equalsIgnoreCase("http://www.w3.org/2001/XMLSchema")) + { + + /////////////////////////////////////////////////////////////////////// + // Handle schema + // Set the URI from the targetNamespace of the xsd:schema element + // Remember namespace mappings + // Create the root Type + /////////////////////////////////////////////////////////////////////// + + + if (localname.equalsIgnoreCase("schema")) + { + bInSchema = true; + // Handle namespace definitions + + + schemaInfo.getSchemaNamespaces().merge(namespaces); + + // Handle attributes + for (int i=0; i < attributes.size(); i++) + { + if (attributes[i].getName().equalsIgnoreCase("targetNamespace")) + { + schemaInfo.setTargetNamespaceURI(attributes[i].getValue()); + } + + if (attributes[i].getName().equalsIgnoreCase("elementFormDefault")) + { + if (attributes[i].getValue().equals("qualified")) + { + schemaInfo.setElementFormDefaultQualified(true); + } + } + } + + currentType.uri = schemaInfo.getTargetNamespaceURI(); + currentType.name = "RootType"; + currentType.localname="RootType"; + definedNamespaces.push_back(currentType.uri); + return; + + } // end schema handling + if (preParsing) + { + // we are now pre-parsing groups so that we can allow them to be + // defined after use. + + if (inGroup > 0) + { + if ( localname.equalsIgnoreCase("group") + || localname.equalsIgnoreCase("attributeGroup")) + { + inGroup++; + } + // check for a group reference first + // we are inside a group.... + storeStartElementEvent( + localname, + prefix, + URI, + namespaces, + attributes); + return; + } + + if ( localname.equalsIgnoreCase("group") + || localname.equalsIgnoreCase("attributeGroup")) + { + inGroup++; + int i; + for (i=0; i < attributes.size(); i++) + { + if (attributes[i].getName().equalsIgnoreCase("ref")) + { + // dont store references. + return; + } + } + + groupList.insert(groupList.begin(),GroupDefinition()); + currentGroup = &groupList[0]; + + if (localname.equalsIgnoreCase("group")) + currentGroup->isAttributeGroup = false; + else currentGroup->isAttributeGroup = true; + + for (i=0; i < attributes.size(); i++) + { + if (attributes[i].getName().equalsIgnoreCase("name")) + { + currentGroup->uri = schemaInfo.getTargetNamespaceURI(); + currentGroup->name = attributes[i].getValue(); + } + } + } + } // end of preParsing groups. + else + { + if (inGroup == 0) + { + // Handle of other schema + if (localname.equalsIgnoreCase("import")) + { + // TODO - import and include treated equally for now - need to + // separate out the namespace info for import + startInclude(localname, prefix, URI, namespaces, attributes); + } + + // Handle of other schema + else if (localname.equalsIgnoreCase("include")) + { + startInclude(localname, prefix, URI, namespaces, attributes); + } + + /////////////////////////////////////////////////////////////////////// + // Handle elements and attributes + // These become Properties of the current Type + // ?? Any special handling of global elements??? + /////////////////////////////////////////////////////////////////////// + else if (localname.equalsIgnoreCase("element")) + { + if (!bInInvalidContent) startElement(localname, prefix, URI, namespaces, attributes); + } + else if (localname.equalsIgnoreCase("attribute")) + { + if (!bInInvalidContent) startAttribute(localname, prefix, URI, namespaces, attributes); + } + else if (localname.equalsIgnoreCase("any") + || localname.equalsIgnoreCase("anyAttribute")) + { + // the type containing this is to be created as open + if (!bInInvalidContent) currentType.isOpen = true; + } + + + /////////////////////////////////////////////////////////////////////// + // Handle complexType + // These become new types + /////////////////////////////////////////////////////////////////////// + else if (localname.equalsIgnoreCase("complexType")) + { + if (!bInInvalidContent) startComplexType(localname, prefix, URI, namespaces, attributes); + } // end complexType handling + + else if (localname.equalsIgnoreCase("choice") + || localname.equalsIgnoreCase("sequence") + || localname.equalsIgnoreCase("all")) + { + if (!bInInvalidContent) startGroup(localname, prefix, URI, namespaces, attributes); + } // end Group handling + + else if ( localname.equalsIgnoreCase("group") + || localname.equalsIgnoreCase("attributeGroup")) + { + + int i; + for (i=0; i < attributes.size(); i++) + { + if (attributes[i].getName().equalsIgnoreCase("ref")) + { + XMLQName qname(attributes[i].getValue(), + schemaInfo.getSchemaNamespaces(), + namespaces); + if (qname.getURI().isNull()) + { + replayEvents(schemaInfo.getTargetNamespaceURI(), qname.getLocalName(), + localname.equalsIgnoreCase("group"), attributes); + } + else + { + replayEvents(qname.getURI(), qname.getLocalName(), + localname.equalsIgnoreCase("group"), attributes); + } + } + } + inGroup++; + // if theres no 'ref' then its a group definition, and we + // already pre-parsed it. + } + else if (localname.equalsIgnoreCase("list")) + { + startList( + localname, + prefix, + URI, + namespaces, + attributes); + } + + /////////////////////////////////////////////////////////////////////// + // Handle simpleType + // These become new types + /////////////////////////////////////////////////////////////////////// + else if (localname.equalsIgnoreCase("simpleType")) + { + if (!bInInvalidContent) startSimpleType(localname, prefix, URI, namespaces, attributes); + } // end complexType handling + + else if (localname.equalsIgnoreCase("restriction")) + { + if (!bInInvalidContent) startRestriction(localname, prefix, URI, namespaces, attributes); + } + + else if (localname.equalsIgnoreCase("extension")) + { + if (!bInInvalidContent) startExtension(localname, prefix, URI, namespaces, attributes); + } + // Handle of other schema + else if (localname.equalsIgnoreCase("union")) + { + // TODO - unions not yet properly supported - for now, whatever the + // enclosing thing is, we will make it an extended primitive based on + // String. + bInInvalidContent = true; + //if (setter) + //{ + // setter->setError("Schema contains a union which is not yet implemented"); + //} + + currentType.parentTypeUri = "commonj.sdo"; + currentType.parentTypeName = "String"; + currentType.isRestriction = true; + + } + } + } + } + else // not in schema - check for any extra namespaces + { + schemaInfo.getSchemaNamespaces().merge(namespaces); + } + + } + + + // ============================================================================ + // endElementNs + // ============================================================================ + void SDOSchemaSAX2Parser::endElementNs( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI) + { + LOGINFO_1( INFO,"SchemaParser:endElementNs:%s",(const char*)localname); + + if (URI.equalsIgnoreCase("http://www.w3.org/2001/XMLSchema")) + { + if (localname.equalsIgnoreCase("schema")) + { + bInSchema = false; + } + + /////////////////////////////////////////////////////////////////////// + // Handle complexType + // Pop the Type off our stack + /////////////////////////////////////////////////////////////////////// + + // We do not support unions, so all inside a union, plus the containing + // element are invalid for now. + // + if (!bInInvalidContent) + { + if (preParsing) + { + if (inGroup > 0) + { + if (localname.equalsIgnoreCase("group") + || localname.equalsIgnoreCase("attributeGroup")) + { + inGroup--; + if (inGroup < 0)inGroup = 0; // should never happen. + } + if (inGroup > 0) // still need to store end of group ref + { + storeEndElementEvent( + localname, + prefix, + URI); + } + } + } + else + { + if (localname.equalsIgnoreCase("group") + || localname.equalsIgnoreCase("attributeGroup")) + { + inGroup--; + if (inGroup < 0) inGroup = 0; + // outside of preparse, dont need to do anything. + } + else if (inGroup == 0) + { + if (localname.equalsIgnoreCase("complexType")) + { + if (!bInvalidElement) defineType(); + } // end complexType handling + else if (localname.equalsIgnoreCase("simpleType")) + { + if (!bInvalidElement) defineType(); + } + else if (localname.equalsIgnoreCase("schema")) + { + if (!bInvalidElement) defineType(); + } // end complexType handling + else if (localname.equalsIgnoreCase("element") + || localname.equalsIgnoreCase("attribute")) + { + // PropertyDefinition should now be complete + if (!bInvalidElement) defineProperty(); + } + else if (localname.equalsIgnoreCase("choice") + || localname.equalsIgnoreCase("sequence") + || localname.equalsIgnoreCase("all")) + { + if (!bInvalidElement) currentType.isMany = false; + } + else if (localname.equalsIgnoreCase("list")) + { + // PropertyDefinition should now be complete + if (!bInvalidList) defineProperty(); + bInvalidList = false; + } + bInvalidElement = false; + } + } + + } // bInUnsupportedContent + if (localname.equalsIgnoreCase("union")) + { + bInInvalidContent = false; + // the enclosing element is not useful + // TODO - Instead of making the union invalid, we make it an + // extended primitive based on string - so its no longer invalid. + //bInvalidElement = true; + } + } + + } + + int SDOSchemaSAX2Parser::parseURI(const SDOXMLString& location, const SDOXMLString& base) + { + xmlChar* absoluteUri = xmlBuildURI(location, base); + if (! absoluteUri) + { + SDO_THROW_EXCEPTION("parseURI", SDOFileNotFoundException, location); + } + SDOXMLString absUri(absoluteUri); + xmlFree(absoluteUri); + + // Determine if this location has been parsed already + PARSED_LOCATIONS::iterator iter; + iter = parsedLocations.find(absUri); + if (iter != parsedLocations.end()) + { + schemaInfo.setTargetNamespaceURI(iter->second); + return 0; + } + + + try + { + int rc = parse(absUri); + // add new location to map + parsedLocations[absUri] = schemaInfo.getTargetNamespaceURI(); + return rc; + } + catch (SDORuntimeException) {} + + return -1; + } + + // ============================================================================ + // startInclude + // ============================================================================ + void SDOSchemaSAX2Parser::startInclude( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes) + { + LOGINFO_1( INFO,"SchemaParser:startInclude:%s",(const char*)localname); + + if (!bInSchema) return; + + + SDOXMLString importNamespace = attributes.getValue("namespace"); + SDOXMLString schemaLocation = attributes.getValue("schemaLocation"); + + SchemaInfo schemaInf; + SDOSchemaSAX2Parser schemaParser(schemaInf, setter, parsedLocations, definedNamespaces); + + if (!schemaLocation.isNull()) + { + if (0 != schemaParser.parseURI(schemaLocation, getCurrentFile())) + return; + } + else + { + // schemaLocation isn't present. Try loading namespace for import + if (localname.equalsIgnoreCase("import") + && !importNamespace.isNull()) + { + // Do not attempt to import namespaces alredy defined + for (unsigned int i = 0; i < definedNamespaces.size(); i++) + { + if (definedNamespaces[i].equals(importNamespace)) + { + return; + } + } + + if (0 != schemaParser.parseURI(importNamespace, SDOXMLString())) + return; + } + else + { + return; + } + } + + // Add the parsed types to this parsers list + TypeDefinitionsImpl& typedefs = schemaParser.getTypeDefinitions(); + XMLDAS_TypeDefs types = typedefs.types; + XMLDAS_TypeDefs::iterator iter; + for (iter=types.begin(); iter != types.end(); iter++) + { + if ((*iter).second.name.equals("RootType") + && currentType.name.equals("RootType") + && (*iter).second.uri.equals(currentType.uri)) + { + // This must be true for an import/include to be + // legally positioned + + XMLDAS_TypeDefs::iterator find = typeDefinitions.types.find( + (*iter).first); + + std::list::iterator propit; + std::list::iterator currpropit; + bool found; + + for (propit = (*iter).second.properties.begin() ; + propit != (*iter).second.properties.end(); ++ propit) + { + found = false; + // do not merge properties whose names clash + for ( currpropit = currentType.properties.begin(); + currpropit != currentType.properties.end(); + ++currpropit) + { + if ((*currpropit).name.equals((*propit).name)) + { + found = true; + break; + } + } + if (!found) + { + currentType.properties.push_back(*propit); + } + } + } + else + { + typeDefinitions.types.insert(*iter); + } + } + + } + + + // ============================================================================ + // startList + // ============================================================================ + void SDOSchemaSAX2Parser::startList( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes) + { + + LOGINFO_1( INFO,"SchemaParser:startList:%s",(const char*)localname); + + if (!bInSchema) return; + + // invent a property called "values" to hold the list + + SDOXMLString typeName = attributes.getValue("itemType"); + + if (typeName.isNull()) + { + // we do not support lists with no item type (yet). + if (setter) + { + setter->setError("Schema contains a list with no type - not supported"); + } + bInvalidList = true; + return; + } + + currentType.dataType = false; + currentType.isFromList = true; + + // attribute to set the list type + // define an internal property to hold the list + PropertyDefinitionImpl thisProperty; + thisProperty.name = "values"; + thisProperty.localname = "values"; + thisProperty.isContainment = false; + thisProperty.isElement=true; + thisProperty.isMany = true; + + XMLQName qname = resolveTypeName( + typeName, + namespaces, + thisProperty.typeUri, + thisProperty.typeName); + thisProperty.fullTypeName = typeName; + + setCurrentProperty(thisProperty); + + } + + // ============================================================================ + // startElement + // ============================================================================ + void SDOSchemaSAX2Parser::startElement( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes) + { + + if (!bInSchema) return; + + PropertyDefinitionImpl thisProperty; + + LOGINFO_1( INFO,"SchemaParser:startElement:%s",(const char*)localname); + + thisProperty.isElement = true; + + setName(attributes, + thisProperty.name, + thisProperty.localname); + + // Set the property's namespace if elementForm is "qualified" + bool elementFormQualified = schemaInfo.isElementFormDefaultQualified(); + SDOXMLString elementForm = attributes.getValue("form"); + if (!elementForm.isNull()) + { + elementFormQualified = false; + if (elementForm.equals("qualified")) + { + elementFormQualified = true; + } + } + + if (elementFormQualified + || currentType.name.equals("RootType")) + { + thisProperty.namespaceURI = schemaInfo.getTargetNamespaceURI(); + } + + setType(thisProperty, attributes, namespaces); + + // Set isMany. currentType.isMany = true indicates we are in a + // group definition (sequence/choice) with maxOccurs>1 + if (currentType.isMany) + { + thisProperty.isMany = true; + } + else + { + SDOXMLString maxOccurs = attributes.getValue("maxOccurs"); + if (!maxOccurs.isNull()) + { + if (!maxOccurs.equalsIgnoreCase("1")) + { + thisProperty.isMany = true; + } + } + } + + // find aliases + thisProperty.aliases = attributes.getValue("aliasName"); + + // mark this as a substitution group. + // TODO - what about properties which have already been set into the tree, + // and might have a substitution? + + SDOXMLString substituteName = attributes.getValue("substitutionGroup"); + if (! substituteName.isNull()) + { + XMLQName qname = resolveTypeName( + substituteName, + namespaces, + thisProperty.substituteUri, + thisProperty.substituteName); + thisProperty.isSubstitute=true; + } + + // count the number of elements in the group + if (currentType.isMany) + { + currentType.groupElementCount++; + } + + setCurrentProperty(thisProperty); + + } + + // ============================================================================ + // startAttribute + // ============================================================================ + void SDOSchemaSAX2Parser::startAttribute( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes) + { + + LOGINFO_1( INFO,"SchemaParser:startAttribute:%s",(const char*)localname); + + if (!bInSchema) return; + + PropertyDefinitionImpl thisProperty; + + thisProperty.isElement = false; + + setName(attributes, + thisProperty.name, + thisProperty.localname); + + thisProperty.namespaceURI = schemaInfo.getTargetNamespaceURI(); + + setType(thisProperty, attributes, namespaces); + + setCurrentProperty(thisProperty); + } + + // ============================================================================ + // startComplexType + // ============================================================================ + void SDOSchemaSAX2Parser::startComplexType( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes) + { + LOGINFO_1( INFO,"SchemaParser:startComplexType:%s",(const char*)localname); + + if (!bInSchema) return; + + TypeDefinitionImpl thisType; // set defaults + thisType.uri=schemaInfo.getTargetNamespaceURI(); + + setTypeName(thisType, attributes,namespaces); + + + + for (int i=0; i < attributes.size(); i++) + { + // If sdo:sequence="true" or mixed="true" it is sequenced + if ( (attributes[i].getUri().equalsIgnoreCase("commonj.sdo/xml") + && attributes[i].getName().equalsIgnoreCase("sequence")) + || attributes[i].getName().equalsIgnoreCase("mixed")) + { + if (attributes[i].getValue().equals("true")) + { + thisType.isSequenced = true; + } + } + // If abstract="true" it is abstract + else if (attributes[i].getName().equalsIgnoreCase("abstract")) + { + if (attributes[i].getValue().equals("true")) + { + thisType.isAbstract = true; + } + } + else if (attributes[i].getName().equalsIgnoreCase("aliasName")) + { + thisType.aliases = attributes[i].getValue(); + } + } + + setCurrentType(thisType); + } + + // ============================================================================ + // startSimpleType + // ============================================================================ + void SDOSchemaSAX2Parser::startSimpleType( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes) + { + LOGINFO_1( INFO,"SchemaParser:startSimpleType:%s",(const char*)localname); + + if (!bInSchema) return; + + TypeDefinitionImpl thisType; // set defaults + thisType.uri=schemaInfo.getTargetNamespaceURI(); + thisType.dataType = true; + + for (int i=0; i < attributes.size(); i++) + { + // If abstract="true" it is abstract + if (attributes[i].getName().equalsIgnoreCase("abstract")) + { + if (attributes[i].getValue().equals("true")) + { + thisType.isAbstract = true; + } + } + else if (attributes[i].getName().equalsIgnoreCase("aliasName")) + { + thisType.aliases = attributes[i].getValue(); + } + } + setTypeName(thisType, attributes,namespaces); + + // see if the type is going to be abstract... + + + setCurrentType(thisType); + } + + // ============================================================================ + // startRestriction + // ============================================================================ + void SDOSchemaSAX2Parser::startRestriction( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes) + { + LOGINFO_1( INFO,"SchemaParser:startRestriction:%s",(const char*)localname); + + if (!bInSchema) return; + + SDOXMLString base = attributes.getValue("base"); + if (!base.isNull()) + { + // Resolve typename to uri:name + XMLQName qname = resolveTypeName( + base, + namespaces, + currentType.parentTypeUri, + currentType.parentTypeName); + + currentType.isRestriction=true; + + + if(qname.getLocalName().equals("QName")) + { + currentType.isQName = true; + } + } + } + + // ============================================================================ + // startExtension + // ============================================================================ + void SDOSchemaSAX2Parser::startExtension( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes) + { + LOGINFO_1( INFO,"SchemaParser:startExtension:%s",(const char*)localname); + + if (!bInSchema) return; + + SDOXMLString base = attributes.getValue("base"); + if (!base.isNull()) + { + SDOXMLString typeUri; + SDOXMLString typeName; + // Resolve typename to uri:name + XMLQName qname = resolveTypeName( + base, + namespaces, + typeUri, + typeName); + + // If extending a simple type (an SDO DataType) we create a + // Property named "value" of this type rather than set the + // simple type as a base + currentType.isRestriction=false; + + // ?? Does this only apply within a tag?? + if (typeUri.equalsIgnoreCase(Type::SDOTypeNamespaceURI.c_str())) + { + // here the type needs to be flagged so that + // we know to serialize this property as an element with + // just the contents abc rather than + // value=abc + + + PropertyDefinitionImpl thisProperty; + thisProperty.name = "value"; + thisProperty.localname = "value"; + thisProperty.typeUri = typeUri; + thisProperty.typeName = typeName; + thisProperty.fullTypeName = base; + thisProperty.isContainment = false; + thisProperty.isElement=true; + + currentType.isExtendedPrimitive= true; + + if(qname.getLocalName().equals("QName")) + { + thisProperty.isQName = true; + } + + setCurrentProperty(thisProperty); + defineProperty(); + } + else + { + currentType.parentTypeUri = typeUri; + currentType.parentTypeName = typeName; + } + } + } + + // ============================================================================ + // startGroup + // ============================================================================ + void SDOSchemaSAX2Parser::startGroup( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes) + { + LOGINFO_1( INFO,"SchemaParser:startGroup:%s",(const char*)localname); + + if (!bInSchema) return; + + SDOXMLString maxOccurs = attributes.getValue("maxOccurs"); + if (!maxOccurs.isNull()) + { + if (!maxOccurs.equalsIgnoreCase("1")) + { + currentType.isMany = true; + } + } + } + + // ============================================================================ + // setCurrentType + // ============================================================================ + void SDOSchemaSAX2Parser::setCurrentType(const TypeDefinitionImpl& type) + { + typeStack.push(currentType); + currentType = type; + } + + // ============================================================================ + // defineType + // ============================================================================ + void SDOSchemaSAX2Parser::defineType() + { + // Set this Type as sequenced of more than one element in a group definition + if (currentType.groupElementCount > 1) + { + currentType.isSequenced = true; + } + + SDOXMLString typeQname = TypeDefinitionsImpl::getTypeQName(currentType.uri, currentType.localname); + typeDefinitions.types[typeQname] = currentType; + + if (currentProperty.typeName.isNull()) + { + // Set the type name to the name of this type + currentProperty.typeUri = currentType.uri; + currentProperty.typeName = currentType.localname; + } + + if (typeStack.size() != 0) + { + currentType = typeStack.top(); + typeStack.pop(); + } + else + { + currentType = TypeDefinitionImpl(); + } + } + + // ============================================================================ + // setCurrentProperty + // ============================================================================ + void SDOSchemaSAX2Parser::setCurrentProperty(const PropertyDefinitionImpl& prop) + { + propertyStack.push(currentProperty); + currentProperty = prop; + } + + // ============================================================================ + // defineProperty + // ============================================================================ + void SDOSchemaSAX2Parser::defineProperty() + { + + if (currentProperty.typeName.isNull()) + { + // Set the type of this property to default (sdo:String) + currentProperty.typeUri = Type::SDOTypeNamespaceURI.c_str(); + currentProperty.typeName = "String"; + } + + if (currentProperty.localname.isNull()) + currentProperty.localname = currentProperty.typeName; + + // Set isMany if property isMany OR if containing type isMany + // NOTE: The above comment is as per the SDO2.0 spec however this does not + // work when serializing a sequence containing a single-valued property and + // then deserializing. + // currentProperty.isMany = currentProperty.isMany || currentType.isMany; + + currentType.properties.push_back(currentProperty); + if (propertyStack.size() != 0) + { + currentProperty = propertyStack.top(); + propertyStack.pop(); + } + else + currentProperty = PropertyDefinitionImpl(); + + } + + // ============================================================================ + // setDefault + // ============================================================================ + void SDOSchemaSAX2Parser::setDefault( + PropertyDefinitionImpl& thisProperty, + const SAX2Attributes& attributes) + { + thisProperty.defaultValue = attributes.getValue("fixed"); + if (!thisProperty.defaultValue.isNull()) + { + thisProperty.isReadOnly = true; + } + else + { + thisProperty.defaultValue = attributes.getValue("default"); + } + } + + // ============================================================================ + // setName + // ============================================================================ + void SDOSchemaSAX2Parser::setName( + const SAX2Attributes& attributes, + SDOXMLString& sdoname, + SDOXMLString& localname) + { + for (int i=0; i < attributes.size(); i++) + { + // Handle sdo: annotations + if (attributes[i].getUri().equalsIgnoreCase("commonj.sdo/xml")) + { + // sdo:name overrides the property name + if (attributes[i].getName().equalsIgnoreCase("name")) + { + sdoname = attributes[i].getValue(); + } + } + else + { + + if (attributes[i].getName().equalsIgnoreCase("name")) + { + localname = attributes[i].getValue(); + // If name is already set it must have been an + // override using sdo:name + if (sdoname.isNull()) + { + sdoname = localname; + } + } + } + } + + } + + // ============================================================================ + // setType + // ============================================================================ + void SDOSchemaSAX2Parser::setType( + PropertyDefinitionImpl& property, + const SAX2Attributes& attributes, + const SAX2Namespaces& namespaces) + { + property.fullLocalTypeName = attributes.getValue("type"); + if (!property.fullLocalTypeName.isNull()) + { + XMLQName qname(property.fullLocalTypeName,schemaInfo.getSchemaNamespaces(), namespaces); + if (qname.getLocalName().equals("IDREF") + || qname.getLocalName().equals("IDREFS")) + { + property.fullTypeName = attributes.getValue("commonj.sdo/xml","propertyType"); + + property.isIDREF = true; + property.isContainment = false; + + if (qname.getLocalName().equals("IDREFS")) + { + property.isMany = true; + } + } + else if (qname.getLocalName().equals("anyURI")) + { + property.fullTypeName = attributes.getValue("commonj.sdo/xml","propertyType"); + } + else if (qname.getLocalName().equals("ID")) + { + property.isID = true; + currentType.IDPropertyName = property.name; + } + + else + { + property.fullTypeName = attributes.getValue("commonj.sdo/xml","dataType"); + } + } + + else + { + property.fullLocalTypeName = attributes.getValue("ref"); + if (!property.fullLocalTypeName.isNull()) + { + property.isReference = true; + } + } + + if (property.fullTypeName.isNull()) + { + property.fullTypeName = property.fullLocalTypeName; + } + + if (!property.fullTypeName.isNull()) + { + // Resolve typename to uri:name + XMLQName qname = resolveTypeName( + property.fullTypeName, + namespaces, + property.typeUri, + property.typeName); + + if(qname.getLocalName().equals("QName")) + { + property.isQName = true; + } + } + + } + + // ============================================================================ + // setTypeName + // ============================================================================ + void SDOSchemaSAX2Parser::setTypeName( + TypeDefinitionImpl& type, + const SAX2Attributes& attributes, + const SAX2Namespaces& namespaces) + { + setName(attributes, type.name, type.localname); + + + // If localname is not set it is anonymous so use the enclosing element name + if (type.localname.isNull()) + { + type.localname = currentProperty.name; + + // ensure anonymous type name does not clash with existing type + for (int suffix = 1; ; suffix++) + { + SDOXMLString typeUri = TypeDefinitionsImpl::getTypeQName(type.uri, type.localname); + XMLDAS_TypeDefs::iterator it = typeDefinitions.types.find(typeUri); + if(it == typeDefinitions.types.end()) + { + break; + } + char buff[32]; + sprintf(buff, "%d", suffix); + type.localname += buff; + } + } + else + { + // check for an overriding url in the name + int i; + if ((i = type.localname.firstIndexOf(':')) > 0) + { + XMLQName qname(type.localname, + schemaInfo.getSchemaNamespaces(), + namespaces); + type.uri = qname.getURI(); + type.localname = qname.getLocalName(); + } + } + + // Set SDO name if not specified + if (type.name .isNull()) + { + type.name = type.localname ; + } + else + { + // check for an overriding url in the name + int i; + if ((i = type.name.firstIndexOf(':')) > 0) + { + XMLQName qname(type.name, + schemaInfo.getSchemaNamespaces(), + namespaces); + type.uri = qname.getURI(); + type.name = qname.getLocalName(); + } + } + } + + std::istream& operator>>(std::istream& input, SDOSchemaSAX2Parser& parser) + { + parser.stream(input); + + return input; + } + + std::istringstream& operator>>(std::istringstream& input, SDOSchemaSAX2Parser& parser) + { + parser.stream(input); + + return input; + } + + void SDOSchemaSAX2Parser::stream(std::istream& input) + { + // override to parse twice for groups + + stream_twice(input); + } + + + int SDOSchemaSAX2Parser::parse(const char* filename) + { + return parse_twice(filename); + } + + + + // ============================================================================ + // resolveTypeName + // ============================================================================ + XMLQName SDOSchemaSAX2Parser::resolveTypeName( + const SDOXMLString& fullTypeName, + const SAX2Namespaces& namespaces, + SDOXMLString& uri, + SDOXMLString& name) + { + XMLQName qname(fullTypeName, + schemaInfo.getSchemaNamespaces(), + namespaces); + + uri = qname.getURI(); + name = qname.getLocalName(); + + /////////////////////////////////////////////////////////////////////// + // Map the xsd types to SDO Types + /////////////////////////////////////////////////////////////////////// + if (qname.getURI().equalsIgnoreCase("http://www.w3.org/2001/XMLSchema")) + { + uri = Type::SDOTypeNamespaceURI.c_str(); + name = SDOUtils::XSDToSDO((const char*)(qname.getLocalName())); + if (name.isNull()) + { + name = "String"; + } + + } + + // Temporary hack: ChangeSummaryType is ChangeSummary in core + else if (qname.getURI().equalsIgnoreCase(Type::SDOTypeNamespaceURI.c_str())) + { + if (qname.getLocalName().equalsIgnoreCase("ChangeSummaryType")) + { + name = "ChangeSummary"; + } + + } + else if (qname.getURI().isNull()) + { + uri = schemaInfo.getTargetNamespaceURI(); + } + + return qname; + } + + } // End - namespace sdo + +} // End - namespace commonj + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOSchemaSAX2Parser.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOSchemaSAX2Parser.h new file mode 100644 index 0000000000..07d5538a0e --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOSchemaSAX2Parser.h @@ -0,0 +1,235 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _SDOSCHEMASAX2PARSER_H_ +#define _SDOSCHEMASAX2PARSER_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/SAX2Parser.h" +#include "commonj/sdo/SchemaInfo.h" +#include "stack" +#include "commonj/sdo/TypeDefinitionsImpl.h" +#include "commonj/sdo/GroupDefinition.h" +#include "commonj/sdo/XMLQName.h" +#include "commonj/sdo/ParserErrorSetter.h" + +namespace commonj +{ + namespace sdo + { + +/** + * SDOSAX2Parser implements SAX2Parser. + * This class gets called back by the libxml library, and + * deals with the creation of metadata objects from XSD. + */ + + class SDOSchemaSAX2Parser : public SAX2Parser + { + + public: + typedef std::map PARSED_LOCATIONS; + typedef std::vector DEFINED_NAMESPACES; + + SDOSchemaSAX2Parser(SchemaInfo& schemaInfo, + ParserErrorSetter* insetter, + PARSED_LOCATIONS& parsedLocations, + DEFINED_NAMESPACES& definedNamepaces); + + virtual ~SDOSchemaSAX2Parser(); + + + virtual void startElementNs( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes); + + virtual void endElementNs( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI); + + + virtual void stream(std::istream& input); + + virtual int parse(const char* filename); + virtual void endDocument(); + + + const SDOXMLString& getTargetNamespaceURI() const {return schemaInfo.getTargetNamespaceURI();} + + TypeDefinitionsImpl& getTypeDefinitions() {return typeDefinitions;} + + friend std::istream& operator>>(std::istream& input, SDOSchemaSAX2Parser& parser); + friend std::istringstream& operator>>(std::istringstream& input, SDOSchemaSAX2Parser& parser); + + + int parseURI(const SDOXMLString& location, const SDOXMLString& base); + + private: + + // group handling. + + int inGroup; + bool preParsing; + GroupDefinition* currentGroup; + std::vector groupList; + + bool bInSchema; // only parse when within a schema + bool bInvalidElement; // where element content is not valid + bool bInInvalidContent; // actually inside invalid content. + bool bInvalidList; // a list with no type - not supported. + + virtual void replayEvents( + const SDOXMLString& uri, + const SDOXMLString& name, + bool isGroup, + const SAX2Attributes& groupAttributes); + + virtual void storeStartElementEvent( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes); + + virtual void storeEndElementEvent( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI + ); + + virtual void startInclude( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes); + + virtual void startElement( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes); + + virtual void startAttribute( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes); + + virtual void startComplexType( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes); + + virtual void startSimpleType( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes); + + virtual void startRestriction( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes); + + virtual void startExtension( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes); + + virtual void startGroup( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes); + + virtual void startList( + const SDOXMLString& localname, + const SDOXMLString& prefix, + const SDOXMLString& URI, + const SAX2Namespaces& namespaces, + const SAX2Attributes& attributes); + + XMLQName resolveTypeName( + const SDOXMLString& fullTypeName, + const SAX2Namespaces& namespaces, + SDOXMLString& uri, + SDOXMLString& name); + + void setName( + const SAX2Attributes& attributes, + SDOXMLString& sdoname, + SDOXMLString& localname + ); + + void setType( + PropertyDefinitionImpl& property, + const SAX2Attributes& attributes, + const SAX2Namespaces& namespaces); + + void setTypeName( + TypeDefinitionImpl& type, + const SAX2Attributes& attributes, + const SAX2Namespaces& namespaces); + + void setDefault( + PropertyDefinitionImpl& thisProperty, + const SAX2Attributes& attributes); + + + SchemaInfo& schemaInfo; + + PropertyDefinitionImpl currentProperty; + std::stack propertyStack; + void setCurrentProperty(const PropertyDefinitionImpl& property); + void defineProperty(); + + TypeDefinitionImpl currentType; + std::stack typeStack; + void setCurrentType(const TypeDefinitionImpl& type); + void defineType(); + + TypeDefinitionsImpl typeDefinitions; + + PARSED_LOCATIONS& parsedLocations; + DEFINED_NAMESPACES& definedNamespaces; + + }; + + + } // End - namespace sdo +} // End - namespace commonj +#endif //_SDOSCHEMASAX2PARSER_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOString.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOString.h new file mode 100644 index 0000000000..9661bb6294 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOString.h @@ -0,0 +1,31 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +// #include "commonj/sdo/disable_warn.h" + +#ifndef _SDOString_H_ +#define _SDOString_H_ +#include "commonj/sdo/export.h" + +#include +typedef std::string SDOString; + +#endif // _SDOString_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOUserMacros.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOUserMacros.h new file mode 100644 index 0000000000..50f8733606 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOUserMacros.h @@ -0,0 +1,30 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _SDO_SDOUSERMACROS_H_ +#define _SDO_SDOUSERMACROS_H_ + +// This file is deliberately empty. It is included by SDO source files +// that allow macros to be overridden by user definitions. See SDODate.h/.cpp +// for an example of this. + +#endif //_SDO_SDODATE_H_ + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOUtils.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOUtils.cpp new file mode 100644 index 0000000000..cb4e0d0b24 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOUtils.cpp @@ -0,0 +1,442 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SDOUtils.h" +#include +using namespace std; + +// +// Utility methods to print a DataObject tree +// + +namespace commonj { + namespace sdo { + + const char *SDOUtils::CDataStartMarker = "XXXCDATA@STARTXXX"; + const char *SDOUtils::XMLCDataStartMarker = ""; + +////////////////////////////////////////////////////////////////////////// +// Conversions +////////////////////////////////////////////////////////////////////////// + + + std::map SDOUtils::SdoToXsd; + + std::map SDOUtils::XsdToSdo; + + std::map SDOUtils::HtmlEntities; + + bool SDOUtils::populated = false; + + bool SDOUtils::populate() + { + SDOUtils::XsdToSdo["ID"] = "String"; + SDOUtils::XsdToSdo["NCName"] = "String"; + SDOUtils::XsdToSdo["string"] = "String"; + SDOUtils::XsdToSdo["anyType"] = "DataObject"; + SDOUtils::XsdToSdo["int"] = "Integer"; + SDOUtils::XsdToSdo["integer"] = "Integer"; + SDOUtils::XsdToSdo["negativeInteger"] = "Integer"; + SDOUtils::XsdToSdo["nonNegativeInteger"] = "Integer"; + SDOUtils::XsdToSdo["positiveInteger"] = "Integer"; + SDOUtils::XsdToSdo["nonpositiveInteger"] = "Integer"; + SDOUtils::XsdToSdo["unsignedShort"] = "Integer"; + SDOUtils::XsdToSdo["unsignedInt"] = "Integer"; + SDOUtils::XsdToSdo["unsignedLong"] = "Long"; + SDOUtils::XsdToSdo["double"] = "Double"; + SDOUtils::XsdToSdo["short"] = "Short"; + SDOUtils::XsdToSdo["unsignedByte"] = "Short"; + SDOUtils::XsdToSdo["float"] = "Float"; + SDOUtils::XsdToSdo["boolean"] = "Boolean"; + SDOUtils::XsdToSdo["byte"] = "Byte"; + SDOUtils::XsdToSdo["base64Binary"] = "Bytes"; + SDOUtils::XsdToSdo["hexBinary"] = "Bytes"; + SDOUtils::XsdToSdo["anyURI"] = "URI"; + SDOUtils::XsdToSdo["QName"] = "URI"; + + SDOUtils::SdoToXsd["String"] = "string"; + SDOUtils::SdoToXsd["DataObject"] = "anyType"; + SDOUtils::SdoToXsd["Integer"] = "integer"; + SDOUtils::SdoToXsd["Long"] = "unsignedLong"; + SDOUtils::SdoToXsd["Double"] = "double"; + SDOUtils::SdoToXsd["Short"] = "short"; + SDOUtils::SdoToXsd["Float"] = "float"; + SDOUtils::SdoToXsd["Boolean"] = "boolean"; + SDOUtils::SdoToXsd["Byte"] = "byte"; + SDOUtils::SdoToXsd["Bytes"] = "base64Binary"; + SDOUtils::SdoToXsd["URI"] = "anyURI"; + + SDOUtils::HtmlEntities['&'] = "&"; + SDOUtils::HtmlEntities['<'] = "<"; + SDOUtils::HtmlEntities['>'] = ">"; + SDOUtils::HtmlEntities['\''] = "'"; + SDOUtils::HtmlEntities['"'] = """; + + SDOUtils::populated = true; + return true; + } + + const char* SDOUtils::SDOToXSD(const char* sdoname) + { + if (sdoname == 0) + { + return SDOUtils::SdoToXsd["String"].c_str(); + } + if (!SDOUtils::populated) SDOUtils::populate(); + string& s = SDOUtils::SdoToXsd[sdoname]; + if (s.empty()) + { + return SDOUtils::SdoToXsd["String"].c_str(); + } + return s.c_str(); + } + + + const char* SDOUtils::XSDToSDO(const char* xsdname) + { + if (xsdname == 0) + { + return SDOUtils::XsdToSdo["string"].c_str(); + } + if (!SDOUtils::populated) SDOUtils::populate(); + string& s = SDOUtils::XsdToSdo[xsdname]; + if (s.empty()) + return SDOUtils::XsdToSdo["string"].c_str(); + return s.c_str(); + } + +////////////////////////////////////////////////////////////////////////// +// Print Tabs +////////////////////////////////////////////////////////////////////////// + + void SDOUtils::printTabs(ostream& out, unsigned int incr) + { + for (unsigned int ind=0; ind < incr; ind++) + { + out << " "; + } + } + +////////////////////////////////////////////////////////////////////////// +// Print a DatObject tree +////////////////////////////////////////////////////////////////////////// + + void SDOUtils::printDataObject(ostream& out, DataObjectPtr dataObject) + { + printDataObject(out, dataObject,0); + } + + + void SDOUtils::printDataObject(ostream& out ,DataObjectPtr dataObject, + unsigned int incr) + { + + out << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> start of DO" + << endl; + + if (!dataObject)return; + + const Type& dataObjectType = dataObject->getType(); + printTabs(out, incr); + out << "DataObject type: " + << dataObjectType.getURI() + << "#" << dataObjectType.getName() << endl; + + incr++; + + ////////////////////////////////////////////////////////////// + // Iterate over all the properties + ////////////////////////////////////////////////////////////// + PropertyList pl = dataObject->getInstanceProperties(); + for (unsigned int i = 0; i < pl.size(); i++) + { + printTabs(out, incr); + out << "Property: " << pl[i].getName() << endl; + + const Type& propertyType = pl[i].getType(); + + printTabs(out, incr); + + out << "Property Type: " + << propertyType.getURI() + << "#" << propertyType.getName() << endl; + + if (dataObject->isSet(pl[i])) + { + + /////////////////////////////////////////////////////////// + // For a many-valued property get the list of values + /////////////////////////////////////////////////////////// + if (pl[i].isMany()) + { + incr++; + DataObjectList& dol = dataObject->getList(pl[i]); + char cc[20]; + for (unsigned int j = 0; j objectToXPath() <isNull(pl[i])) + out << "NULL" << endl; + else + out << dataObject->getCString(pl[i]) <getDataObject(pl[i])->objectToXPath() <getDataObject(pl[i]),incr); + } + incr--; + } + } + else + { + printTabs(out, incr); + out << "Property Value: not set" <getTypes(); + for (unsigned int i = 0; i < tl.size(); i++) + { + out << "Type: " << tl[i].getURI()<< "#" << tl[i].getName() << + " isOpen: " << tl[i].isOpenType() + << " isSequenced: " << tl[i].isSequencedType() << endl; + + const std::list pl = tl[i].getPropertyListReference(); + + for (std::list::const_iterator j = pl.begin(); + j != pl.end(); + j++) + { + const Property* current = (Property*) (*j); + + out << "\tProperty: " + << current->getName() + << " type: " + << current->getType().getURI() + << "#" + << current->getType().getName() + << " isMany: " + << current->isMany() + << endl; + } + } + + } + + /* + * A local utility function that replaces one string with and another within a + * host string and adjusts the lenght of the host string accordingly. + */ + SDOString SDOUtils::replace(SDOString hostString, const char *fromString, const char *toString) + { + SDOString returnString(""); + + // find and replace all occurances of fromString with toString. The start, end + // and length variables are used to indicate the start, end and length + // of the text sections to be copied from the host string to the return + // string. toString is appended in between these copied sections because the + // string is broken whenever fromString is found + std::string::size_type start = 0; + std::string::size_type end = hostString.find(fromString, 0); + std::string::size_type length = 0; + + while ( end != std::string::npos ) + { + // copy all the text up to the fromString + length = end - start; + returnString.append(hostString.substr(start, length)); + + // add in the toString + returnString.append(toString); + + // find the next fromString + start = end + strlen(fromString); + end = hostString.find(fromString, start); + } + + // copy any text left at the end of the host string + returnString.append(hostString.substr(start)); + + return returnString; + } + + + /* + * Processes a string, substituting entities (such as &) for special characters + * Does not double-encode, that is, & is not converted to &amp; + */ + SDOString SDOUtils::escapeHtmlEntities(SDOString inputString) + { + if (inputString.size() == 0) + return inputString; + + if (!SDOUtils::populated) SDOUtils::populate(); + + SDOString returnString = SDOString(); + + SDOString::iterator start = inputString.begin(); + SDOString::iterator end = inputString.end(); + SDOString::iterator cur = start; + + while(cur < end) { + //cout << SDOString(cur) <::iterator iter = HtmlEntities.begin(); + iter != HtmlEntities.end(); iter++ ) { + if (SDOString(cur, end).compare(0, (*iter).second.length(), (*iter).second) == 0) { + cur += (*iter).second.length(); + skip = true; + break; + } + } + + if (skip) continue; + } + + /* + * look for characters which need encoding + */ + for (map::iterator iter = HtmlEntities.begin(); + iter != HtmlEntities.end(); iter++ ) { + if ((*cur) == (*iter).first) { + returnString += SDOString(start, cur); + // cout << returnString < +#include + +namespace commonj +{ + namespace sdo + { + + + /** + * SDOUtils will provide utility functions. + * The class currently holds a method to print data objects. + */ + + class SDOUtils + { + + public: + + static SDO_API void printDataObject(std::ostream& out, DataObjectPtr d); + static SDO_API const char* SDOToXSD(const char* sdoname); + static SDO_API const char* XSDToSDO(const char* xsdname); + static SDO_API void printTypes(std::ostream& out, DataFactoryPtr df); + static SDOString replace(SDOString hostString, const char *fromString, const char *toString); + static SDOString escapeHtmlEntities(SDOString inputString); + static SDOString escapeHtmlEntitiesExcludingCData(SDOString inputString); + + /* + * Markers used to represent the start and end of CDATA sections in the + * settings value. The noew XML CDATA markers are not used here because the + * XML string processing URL encodes parts of the markers + */ + static SDO_API const char *CDataStartMarker; + static SDO_API const char *XMLCDataStartMarker; + static SDO_API const char *CDataEndMarker; + static SDO_API const char *XMLCDataEndMarker; + + private: + + static bool populate(); + static bool populated; + + static void printDataObject(std::ostream& out, DataObjectPtr d, unsigned int incr); + static void printTabs(std::ostream& out, unsigned int incr); + + static std::map XsdToSdo; + static std::map SdoToXsd; + static std::map HtmlEntities; + + }; + } // End - namespace sdo +} // End - namespace commonj + + +#endif //_SDOUTILS_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOValue.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOValue.cpp new file mode 100644 index 0000000000..30997ef16c --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOValue.cpp @@ -0,0 +1,236 @@ +/* + * + * Copyright 2007 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SDOValue.h" + +namespace commonj +{ + namespace sdo + { + + SDOValue::SDOValue(const char* inValue, unsigned int len) : + typeOfValue(DataTypeInfo::SDOByteArray), transient_buffer(0) + { + char* temp_buffer = new char[len + 1]; + + // We would like to use strncpy at this point, but it is + // deprecated and its preferred alternative, strncpy_s, does + // not copy nulls if they appear in the input stream so we'll + // do it by hand. + for (unsigned int i = 0; i < len; i++) + { + temp_buffer[i] = (char) inValue[i]; + } + temp_buffer[len] = 0; + + value.TextString = new SDOString(temp_buffer, len); + + delete[] temp_buffer; + } + + SDOValue::SDOValue(const wchar_t* inValue, unsigned int len) : + typeOfValue(DataTypeInfo::SDOWideString), transient_buffer(0) + { + value.WideString.data = new wchar_t[len + 1]; + + for (unsigned int i = 0; i < len; i++) + { + value.WideString.data[i] = (wchar_t) inValue[i]; + } + value.WideString.data[len] = (wchar_t) 0; + + value.WideString.length = len; // NOTE: length is the number of _real_ + // characters in the WideString + + } + + // Copy constructor + SDOValue::SDOValue(const SDOValue& inValue) : + typeOfValue(inValue.typeOfValue), transient_buffer(0) + { + switch (inValue.typeOfValue) + { + case DataTypeInfo::SDObool: + value.Boolean = inValue.value.Boolean; + break; + case DataTypeInfo::SDOchar: + value.Character = inValue.value.Character; + break; + case DataTypeInfo::SDOwchar_t: + value.WideChar = inValue.value.WideChar; + break; + case DataTypeInfo::SDOshort: + value.Short = inValue.value.Short; + break; + case DataTypeInfo::SDOlong: + value.Integer = inValue.value.Integer; + break; + case DataTypeInfo::SDOfloat: + value.Float = inValue.value.Float; + break; + case DataTypeInfo::SDOdouble: + value.Double = inValue.value.Double; + break; + case DataTypeInfo::SDOSDODate: + value.Date = new SDODate((inValue.value.Date)->getTime()); + break; + case DataTypeInfo::SDOCString: + case DataTypeInfo::SDOByteArray: + value.TextString = new SDOString(*(inValue.value.TextString)); + break; + case DataTypeInfo::SDOWideString: + value.WideString.data = new wchar_t[inValue.value.WideString.length + 1]; + // The loop copies the null terminator that was added to the end + // of the source data when _it_ was constructed. + for (unsigned int i = 0; i <= inValue.value.WideString.length; i++) + { + value.WideString.data[i] = inValue.value.WideString.data[i]; + } + value.WideString.length = inValue.value.WideString.length; + break; + } + } + // End of copy constructor + + // Copy assignment + SDOValue& SDOValue::operator=(const SDOValue& inValue) + { + if (this != &inValue) // sval = sval is a no-op. + { + // Clear out any allocated data in the target SDOValue. + switch (typeOfValue) + { + case DataTypeInfo::SDOSDODate: + delete value.Date; + value.Date = 0; + break; + case DataTypeInfo::SDOCString: + case DataTypeInfo::SDOByteArray: + delete value.TextString; + value.TextString = 0; + break; + case DataTypeInfo::SDOWideString: + delete[] value.WideString.data; + value.WideString.data = 0; + value.WideString.length = 0; + break; + default: + // Nothing to delete. + break; + } + + if (transient_buffer != 0) + { + delete transient_buffer; + transient_buffer = 0; + } + + // Copy the source data into the target + switch (inValue.typeOfValue) + { + case DataTypeInfo::SDObool: + value.Boolean = inValue.value.Boolean; + break; + case DataTypeInfo::SDOchar: + value.Character = inValue.value.Character; + break; + case DataTypeInfo::SDOwchar_t: + value.WideChar = inValue.value.WideChar; + break; + case DataTypeInfo::SDOshort: + value.Short = inValue.value.Short; + break; + case DataTypeInfo::SDOlong: + value.Integer = inValue.value.Integer; + break; + case DataTypeInfo::SDOint64_t: + value.Int64 = inValue.value.Int64; + break; + case DataTypeInfo::SDOfloat: + value.Float = inValue.value.Float; + break; + case DataTypeInfo::SDOdouble: + value.Double = inValue.value.Double; + break; + case DataTypeInfo::SDOSDODate: + value.Date = new SDODate((inValue.value.Date)->getTime()); + break; + case DataTypeInfo::SDOCString: + case DataTypeInfo::SDOByteArray: + value.TextString = new SDOString(*(inValue.value.TextString)); + break; + case DataTypeInfo::SDOWideString: + value.WideString.data = new wchar_t[inValue.value.WideString.length + 1]; + // The loop copies the null terminator that was added to the end + // of the source data when _it_ was constructed. + for (unsigned int i = 0; i <= inValue.value.WideString.length; i++) + { + value.WideString.data[i] = inValue.value.WideString.data[i]; + } + value.WideString.length = inValue.value.WideString.length; + break; + } + // Finally, set the new type. + typeOfValue = inValue.typeOfValue; + } + return *this; + } + // End of copy assignment + + // Destructor + SDOValue::~SDOValue() + { + + // Clear out any allocated data in the target SDOValue. + switch (typeOfValue) + { + case DataTypeInfo::SDOSDODate: + delete value.Date; + value.Date = 0; + break; + case DataTypeInfo::SDOCString: + case DataTypeInfo::SDOByteArray: + delete value.TextString; + value.TextString = 0; + break; + case DataTypeInfo::SDOWideString: + delete[] value.WideString.data; + value.WideString.data = 0; + value.WideString.length = 0; + break; + default: + // Nothing to delete. + break; + } + + if (transient_buffer != 0) + { + delete transient_buffer; + transient_buffer = 0; + } + + typeOfValue = DataTypeInfo::SDOunset; + } + // End of Destructor + + + const SDOValue SDOValue::nullSDOValue = SDOValue(DataTypeInfo::SDOnull); + const SDOValue SDOValue::unsetSDOValue = SDOValue(DataTypeInfo::SDOunset); + } // End - namespace sdo +} // End - namespace commonj diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOValue.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOValue.h new file mode 100644 index 0000000000..4b675974dd --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOValue.h @@ -0,0 +1,258 @@ +/* +* +* Copyright 2007 The Apache Software Foundation or its licensors, as applicable. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* $Rev$ $Date$ */ + +#ifndef _SDOValue_H_ +#define _SDOValue_H_ + +#include "commonj/sdo/export.h" +#include "commonj/sdo/SDODate.h" +#include "commonj/sdo/SDOString.h" +#include "commonj/sdo/SDODataConverter.h" +#include "commonj/sdo/DataTypeInfo.h" + +#include + +namespace commonj +{ + namespace sdo + { + + // The SDOValue class provides a discriminated data type that wraps the + // many different primitive data types that SDO must use. This allows + // common treatment of SDO values by all methods except those that + // really must do different things for different types. The key point is + // that instances of the class combine a union with and enum that says + // which member of the union is actually present. The enum also allows + // for the possibility that the value is unset or has been explicitly + // set to null. + + class SDOValue + { + private: + // Entities with copy constructors/destructors are not allowed in a union, + // since in general, the compiler doesn't know what type is + // actually in there so it can't know which constructor/destructor + // to call, hence the use of pointers for certain datatypes. + DataTypeInfo::SDODataTypeUnion value; + + DataTypeInfo::RawDataType typeOfValue; + + mutable SDOString* transient_buffer; + + public: + + // Constructors + SDO_API SDOValue(bool inValue) : + typeOfValue(DataTypeInfo::SDObool), transient_buffer(0) + { + value.Boolean = inValue; + } + SDO_API SDOValue(float inValue) : + typeOfValue(DataTypeInfo::SDOfloat), transient_buffer(0) + { + value.Float = inValue; + } + SDO_API SDOValue(long double inValue) : + typeOfValue(DataTypeInfo::SDOdouble), transient_buffer(0) + { + value.Double = inValue; + } + SDO_API SDOValue(short inValue) : + typeOfValue(DataTypeInfo::SDOshort), transient_buffer(0) + { + value.Short = inValue; + } +#if __WORDSIZE != 64 + SDO_API SDOValue(long inValue) : + typeOfValue(DataTypeInfo::SDOlong), transient_buffer(0) + { + value.Integer = inValue; + } +#endif + SDO_API SDOValue(int64_t inValue) : + typeOfValue(DataTypeInfo::SDOint64_t), transient_buffer(0) + { + value.Int64 = inValue; + } + SDO_API SDOValue(char inValue) : + typeOfValue(DataTypeInfo::SDOchar), transient_buffer(0) + { + value.Character = inValue; + } + SDO_API SDOValue(wchar_t inValue) : + typeOfValue(DataTypeInfo::SDOwchar_t), transient_buffer(0) + { + value.WideChar = inValue; + } + SDO_API SDOValue(const SDODate inValue) : + typeOfValue(DataTypeInfo::SDOSDODate), transient_buffer(0) + { + value.Date = new SDODate(inValue.getTime()); + } + SDO_API SDOValue(const SDOString& inValue) : + typeOfValue(DataTypeInfo::SDOCString), transient_buffer(0) + { + value.TextString = new SDOString(inValue); + } + + SDO_API SDOValue(const char* inValue) : + typeOfValue(DataTypeInfo::SDOCString), transient_buffer(0) + { + value.TextString = new SDOString(inValue); + } + + SDO_API SDOValue(const char* inValue, unsigned int len); + + SDO_API SDOValue(const wchar_t* inValue, unsigned int len); + + SDO_API SDOValue() : typeOfValue(DataTypeInfo::SDOunset), transient_buffer(0) + { + } + //End of Constructors + + // Copy constructor + SDO_API SDOValue(const SDOValue& inValue); + + // Copy assignment + SDO_API SDOValue& operator=(const SDOValue& inValue); + + // Destructor + SDO_API virtual ~SDOValue(); + + inline SDO_API bool isSet() const + { + return (typeOfValue != DataTypeInfo::SDOunset); + } + inline SDO_API bool isNull() const + { + return (typeOfValue == DataTypeInfo::SDOnull); + } + + // Get methods to retrieve the stored value. + SDO_API bool getBoolean() const + { + return SDODataConverter::convertToBoolean(value, + (DataTypeInfo::TrueDataType) typeOfValue); + } + + SDO_API float getFloat() const + { + return SDODataConverter::convertToFloat(value, + (DataTypeInfo::TrueDataType) typeOfValue); + } + + SDO_API long double getDouble() const + { + return SDODataConverter::convertToDouble(value, + (DataTypeInfo::TrueDataType) typeOfValue); + } + + SDO_API const SDODate getDate() const + { + return SDODataConverter::convertToDate(value, + (DataTypeInfo::TrueDataType) typeOfValue); + } + + SDO_API short getShort() const + { + return SDODataConverter::convertToShort(value, + (DataTypeInfo::TrueDataType) typeOfValue); + } + + SDO_API long getInteger() const + { + return SDODataConverter::convertToInteger(value, + (DataTypeInfo::TrueDataType) typeOfValue); + } + + SDO_API char getByte() const + { + return SDODataConverter::convertToByte(value, + (DataTypeInfo::TrueDataType) typeOfValue); + } + + SDO_API wchar_t getCharacter() const + { + return SDODataConverter::convertToCharacter(value, + (DataTypeInfo::TrueDataType) typeOfValue); + } + + SDO_API int64_t getLong() const + { + return SDODataConverter::convertToLong(value, + (DataTypeInfo::TrueDataType) typeOfValue); + } + + // The following method is regrettably necessary to provide the + // CString style interface for the V2.01 spec. + SDO_API const char* getCString() const + { + if (transient_buffer != 0) + { + delete transient_buffer; + } + transient_buffer = + SDODataConverter::convertToSDOString(value, + (DataTypeInfo::TrueDataType) typeOfValue); + return transient_buffer->c_str(); + } + + // This method is the preferred way to retrieve a string value + SDO_API SDOString getString() const + { + return *SDODataConverter::convertToSDOString(value, + (DataTypeInfo::TrueDataType) typeOfValue); + } + + SDO_API unsigned int getString(wchar_t* outptr, const unsigned int max_length) const + { + return SDODataConverter::convertToString(value, + (DataTypeInfo::TrueDataType) typeOfValue, + outptr, + max_length); + } + + SDO_API unsigned int getBytes(char* outptr, const unsigned int max_length) const + { + return SDODataConverter::convertToBytes(value, + (DataTypeInfo::TrueDataType) typeOfValue, + outptr, + max_length); + } + + // Beware, the array does not contain values for all the + // enumeration values and it is the callers job to avoid + // triggering that. + SDO_API const SDOString& convertTypeEnumToString() const + { + return DataTypeInfo::convertTypeEnumToString((DataTypeInfo::TrueDataType) typeOfValue); + } + + static SDO_API const SDOValue nullSDOValue; + static SDO_API const SDOValue unsetSDOValue; + // static SDO_API const SDOString rawTypeNames[]; + + private: + SDO_API SDOValue(DataTypeInfo::RawDataType rdt) : typeOfValue(rdt), transient_buffer(0) {} + + }; + } // End - namespace sdo +} // End - namespace commonj + +#endif // _SDOValue_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLBufferWriter.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLBufferWriter.cpp new file mode 100644 index 0000000000..38a4ff9799 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLBufferWriter.cpp @@ -0,0 +1,57 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SDOXMLBufferWriter.h" +#include "commonj/sdo/SDORuntimeException.h" + +namespace commonj +{ + namespace sdo + { + + + + + SDOXMLBufferWriter::SDOXMLBufferWriter(DataFactoryPtr dataFactory) + : SDOXMLWriter(dataFactory) + { + buf = xmlBufferCreate(); + if (buf == NULL) + { + SDO_THROW_EXCEPTION("SDOXMLBufferWriter", SDOXMLParserException, "xmlBufferCreate failed"); + } + setWriter(xmlNewTextWriterMemory(buf, 0)); + } + + SDOXMLBufferWriter::~SDOXMLBufferWriter() + { + freeWriter(); + xmlBufferFree(buf); + } + + SDOXMLString SDOXMLBufferWriter::getBuffer() + { + freeWriter(); + return buf->content; + } + } // End - namespace sdo +} // End - namespace commonj + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLBufferWriter.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLBufferWriter.h new file mode 100644 index 0000000000..bcfb226806 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLBufferWriter.h @@ -0,0 +1,53 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _SDOXMLBUFFERWRITER_H_ +#define _SDOXMLBUFFERWRITER_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/SDOXMLWriter.h" + +namespace commonj +{ + namespace sdo + { + +/** + * SDOXMLBufferWriter extends SDOXMLWriter and writes a buffer. + */ + class SDOXMLBufferWriter : public SDOXMLWriter + { + + public: + + SDOXMLBufferWriter(DataFactoryPtr dataFactory = NULL); + virtual ~SDOXMLBufferWriter(); + + SDOXMLString getBuffer(); + private: + xmlBufferPtr buf; + }; + } // End - namespace sdo +} // End - namespace commonj + + +#endif //_SDOXMLBUFFERWRITER_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLFileWriter.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLFileWriter.cpp new file mode 100644 index 0000000000..6420af9a96 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLFileWriter.cpp @@ -0,0 +1,46 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SDOXMLFileWriter.h" + +namespace commonj +{ + namespace sdo + { + + + + + SDOXMLFileWriter::SDOXMLFileWriter(const char* xmlFile, DataFactoryPtr dataFactory) + : SDOXMLWriter(dataFactory) + { + setWriter(xmlNewTextWriterFilename(xmlFile, 0)); + } + + SDOXMLFileWriter::~SDOXMLFileWriter() + { + + } + + + } // End - namespace sdo +} // End - namespace commonj + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLFileWriter.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLFileWriter.h new file mode 100644 index 0000000000..83e2aa5a2c --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLFileWriter.h @@ -0,0 +1,54 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _SDOXMLFILEWRITER_H_ +#define _SDOXMLFILEWRITER_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/SDOXMLWriter.h" + + + +namespace commonj +{ + namespace sdo + { + +/** + * SDOXMLFileWriter extends SDOXMLWriter and writes a file. + */ + class SDOXMLFileWriter : public SDOXMLWriter + { + + public: + + SDOXMLFileWriter(const char* xmlFile, DataFactoryPtr dataFactory = NULL); + + virtual ~SDOXMLFileWriter(); + + + }; + } // End - namespace sdo +} // End - namespace commonj + + +#endif //_SDOXMLFILEWRITER_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLStreamWriter.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLStreamWriter.cpp new file mode 100644 index 0000000000..12b1e59b9e --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLStreamWriter.cpp @@ -0,0 +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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SDOXMLStreamWriter.h" +#include + +namespace commonj +{ + namespace sdo + { + + + + + SDOXMLStreamWriter::SDOXMLStreamWriter(std::ostream& outXML, DataFactoryPtr dataFactory) + : SDOXMLBufferWriter(dataFactory), outXmlStream(outXML) + { + } + + SDOXMLStreamWriter::~SDOXMLStreamWriter() + { + } + + int SDOXMLStreamWriter::write(XMLDocumentPtr doc, int indent) + { + int rc = SDOXMLBufferWriter::write(doc, indent); + + // Now stream the buffer + outXmlStream << getBuffer(); + return rc; + } + } // End - namespace sdo +} // End - namespace commonj + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLStreamWriter.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLStreamWriter.h new file mode 100644 index 0000000000..977ff63a63 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLStreamWriter.h @@ -0,0 +1,56 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _SDOXMLSTREAMWRITER_H_ +#define _SDOXMLSTREAMWRITER_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/SDOXMLBufferWriter.h" +#include + + +namespace commonj +{ + namespace sdo + { + +/** + * SDOXMLStreamWriter extends SDOXMLWriter and writes a stream. + */ + class SDOXMLStreamWriter : public SDOXMLBufferWriter + { + + public: + + SDOXMLStreamWriter(std::ostream& outXML, DataFactoryPtr dataFactory = NULL); + virtual ~SDOXMLStreamWriter(); + + int write(XMLDocumentPtr doc, int indent = -1); + private: + std::ostream& outXmlStream; + + }; + } // End - namespace sdo +} // End - namespace commonj + + +#endif //_SDOXMLSTREAMWRITER_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLString.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLString.cpp new file mode 100644 index 0000000000..bee23a3852 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLString.cpp @@ -0,0 +1,234 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SDOXMLString.h" +#include +#include "libxml/globals.h" + +#include + +namespace commonj +{ + namespace sdo + { + + SDOXMLString::SDOXMLString() + : xmlForm(0) + { + } + + SDOXMLString::SDOXMLString(const xmlChar* xmlString) + { + xmlForm = xmlStrdup(xmlString); + } + + SDOXMLString::SDOXMLString(const char* localString) + { + xmlForm = xmlCharStrdup(localString); + } + + SDOXMLString::SDOXMLString(const SDOXMLString& str) + { + xmlForm = xmlStrdup(str.xmlForm); + } + + SDOXMLString::SDOXMLString(const xmlChar* str, int start, int len) + { + xmlForm = xmlStrsub(str, start, len); + } + + SDOXMLString& SDOXMLString::operator=(const SDOXMLString& str) + { + if (this != &str) + { + release(); + xmlForm = xmlStrdup(str.xmlForm); + } + return *this; + } + + SDOXMLString::operator std::string() const + { + if (xmlForm) + { + return (const char *)xmlForm; + } + return ""; + } + + SDOXMLString SDOXMLString::operator+(const SDOXMLString& str) const + { + xmlChar* newString = xmlStrncatNew(xmlForm, str.xmlForm, xmlStrlen(str.xmlForm)); + SDOXMLString retString(newString); + if (newString) + xmlFree(newString); + return retString; + } + + SDOXMLString& SDOXMLString::operator+=(const SDOXMLString& str) + { + xmlForm = xmlStrncat(xmlForm, str.xmlForm, xmlStrlen(str.xmlForm)); + return *this; + } + + SDOXMLString::~SDOXMLString() + { + release(); + } + + void SDOXMLString::release() + { + if (xmlForm) + xmlFree((void*)xmlForm); + } + + bool SDOXMLString::operator< (const SDOXMLString& str) const + { + if (xmlStrcmp(xmlForm, str.xmlForm) <0) + return true; + else + return false; + } + + bool SDOXMLString::operator==(const SDOXMLString& str) const + { + if (xmlStrEqual(xmlForm, str.xmlForm)) + return true; + else + return false; + } + + bool SDOXMLString::equals(const SDOXMLString& str) const + { + return equals(str.xmlForm); + } + + bool SDOXMLString::equals(const char* localString) const + { + return equals(SDOXMLString(localString)); + } + + + bool SDOXMLString::equals(const xmlChar* xmlString) const + { + if (xmlStrEqual(xmlForm, xmlString)) + return true; + else + return false; + } + + bool SDOXMLString::equalsIgnoreCase(const SDOXMLString& str) const + { + return equalsIgnoreCase(str.xmlForm); + } + + bool SDOXMLString::equalsIgnoreCase(const char* localString) const + { + return equalsIgnoreCase(SDOXMLString(localString)); + } + + + bool SDOXMLString::equalsIgnoreCase(const xmlChar* xmlString) const + { + if (xmlStrcasecmp(xmlForm, xmlString) == 0) + return true; + else + return false; + } + + + std::ostream& operator<<(std::ostream& output, const SDOXMLString& str) + { + if (str.xmlForm) + output << str.xmlForm; + return output; + } + + bool SDOXMLString::isNull() const + { + if (xmlForm) + return false; + else + return true; + } + + SDOXMLString SDOXMLString::toLower(unsigned int start, unsigned int length) + { + char* newString = new char[strlen(*this)+1]; + strcpy(newString, *this); + for (unsigned int i = start; (i<=(strlen(newString)) && i < length); i++) + { + newString[i] = tolower(newString[i]); + } + SDOXMLString retString(newString); + delete[] newString; + return retString; + } + + int SDOXMLString::firstIndexOf(const char ch) const + { + const xmlChar* loc = xmlStrchr(xmlForm, ch); + if (loc == 0) + { + return -1; + } + + return int(loc-xmlForm); + } + + int SDOXMLString::lastIndexOf(const char ch) const + { + const xmlChar* index = 0; + const xmlChar* loc = xmlStrchr(xmlForm, ch); + while (loc !=0) + { + index = loc; + loc = xmlStrchr(loc+1, ch); + } + + if (index == 0) + return -1; + + return int(index-xmlForm); + } + + SDOXMLString SDOXMLString::substring(int start, int length) const + { + if (length >0) + { + return SDOXMLString(xmlForm, start, length); + } + else + return SDOXMLString(); + } + + SDOXMLString SDOXMLString::substring(int start) const + { + + return SDOXMLString(xmlForm, start, xmlStrlen(xmlForm) - start); + } + + + } // End - namespace sdo +} // End - namespace commonj + + + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLString.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLString.h new file mode 100644 index 0000000000..9b1026f1d8 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLString.h @@ -0,0 +1,94 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/disable_warn.h" + +#ifndef _SDOXMLString_H_ +#define _SDOXMLString_H_ +#include "commonj/sdo/export.h" + +#include +#include + +namespace commonj +{ + namespace sdo + { + /** + * SDOXMLString - utility class for string handling. + * Keeps the string handling local to one place, so we can + * replace it with a more NLS friendly version later. + * Many places within the core should use this too instead + * of allocated char* buffers. (DataObject etc...) + */ + + class SDOXMLString + { + public: + SDO_SPI SDOXMLString(); + SDO_SPI SDOXMLString(const xmlChar* xmlString); + SDO_SPI SDOXMLString(const char* localString); + SDO_SPI SDOXMLString(const SDOXMLString& str); + SDO_SPI SDOXMLString(const xmlChar* str, int start, int len); + SDO_SPI virtual ~SDOXMLString(); + + SDO_SPI SDOXMLString& operator=(const SDOXMLString& str); + SDO_SPI SDOXMLString operator+(const SDOXMLString& str) const; + SDO_SPI SDOXMLString& operator+=(const SDOXMLString& str); + + + SDO_SPI bool operator== (const SDOXMLString& str) const; + SDO_SPI bool equals(const xmlChar* xmlString) const; + SDO_SPI bool equals(const char* localString) const; + SDO_SPI bool equals(const SDOXMLString& str) const; + SDO_SPI bool equalsIgnoreCase(const xmlChar* xmlString) const; + SDO_SPI bool equalsIgnoreCase(const char* localString) const; + SDO_SPI bool equalsIgnoreCase(const SDOXMLString& str) const; + + SDO_SPI bool operator< (const SDOXMLString& str) const; + + SDO_SPI operator std::string() const; + SDO_SPI operator const char*() const {return (const char*) xmlForm;} + SDO_SPI operator const xmlChar*() const {return xmlForm;} + + SDO_SPI friend std::ostream& operator<<(std::ostream& output, const SDOXMLString& str); + + SDO_SPI bool isNull() const; + + SDO_SPI SDOXMLString toLower( + unsigned int start = 0, + unsigned int length = 0); + + + SDO_SPI int firstIndexOf(const char ch) const; + SDO_SPI int lastIndexOf(const char ch) const; + SDO_SPI SDOXMLString substring(int start, int length) const; + SDO_SPI SDOXMLString substring(int start) const; + private : + xmlChar* xmlForm; + void release(); + }; + } // End - namespace sdo +} // End - namespace commonj + + + +#endif // _SDOXMLString_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLWriter.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLWriter.cpp new file mode 100644 index 0000000000..728023a59a --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLWriter.cpp @@ -0,0 +1,1410 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SDOXMLWriter.h" +#include "commonj/sdo/SDOXMLString.h" +#include "commonj/sdo/SDOString.h" +#include "iostream" +using namespace::std; +#include "commonj/sdo/DASProperty.h" +#include "commonj/sdo/XSDPropertyInfo.h" +#include "commonj/sdo/XSDTypeInfo.h" +#include "commonj/sdo/ChangeSummary.h" +#include "commonj/sdo/Sequence.h" +#include "commonj/sdo/SDORuntimeException.h" +#include "commonj/sdo/XMLQName.h" +#include "commonj/sdo/DataObjectImpl.h" +#include "commonj/sdo/DataFactoryImpl.h" +#include "commonj/sdo/PropertySetting.h" +#include "commonj/sdo/SDOUtils.h" + +namespace commonj +{ + namespace sdo + { + + const SDOXMLString SDOXMLWriter::s_xsi("xsi"); + const SDOXMLString SDOXMLWriter::s_type("type"); + const SDOXMLString SDOXMLWriter::s_nil("nil"); + const SDOXMLString SDOXMLWriter::s_true("true"); + const SDOXMLString SDOXMLWriter::s_xsiNS("http://www.w3.org/2001/XMLSchema-instance"); + const SDOXMLString SDOXMLWriter::s_xmlns("xmlns"); + const SDOXMLString SDOXMLWriter::s_commonjsdo("commonj.sdo"); + const SDOXMLString SDOXMLWriter::s_wsdluri("http://schemas.xmlsoap.org/wsdl/"); + const SDOXMLString SDOXMLWriter::s_wsdl("wsdl"); + const SDOXMLString SDOXMLWriter::s_soapuri("http://schemas.xmlsoap.org/wsdl/soap/"); + const SDOXMLString SDOXMLWriter::s_soap("soap"); + const SDOXMLString SDOXMLWriter::s_httpuri("http://schemas.xmlsoap.org/wsdl/http/"); + const SDOXMLString SDOXMLWriter::s_http("http"); + + + SDOXMLWriter::SDOXMLWriter( + DataFactoryPtr dataFact) + : dataFactory(dataFact) + { + + } + + SDOXMLWriter::~SDOXMLWriter() + { + freeWriter(); + } + + void SDOXMLWriter::setWriter(xmlTextWriterPtr textWriter) + { + writer = textWriter; + } + + void SDOXMLWriter::freeWriter() + { + if (writer != NULL) + { + xmlFreeTextWriter(writer); + writer = NULL; + } + } + + int SDOXMLWriter::write(XMLDocumentPtr doc, int indent) + { + if (!doc) + { + return 0; + } + + if (writer == NULL) + { + // Throw exception + return -1; + } + + int rc = 0; + namespaceMap.empty(); + + if (indent >= 0) + { + xmlTextWriterSetIndent(writer, 1); + if (indent > 0) + { + char * chars = new char[indent+1]; + for (int i=0;igetXMLDeclaration()) + { + rc = xmlTextWriterStartDocument(writer, doc->getXMLVersion(), doc->getEncoding(), NULL); + if (rc < 0) { + SDO_THROW_EXCEPTION("write", SDOXMLParserException, "xmlTextWriterStartDocument failed"); + } + } + + DataObjectPtr root = doc->getRootDataObject(); + if (root) + { + const Type& rootType = root->getType(); + SDOXMLString rootTypeURI = rootType.getURI(); + SDOXMLString rootTypeName = rootType.getName(); + + // For the root DataObject we need to determine the element name + SDOXMLString elementURI = doc->getRootElementURI(); + SDOXMLString elementName = doc->getRootElementName(); + if (elementName.isNull() || elementName.equals("")) + { + elementName = rootTypeName; + elementName = elementName.toLower(0,1); + } + + // If the element name is defined as a global element then we + // can supress the writing of xsi:type according to the spec + bool writeXSIType = true; + + try + { + // Locate the RootType + const Type& rootTy = dataFactory->getType(elementURI, "RootType"); + // Does a property exist with the given element name? + const Property& rootProp = rootTy.getProperty((const char*)elementName); + // Is this property of the correct Type? + const Type& rootPropType = rootProp.getType(); + if (rootTypeURI == (SDOXMLString)rootPropType.getURI() + && rootTypeName == (SDOXMLString)rootPropType.getName()) + { + writeXSIType = false; + } + } + catch(SDORuntimeException&) + { + } + + // Supress the writing of xsi:type as well for DataObjects of type + // commonj.sdo#OpenDataObject + if (writeXSIType && + rootTypeURI.equals("commonj.sdo") && rootTypeName.equals("OpenDataObject")) + { + writeXSIType = false; + } + + writeDO(root, elementURI, elementName, writeXSIType, true); + } + rc = xmlTextWriterEndDocument(writer); + if (rc < 0) { + SDO_THROW_EXCEPTION("write", SDOXMLParserException, "xmlTextWriterEndDocument failed"); + return rc; + } + + xmlTextWriterFlush(writer); + freeWriter(); + + return rc; + } + + ////////////////////////////////////////////////////////////////////////// + // Write Change Summary attributes + ////////////////////////////////////////////////////////////////////////// + + void SDOXMLWriter::handleChangeSummaryAttributes( + ChangeSummaryPtr cs, + DataObjectPtr dol) + { + int rc; + + SettingList& sl = cs->getOldValues(dol); + if (sl.size() == 0) + { + // no attributes + return; + } + for (int j=0;j< sl.size(); j++) + { + try { + + if (sl.get(j)->getProperty().isMany()) + { + // manys are elements + continue; + } + + if (sl.get(j)->getProperty().getType().isDataType()) + { + // data types are OK + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString(sl.get(j)->getProperty().getName()), + SDOXMLString(sl.get(j)->getCStringValue())); + } + else + { + DataObjectPtr dob = sl.get(j)->getDataObjectValue(); + if (dob) + { + if (cs->isDeleted(dob)) + { + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString(sl.get(j)->getProperty().getName()), + SDOXMLString(cs->getOldXpath(dob))); + } + else + { + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString(sl.get(j)->getProperty().getName()), + SDOXMLString(dob->objectToXPath())); + } + } + else + { + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString(sl.get(j)->getProperty().getName()), + SDOXMLString("")); + } + } + } + catch (SDORuntimeException e) + { + // ignore this attribute + } + } + } + + ////////////////////////////////////////////////////////////////////////// + // Write Change Summary elements + ////////////////////////////////////////////////////////////////////////// + + void SDOXMLWriter::handleChangeSummaryElements( + ChangeSummaryPtr cs, + DataObjectPtr dob) + { + int rc; + + SettingList& sl = cs->getOldValues(dob); + + if (sl.size() == 0) + { + // there are no setting for this element. + return; + } + + for (int j=0;j< sl.size(); j++) + { + try + { + + // single values will have been covered by the attributes. + if (!sl.get(j)->getProperty().isMany()) continue; + + if (sl.get(j)->getProperty().getType().isDataType()) + { + + rc = xmlTextWriterWriteElement( + writer, + SDOXMLString(sl.get(j)->getProperty().getName()), + SDOXMLString(sl.get(j)->getCStringValue())); + + } // if datatype + else + { + DataObjectPtr dob2 = sl.get(j)->getDataObjectValue(); + if (!dob2) + { + continue; + } + if (cs->isDeleted(dob2)) + { + handleChangeSummaryDeletedObject(sl.get(j)->getProperty().getName(), cs,dob2); + } + else + { + rc = xmlTextWriterStartElement( + writer, + SDOXMLString(sl.get(j)->getProperty().getName())); + rc = xmlTextWriterWriteAttribute( + writer, + SDOXMLString("sdo:ref"), + SDOXMLString(dob2->objectToXPath())); + rc = xmlTextWriterEndElement( + writer); + } + } + } + catch (SDORuntimeException e) + { + // ignore this element + } + } // for + } + + + ////////////////////////////////////////////////////////////////////////// + // Write a deleted object and all its props + ////////////////////////////////////////////////////////////////////////// + + void SDOXMLWriter::handleChangeSummaryDeletedObject( + const char* name, + ChangeSummaryPtr cs, + DataObjectPtr dob) + { + + int rc, k; // TODO error handling + + SettingList& sl = cs->getOldValues(dob); + + rc = xmlTextWriterStartElement( + writer, + SDOXMLString(name)); + + if (sl.size() == 0) + { + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("sdo:ref"), + SDOXMLString(cs->getOldXpath(dob))); + rc = xmlTextWriterEndElement(writer); + return; + } + + + try + { + // print single valued datatypes as attributes + + for (int j=0;j< sl.size(); j++) + { + //if (!sl.get(j)->isSet()) + //{ + // // unset properties dont need recording - ah but they do! + // + // continue; + //} + if ( sl.get(j)->getProperty().isMany()) + { + // manys are elements + continue; + } + if (!sl.get(j)->getProperty().getType().isDataType()) + { + // data objects are element in a deleted data object. + continue; + } + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString(sl.get(j)->getProperty().getName()), + SDOXMLString(sl.get(j)->getCStringValue())); + + } // for attributes + + + // now we are onto the many-values, + // and dataobject single values. + // + // handle deletions within deletions in reverse order, so they match the + // deletion records above. + + for (k=sl.size()-1;k>=0; k--) + { + + if ( !sl.get(k)->getProperty().getType().isDataType() && + sl.get(k)->getProperty().isMany()) + { + // its a dataobject type + DataObjectPtr dob2 = sl.get(k)->getDataObjectValue(); + if (!dob2) continue; + if (!cs->isDeleted(dob2)) continue; + handleChangeSummaryDeletedObject(sl.get(k)-> + getProperty().getName(),cs,dob2); + } + } // for attributes + + for (k=0;k< sl.size(); k++) + { + + if ( !sl.get(k)->getProperty().getType().isDataType()) + { + if (sl.get(k)->getProperty().isMany()) continue; + // its a single valued dataobject type + + DataObjectPtr dob2 = sl.get(k)->getDataObjectValue(); + if (!dob2) continue; + if (!cs->isDeleted(dob2)) continue; + handleChangeSummaryDeletedObject(sl.get(k)-> + getProperty().getName(),cs,dob2); + + } + else + { + if ( !sl.get(k)->getProperty().isMany()) continue; + + // could only be many valued data type + + rc = xmlTextWriterWriteElement(writer, + SDOXMLString(sl.get(k)->getProperty().getName()), + SDOXMLString(sl.get(k)->getCStringValue())); + } + } // for attributes + } + catch (SDORuntimeException e) + { + // ignore - and write the end-element + } + + rc = xmlTextWriterEndElement(writer); + } + + + ////////////////////////////////////////////////////////////////////////// + // Write the list of elements of a change summary + ////////////////////////////////////////////////////////////////////////// + + void SDOXMLWriter::handleSummaryChange( + const SDOXMLString& elementName, + ChangeSummaryPtr cs, + DataObjectPtr dob) + { + int rc; + DataObject* temp = dob; + const char* name; + try + { + name = temp->getContainmentProperty().getName(); + } + catch (SDORuntimeException e) + { + // This could be a root, and have no name. + name = 0; + } + + if (name == 0) + { + rc = xmlTextWriterStartElement( + writer, + elementName); + } + else + { + rc = xmlTextWriterStartElement( + writer, + SDOXMLString(name)); + } + + if (rc != 0) + { + // failed to write an element + return; + } + + try + { + name = temp->objectToXPath(); + } + catch (SDORuntimeException e) + { + name = 0; + } + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("sdo:ref"), + SDOXMLString(name)); + + handleChangeSummaryAttributes(cs, temp); + + handleChangeSummaryElements(cs, temp); + + rc = xmlTextWriterEndElement(writer); + + } + + ////////////////////////////////////////////////////////////////////////// + // Write a Change Summary + ////////////////////////////////////////////////////////////////////////// + + void SDOXMLWriter::handleChangeSummary( + const SDOXMLString& elementName, + ChangeSummaryPtr cs) + { + unsigned int i; + int rc; + + ChangedDataObjectList& changedDOs = cs->getChangedDataObjects(); + rc = xmlTextWriterStartElementNS(writer, + SDOXMLString("sdo"), SDOXMLString("changeSummary"), SDOXMLString(Type::SDOTypeNamespaceURI.c_str())); + if (rc != 0) return; + if (cs->isLogging()) + { + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("logging"), + SDOXMLString("true")); + } + + if (changedDOs.size() > 0) + { + + // write the creates/deletes in the order they + // happened, as elements. + + for (i=0;i< changedDOs.size();i++) + { + if (cs->isCreated(changedDOs[i]) + && changedDOs.getType(i) == ChangedDataObjectList::Create) + { + // TODO - should work out if theres a IDREF here + // TODO - can we have more than one create like this? + try + { + rc = xmlTextWriterWriteElement(writer, + SDOXMLString("create"), + SDOXMLString(changedDOs[i]->objectToXPath())); + } + catch (SDORuntimeException e) + { + // The object was not in our tree - we ignore it. + } + } + if (cs->isDeleted(changedDOs[i]) + && changedDOs.getType(i) == ChangedDataObjectList::Delete) + { + // TODO - should work out if theres a IDREF here + try + { + rc = xmlTextWriterWriteElement(writer, + SDOXMLString("delete"), + SDOXMLString(cs->getOldXpath(changedDOs[i]))); + } + catch (SDORuntimeException e) + { + // The object was not in the deleted list - we ignore it. + } + } + } + + + for (i=0;i< changedDOs.size();i++) + { + if (cs->isModified(changedDOs[i])) + { + handleSummaryChange(elementName, cs, changedDOs[i]); + } + } + + } + rc = xmlTextWriterEndElement(writer); + } + + void SDOXMLWriter::addNamespace(const SDOXMLString& uri, bool tns) + { + std::map::iterator it = namespaceMap.find(uri); + if (it == namespaceMap.end()) + { + SDOXMLString prefix = "tns"; + // Handle some common namespaces + if (uri.equals(s_wsdluri)) + { + prefix = s_wsdl; + } + else if (uri.equals(s_soapuri)) + { + prefix = s_soap; + } + else if (uri.equals(s_httpuri)) + { + prefix = s_http; + } + else if (!tns) + { + char buf[20]; + sprintf(buf,"%d", namespaceMap.size()); + prefix += buf; + } + namespaceMap[uri] = prefix; + } + + } + ////////////////////////////////////////////////////////////////////////// + // Add to namespaces + ////////////////////////////////////////////////////////////////////////// + + void SDOXMLWriter::addToNamespaces(DataObjectImpl* dob) + { + std::map::iterator it; + SDOXMLString uri = dob->getType().getURI(); + SDOXMLString typeName = dob->getType().getName(); + if (!(uri.equals("commonj.sdo") && typeName.equals("OpenDataObject"))) + { + addNamespace(uri); + } + + PropertyList pl = dob->getInstanceProperties(); + for (unsigned int i = 0; i < pl.size(); i++) + { + if (!dob->isSet(pl[i]))continue; + + if (pl[i].isMany()) + { + if (!pl[i].getType().isDataType()) + { + DataObjectList& dl = dob->getList(pl[i]); + for (unsigned int k=0;k< dl.size() ;k++) + { + DataObjectImpl* d = (DataObjectImpl*)(DataObject*)dl[k]; + if (d != 0)addToNamespaces(d); + } + } + } + else + { + if (!pl[i].getType().isDataType()) + { + DataObjectImpl* d = (DataObjectImpl*)(DataObject*)dob->getDataObject(pl[i]); + if (d != 0)addToNamespaces(d); + } + else + { + XSDPropertyInfo* pi = getPropertyInfo(pl[i]); + if (pi) + { + PropertyDefinitionImpl propdef; + propdef = pi->getPropertyDefinition(); + if (propdef.isElement)continue; + if (!propdef.isQName)continue; + + SDOXMLString propertyValue = (dob->getCString(pl[i])); + XMLQName qname(propertyValue); + + SDOXMLString qnameuri = qname.getURI(); + if (qnameuri.equals("") || qnameuri.isNull() ) + { + continue; + } + + it = namespaceMap.find(qnameuri); + if (it == namespaceMap.end()) + { + addNamespace(qnameuri); + } + } + } + } + } + } + + + + /** + * WriteDO - write a DataObject tree + * + */ + + int SDOXMLWriter::writeDO( + DataObjectPtr dataObject, + const SDOXMLString& elementURI, + const SDOXMLString& elementName, + bool writeXSIType, + bool isRoot) + { + + int rc; + + if (dataObject == 0) + return 0; + + const Type& dataObjectType = dataObject->getType(); + SDOXMLString typeURI = dataObjectType.getURI(); + SDOXMLString typeName = dataObjectType.getName(); + bool isOpen = dataObjectType.isOpenType(); + DataObjectImpl* dataObjectImpl = (DataObjectImpl*)(DataObject*)dataObject; + const TypeImpl& typeImpl = dataObjectImpl->getTypeImpl(); + + + // --------------------------------------- + // First we need to write the startElement + if (isRoot) + { + // For the root element we will now gather all the namespace information + addNamespace(elementURI, true); + + // We always add the xsi namespace. TODO we should omit if we can + namespaceMap[s_xsiNS] = s_xsi; + + DataObjectImpl* d = (DataObjectImpl*)(DataObject*)dataObject; + addToNamespaces(d); + + if (elementURI.equals(s_commonjsdo)) + { + tnsURI = ""; + } + else + { + tnsURI = elementURI; + } + } + // Write the startElement for non-root object + SDOXMLString theName=elementName; + + // If an elementURI is specified then the elementForm is "qualified" + if (!elementURI.isNull() + && !elementURI.equals("") + && !elementURI.equals(s_commonjsdo) + //&& !elementURI.equals(tnsURI) + ) + { + // Locate the namespace prefix + std::map::iterator it = namespaceMap.find(elementURI); + if (it != namespaceMap.end()) + { + theName = (*it).second; + theName += ":"; + theName += elementName; + } + } + + rc = xmlTextWriterStartElement(writer, theName); + if (rc < 0) { + SDO_THROW_EXCEPTION("writeDO", SDOXMLParserException, "xmlTextWriterStartElement failed"); + } + + // End - startElement is written + // ----------------------------- + + + // ------------------------------------------- + // For a primitive type - just write the value + if (dataObjectType.isDataType()) + { + if (dataObject->isNull("")) + { + rc = xmlTextWriterWriteAttributeNS(writer, s_xsi, s_nil, NULL, s_true); + } + else + { + /* Use our wrapper function just in case the element has CDATA in it */ + writeXMLElement(writer, + elementName, + dataObject->getCString("")); + } + + // Write the end element and return + rc = xmlTextWriterEndElement(writer); + return 0; + } + // End - primitive value is written + // -------------------------------- + + + //------------------------------------------- + // Write the xsi:type= attribute if necessary + if (writeXSIType) + { + // Supress the writing of xsi:type as well for DataObjects of type + // commonj.sdo#OpenDataObject + if (typeURI.equals("commonj.sdo") && typeName.equals("OpenDataObject")) + { + } + else + { + SDOXMLString theName=typeName; + + if (!typeURI.isNull() && !typeURI.equals("")) + { + std::map::iterator it = namespaceMap.find(typeURI); + if (it != namespaceMap.end()) + { + theName = (*it).second; + theName += ":"; + theName += typeName; + } + } + + rc = xmlTextWriterWriteAttributeNS(writer, + s_xsi, s_type, + NULL, + theName); + } + } + // End - xsi:type= attribute is written + // ------------------------------------ + + + // ------------------------------- + // Write the namespace information + if (isRoot) + { + // Now write all the namespace information + for (std::map::iterator it = namespaceMap.begin(); + it != namespaceMap.end(); ++it) + { + if ((*it).first.equals("")) continue; + rc = xmlTextWriterWriteAttributeNS(writer, s_xmlns, (*it).second, NULL, (*it).first); + } + } + // End - namespace information is written + // -------------------------------------- + + + // --------------------- + // write nil if required + if (dataObject->isNull("")) + { + rc = xmlTextWriterWriteAttributeNS(writer, s_xsi, s_nil, NULL, s_true); + } + // xsi:nil is written + // ------------------ + + + // -------------------------------------------------- + // Iterate over all the properties to find attributes + unsigned int i; + unsigned int j = 1; + PropertyList pl = dataObject->getInstanceProperties(); + for (i = 0; i < pl.size(); i++) + { + if (dataObject->isSet(pl[i])) + { + SDOXMLString propertyName(pl[i].getName()); + XSDPropertyInfo* pi = getPropertyInfo(pl[i]); + PropertyDefinitionImpl propdef; + if (pi) + { + propdef = pi->getPropertyDefinition(); + propertyName = propdef.localname; + } + + // Elements are written as + if (propdef.isElement) + continue; + + // Many-valued properties are written as + if (pl[i].isMany()) + continue; + + // Non contained properties become attributes + const Type& propertyType = pl[i].getType(); + + if (propertyType.isDataType()) + { + SDOXMLString propertyValue = (dataObject->getCString(pl[i])); + if (pi && pi->getPropertyDefinition().isQName) + { + XMLQName qname(propertyValue); + + // TODO: this logic seems bad. We should already have the namespace in the map + std::map::iterator it = namespaceMap.find(qname.getURI()); + if (it != namespaceMap.end()) + { + propertyValue = (*it).second + ":" + qname.getLocalName(); + } + else + { + char buffer[20]; + SDOXMLString pref = "tnss"; + sprintf(buffer, "%d", j++); + pref += buffer; + rc = xmlTextWriterWriteAttributeNS(writer, s_xmlns, pref, NULL, qname.getURI()); + propertyValue = pref + ":" + qname.getLocalName(); + } + + } + rc = xmlTextWriterWriteAttribute(writer, + propertyName, propertyValue); + } + else + { + // Handle non-containment reference to DataObject + if (pl[i].isReference()) + { + writeReference(propertyName, dataObject, pl[i], false); + } + } + } + } + // End - attributes are written + // ---------------------------- + + + // -------------------- + // Handle ChangeSummary + if (dataObject->getType().isChangeSummaryType()) + { + ChangeSummaryPtr changeSummary = dataObject->getChangeSummary(); + if (changeSummary) + { + handleChangeSummary(elementName, changeSummary); + } + } + // End - ChangeSummary is written + // ------------------------------ + + + // -------------------- + // Write Sequenced Data + if (dataObjectType.isSequencedType()) + { + SequencePtr sequence = dataObject->getSequence(); + if (sequence) + { + for (i=0; isize(); i++) + { + if (sequence->isText(i)) + { + // This is a raw write rather than xmlTextWriterWriteString + // just in case the text has a CDATA section in it + rc = xmlTextWriterWriteRaw( + writer, + SDOXMLString(sequence->getCStringValue(i))); + continue; + } // end TextType + + const Property& seqProp = sequence->getProperty(i); + const Type& seqPropType = seqProp.getType(); + SDOXMLString seqPropName; + SDOXMLString seqPropURI; + + // This call sets the property name and type URI and returns if xsi:type= is required + bool xsiTypeNeeded = determineNamespace(dataObject, seqProp, seqPropURI, seqPropName); + + // Do not write attributes as members of the sequence + XSDPropertyInfo* pi = getPropertyInfo(seqProp); + PropertyDefinitionImpl propdef; + if (pi) + { + propdef = pi->getPropertyDefinition(); + if (!(propdef.isElement)) + { + continue; + } + } + + + if (seqPropType.isDataObjectType()) + { + DataObjectPtr doValue = sequence->getDataObjectValue(i); + + if (doValue) + { + // Handle non-containment reference to DataObject + if (seqProp.isReference()) + { + writeReference(seqPropName, dataObject, seqProp, true, doValue); + } + else + { + // If property is an undeclared propery of an open type + // we write xsi:type + bool xsiTypeNeeded = false; + if (isOpen) + { + if (typeImpl.getPropertyImpl(seqPropName) == 0) + { + xsiTypeNeeded = true; + } + } + + writeDO(doValue, seqPropURI, seqPropName, xsiTypeNeeded); + } + } + } // end DataObject + + else + { + // Sequence member is a primitive + // Only write a primitive as an element if defined by the schema or if it's + // many-valued. + if (!pi && !seqProp.isMany()) continue; + + // Write the startElement for non-root object + SDOXMLString theName=seqPropName; + + if (!seqPropURI.isNull() + && !seqPropURI.equals("") + && !seqPropURI.equals(s_commonjsdo)) + { + // Locate the namespace prefix + std::map::iterator it = namespaceMap.find(seqPropURI); + if (it != namespaceMap.end()) + { + theName = (*it).second; + theName += ":"; + theName += seqPropName; + } + } + xmlTextWriterStartElement(writer, theName); + + /* Use our wrapper function just in case the element has CDATA in it */ + writeXMLElement(writer, + seqPropName, + sequence->getCStringValue(i)); + xmlTextWriterEndElement(writer); + + } // end DataType + } // end - iterate over sequence + + } + } + // End = sequenced data is written + // ------------------------------- + + + // ------------------------ + // Non-sequenced DataObject + else + { + // Write elements for this DataObject + + PropertyList definedProps = dataObjectType.getProperties(); + unsigned int nDefinedProps = typeImpl.getPropertiesSize(); + unsigned int nOpenProps = pl.size() - nDefinedProps; + unsigned int openPropIndex = nDefinedProps; + + const TypeImpl* doTypeImpl = &typeImpl; + if (nOpenProps != 0) + { + while(doTypeImpl->isOpenTypeImplicitly()) + { + doTypeImpl = doTypeImpl->getBaseTypeImpl(); + } + openPropIndex = doTypeImpl->getPropertiesSize(); + } + + writeDOElements(dataObject, pl, 0, openPropIndex); + writeDOElements(dataObject, pl, nDefinedProps, nOpenProps ); + writeDOElements(dataObject, pl, openPropIndex, nDefinedProps - openPropIndex); + + } + // End - non-sequenced DO + // ---------------------- + + rc = xmlTextWriterEndElement(writer); + return rc; + + } // End - writeDO + + void SDOXMLWriter::writeDOElements(DataObjectPtr dataObject, + const PropertyList& pl, + unsigned int start, + unsigned int number) + { + for (unsigned int pi = 0; pi < number; pi++) + { + unsigned int i = start + pi; + if (dataObject->isSet(pl[i])) + { + SDOXMLString propertyName; + SDOXMLString propertyTypeURI; + + // This call sets the property name and type URI and returns if xsi:type= is required + bool xsiTypeNeeded = determineNamespace(dataObject, pl[i], propertyTypeURI, propertyName); + + const Type& propertyType = pl[i].getType(); + XSDPropertyInfo* pi = getPropertyInfo(pl[i]); + PropertyDefinitionImpl propdef; + if (pi) + { + propdef = pi->getPropertyDefinition(); + if (!(propdef.isElement)) + { + continue; + } + } + + // ------------------------------------------------- + // For a many-valued property get the list of values + if (pl[i].isMany()) + { + DataObjectList& dol = dataObject->getList(pl[i]); + for (unsigned int j = 0; j getDataObject(pl[i]); + writeDO(propDO, propertyTypeURI, propertyName, xsiTypeNeeded); + } + } + // End - write DataObject + // ---------------------- + + + // --------------- + // For a primitive + else + { + // Only write a primitive as an element if defined by the XSD + if (pi) + { + const Type& tp = dataObject->getType(); + XSDTypeInfo* typeInfo = (XSDTypeInfo*) + ((DASType*)&tp)->getDASValue("XMLDAS::TypeInfo"); + if (typeInfo && typeInfo->getTypeDefinition().isExtendedPrimitive) + { + xmlTextWriterWriteRaw( + writer, + SDOXMLString(dataObject->getCString(pl[i]))); + } + else + { + // Write the startElement for non-root object + SDOXMLString theName=propertyName; + + if (!propertyTypeURI.isNull() + && !propertyTypeURI.equals("") + && !propertyTypeURI.equals(s_commonjsdo) + /* && !propertyTypeURI.equals(tnsURI) */) + { + // Locate the namespace prefix + std::map::iterator it = namespaceMap.find(propertyTypeURI); + if (it != namespaceMap.end()) + { + theName = (*it).second; + theName += ":"; + theName += propertyName; + } + } + + xmlTextWriterStartElement(writer, theName); + + //xmlTextWriterStartElementNS(writer, NULL, propertyName, NULL); + if (dataObject->isNull(pl[i])) + { + xmlTextWriterWriteAttributeNS(writer, s_xsi, s_nil, NULL, s_true); + } + else + { + writeXMLElement(writer, + propertyName, + dataObject->getCString(pl[i])); + } + xmlTextWriterEndElement(writer); + } + } + } + // End - handle primitive + // ---------------------- + + } // end isSet + } + // End - elements are written + // -------------------------- + + } + + XSDPropertyInfo* SDOXMLWriter::getPropertyInfo(const Property& property) + { + return (XSDPropertyInfo*)((DASProperty*)&property)->getDASValue("XMLDAS::PropertyInfo"); + } + + + void SDOXMLWriter::writeReference( + const SDOXMLString& propertyName, + DataObjectPtr dataObject, + const Property& property, + bool isElement, + DataObjectPtr refferedToObject) + { + DataObjectPtr reffedObject = refferedToObject; + if (reffedObject == 0) + { + reffedObject = dataObject->getDataObject(property); + } + + // Get ID from referred to DataObject or use XPath + SDOXMLString refValue; + XSDTypeInfo* ti = (XSDTypeInfo*)((DASType*)&reffedObject->getType())-> + getDASValue("XMLDAS::TypeInfo"); + if (ti) + { + TypeDefinitionImpl typeDef = ti->getTypeDefinition(); + if (!typeDef.IDPropertyName.isNull()) + { + refValue = reffedObject->getCString((const char*)typeDef.IDPropertyName); + } + } + + if (refValue.isNull()) + { + // need to get XPATH + refValue = ((DataObjectImpl*)(DataObject*)reffedObject)->objectToXPath(); + } + + if (!refValue.isNull()) + { + if (isElement) + { + // Set the IDREF value + xmlTextWriterWriteElement(writer, + propertyName, refValue); + } + else + { + // Set the IDREF value + xmlTextWriterWriteAttribute(writer, + propertyName, refValue); + } + } + } + + + + /** + * A wrapper for the libxml2 function xmlTextWriterWriteElement + * it detects CDATA sections before writing out element contents + */ + int SDOXMLWriter::writeXMLElement(xmlTextWriterPtr writer, + const SDOXMLString& name, + const SDOXMLString& content) + { + int rc = 0; + rc = xmlTextWriterWriteRaw(writer, SDOXMLString(SDOUtils::escapeHtmlEntitiesExcludingCData(content).c_str())); + + /* A more complex version that doesn't work! + * I've left it here just in case we need to go back and separate out + * CDATA from text. This might provide a starting point + SDOString contentString(content); + + // write the start of the element. we could write a mixture of + // text and CDATA before writing the end element + rc = xmlTextWriterStartElement(writer, name); + + // Iterate along the string writing out text and CDATA sections + // separately using the appropriate libxml2 calls + std::string::size_type start = 0; + std::string::size_type end = contentString.find(PropertySetting::XMLCDataStartMarker, 0); + std::string::size_type length = 0; + + // loop while we still find a CDATA section that needs writing + while ( end != std::string::npos ) + { + // write out text from current pos to start of CDATA section + length = end - start; + rc = xmlTextWriterWriteString(writer, + SDOXMLString(contentString.substr(start, length).c_str())); + + // find the end of the CDATA section + start = end; + end = contentString.find(PropertySetting::XMLCDataEndMarker, start); + + if ( end != std::string::npos ) + { + // we only nudge the start marker on to the end of the CDATA marker here + // so that if we fail to find the end CDATA marker the whole string gets + // printed out by virtue of the line that follows the while loop + start = start + strlen(PropertySetting::XMLCDataStartMarker); + + // write our the text from the CDATA section + length = end - start; + rc = xmlTextWriterWriteCDATA(writer, + SDOXMLString(contentString.substr(start, length).c_str())); + + // set current pos to end of CDATA section and + // start looking for the start marker again + start = end + strlen(PropertySetting::XMLCDataEndMarker); + end = contentString.find(PropertySetting::XMLCDataStartMarker, start); + } + } + + // write out text following the last CDATA section + rc = xmlTextWriterWriteString(writer, + SDOXMLString(contentString.substr(start).c_str())); + + // close off the element + rc = xmlTextWriterEndElement(writer); + */ + return rc; + } + + bool SDOXMLWriter::determineNamespace(DataObjectPtr dataObject, const Property& prop, + SDOXMLString& elementURI, SDOXMLString& elementName) + { + bool xsiTypeNeeded = false; + + const Type& propertyType = prop.getType(); + + // If this is a defined property with property information + // we use the uri and name from the definition + XSDPropertyInfo* pi = getPropertyInfo(prop); + PropertyDefinitionImpl propdef; + if (pi) + { + propdef = pi->getPropertyDefinition(); + elementName = propdef.localname; + elementURI = propdef.namespaceURI; + } + else + { + elementName = prop.getName(); + + SDOXMLString propTypeName = propertyType.getName(); + SDOXMLString propTypeURI = propertyType.getURI(); + DataObjectImpl* dataObjectImpl = (DataObjectImpl*)(DataObject*)dataObject; + const TypeImpl& typeImpl = dataObjectImpl->getTypeImpl(); + + + // If property is an undeclared propery of an open type + if (typeImpl.getPropertyImpl(prop.getName()) == 0) + { + // we need to write xsi:type information + xsiTypeNeeded = true; + + // Determine the namespace of the property + // First see if there is a matching property in the namespace + // of the Type of this property. + DataFactoryImpl* df = (DataFactoryImpl*)dataObject->getDataFactory(); + const TypeImpl* ti = df->findTypeImpl(propertyType.getURI(), "RootType"); + if (ti) + { + PropertyImpl* propi = ti->getPropertyImpl(elementName); + if (propi) + { + SDOXMLString propiTypeName = propi->getType().getName(); + SDOXMLString propiTypeURI = propi->getType().getURI(); + if (propiTypeName.equals(propTypeName) + && propiTypeURI.equals(propTypeURI) ) + { + // We have a match + + // it's a global element so we do not need xsi:type + xsiTypeNeeded = false; + + XSDPropertyInfo* ppi = getPropertyInfo(*propi); + PropertyDefinitionImpl propdef; + if (ppi) + { + propdef = ppi->getPropertyDefinition(); + elementName = propdef.localname; + elementURI = propdef.namespaceURI; + } + } + } + } + else + { + // For now we will just set the elementURI to "" + // We need to check further here for the element defined in + // the namespace of the parent object etc. etc. + elementURI = ""; + } + } + else + { + // The property has been defined programatically so we will + // assume elementForm is "unqualified" + elementURI = ""; + } + + } + + if (propertyType.isAbstractType()) + { + xsiTypeNeeded = true; + } + + return xsiTypeNeeded; + + } + + } // End - namespace sdo +} // End - namespace commonj + + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLWriter.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLWriter.h new file mode 100644 index 0000000000..c4d871b63e --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXMLWriter.h @@ -0,0 +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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _SDOXMLWRITER_H_ +#define _SDOXMLWRITER_H_ + +#include "commonj/sdo/disable_warn.h" + +#include +#include "commonj/sdo/XMLDocument.h" +#include "commonj/sdo/SDOXMLString.h" +#include "commonj/sdo/SchemaInfo.h" +#include "commonj/sdo/DataFactory.h" +#include "commonj/sdo/XSDPropertyInfo.h" +#include +#include "commonj/sdo/SAX2Namespaces.h" +#include "commonj/sdo/DataObjectImpl.h" + + +namespace commonj +{ + namespace sdo + { + +/** + * SDOXMLWriter writes a data object tree to XML + */ + class SDOXMLWriter + { + + public: + + SDOXMLWriter(DataFactoryPtr dataFactory = NULL); + + virtual ~SDOXMLWriter(); + + int write(XMLDocumentPtr doc, int indent=-1); + + protected: + void setWriter(xmlTextWriterPtr textWriter); + void freeWriter(); + + private: + xmlTextWriterPtr writer; + + void handleChangeSummaryAttributes( + ChangeSummaryPtr cs, + DataObjectPtr doB); + + void handleChangeSummaryElements( + ChangeSummaryPtr cs, + DataObjectPtr dob); + + void handleChangeSummaryDeletedObject( + const char* name, + ChangeSummaryPtr cs, + DataObjectPtr dob); + + void handleSummaryChange( + const SDOXMLString& elementName, + ChangeSummaryPtr cs, + DataObjectPtr dob); + + void handleChangeSummary( + const SDOXMLString& elementName, + ChangeSummaryPtr cs); + + void addToNamespaces(DataObjectImpl* dob); + + void addNamespace(const SDOXMLString& uri, bool tns=false); + + int writeDO( + DataObjectPtr dataObject, + const SDOXMLString& elementURI, + const SDOXMLString& elementName, + bool writeXSIType = false, + bool isRoot = false); + + void writeDOElements(DataObjectPtr dataObject, + const PropertyList& pl, + unsigned int start, + unsigned int number); + + /** + * A wrapper for the libxml2 function xmlTextWriterWriteElement + * it detects CDATA sections before wrting out element contents + */ + int writeXMLElement(xmlTextWriterPtr writer, + const SDOXMLString& name, + const SDOXMLString& content); + + SchemaInfo* schemaInfo; + DataFactoryPtr dataFactory; + + XSDPropertyInfo* getPropertyInfo(const Property& property); + + std::map namespaceMap; + SDOXMLString tnsURI; + + bool determineNamespace(DataObjectPtr dataObject, const Property& prop, + SDOXMLString& elementURI, SDOXMLString& elementName); + + void writeReference( + const SDOXMLString& propertyName, + DataObjectPtr dataObject, + const Property& property, + bool isElement, + DataObjectPtr refferedToObject = 0); + + static const SDOXMLString s_xsi; + static const SDOXMLString s_type; + static const SDOXMLString s_nil; + static const SDOXMLString s_true; + static const SDOXMLString s_xsiNS; + static const SDOXMLString s_xmlns; + static const SDOXMLString s_commonjsdo; + static const SDOXMLString s_wsdl; + static const SDOXMLString s_wsdluri; + static const SDOXMLString s_soap; + static const SDOXMLString s_soapuri; + static const SDOXMLString s_http; + static const SDOXMLString s_httpuri; + + }; + } // End - namespace sdo +} // End - namespace commonj + + +#endif //_SDOXMLWRITER_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDBufferWriter.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDBufferWriter.cpp new file mode 100644 index 0000000000..dfd464854a --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDBufferWriter.cpp @@ -0,0 +1,55 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SDOXSDBufferWriter.h" +#include "commonj/sdo/SDORuntimeException.h" + +namespace commonj +{ + namespace sdo + { + + + + + SDOXSDBufferWriter::SDOXSDBufferWriter() + { + buf = xmlBufferCreate(); + if (buf == NULL) + { + SDO_THROW_EXCEPTION("SDOXSDBufferWriter", SDOXMLParserException, "xmlBufferCreate failed"); + } + setWriter(xmlNewTextWriterMemory(buf, 0)); + } + + SDOXSDBufferWriter::~SDOXSDBufferWriter() + { + freeWriter(); + xmlBufferFree(buf); + } + + SDOXMLString SDOXSDBufferWriter::getBuffer() + { + freeWriter(); + return xmlBufferContent(buf); + } + } // End - namespace sdo +} // End - namespace commonj diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDBufferWriter.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDBufferWriter.h new file mode 100644 index 0000000000..c9354a8916 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDBufferWriter.h @@ -0,0 +1,54 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _SDOXSDBUFFERWRITER_H_ +#define _SDOXSDBUFFERWRITER_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/SDOXSDWriter.h" + + +namespace commonj +{ + namespace sdo + { + +/** + * SDOXSDBufferWriter extends SDOXSDWriter and writes a buffer. + */ + class SDOXSDBufferWriter : public SDOXSDWriter + { + + public: + + SDOXSDBufferWriter(); + virtual ~SDOXSDBufferWriter(); + + SDOXMLString getBuffer(); + private: + xmlBufferPtr buf; + }; + } // End - namespace sdo +} // End - namespace commonj + + +#endif //_SDOXSDBUFFERWRITER_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDFileWriter.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDFileWriter.cpp new file mode 100644 index 0000000000..2794026aa3 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDFileWriter.cpp @@ -0,0 +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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SDOXSDFileWriter.h" + +namespace commonj +{ + namespace sdo + { + + + + + SDOXSDFileWriter::SDOXSDFileWriter(const char* xsdFile) + { + setWriter(xmlNewTextWriterFilename(xsdFile, 0)); + } + + SDOXSDFileWriter::~SDOXSDFileWriter() + { + + } + + + } // End - namespace sdo +} // End - namespace commonj + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDFileWriter.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDFileWriter.h new file mode 100644 index 0000000000..a91becc15c --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDFileWriter.h @@ -0,0 +1,53 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _SDOXSDFILEWRITER_H_ +#define _SDOXSDFILEWRITER_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/SDOXSDWriter.h" + + +namespace commonj +{ + namespace sdo + { + +/** + * SDOXSDFileWriter extends SDOXSDWriter and writes a file. + */ + class SDOXSDFileWriter : public SDOXSDWriter + { + + public: + + SDOXSDFileWriter(const char* xsdFile); + + virtual ~SDOXSDFileWriter(); + + + }; + } // End - namespace sdo +} // End - namespace commonj + + +#endif //_SDOXSDFILEWRITER_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDStreamWriter.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDStreamWriter.cpp new file mode 100644 index 0000000000..0da33a80c0 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDStreamWriter.cpp @@ -0,0 +1,53 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SDOXSDStreamWriter.h" +#include + +namespace commonj +{ + namespace sdo + { + + + + + SDOXSDStreamWriter::SDOXSDStreamWriter(std::ostream& outXML) + : outXmlStream(outXML) + { + } + + SDOXSDStreamWriter::~SDOXSDStreamWriter() + { + } + + int SDOXSDStreamWriter::write(const TypeList& types, const SDOXMLString& targetNamespaceURI, + const propertyMap& openprops, int indent) + { + int rc = SDOXSDBufferWriter::write(types, targetNamespaceURI, openprops, indent); + + // Now stream the buffer + outXmlStream << getBuffer(); + return rc; + } + } // End - namespace sdo +} // End - namespace commonj + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDStreamWriter.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDStreamWriter.h new file mode 100644 index 0000000000..18dade91ef --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDStreamWriter.h @@ -0,0 +1,57 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _SDOXSDSTREAMWRITER_H_ +#define _SDOXSDSTREAMWRITER_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/SDOXSDBufferWriter.h" +#include + + +namespace commonj +{ + namespace sdo + { + +/** + * SDOXSDStreamWriter extends SDOXSDWriter and writes a stream. + */ + class SDOXSDStreamWriter : public SDOXSDBufferWriter + { + + public: + + SDOXSDStreamWriter(std::ostream& outXML); + virtual ~SDOXSDStreamWriter(); + + int write(const TypeList& types, const SDOXMLString& targetNamespaceURI, + const propertyMap& openprops, int indent = -1); + private: + std::ostream& outXmlStream; + + }; + } // End - namespace sdo +} // End - namespace commonj + + +#endif //_SDOXSDSTREAMWRITER_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDWriter.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDWriter.cpp new file mode 100644 index 0000000000..243957042c --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDWriter.cpp @@ -0,0 +1,845 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SDOXSDWriter.h" +#include "iostream" +using namespace::std; +#include "commonj/sdo/DASProperty.h" +#include "commonj/sdo/XSDPropertyInfo.h" +#include "commonj/sdo/SDORuntimeException.h" +#include "commonj/sdo/DataFactoryImpl.h" + +namespace commonj +{ + namespace sdo + { + + + + + SDOXSDWriter::SDOXSDWriter( + DataFactoryPtr dataFact) + : dataFactory(dataFact) + { + + } + + SDOXSDWriter::~SDOXSDWriter() + { + freeWriter(); + } + + void SDOXSDWriter::setWriter(xmlTextWriterPtr textWriter) + { + writer = textWriter; + } + + void SDOXSDWriter::freeWriter() + { + if (writer != NULL) + { + xmlFreeTextWriter(writer); + writer = NULL; + } + } + + + void SDOXSDWriter::writeProps( const propertyMap& pl, const SDOXMLString& targetNamespaceURI, + SDOXMLString& xsd) + { + int rc; + + // ------------------------------------------------------- + // Create definitions + // ------------------------------------------------------- + + propertyMap::const_iterator j; + for (j = pl.begin(); j != pl.end(); ++j) + { + const PropertyImpl& prop = (*j).second; + const Type& propType = prop.getType(); + + + SDOXMLString propTypeName = resolveName(propType.getURI(), + propType.getName(), targetNamespaceURI); + + + if (prop.isMany() || !prop.getType().isDataType()) + { + // ----------------------------- + // Write an definition + // ----------------------------- + rc = xmlTextWriterStartElementNS(writer, xsd, SDOXMLString("element"), NULL); + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("name"), + SDOXMLString(prop.getName())); + + if (!propType.isDataType() && !prop.isContainment()) + { + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("sdoxml:propertyType"), + propTypeName); + propTypeName = "xsd:anyURI"; + } + + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("type"), + propTypeName); + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("minOccurs"), + SDOXMLString("0")); + + if (prop.isMany()) + { + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("maxOccurs"), + SDOXMLString("unbounded")); + } + + // End element + rc = xmlTextWriterEndElement(writer); + } + else + { + // ------------------------------- + // Write an definition + // ------------------------------- + rc = xmlTextWriterStartElementNS(writer, xsd, SDOXMLString("attribute"), NULL); + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("name"), + SDOXMLString(prop.getName())); + + if (!propType.isDataType()) + { + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("sdoxml:propertyType"), + propTypeName); + if (prop.isReference()) + { + propTypeName = "xsd:IDREF"; + } + else + { + propTypeName = "xsd:anyURI"; + } + } + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("type"), + propTypeName); + + // End attribute + rc = xmlTextWriterEndElement(writer); + + } // else + } // for + } // method + + + //////////////////////////////////////// + + int SDOXSDWriter::write(const TypeList& types, const SDOXMLString& targetNamespaceURI, + const propertyMap& openprops, int indent) + { + unsigned int i; + if (writer == NULL) + { + // Throw exception + return -1; + } + + int rc = 0; + + if (indent >= 0) + { + xmlTextWriterSetIndent(writer, 1); + if (indent > 0) + { + char * chars = new char[indent+1]; + for (int i=0;i definition including namespace information + // -------------------------------------------------------------- + SDOXMLString tns; + SDOXMLString xsd("xsd"); + SDOXMLString sdoURI(Type::SDOTypeNamespaceURI.c_str()); + + SDOXMLString schemaURI = "http://www.w3.org/2001/XMLSchema"; + rc = xmlTextWriterStartElementNS(writer, xsd, SDOXMLString("schema"), schemaURI); + if (rc < 0) { + SDO_THROW_EXCEPTION("write", SDOXMLParserException, "xmlTextWriterStartElementNS failed"); + } + + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("xmlns:sdo"), + sdoURI); + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("xmlns:sdoxml"), + sdoURI + "/xml"); + + // -------------------------------------------------------------- + // Add all namespaces found in type list + // -------------------------------------------------------------- + int spacecount = 0; + + std::map::iterator it; + + for (i = 0; i::iterator it = namespaceMap.find(uri); + if (it == namespaceMap.end()) + { + char buf[4]; + if (!targetNamespaceURI.isNull() + && !targetNamespaceURI.equals(uri)) + { + sprintf(buf,"%d",++spacecount); + SDOXMLString s = SDOXMLString("tns") + buf; + namespaceMap.insert(make_pair(uri,s)); + } + } + } + + for (it = namespaceMap.begin();it != namespaceMap.end(); ++it) + { + SDOXMLString space = SDOXMLString("xmlns:") + (*it).second; + rc = xmlTextWriterWriteAttribute(writer, + space, (*it).first); + } + + // -------------------------------------------------------------- + // Add targetNamespace if necessary + // -------------------------------------------------------------- + if (!targetNamespaceURI.isNull() && !targetNamespaceURI.equals("")) + { + tns = "tns:"; + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("xmlns:tns"), + targetNamespaceURI); + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("targetNamespace"), + targetNamespaceURI); + } + + + // -------------------------------------------------------------- + // Now iterate through the Types creating elements as appropriate + // -------------------------------------------------------------- + for (i = 0; i 0) + { + unsigned int j = type.getAliasCount(); + SDOXMLString value = ""; + for (unsigned int i=0;igetURI(), baseType->getName(), targetNamespaceURI); + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("base"), + baseName); + + + rc = xmlTextWriterEndElement(writer); + } + rc = xmlTextWriterEndElement(writer); + + } + else + // --------------------------------------------------------------------- + // DataObject Types become ComplexType definitions with a global element + // --------------------------------------------------------------------- + { + rc = xmlTextWriterStartElementNS(writer,xsd, SDOXMLString("element"), NULL); + if (rc < 0) { + SDO_THROW_EXCEPTION("write", SDOXMLParserException, "xmlTextWriterStartElementNS failed"); + } + + SDOXMLString typeName; + it = namespaceMap.find(type.getURI()); + if (it != namespaceMap.end() && + !targetNamespaceURI.equals((*it).first)) + { + typeName = (*it).second + ":" + name; + } + else + { + typeName = name; + } + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("name"), + name.toLower(0,1)); + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("type"), + typeName); + + rc = xmlTextWriterEndElement(writer); + + rc = xmlTextWriterStartElementNS(writer, xsd, SDOXMLString("complexType"), NULL); + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("name"), + typeName); + + // ----------------------------------------------------- + // If there is an alias, write it + // ----------------------------------------------------- + if (type.getAliasCount() > 0) + { + unsigned int j = type.getAliasCount(); + SDOXMLString value = ""; + for (unsigned int i=0;i + // ----------------------------------------------------- + if (baseType != 0) + { + rc = xmlTextWriterStartElementNS(writer, xsd, SDOXMLString("complexContent"), NULL); + rc = xmlTextWriterStartElementNS(writer, xsd, SDOXMLString("extension"), NULL); + + SDOXMLString baseName = resolveName(baseType->getURI(), baseType->getName(), targetNamespaceURI); + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("base"), + baseName); + + // End extension + rc = xmlTextWriterEndElement(writer); + } + + // --------------------------- + // Iterate over the properties + // --------------------------- + const std::list pl = type.getPropertyListReference(); + + if (pl.size() != 0) + { + bool inSequence = false; + + // ------------------------------------------------------- + // Create definitions + // ------------------------------------------------------- + + for (std::list::const_iterator j = pl.begin(); + j != pl.end(); + j++) + { + const Property& prop = *(*j); + const Type& propType = prop.getType(); + + SDOXMLString propTypeName = resolveName(propType.getURI(), + propType.getName(), targetNamespaceURI); + + bool isElement = false; + bool isQName = false; + XSDPropertyInfo* pi = (XSDPropertyInfo*) + ((DASProperty*)&prop)->getDASValue("XMLDAS::PropertyInfo"); + if (pi) + { + PropertyDefinitionImpl propdef = pi->getPropertyDefinition(); + if (propdef.isElement) + isElement=true; + if (propdef.isQName) + isQName=true; + } + + if (prop.isMany() + || prop.isContainment() + || isElement) + { + // ------------------------------------------------- + // Write or before first element + // ------------------------------------------------- + if (!inSequence) + { + if (type.isSequencedType()) + { + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("mixed"), + SDOXMLString("true")); + + rc = xmlTextWriterStartElementNS(writer, xsd, SDOXMLString("choice"), NULL); + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("maxOccurs"), + SDOXMLString("unbounded")); + } + else + { + rc = xmlTextWriterStartElementNS(writer, xsd, SDOXMLString("sequence"), NULL); + } + inSequence = true; + } + // ----------------------------- + // Write an definition + // ----------------------------- + rc = xmlTextWriterStartElementNS(writer, xsd, SDOXMLString("element"), NULL); + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("name"), + SDOXMLString(prop.getName())); + + if (!propType.isDataType() && !prop.isContainment()) + { + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("sdoxml:propertyType"), + propTypeName); + propTypeName = "xsd:anyURI"; + } + + if (isQName) + { + propTypeName = "xsd:QName"; + } + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("type"), + propTypeName); + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("minOccurs"), + SDOXMLString("0")); + + if (prop.isMany()) + { + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("maxOccurs"), + SDOXMLString("unbounded")); + } + + // ----------------------------------------------------- + // If there is an alias... + // ----------------------------------------------------- + if (prop.getAliasCount() > 0) + { + unsigned int j = prop.getAliasCount(); + SDOXMLString value = ""; + for (unsigned int i=0;i / if necessary + // ----------------------------------------------------- + if (inSequence) + { + // End sequence + rc = xmlTextWriterEndElement(writer); + } + + // --------------------------------- + // Add ChangeSummary if there is one + // --------------------------------- + if (type.isChangeSummaryType()) + { + rc = xmlTextWriterStartElementNS(writer, xsd, SDOXMLString("element"), NULL); + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("name"), + SDOXMLString("changeSummary")); + + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("type"), + SDOXMLString("sdo:ChangeSummaryType")); + + rc = xmlTextWriterEndElement(writer); + } + + // ------------------------------------------------------- + // Create definitions + // ------------------------------------------------------- + for (std::list::const_iterator k = pl.begin(); + k != pl.end(); + k++) + { + const Property& prop = *(*k); + const Type& propType = prop.getType(); + + + SDOXMLString propTypeName = resolveName(propType.getURI(), + propType.getName(), targetNamespaceURI); + + bool isElement = false; + XSDPropertyInfo* pi = (XSDPropertyInfo*) + ((DASProperty*)&prop)->getDASValue("XMLDAS::PropertyInfo"); + if (pi) + { + if (pi->getPropertyDefinition().isElement) + isElement=true; + } + + if (!isElement + && !prop.isMany() + && !prop.isContainment()) + { + // ------------------------------- + // Write an definition + // ------------------------------- + rc = xmlTextWriterStartElementNS(writer, xsd, SDOXMLString("attribute"), NULL); + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("name"), + SDOXMLString(prop.getName())); + + if (!propType.isDataType()) + { + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("sdoxml:propertyType"), + propTypeName); + if (prop.isReference()) + { + propTypeName = "xsd:IDREF"; + } + else + { + propTypeName = "xsd:anyURI"; + } + } + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("type"), + propTypeName); + + // End attribute + rc = xmlTextWriterEndElement(writer); + + } + + } + + } + + // ----------------------------------------------------- + // Write open type information + // ----------------------------------------------------- + if (type.isOpenType()) + { + // + + rc = xmlTextWriterStartElementNS(writer, xsd, SDOXMLString("any"), NULL); + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("namespace"), + SDOXMLString("##other")); + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("processContents"), + SDOXMLString("lax")); + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("minOccurs"), + SDOXMLString("0")); + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("maxOccurs"), + SDOXMLString("unbounded")); + + + // End element + rc = xmlTextWriterEndElement(writer); + + // ----------------------------------------------------- + // Write open type information 2 + // ----------------------------------------------------- + // + + rc = xmlTextWriterStartElementNS(writer, xsd, SDOXMLString("anyAttribute"), NULL); + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("namespace"), + SDOXMLString("##any")); + + rc = xmlTextWriterWriteAttribute(writer, + SDOXMLString("processContents"), + SDOXMLString("lax")); + + // End element + rc = xmlTextWriterEndElement(writer); + + } + + // ----------------------------------------------------- + // End if necessary + // ----------------------------------------------------- + if (baseType != 0) + { + rc = xmlTextWriterEndElement(writer); + } + + + rc = xmlTextWriterEndElement(writer); + } + } + + + // ----------------------------------------------- + // Write any open content from the factory + // ----------------------------------------------- + if (openprops.size() != 0) + { + writeProps(openprops, targetNamespaceURI, xsd); + } + // End the definition + rc = xmlTextWriterEndElement(writer); + return rc; + } + + + // ======================================================================================== + // resolveName - resolve a Type uri and name to xsd equivalent + // ======================================================================================== + SDOXMLString SDOXSDWriter::resolveName(const SDOXMLString& uri, const SDOXMLString& name, const SDOXMLString& targetNamespaceURI) + { + SDOXMLString resolvedName = name; + if (uri.equals(Type::SDOTypeNamespaceURI.c_str())) + { + resolvedName = "xsd:"; + if (name.equalsIgnoreCase("Boolean")) + { + resolvedName += "boolean"; + } + else if (name.equalsIgnoreCase("Byte")) + { + resolvedName += "byte"; + } + else if (name.equalsIgnoreCase("Bytes")) + { + resolvedName += "hexBinary"; + } + else if (name.equalsIgnoreCase("Character")) + { + resolvedName += "string"; + } + else if (name.equalsIgnoreCase("DataObject")) + { + resolvedName += "anyType"; + } + else if (name.equalsIgnoreCase("Date")) + { + resolvedName += "dateTime"; + } + else if (name.equalsIgnoreCase("DateTime")) + { + resolvedName += "dateTime"; + } + else if (name.equalsIgnoreCase("Day")) + { + resolvedName += "gDay"; + } + else if (name.equalsIgnoreCase("Decimal")) + { + resolvedName += "decimal"; + } + else if (name.equalsIgnoreCase("Double")) + { + resolvedName += "double"; + } + else if (name.equalsIgnoreCase("Duration")) + { + resolvedName += "duration"; + } + else if (name.equalsIgnoreCase("Float")) + { + resolvedName += "float"; + } + else if (name.equalsIgnoreCase("Int")) + { + resolvedName += "int"; + } + else if (name.equalsIgnoreCase("Integer")) + { + resolvedName += "integer"; + } + else if (name.equalsIgnoreCase("Long")) + { + resolvedName += "long"; + } + else if (name.equalsIgnoreCase("Month")) + { + resolvedName += "gMonth"; + } + else if (name.equalsIgnoreCase("MonthDay")) + { + resolvedName += "gMonthDay"; + } + else if (name.equalsIgnoreCase("Object")) + { + resolvedName += "anySimpleType"; + } + else if (name.equalsIgnoreCase("Short")) + { + resolvedName += "short"; + } + else if (name.equals("String")) + { + resolvedName += "String"; + } + else if (name.equalsIgnoreCase("Strings")) + { + resolvedName += "string"; + } + else if (name.equalsIgnoreCase("Time")) + { + resolvedName += "time"; + } + else if (name.equalsIgnoreCase("Year")) + { + resolvedName += "gYear"; + } + else if (name.equalsIgnoreCase("YearMonth")) + { + resolvedName += "gYearMonth"; + } + else if (name.equalsIgnoreCase("YearMonthDay")) + { + resolvedName += "date"; + } + else if (name.equalsIgnoreCase("URI")) + { + resolvedName += "anyURI"; + } + else + { + resolvedName += "String"; + } + } + else if (!targetNamespaceURI.isNull() && uri.equals(targetNamespaceURI)) + { + resolvedName = "tns:"; + resolvedName += name; + } + else + { + SDOXMLString propTypeName; + std::map::iterator it; + it = namespaceMap.find(uri); + if (it != namespaceMap.end() && + !targetNamespaceURI.equals((*it).first)) + { + resolvedName = (*it).second + ":" + name; + } + } + + return resolvedName; + } + + + + } // End - namespace sdo +} // End - namespace commonj + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDWriter.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDWriter.h new file mode 100644 index 0000000000..7ba5b2421d --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDOXSDWriter.h @@ -0,0 +1,77 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _SDOXSDWRITER_H_ +#define _SDOXSDWRITER_H_ + +#include "commonj/sdo/disable_warn.h" + +#include +#include "commonj/sdo/SDOXMLString.h" +#include "commonj/sdo/DataObject.h" +#include "commonj/sdo/DataFactoryImpl.h" + + +namespace commonj +{ + namespace sdo + { + +/** + * SDOXSDWriter writes XSD from types and properties. + * The writer takes the contents of a data factory and writes an + * XSD which will be usable to serialize data from the graph. + */ + class SDOXSDWriter + { + + public: + + SDOXSDWriter(DataFactoryPtr dataFactory = NULL); + + virtual ~SDOXSDWriter(); + + int write(const TypeList& types, const SDOXMLString& targetNamespaceURI, + const propertyMap& openprops, int indent = -1); + + protected: + void setWriter(xmlTextWriterPtr textWriter); + void freeWriter(); + + private: + xmlTextWriterPtr writer; + + std::map namespaceMap; + + void writeProps( const propertyMap& pl, const SDOXMLString& targetNamespaceURI, + SDOXMLString& xsd); + int writeDO(DataObjectPtr dataObject, const SDOXMLString& elementName); + + DataFactoryPtr dataFactory; + + SDOXMLString resolveName(const SDOXMLString& uri, const SDOXMLString& name, const SDOXMLString& targetNamespaceURI); + + }; + } // End - namespace sdo +} // End - namespace commonj + + +#endif //_SDOXSDWRITER_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SchemaInfo.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SchemaInfo.cpp new file mode 100644 index 0000000000..ce6097f248 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SchemaInfo.cpp @@ -0,0 +1,39 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SchemaInfo.h" +namespace commonj +{ + namespace sdo + { + + SchemaInfo::SchemaInfo() + : targetNamespaceURI(""), + elementFormDefaultQualified(false) + { + } + + SchemaInfo::~SchemaInfo() + { + } + + } // End - namespace sdo +} // End - namespace commonj diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SchemaInfo.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SchemaInfo.h new file mode 100644 index 0000000000..b55e06efdb --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SchemaInfo.h @@ -0,0 +1,64 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _SCHEMAINFO_H_ +#define _SCHEMAINFO_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/SAX2Namespaces.h" +#include "commonj/sdo/DataObject.h" + +namespace commonj +{ + namespace sdo + { + +/** + * + * SchemaInfo holds information supplied by the parser on the schema + * held in an XSD + */ + class SchemaInfo + { + + public: + SDO_SPI SchemaInfo(); + SDO_SPI virtual ~SchemaInfo(); + + SDO_SPI SAX2Namespaces& getSchemaNamespaces() {return schemaNamespaces;} + + SDO_SPI const SDOXMLString& getTargetNamespaceURI() const {return targetNamespaceURI;} + SDO_SPI void setTargetNamespaceURI(const SDOXMLString& URI) {targetNamespaceURI = URI;} + + SDO_SPI bool isElementFormDefaultQualified() {return elementFormDefaultQualified;} + SDO_SPI void setElementFormDefaultQualified(bool qualified) {elementFormDefaultQualified = qualified;} + private: + SAX2Namespaces schemaNamespaces; + SDOXMLString targetNamespaceURI; + bool elementFormDefaultQualified; + + }; + } // End - namespace sdo +} // End - namespace commonj + + +#endif //_SCHEMAINFO_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SdoCheck.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SdoCheck.cpp new file mode 100644 index 0000000000..fcf252ece1 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SdoCheck.cpp @@ -0,0 +1,29 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SdoCheck.h" + +extern "C" { + SDO_API int SDOCheck(void) + { + return 0; + } +} diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SdoCheck.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SdoCheck.h new file mode 100644 index 0000000000..858009dee3 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SdoCheck.h @@ -0,0 +1,35 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/export.h" + + +/** + * SDOCheck is a simple C method which can be called to verify that + * this is an SDO library - this is used in building + */ + +extern "C" { + SDO_API int SDOCheck(void); +} + + + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SdoRuntime.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SdoRuntime.cpp new file mode 100644 index 0000000000..54fcc8c2fc --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SdoRuntime.cpp @@ -0,0 +1,66 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SdoRuntime.h" +#include +#include + +namespace commonj{ +namespace sdo{ + + +const unsigned int SdoRuntime::major = 0; +const unsigned int SdoRuntime::minor = 9; +const unsigned int SdoRuntime::fix =4; +char* SdoRuntime::version = 0; + + + +const char* SdoRuntime::getVersion() +{ + if (SdoRuntime::version == 0) + { + SdoRuntime::version = new char[11]; + sprintf(SdoRuntime::version,"%02d:%02d:%04d", + SdoRuntime::major, SdoRuntime::minor, SdoRuntime::fix); + } + return (const char *)SdoRuntime::version; + +} + +const unsigned int SdoRuntime::getMajor() +{ + return SdoRuntime::major; +} + +const unsigned int SdoRuntime::getMinor() +{ + return SdoRuntime::minor; +} + +const unsigned int SdoRuntime::getFix() +{ + return SdoRuntime::fix; +} + +}; +}; + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SdoRuntime.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SdoRuntime.h new file mode 100644 index 0000000000..3503307939 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SdoRuntime.h @@ -0,0 +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. + */ + +/* $Rev$ $Date$ */ + +#ifndef SDO_RUNTIME_H +#define SDO_RUNTIME_H +#include "commonj/sdo/export.h" + +namespace commonj{ +namespace sdo{ + +/** + * SDORuntime gives information about the version of the library. + */ + +class SdoRuntime +{ + public: + + virtual ~SdoRuntime(); + + /** + * The version as a string major:minor:fix + */ + + static SDO_API const char* getVersion(); + + /** + * The major version as an integer. + */ + + static SDO_API const unsigned int getMajor(); + + /** + * The minor version as an integer. + */ + + static SDO_API const unsigned int getMinor(); + + /** + * The fix level as an integer. + */ + + static SDO_API const unsigned int getFix(); + + + private: + static const unsigned int major; + static const unsigned int minor; + static const unsigned int fix; + static char* version; + +}; +}; +}; + + +#endif + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Sequence.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Sequence.cpp new file mode 100644 index 0000000000..489fb3f505 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Sequence.cpp @@ -0,0 +1,39 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + + +#include "commonj/sdo/Property.h" +#include "commonj/sdo/Type.h" +#include "commonj/sdo/TypeList.h" + +#include "commonj/sdo/Sequence.h" + +#include "commonj/sdo/DataObject.h" +#include "commonj/sdo/SDORuntimeException.h" + + +namespace commonj{ +namespace sdo{ + +// all delegated to sequenceimpl +}; +}; + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Sequence.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Sequence.h new file mode 100644 index 0000000000..9a810c2284 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Sequence.h @@ -0,0 +1,319 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _SEQUENCE_H_ +#define _SEQUENCE_H_ + + +#include "commonj/sdo/export.h" +#include "commonj/sdo/RefCountingObject.h" +#include "commonj/sdo/RefCountingPointer.h" +#include "commonj/sdo/SDODate.h" +#include "commonj/sdo/Type.h" +#include "commonj/sdo/SDOValue.h" + + +namespace commonj{ +namespace sdo{ + +class Property; /* forward declaration */ +class DataObject; + +/** + * A sequence is a heterogeneous list of properties and corresponding values. + * It represents an ordered arbitrary mixture of data values from more + * than one property of a {@link DataObject data object}. + */ + +class Sequence : public RefCountingObject +{ + public: + /** size() returns the number of elements + * + * Returns the number of entries in the sequence. + */ + + SDO_API virtual unsigned int size() = 0; + + /** + * + * A Sequence element is either a free text item, or represents a property + * setting. If the element is a property setting, then the information + * held in the element consists of: + * -# The property which was set. + * -# The element of that property if it was many valued. + * -# The value which was set. + * + * If the sequence element is text, then there is no property, and only the + * methods for text retrieval will work. Use the isText() method to check + * before calling getProperty(). + */ + + SDO_API virtual const Property& getProperty(unsigned int index) = 0; + + /** + * Return the data object associated with this sequence + */ + + SDO_API virtual const DataObjectPtr getDataObject() = 0; + + /** + * + * The element of that property if it was many valued. Zero if the + * property was single valued. + */ + + SDO_API virtual unsigned int getListIndex(unsigned int index) = 0; + + /** + * + * The element contains the actual value set within the property. The + * method required to get that value will vary depending on the type + * of the property. This is shorthand for getProperty.getTypeEnum(). + */ + + SDO_API virtual Type::Types getTypeEnum(unsigned int index) = 0; + + /** + * + * This method searched the sequence for a setting which corresponds + * to the specified index of the specified property. Searches for single + * valued property settings may omit the pindex parameter. + */ + + + SDO_API virtual unsigned int getIndex(const Property& p, unsigned int pindex=0) = 0; + SDO_API virtual unsigned int getIndex(const char* propName, unsigned int pindex=0) = 0; + + /** + * + * These methods retrieve the setting according to the type of the + * property concerned. If a retrieval method is used which does not correspond to + * the correct type, a conversion will be performed, or an illegal conversion + * exception will be thrown. + */ + + SDO_API virtual const char* getCStringValue(unsigned int index) = 0; + SDO_API virtual bool getBooleanValue(unsigned int index) = 0; + SDO_API virtual char getByteValue(unsigned int index) = 0; + SDO_API virtual wchar_t getCharacterValue(unsigned int index) = 0; + SDO_API virtual unsigned int getStringValue(unsigned int index, wchar_t* val, unsigned int max) = 0; + SDO_API virtual unsigned int getBytesValue(unsigned int index, char* val, unsigned int max) = 0; + SDO_API virtual short getShortValue(unsigned int index) = 0; + SDO_API virtual long getIntegerValue(unsigned int index) = 0; + SDO_API virtual int64_t getLongValue(unsigned int index) = 0; + SDO_API virtual float getFloatValue(unsigned int index) = 0; + SDO_API virtual long double getDoubleValue(unsigned int index) = 0; + SDO_API virtual const SDODate getDateValue(unsigned int index) = 0; + SDO_API virtual DataObjectPtr getDataObjectValue(unsigned int index) = 0; + SDO_API virtual const SDOValue& getSDOValue(unsigned int index) = 0; + + /** + * + * getlength applies to string and byte buffer types, and allows the + * client to allocate the correct size of buffer before retrieving the + * value. + */ + + SDO_API virtual unsigned int getLength(unsigned int index) = 0; + + + /** + * + * The setter methods use an element of the sequence to perform a + * property setting. The value in the sequence is updated, and so is the + * rel value of the property in the data object. + */ + + SDO_API virtual void setCStringValue( unsigned int index, const char* s ) = 0; + SDO_API virtual void setBooleanValue( unsigned int index, bool b ) = 0; + SDO_API virtual void setByteValue( unsigned int index, char c ) = 0; + SDO_API virtual void setCharacterValue( unsigned int index, wchar_t c ) = 0; + SDO_API virtual void setStringValue( unsigned int index, const wchar_t* s , unsigned int len) = 0; + SDO_API virtual void setBytesValue( unsigned int index, const char* s , unsigned int len) = 0; + SDO_API virtual void setShortValue( unsigned int index, short s ) = 0; + SDO_API virtual void setIntegerValue( unsigned int index, long i ) = 0; + SDO_API virtual void setLongValue( unsigned int index, int64_t l ) = 0; + SDO_API virtual void setFloatValue( unsigned int index, float f ) = 0; + SDO_API virtual void setDoubleValue(unsigned int index, long double d ) = 0; + SDO_API virtual void setDateValue(unsigned int index, const SDODate t ) = 0; + SDO_API virtual void setDataObjectValue(unsigned int index, DataObjectPtr d ) = 0; + + + /** + * + * Sequences may be added to by usign the addXXX methods. These provoke + * a setting of the real value of the property concerned, and also append + * an element to the sequence to reflect that setting. + * Additions may be performed based on property name, property index or + * the Property itself. + */ + + SDO_API virtual bool addCString( const char* propertyName,const char* s ) = 0; + SDO_API virtual bool addBoolean( const char* propertyName,bool b ) = 0; + SDO_API virtual bool addByte( const char* propertyName,char c ) = 0; + SDO_API virtual bool addCharacter( const char* propertyName,wchar_t c ) = 0; + SDO_API virtual bool addString( const char* propertyName,const wchar_t* s , unsigned int len) = 0; + SDO_API virtual bool addBytes ( const char* propertyName,const char* s , unsigned int len) = 0; + SDO_API virtual bool addShort( const char* propertyName,short s ) = 0; + SDO_API virtual bool addInteger( const char* propertyName,long i ) = 0; + SDO_API virtual bool addLong( const char* propertyName,int64_t l ) = 0; + SDO_API virtual bool addFloat( const char* propertyName,float f ) = 0; + SDO_API virtual bool addDouble(const char* propertyName,long double d ) = 0; + SDO_API virtual bool addDate(const char* propertyName,const SDODate t ) = 0; + SDO_API virtual bool addDataObject(const char* propertyName,DataObjectPtr d ) = 0; + SDO_API virtual bool addSDOValue(const char* propertyName, const SDOValue& sval) = 0; + + + SDO_API virtual bool addCString( unsigned int propertyIndex,const char* s ) = 0; + SDO_API virtual bool addBoolean( unsigned int propertyIndex,bool b ) = 0; + SDO_API virtual bool addByte( unsigned int propertyIndex,char c ) = 0; + SDO_API virtual bool addCharacter( unsigned int propertyIndex,wchar_t c ) = 0; + SDO_API virtual bool addString( unsigned int propertyIndex,const wchar_t* s , unsigned int len) = 0; + SDO_API virtual bool addBytes( unsigned int propertyIndex,const char* s , unsigned int len) = 0; + SDO_API virtual bool addShort( unsigned int propertyIndex,short s ) = 0; + SDO_API virtual bool addInteger( unsigned int propertyIndex,long i ) = 0; + SDO_API virtual bool addLong( unsigned int propertyIndex,int64_t l ) = 0; + SDO_API virtual bool addFloat( unsigned int propertyIndex,float f ) = 0; + SDO_API virtual bool addDouble(unsigned int propertyIndex,long double d ) = 0; + SDO_API virtual bool addDate(unsigned int propertyIndex,const SDODate t ) = 0; + SDO_API virtual bool addDataObject(unsigned int propertyIndex,DataObjectPtr d ) = 0; + SDO_API virtual bool addSDOValue(unsigned int propertyIndex, const SDOValue& sval) = 0; + + + + SDO_API virtual bool addCString( const Property& property,const char* s ) = 0; + SDO_API virtual bool addBoolean( const Property& property,bool b ) = 0; + SDO_API virtual bool addByte( const Property& property,char c ) = 0; + SDO_API virtual bool addCharacter( const Property& property,wchar_t c ) = 0; + SDO_API virtual bool addString ( const Property& property,const wchar_t* s , unsigned int len) = 0; + SDO_API virtual bool addBytes( const Property& property,const char* s , unsigned int len) = 0; + SDO_API virtual bool addShort( const Property& property,short s ) = 0; + SDO_API virtual bool addInteger( const Property& property,long i ) = 0; + SDO_API virtual bool addLong( const Property& property,int64_t l ) = 0; + SDO_API virtual bool addFloat( const Property& property,float f ) = 0; + SDO_API virtual bool addDouble(const Property& property,long double d ) = 0; + SDO_API virtual bool addDate(const Property& property,const SDODate t ) = 0; + SDO_API virtual bool addDataObject(const Property& property,DataObjectPtr d ) = 0; + SDO_API virtual bool addSDOValue(const Property& property, const SDOValue& sval) = 0; + + + /** + * + * Sequences may be added to by usign the addXXX methods. These provoke + * a setting of the real value of the property concerned, and also append + * an element to the sequence to reflect that setting. + * Additions may be performed based on property name, property index or + * the Property itself. + * The add method also has an override to allow insertion of a sequence element + * before any index. + */ + + SDO_API virtual bool addCString( unsigned int index,const char* propertyName,const char* s ) = 0; + SDO_API virtual bool addBoolean( unsigned int index,const char* propertyName,bool b ) = 0; + SDO_API virtual bool addByte( unsigned int index,const char* propertyName,char c ) = 0; + SDO_API virtual bool addCharacter( unsigned int index,const char* propertyName,wchar_t c ) = 0; + SDO_API virtual bool addString( unsigned int index,const char* propertyName,const wchar_t* s, unsigned int len ) = 0; + SDO_API virtual bool addBytes( unsigned int index,const char* propertyName,const char* s , unsigned int len) = 0; + SDO_API virtual bool addShort( unsigned int index,const char* propertyName,short s ) = 0; + SDO_API virtual bool addInteger( unsigned int index,const char* propertyName,long i ) = 0; + SDO_API virtual bool addLong( unsigned int index,const char* propertyName,int64_t l ) = 0; + SDO_API virtual bool addFloat( unsigned int index,const char* propertyName,float f ) = 0; + SDO_API virtual bool addDouble(unsigned int index,const char* propertyName,long double d ) = 0; + SDO_API virtual bool addDate(unsigned int index,const char* propertyName,const SDODate t ) = 0; + SDO_API virtual bool addDataObject(unsigned int index,const char* propertyName,DataObjectPtr d ) = 0; + SDO_API virtual bool addSDOValue(unsigned int index, const char* propertyName, const SDOValue& sval) = 0; + + + SDO_API virtual bool addCString( unsigned int index,unsigned int propertyIndex,const char* s ) = 0; + SDO_API virtual bool addBoolean( unsigned int index,unsigned int propertyIndex,bool b ) = 0; + SDO_API virtual bool addByte( unsigned int index,unsigned int propertyIndex,char c ) = 0; + SDO_API virtual bool addCharacter( unsigned int index,unsigned int propertyIndex,wchar_t c ) = 0; + SDO_API virtual bool addString( unsigned int index,unsigned int propertyIndex,const wchar_t* s , unsigned int len) = 0; + SDO_API virtual bool addBytes( unsigned int index,unsigned int propertyIndex,const char* s , unsigned int len) = 0; + SDO_API virtual bool addShort( unsigned int index,unsigned int propertyIndex,short s ) = 0; + SDO_API virtual bool addInteger( unsigned int index,unsigned int propertyIndex,long i ) = 0; + SDO_API virtual bool addLong( unsigned int index,unsigned int propertyIndex,int64_t l ) = 0; + SDO_API virtual bool addFloat( unsigned int index,unsigned int propertyIndex,float f ) = 0; + SDO_API virtual bool addDouble(unsigned int index,unsigned int propertyIndex,long double d ) = 0; + SDO_API virtual bool addDate(unsigned int index,unsigned int propertyIndex,const SDODate t ) = 0; + SDO_API virtual bool addDataObject(unsigned int index,unsigned int propertyIndex,DataObjectPtr d ) = 0; + SDO_API virtual bool addSDOValue(unsigned int index, unsigned int propertyIndex, const SDOValue& sval) = 0; + + + SDO_API virtual bool addCString( unsigned int index,const Property& property,const char* s ) = 0; + SDO_API virtual bool addBoolean( unsigned int index,const Property& property,bool b ) = 0; + SDO_API virtual bool addByte( unsigned int index,const Property& property,char c ) = 0; + SDO_API virtual bool addCharacter( unsigned int index,const Property& property,wchar_t c ) = 0; + SDO_API virtual bool addString( unsigned int index,const Property& property,const wchar_t* s , unsigned int len) = 0; + SDO_API virtual bool addBytes( unsigned int index,const Property& property,const char* s , unsigned int len) = 0; + SDO_API virtual bool addShort( unsigned int index,const Property& property,short s ) = 0; + SDO_API virtual bool addInteger( unsigned int index,const Property& property,long i ) = 0; + SDO_API virtual bool addLong( unsigned int index,const Property& property,int64_t l ) = 0; + SDO_API virtual bool addFloat( unsigned int index,const Property& property,float f ) = 0; + SDO_API virtual bool addDouble(unsigned int index,const Property& property,long double d ) = 0; + SDO_API virtual bool addDate(unsigned int index,const Property& property,const SDODate t ) = 0; + SDO_API virtual bool addDataObject(unsigned int index,const Property& property,DataObjectPtr d ) = 0; + SDO_API virtual bool addSDOValue(unsigned int index, const Property& property, const SDOValue& sval) = 0; + + + /** remove() removes an item. + * + * Remove the item at the specified index in the sequence. + * This has no effect on the value of the property in the data object, + * but the setting is no longer recorded. + */ + SDO_API virtual void remove(unsigned int index) = 0; + SDO_API virtual void removeAll(const Property& p) = 0; + + /** + * Moves an entry in the sequence from one index to another. This + * makes the entry appear to have been set at a different point in + * the sequence, but does not alter the actual value set. + */ + + SDO_API virtual void move(unsigned int toIndex, unsigned int fromIndex) = 0; + + /** + * The text setting APIs add an element to the sequence which + * is not a property setting. + * This is text which may be retieved in sequence with the settings. + */ + + SDO_API virtual bool addText(const char* text) = 0; + SDO_API virtual bool addText(unsigned int index, const char* text) = 0; + SDO_API virtual bool setText(unsigned int index, const char* text) = 0; + + /** + * isText returns true if the element is not a property setting. + * This method should be used before getting the Property, to avoid an + * exception + */ + + SDO_API virtual bool isText(unsigned int index) = 0; + +}; + + +}; +}; + +#endif //_SEQUENCE_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SequenceImpl.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SequenceImpl.cpp new file mode 100644 index 0000000000..71bcc6e07f --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SequenceImpl.cpp @@ -0,0 +1,1328 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/disable_warn.h" +#include "commonj/sdo/Property.h" +#include "commonj/sdo/Type.h" +#include "commonj/sdo/TypeList.h" + +#include "commonj/sdo/SequenceImpl.h" + +#include "commonj/sdo/DataObject.h" +#include "commonj/sdo/DataObjectImpl.h" +#include "commonj/sdo/SDORuntimeException.h" +using namespace std; + + +#define CHECK_RANGE\ + if (index >= the_list.size()){\ + std::string msg("Index out of range:");\ + msg += index;\ + SDO_THROW_EXCEPTION("Sequence API", SDOIndexOutOfRangeException,\ + msg.c_str());\ + }\ + unsigned int j = 0;\ + for (i = the_list.begin(); (j < index) && (i != the_list.end()); ++i)\ + {\ + j++;\ + } + + +namespace commonj +{ + namespace sdo + { + + SequenceImpl::SequenceImpl() + { + SDO_THROW_EXCEPTION("Sequence constructor", + SDORuntimeException, + "SequenceImpl::construction without a data object"); + } + + SequenceImpl::SequenceImpl(DataObject* indo) + { + the_do = (DataObjectImpl*) indo; + } + + SequenceImpl::SequenceImpl(SequenceImpl* inseq) + { + // take a copy of the_list + the_list = inseq->the_list; + } + + unsigned int SequenceImpl::size() + { + return the_list.size(); + } + + // Convert an index into the sequence into an iterator (pointer) to the + // list element identified by the index. If the index is invalid then + // throw an exception. + void SequenceImpl::checkRange(unsigned int index, SEQUENCE_ITEM_LIST::iterator& i) + { + if (index >= the_list.size()) + { + std::string msg("Index out of range:"); + msg += index; + SDO_THROW_EXCEPTION("Sequence API", + SDOIndexOutOfRangeException, + msg.c_str()); + } + unsigned int j = 0; + for (i = the_list.begin(); (j < index) && (i != the_list.end()); ++i) + { + j++; + } + return; + } + + // Return the data object associated with this sequence + const DataObjectPtr SequenceImpl::getDataObject() + { + return the_do; + } + + const Property& SequenceImpl::getProperty(unsigned int index) + { + SEQUENCE_ITEM_LIST::iterator i; + + if (isText(index)) + { + std::string msg("Cannot get property of a text item"); + msg += index; + SDO_THROW_EXCEPTION("getProperty", + SDOUnsupportedOperationException, + msg.c_str()); + } + + checkRange(index, i); + + if (i != the_list.end()) + { + return *((*i).getProp()); + } + std::string msg("Index out of range:"); + msg += index; + SDO_THROW_EXCEPTION("getProperty", + SDOIndexOutOfRangeException, + msg.c_str()); + } + + Type::Types SequenceImpl::getTypeEnum(unsigned int index) + { + SEQUENCE_ITEM_LIST::iterator i; + + checkRange(index, i); + + if (i != the_list.end()) + { + if ((*i).getProp() == 0) + { + // text type + return Type::TextType; + } + return (*i).getProp()->getTypeEnum(); + } + std::string msg("Index out of range:"); + msg += index; + SDO_THROW_EXCEPTION("getTypeEnum", + SDOIndexOutOfRangeException, + msg.c_str()); + } + + unsigned int SequenceImpl::getListIndex(unsigned int index) + { + SEQUENCE_ITEM_LIST::iterator i; + + checkRange(index, i); + + if (i != the_list.end()) { + if ((*i).getProp() == 0) + { + std::string msg("Get list index on text property"); + SDO_THROW_EXCEPTION("getListIndex", + SDOUnsupportedOperationException, + msg.c_str()); + } + if ((*i).getProp()->isMany()) + { + return (*i).getIndex(); + } + else + { + std::string msg("Get list index on text single valued property"); + SDO_THROW_EXCEPTION("getListIndex", + SDOUnsupportedOperationException, + msg.c_str()); + } + } + std::string msg("Index out of range:"); + msg += index; + SDO_THROW_EXCEPTION("getListIndex", + SDOIndexOutOfRangeException, + msg.c_str()); + } + + unsigned int SequenceImpl::getIndex(const char* propName, unsigned int pindex) + { + SEQUENCE_ITEM_LIST::iterator i; + unsigned int j = 0; + for (i = the_list.begin(), j = 0; i != the_list.end(); ++i, ++j) + { + const Property* p = (*i).getProp(); + if (p == 0) + { + continue; // avoid text + } + + if (!strcmp(p->getName(), propName)) + { + if (p->isMany()) + { + if (pindex == (*i).getIndex()) + { + return j; + } + } + else + { + return j; + } + } + } + SDO_THROW_EXCEPTION("getIndex", + SDOIndexOutOfRangeException, + "SequenceImpl::getIndex - property Setting not in sequence"); + } + + unsigned int SequenceImpl::getIndex(const Property& p, unsigned int pindex) + { + return getIndex(p.getName(), pindex); + } + + // specific getters for prims and data objects + + // It isn't obvious from the code here, however, this method also + // retrieves free text elements (see the spec) ie text items that can be + // added to the sequence even though they are not associated with a property. + const char* SequenceImpl::getCStringValue(unsigned int index) + { + const SDOValue& result = getSDOValue(index); + + if (result.isSet()) + { + return result.getCString(); + } + else + { + return 0; + } + } + + unsigned int SequenceImpl::getLength(unsigned int index) + { + SEQUENCE_ITEM_LIST::iterator i; + CHECK_RANGE; + const Property* p = (*i).getProp(); + switch (p->getTypeEnum()) + { + case Type::StringType: + return getStringValue(index,0,0); + case Type::BytesType: + return getBytesValue(index,0,0); + default: + return 0; + } + } + + RefCountingPointer SequenceImpl::getDataObjectValue(unsigned int index) + { + SEQUENCE_ITEM_LIST::iterator i; + CHECK_RANGE; + const Property* p = (*i).getProp(); + if (p == 0) { + return 0; + } + if (p->isMany()) + { + DataObjectList& dol = the_do->getList(*p); + DataObject* list_do = dol[(*i).getIndex()]; + if (list_do != 0) + { + return list_do; + } + return 0; + } + return the_do->getDataObject(*((*i).getProp())); + } + + /////////////////////////////////////////////////////////////////////////// + // generic getter for those types which support it + /////////////////////////////////////////////////////////////////////////// + + void SequenceImpl::setCStringValue( unsigned int index, const char* s ) + { + SEQUENCE_ITEM_LIST::iterator i; + CHECK_RANGE; + if ((*i).getProp() == 0) { + (*i).setText(s); + return; + } + the_do->setCString(*((*i).getProp()),s); + + } + void SequenceImpl::setBooleanValue( unsigned int index, bool b ) + { + SEQUENCE_ITEM_LIST::iterator i; + CHECK_RANGE; + if ((*i).getProp() == 0) { + return; + } + the_do->setBoolean(*((*i).getProp()),b); + } + + void SequenceImpl::setByteValue( unsigned int index, char c ) + { + SEQUENCE_ITEM_LIST::iterator i; + CHECK_RANGE; + if ((*i).getProp() == 0) { + return; + } + the_do->setByte(*((*i).getProp()),c); + } + + void SequenceImpl::setCharacterValue( unsigned int index, wchar_t c ) + { + SEQUENCE_ITEM_LIST::iterator i; + CHECK_RANGE; + if ((*i).getProp() == 0) { + return; + } + the_do->setCharacter(*((*i).getProp()),c); + } + void SequenceImpl::setStringValue( unsigned int index, const wchar_t* s , unsigned int len) + { + SEQUENCE_ITEM_LIST::iterator i; + CHECK_RANGE; + if ((*i).getProp() == 0) { + return; + } + the_do->setString(*((*i).getProp()),s, len); + } + void SequenceImpl::setBytesValue( unsigned int index, const char* s , unsigned int len) + { + SEQUENCE_ITEM_LIST::iterator i; + CHECK_RANGE; + if ((*i).getProp() == 0) { + return; + } + the_do->setBytes(*((*i).getProp()),s, len); + } + void SequenceImpl::setShortValue( unsigned int index, short s ) + { + SEQUENCE_ITEM_LIST::iterator i; + CHECK_RANGE; + if ((*i).getProp() == 0) { + return; + } + the_do->setShort(*((*i).getProp()),s); + } + + void SequenceImpl::setIntegerValue( unsigned int index, long l) + { + SEQUENCE_ITEM_LIST::iterator i; + CHECK_RANGE; + if ((*i).getProp() == 0) { + return; + } + the_do->setInteger(*((*i).getProp()),l); + } + + + void SequenceImpl::setLongValue( unsigned int index, int64_t l ) + { + SEQUENCE_ITEM_LIST::iterator i; + CHECK_RANGE; + if ((*i).getProp() == 0) { + return; + } + the_do->setLong(*((*i).getProp()),l); + } + + void SequenceImpl::setFloatValue( unsigned int index, float f ) + { + SEQUENCE_ITEM_LIST::iterator i; + CHECK_RANGE; + if ((*i).getProp() == 0) { + return; + } + the_do->setFloat(*((*i).getProp()),f); + } + + + void SequenceImpl::setDoubleValue(unsigned int index, long double d ) + { + SEQUENCE_ITEM_LIST::iterator i; + CHECK_RANGE; + if ((*i).getProp() == 0) { + return; + } + the_do->setDouble(*((*i).getProp()),d); + } + + void SequenceImpl::setDateValue(unsigned int index, const SDODate t ) + { + SEQUENCE_ITEM_LIST::iterator i; + CHECK_RANGE; + if ((*i).getProp() == 0) { + return; + } + the_do->setDate(*((*i).getProp()),t); + } + + void SequenceImpl::setDataObjectValue(unsigned int index, DataObjectPtr d ) + { + SEQUENCE_ITEM_LIST::iterator i; + CHECK_RANGE; + if ((*i).getProp() == 0) { + return; + } + the_do->setDataObject(*((*i).getProp()),d); + } + + +bool SequenceImpl::addDataObject(const char* propertyName, RefCountingPointer v) +{ + const PropertyImpl* p = the_do->getPropertyImpl(propertyName); + if (p == 0) + { + if (the_do->getType().isOpenType()) + { + p = the_do->defineDataObject(propertyName, v->getType()); + } + if (p == 0) + { + std::string msg("Cannot find property:"); + msg += propertyName; + SDO_THROW_EXCEPTION("getProperty", SDOPropertyNotFoundException, + msg.c_str()); + } + } + return addDataObject((const Property&)*p,v); +} +bool SequenceImpl::addDataObject(unsigned int propertyIndex, RefCountingPointer v) +{ + return addDataObject(the_do->getProperty(propertyIndex), v); +} +bool SequenceImpl::addDataObject(const Property& p, RefCountingPointer v) +{ + // If this is a many valued property. + if (p.isMany()) + { + // Append the incoming data object value to the end of the list of + // values. The sequence is updated as part of the append operation. + DataObjectList& dol = the_do->getList(p); + dol.append((RefCountingPointer) v); + /* the_list.push_back(seq_item(&p,dol.size()-1));*/ + return true; + } + + SEQUENCE_ITEM_LIST::iterator i; + + // Scan the sequence to check that this property has not been set already. + for (i= the_list.begin(); i != the_list.end(); ++i) + { + const Property* pp = (*i).getProp(); + if (pp == 0) + { + continue; // This item is a free text entry. + } + if (!strcmp(pp->getName(), p.getName())) + { + SDO_THROW_EXCEPTION("add", + SDOUnsupportedOperationException, + "Sequence::add of property which already exists in sequence"); + } + } + + the_do->setDataObject(p, v, true); + // the_list.push_back(seq_item(&p, 0)); + return true; +} + + +bool SequenceImpl::addDataObject(unsigned int index, const char* propertyName, RefCountingPointer v) +{ + const PropertyImpl* p = the_do->getPropertyImpl(propertyName); + if (p == 0) + { + if (the_do->getType().isOpenType()) + { + p = the_do->defineDataObject(propertyName, v->getType()); + } + if (p == 0) + { + std::string msg("Cannot find property:"); + msg += propertyName; + SDO_THROW_EXCEPTION("getProperty", SDOPropertyNotFoundException, + msg.c_str()); + } + } + return addDataObject(index,(const Property&)*p,v); +} +bool SequenceImpl::addDataObject(unsigned int index, unsigned int propertyIndex, RefCountingPointer v) +{ + return addDataObject(index,the_do->getProperty(propertyIndex), v); +} +bool SequenceImpl::addDataObject(unsigned int index, const Property& p, RefCountingPointer v) +{ + SEQUENCE_ITEM_LIST::iterator i; + SEQUENCE_ITEM_LIST::iterator i2 = the_list.end(); + unsigned int j = 0; + + if (index >= the_list.size()) + { + return addDataObject(p, v); + } + if (p.isMany()) + { + DataObjectList& dol = the_do->getList(p); + dol.append((RefCountingPointer)v); + + checkRange(index, i); + + /*the_list.insert(i,seq_item(&p,dol.size()-1));*/ + return true; + } + + for (i = the_list.begin(); i != the_list.end(); ++i) + { + const Property* pp = (*i).getProp(); + if (pp == 0) + { + continue; // This item is a free text entry. + } + if (!strcmp(pp->getName(), p.getName())) + { + SDO_THROW_EXCEPTION("Insert", + SDOUnsupportedOperationException, + "Sequence::insert of property which already exists in sequence"); + } + if (j == index) + { + i2 = i; + } + j++; + } + // setDataObject can update the sequence but does not do so by an append + // so tell it to mind its own business and we will update the sequence here. + the_do->setDataObject(p, v, false); + the_list.insert(i2, seq_item(&p, 0)); + return true; +} + + void SequenceImpl::push(const Property& p, unsigned int index) + { + the_list.push_back(seq_item(&p,index)); + } + + void SequenceImpl::remove(unsigned int index) + { + if (index >= the_list.size()) { + std::string msg("Index out of range:"); + msg += index; + SDO_THROW_EXCEPTION("Sequence remove", SDOIndexOutOfRangeException, + msg.c_str()); + } + SEQUENCE_ITEM_LIST::iterator i; + + checkRange(index, i); + + the_list.erase(i); + return; + } + + void SequenceImpl::removeAll(const Property& p) + { + int j = 0; + const Property* prop; + SEQUENCE_ITEM_LIST::iterator i = the_list.begin(); + + while (i != the_list.end()) + { + prop = (*i).getProp(); + if (prop != 0) + { + if (!strcmp(prop->getName(), p.getName())) + { + i = the_list.erase(i); + } + else + { + ++i; + } + } + else + { + ++i; + } + + } + + return; + } + + void SequenceImpl::move(unsigned int toIndex, unsigned int fromIndex) + { + if (fromIndex >= the_list.size()) { + std::string msg("Index out of range:"); + msg += fromIndex; + SDO_THROW_EXCEPTION("Sequence Move", SDOIndexOutOfRangeException, + msg.c_str()); + } + + if (toIndex == fromIndex) return; + + SEQUENCE_ITEM_LIST::iterator i1, + i2 = the_list.end(), + i3 = the_list.end(); + unsigned int j = 0; + for (i3 = the_list.begin(); + j < toIndex && j < fromIndex && + i3 != the_list.end() ; ++i3); + { + if (j == toIndex) i1 = i3; + if (j == fromIndex) i2 = i3; + j++; + } + + if (toIndex < fromIndex) + { + the_list.insert( i1, *i2); + the_list.erase(i2); + } + else + { + if (toIndex + 1 == the_list.size()) + { + the_list.push_back(*i2); + } + else + { + the_list.insert(++i1,*i2); + } + the_list.erase(i2); + } + return; + } + + bool SequenceImpl::addText(const char* text) + { + the_list.push_back(seq_item(text)); + return true; + } + + bool SequenceImpl::isText(unsigned int index) + { + if (index >= the_list.size()) { + return false; + } + SEQUENCE_ITEM_LIST::iterator i; + + checkRange(index, i); + + if ((*i).getProp() == 0) + { + return true; + } + + return false; + } + + bool SequenceImpl::addText(unsigned int index, const char* text) + { + if (index >= the_list.size()) { + return addText(text); + } + + SEQUENCE_ITEM_LIST::iterator i; + + checkRange(index, i); + + the_list.insert(i,seq_item(text)); + return true; + } + + bool SequenceImpl::setText(unsigned int index, const char* text) + { + if (index >= the_list.size()) { + return false; + } + + if (!isText(index)) + { + return false; + } + + SEQUENCE_ITEM_LIST::iterator i; + + checkRange(index, i); + + (*i).setText(text); + return true; + } + +const SDOValue& SequenceImpl::getSDOValue(unsigned int index) +{ + SEQUENCE_ITEM_LIST::iterator i; + + checkRange(index, i); + + const Property* p = (*i).getProp(); + if (p == 0) + { + // There is no property. Either this is a free text element or we have a + // problem. + const SDOValue* freeText = (*i).getFreeText(); + if (freeText != 0) + { + return *freeText; + } + else + { + return SDOValue::unsetSDOValue; + } + } + PropertyImpl* pProp = 0; // Not used. Just a place for getSDOValue to + // write the return value that we don't need. + if (p->isMany()) + { + DataObjectList& dol = the_do->getList(*p); + DataObject* list_do = dol[(*i).getIndex()]; + if (list_do != 0) + { + return ((DataObjectImpl*) list_do)->getSDOValue(&pProp); + } + return SDOValue::unsetSDOValue; + } + return the_do->getSDOValue(*((*i).getProp()), &pProp); +} + +bool SequenceImpl::getBooleanValue(unsigned int index) +{ + const SDOValue& result = getSDOValue(index); + + if (result.isSet()) + { + return result.getBoolean(); + } + else + { + return (bool) 0; + } +} + +char SequenceImpl::getByteValue(unsigned int index) +{ + const SDOValue& result = getSDOValue(index); + + if (result.isSet()) + { + return result.getByte(); + } + else + { + return (char) 0; + } +} + +wchar_t SequenceImpl::getCharacterValue(unsigned int index) +{ + const SDOValue& result = getSDOValue(index); + + if (result.isSet()) + { + return result.getCharacter(); + } + else + { + return (wchar_t) 0; + } +} + +short SequenceImpl::getShortValue(unsigned int index) +{ + const SDOValue& result = getSDOValue(index); + + if (result.isSet()) + { + return result.getShort(); + } + else + { + return (short) 0; + } +} + +long SequenceImpl::getIntegerValue(unsigned int index) +{ + const SDOValue& result = getSDOValue(index); + + if (result.isSet()) + { + return result.getInteger(); + } + else + { + return (long) 0; + } +} + +int64_t SequenceImpl::getLongValue(unsigned int index) +{ + const SDOValue& result = getSDOValue(index); + + if (result.isSet()) + { + return result.getLong(); + } + else + { + return (int64_t) 0; + } +} + +float SequenceImpl::getFloatValue(unsigned int index) +{ + const SDOValue& result = getSDOValue(index); + + if (result.isSet()) + { + return result.getFloat(); + } + else + { + return (float) 0; + } +} + +long double SequenceImpl::getDoubleValue(unsigned int index) +{ + const SDOValue& result = getSDOValue(index); + + if (result.isSet()) + { + return result.getDouble(); + } + else + { + return (long double) 0; + } +} + +const SDODate SequenceImpl::getDateValue(unsigned int index) +{ + const SDOValue& result = getSDOValue(index); + + if (result.isSet()) + { + return result.getDate(); + } + else + { + return (SDODate) 0; + } +} + +bool SequenceImpl::addCString(const char* propertyName, const char* v) +{ + return addSDOValue(propertyName, SDOValue(SDOString(v))); +} +bool SequenceImpl::addCString(const Property& p, const char* v) +{ + return addSDOValue(p, SDOValue(SDOString(v))); +} +bool SequenceImpl::addCString(unsigned int propertyIndex, const char* v) +{ + return addCString(the_do->getProperty(propertyIndex), v); +} + +bool SequenceImpl::addByte(const char* propertyName, char v) +{ + return addSDOValue(propertyName, SDOValue(v)); +} +bool SequenceImpl::addByte(const Property& p, char v) +{ + return addSDOValue(p, SDOValue(v)); +} +bool SequenceImpl::addByte(unsigned int propertyIndex, char v) +{ + return addByte(the_do->getProperty(propertyIndex), v); +} + +bool SequenceImpl::addCharacter(const char* propertyName, wchar_t v) +{ + return addSDOValue(propertyName, SDOValue(v)); +} +bool SequenceImpl::addCharacter(const Property& p, wchar_t v) +{ + return addSDOValue(p, SDOValue(v)); +} +bool SequenceImpl::addCharacter(unsigned int propertyIndex, wchar_t v) +{ + return addCharacter(the_do->getProperty(propertyIndex), v); +} + +bool SequenceImpl::addShort(const char* propertyName, short v) +{ + return addSDOValue(propertyName, SDOValue(v)); +} +bool SequenceImpl::addShort(const Property& p, short v) +{ + return addSDOValue(p, SDOValue(v)); +} +bool SequenceImpl::addShort(unsigned int propertyIndex, short v) +{ + return addShort(the_do->getProperty(propertyIndex), v); +} + +bool SequenceImpl::addFloat(const char* propertyName, float v) +{ + return addSDOValue(propertyName, SDOValue(v)); +} +bool SequenceImpl::addFloat(const Property& p, float v) +{ + return addSDOValue(p, SDOValue(v)); +} +bool SequenceImpl::addFloat(unsigned int propertyIndex, float v) +{ + return addFloat(the_do->getProperty(propertyIndex), v); +} + +bool SequenceImpl::addDouble(const char* propertyName, long double v) +{ + return addSDOValue(propertyName, SDOValue(v)); +} +bool SequenceImpl::addDouble(const Property& p, long double v) +{ + return addSDOValue(p, SDOValue(v)); +} +bool SequenceImpl::addDouble(unsigned int propertyIndex, long double v) +{ + return addDouble(the_do->getProperty(propertyIndex), v); +} + +bool SequenceImpl::addDate(const char* propertyName, const SDODate v) +{ + return addSDOValue(propertyName, SDOValue(v)); +} +bool SequenceImpl::addDate(const Property& p, const SDODate v) +{ + return addSDOValue(p, SDOValue(v)); +} +bool SequenceImpl::addDate(unsigned int propertyIndex, const SDODate v) +{ + return addDate(the_do->getProperty(propertyIndex), v); +} + +bool SequenceImpl::addLong(const char* propertyName, int64_t v) +{ + return addSDOValue(propertyName, SDOValue(v)); +} +bool SequenceImpl::addLong(const Property& p, int64_t v) +{ + return addSDOValue(p, SDOValue(v)); +} +bool SequenceImpl::addLong(unsigned int propertyIndex, int64_t v) +{ + return addLong(the_do->getProperty(propertyIndex), v); +} + +bool SequenceImpl::addInteger(const char* propertyName, long v) +{ + return addSDOValue(propertyName, SDOValue(v)); +} +bool SequenceImpl::addInteger(const Property& p, long v) +{ + return addSDOValue(p, SDOValue(v)); +} +bool SequenceImpl::addInteger(unsigned int propertyIndex, long v) +{ + return addInteger(the_do->getProperty(propertyIndex), v); +} + +bool SequenceImpl::addBoolean(const char* propertyName, bool v) +{ + return addSDOValue(propertyName, SDOValue(v)); +} +bool SequenceImpl::addBoolean(const Property& p, bool v) +{ + return addSDOValue(p, SDOValue(v)); +} + +bool SequenceImpl::addBoolean(unsigned int propertyIndex, bool v) +{ + return addBoolean(the_do->getProperty(propertyIndex), v); +} + +// The return value is not spec compliant (which calls for void) it is a +// yes/no as to whether the call succeeded. +bool SequenceImpl::addSDOValue(const char* propertyName, const SDOValue& sval) +{ + const PropertyImpl* p = the_do->getPropertyImpl(propertyName); + if (p == 0) + { + if (the_do->getType().isOpenType()) + { + p = the_do->defineSDOValue(propertyName, sval); + } + if (p == 0) + { + std::string msg("Cannot find property:"); + msg += propertyName; + SDO_THROW_EXCEPTION("SequenceImpl::addSDOValue", + SDOPropertyNotFoundException, + msg.c_str()); + } + } + return addSDOValue((const Property&) *p, sval); +} +bool SequenceImpl::addSDOValue(const Property& p, const SDOValue& sval) +{ + if (p.isMany()) + { + DataObjectList& dol = the_do->getList(p); + dol.append(sval); + /* the_list.push_back(seq_item(&p,dol.size()-1));*/ + return true; + } +// std::cout << "Incoming property: " << p.getName() << std::endl << std::endl; + SEQUENCE_ITEM_LIST::iterator i; + for (i = the_list.begin(); i != the_list.end(); ++i) + { + const Property* pp = (*i).getProp(); + if (pp == 0) continue; +// std::cout << pp->getName() << std::endl; + if (!strcmp(pp->getName(), p.getName())) + { + SDO_THROW_EXCEPTION("add", + SDOUnsupportedOperationException, + "Sequence::add of property which already exists in sequence"); + } + } +// std::cout << std::endl; + the_do->setSDOValue(p, sval, sval.convertTypeEnumToString(), true); + // the_list.push_back(seq_item(&p, 0)); + return true; +} +bool SequenceImpl::addSDOValue(unsigned int propertyIndex, const SDOValue& sval) +{ + return addSDOValue(the_do->getProperty(propertyIndex), sval); +} + +bool SequenceImpl::addString(const char* propertyName, const wchar_t* v, unsigned int len) +{ + return addSDOValue(propertyName, SDOValue(v, len)); +} +bool SequenceImpl::addString(unsigned int propertyIndex, const wchar_t* v, unsigned int len) +{ + return addString(the_do->getProperty(propertyIndex), v, len); +} +bool SequenceImpl::addString(const Property& p, const wchar_t* v, unsigned int len) +{ + return addSDOValue(p, SDOValue(v, len)); +} + +bool SequenceImpl::addBytes(const char* propertyName, const char* v, unsigned int len) +{ + return addSDOValue(propertyName, SDOValue(v, len)); +} +bool SequenceImpl::addBytes(unsigned int propertyIndex, const char* v, unsigned int len) +{ + return addBytes(the_do->getProperty(propertyIndex), v, len); +} +bool SequenceImpl::addBytes(const Property& p, const char* v, unsigned int len) +{ + return addSDOValue(p, SDOValue(v, len)); +} + + bool SequenceImpl::addByte(unsigned int index, const char* propertyName, char v) + { + return addSDOValue(index, propertyName, SDOValue(v)); + } + bool SequenceImpl::addByte(unsigned int index, unsigned int propertyIndex, char v) + { + return addByte(index, the_do->getProperty(propertyIndex), v); + } + bool SequenceImpl::addByte(unsigned int index, const Property& p, char v) + { + return addSDOValue(index, p, SDOValue(v)); + } + + bool SequenceImpl::addCharacter(unsigned int index, const char* propertyName, wchar_t v) + { + return addSDOValue(index, propertyName, SDOValue(v)); + } + bool SequenceImpl::addCharacter(unsigned int index, unsigned int propertyIndex, wchar_t v) + { + return addCharacter(index, the_do->getProperty(propertyIndex), v); + } + bool SequenceImpl::addCharacter(unsigned int index, const Property& p, wchar_t v) + { + return addSDOValue(index, p, SDOValue(v)); + } + + bool SequenceImpl::addShort(unsigned int index, const char* propertyName, short v) + { + return addSDOValue(index, propertyName, SDOValue(v)); + } + bool SequenceImpl::addShort(unsigned int index, unsigned int propertyIndex, short v) + { + return addShort(index, the_do->getProperty(propertyIndex), v); + } + bool SequenceImpl::addShort(unsigned int index, const Property& p, short v) + { + return addSDOValue(index, p, SDOValue(v)); + } + + bool SequenceImpl::addLong(unsigned int index, const char* propertyName, int64_t v) + { + return addSDOValue(index, propertyName, SDOValue(v)); + } + bool SequenceImpl::addLong(unsigned int index, unsigned int propertyIndex, int64_t v) + { + return addLong(index, the_do->getProperty(propertyIndex), v); + } + bool SequenceImpl::addLong(unsigned int index, const Property& p, int64_t v) + { + return addSDOValue(index, p, SDOValue(v)); + } + + bool SequenceImpl::addFloat(unsigned int index, const char* propertyName, float v) + { + return addSDOValue(index, propertyName, SDOValue(v)); + } + bool SequenceImpl::addFloat(unsigned int index, unsigned int propertyIndex, float v) + { + return addFloat(index, the_do->getProperty(propertyIndex), v); + } + bool SequenceImpl::addFloat(unsigned int index, const Property& p, float v) + { + return addSDOValue(index, p, SDOValue(v)); + } + + bool SequenceImpl::addDouble(unsigned int index, const char* propertyName, long double v) + { + return addSDOValue(index, propertyName, SDOValue(v)); + } + bool SequenceImpl::addDouble(unsigned int index, unsigned int propertyIndex, long double v) + { + return addDouble(index, the_do->getProperty(propertyIndex), v); + } + bool SequenceImpl::addDouble(unsigned int index, const Property& p, long double v) + { + return addSDOValue(index, p, SDOValue(v)); + } + + bool SequenceImpl::addDate(unsigned int index, const char* propertyName, const SDODate v) + { + return addSDOValue(index, propertyName, SDOValue(v)); + } + bool SequenceImpl::addDate(unsigned int index, unsigned int propertyIndex, const SDODate v) + { + return addDate(index, the_do->getProperty(propertyIndex), v); + } + bool SequenceImpl::addDate(unsigned int index, const Property& p, const SDODate v) + { + return addSDOValue(index, p, SDOValue(v)); + } + + bool SequenceImpl::addInteger(unsigned int index, const char* propertyName, long v) + { + return addSDOValue(index, propertyName, SDOValue(v)); + } + bool SequenceImpl::addInteger(unsigned int index, unsigned int propertyIndex, long v) + { + return addInteger(index, the_do->getProperty(propertyIndex), v); + } + bool SequenceImpl::addInteger(unsigned int index, const Property& p, long v) + { + return addSDOValue(index, p, SDOValue(v)); + } + + bool SequenceImpl::addCString(unsigned int index, const char* propertyName, const char* v) + { + return addSDOValue(index, propertyName, SDOValue(SDOString(v))); + } + bool SequenceImpl::addCString(unsigned int index, unsigned int propertyIndex, const char* v) + { + return addCString(index, the_do->getProperty(propertyIndex), v); + } + bool SequenceImpl::addCString(unsigned int index, const Property& p, const char* v) + { + return addSDOValue(index, p, SDOValue(SDOString(v))); + } + + bool SequenceImpl::addBoolean(unsigned int index, const char* propertyName, bool v) + { + return addSDOValue(index, propertyName, SDOValue(v)); + } + bool SequenceImpl::addBoolean(unsigned int index, unsigned int propertyIndex, bool v) + { + return addBoolean(index, the_do->getProperty(propertyIndex), v); + } + bool SequenceImpl::addBoolean(unsigned int index, const Property& p, bool v) + { + return addSDOValue(index, p, SDOValue(v)); + } + + bool SequenceImpl::addSDOValue(unsigned int index, const char* propertyName, const SDOValue& sval) + { + const PropertyImpl* p = the_do->getPropertyImpl(propertyName); + if (p == 0) + { + if (the_do->getType().isOpenType()) + { + p = the_do->defineSDOValue(propertyName, sval); + } + if (p == 0) + { + std::string msg("Cannot find property:"); + msg += propertyName; + SDO_THROW_EXCEPTION("getProperty", + SDOPropertyNotFoundException, + msg.c_str()); + } + } + return addSDOValue(index, (const Property&) *p, sval); + } + bool SequenceImpl::addSDOValue(unsigned int index, unsigned int propertyIndex, const SDOValue& sval) + { + return addSDOValue(index,the_do->getProperty(propertyIndex), sval); + } + bool SequenceImpl::addSDOValue(unsigned int index, const Property& p, const SDOValue& sval) + { + SEQUENCE_ITEM_LIST::iterator i; + SEQUENCE_ITEM_LIST::iterator i2 = the_list.end(); + unsigned int j = 0; + if (index >= the_list.size()) { + return addSDOValue(p, sval); + } + if (p.isMany()) + { + DataObjectList& dol = the_do->getList(p); + dol.append(sval); + + checkRange(index, i); + + /*the_list.insert(i,seq_item(&p,dol.size()-1));*/ + return true; + } + + for (i = the_list.begin(); i != the_list.end(); ++i) + { + const Property* pp = (*i).getProp(); + if (pp == 0) continue; + if (!strcmp(pp->getName(), p.getName())) + { + SDO_THROW_EXCEPTION("Insert", + SDOUnsupportedOperationException, + "Sequence::insert of property which already exists in sequence"); + } + if (j == index) { + i2 = i; + } + j++; + } + + // setSDOValue can update the sequence but does not do so by an append so + // tell it to mind its own business and we will update the sequence here. + the_do->setSDOValue(p, sval, sval.convertTypeEnumToString(), false); + the_list.insert(i2, seq_item(&p, 0)); + return true; + } + +bool SequenceImpl::addString(unsigned int index, + const char* propertyName, + const wchar_t* v, + unsigned int len) +{ + return addSDOValue(index, propertyName, SDOValue(v, len)); +} + +bool SequenceImpl::addString(unsigned int index, unsigned int propertyIndex, const wchar_t* v, unsigned int len) +{ + return addString(index,the_do->getProperty(propertyIndex), v, len); +} +bool SequenceImpl::addString(unsigned int index, const Property& p, const wchar_t* v, unsigned int len) +{ + return addSDOValue(index, p, SDOValue(v, len)); +} + +bool SequenceImpl::addBytes(unsigned int index, + const char* propertyName, + const char* v, + unsigned int len) +{ + return addSDOValue(index, propertyName, SDOValue(v, len)); +} + +bool SequenceImpl::addBytes(unsigned int index, unsigned int propertyIndex, const char* v, unsigned int len) +{ + return addBytes(index,the_do->getProperty(propertyIndex), v, len); +} +bool SequenceImpl::addBytes(unsigned int index, const Property& p, const char* v, unsigned int len) +{ + return addSDOValue(index, p, SDOValue(v, len)); +} + +unsigned int SequenceImpl::getBytesValue(unsigned int index, char* ptr, unsigned int max) +{ + + const SDOValue& result = getSDOValue(index); + + if (result.isSet()) + { + return result.getBytes(ptr, max); + } + else + { + return 0; + } +} +unsigned int SequenceImpl::getStringValue(unsigned int index, wchar_t* ptr, unsigned int max) +{ + + const SDOValue& result = getSDOValue(index); + + if (result.isSet()) + { + return result.getString(ptr, max); + } + else + { + return 0; + } +} + +}; +}; diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SequenceImpl.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SequenceImpl.h new file mode 100644 index 0000000000..90505d047e --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SequenceImpl.h @@ -0,0 +1,405 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _SEQUENCEIMPL_H_ +#define _SEQUENCEIMPL_H_ + +#include "commonj/sdo/disable_warn.h" + +#include + + +#include "commonj/sdo/Sequence.h" +#include "commonj/sdo/SDODate.h" + +#define SequenceImplPtr RefCountingPointer + +namespace commonj{ +namespace sdo{ + +class Property; /* forward declaration */ +class DataObjectImpl; + +/** SequenceImpl implements the abstract class Sequence. + * + * A sequence is a heterogeneous list of properties and corresponding values. + * It represents an ordered arbitrary mixture of data values from more + * than one property of a {@link DataObject data object}. + */ + +class SequenceImpl : public Sequence +{ + public: + /////////////////////////////////////////////////////////////////////////// + // Returns the number of entries in the sequence. + // @return the number of entries. + /////////////////////////////////////////////////////////////////////////// + virtual unsigned int size(); + + /////////////////////////////////////////////////////////////////////////// + // Returns the property for the given entry index. + /////////////////////////////////////////////////////////////////////////// + virtual const Property& getProperty(unsigned int index); + + /** + * Return the data object associated with this sequence + */ + + SDO_API virtual const DataObjectPtr getDataObject(); + + /////////////////////////////////////////////////////////////////////////// + // Returns the property for the given entry index. + /////////////////////////////////////////////////////////////////////////// + virtual unsigned int getIndex(const Property& p, unsigned int pindex=0); + virtual unsigned int getIndex(const char* propName, unsigned int pindex=0); + + virtual unsigned int getListIndex(unsigned int index); + + Type::Types getTypeEnum(unsigned int index); + + + /////////////////////////////////////////////////////////////////////////// + // Returns the property value for the given entry index. + // @param index the index of the entry. + // @return the value for the given entry index.. + /////////////////////////////////////////////////////////////////////////// + virtual const char* getCStringValue(unsigned int index); + virtual bool getBooleanValue(unsigned int index); + virtual char getByteValue(unsigned int index); + virtual wchar_t getCharacterValue(unsigned int index); + virtual unsigned int getStringValue(unsigned int index, wchar_t* val, unsigned int max); + virtual unsigned int getBytesValue(unsigned int index, char* val, unsigned int max); + virtual short getShortValue(unsigned int index); + virtual long getIntegerValue(unsigned int index); + virtual int64_t getLongValue(unsigned int index); + virtual float getFloatValue(unsigned int index); + virtual long double getDoubleValue(unsigned int index); + virtual const SDODate getDateValue(unsigned int index); + virtual DataObjectPtr getDataObjectValue(unsigned int index); + virtual const SDOValue& getSDOValue(unsigned int index); + + virtual unsigned int getLength(unsigned int index); + + /////////////////////////////////////////////////////////////////////////// + // sets the entry at a specified index to the new value. + // @param index the index of the entry. + // @param value the new value for the entry. + /////////////////////////////////////////////////////////////////////////// + + virtual void setCStringValue( unsigned int index, const char* s ); + virtual void setBooleanValue( unsigned int index, bool b ); + virtual void setByteValue( unsigned int index, char c ); + virtual void setCharacterValue( unsigned int index, wchar_t c ); + virtual void setBytesValue( unsigned int index, const char* s , unsigned int len); + virtual void setStringValue( unsigned int index, const wchar_t* s , unsigned int len); + virtual void setShortValue( unsigned int index, short s ); + virtual void setIntegerValue( unsigned int index, long i ); + virtual void setLongValue( unsigned int index, int64_t l ); + virtual void setFloatValue( unsigned int index, float f ); + virtual void setDoubleValue( unsigned int index, long double d ); + virtual void setDateValue( unsigned int index, const SDODate t ); + virtual void setDataObjectValue(unsigned int index, DataObjectPtr d ); + + + /////////////////////////////////////////////////////////////////////////// + // adds a new entry with the specified property name and value + // to the end of the entries. + // @param propertyName the name of the entry's property. + // @param value the value for the entry. + /////////////////////////////////////////////////////////////////////////// + virtual bool addCString( const char* propertyName,const char* s ); + virtual bool addBoolean( const char* propertyName,bool b ); + virtual bool addByte( const char* propertyName,char c ); + virtual bool addCharacter( const char* propertyName,wchar_t c ); + virtual bool addString( const char* propertyName,const wchar_t* s , unsigned int len); + virtual bool addBytes( const char* propertyName,const char* s , unsigned int len); + virtual bool addShort( const char* propertyName,short s ); + virtual bool addInteger( const char* propertyName,long i ); + virtual bool addLong( const char* propertyName,int64_t l ); + virtual bool addFloat( const char* propertyName,float f ); + virtual bool addDouble( const char* propertyName,long double d ); + virtual bool addDate( const char* propertyName,const SDODate t ); + virtual bool addDataObject(const char* propertyName,DataObjectPtr d ); + virtual bool addSDOValue(const char* propertyName, const SDOValue& sval); + + + /////////////////////////////////////////////////////////////////////////// + // adds a new entry with the specified property index and value + // to the end of the entries. + // @param propertyIndex the index of the entry's property. + // @param value the value for the entry. + /////////////////////////////////////////////////////////////////////////// + virtual bool addCString( unsigned int propertyIndex,const char* s ); + virtual bool addBoolean( unsigned int propertyIndex,bool b ); + virtual bool addByte( unsigned int propertyIndex,char c ); + virtual bool addCharacter( unsigned int propertyIndex,wchar_t c ); + virtual bool addString( unsigned int propertyIndex,const wchar_t* s , unsigned int len); + virtual bool addBytes( unsigned int propertyIndex,const char* s , unsigned int len); + virtual bool addShort( unsigned int propertyIndex,short s ); + virtual bool addInteger( unsigned int propertyIndex,long i ); + virtual bool addLong( unsigned int propertyIndex,int64_t l ); + virtual bool addFloat( unsigned int propertyIndex,float f ); + virtual bool addDouble( unsigned int propertyIndex,long double d ); + virtual bool addDate( unsigned int propertyIndex,const SDODate t ); + virtual bool addDataObject(unsigned int propertyIndex,DataObjectPtr d ); + virtual bool addSDOValue(unsigned int propertyIndex, const SDOValue& sval); + + + /////////////////////////////////////////////////////////////////////////// + // adds a new entry with the specified property and value + // to the end of the entries. + // @param property the property of the entry. + // @param value the value for the entry. + /////////////////////////////////////////////////////////////////////////// + + virtual bool addCString( const Property& property,const char* s ); + virtual bool addBoolean( const Property& property,bool b ); + virtual bool addByte( const Property& property,char c ); + virtual bool addCharacter( const Property& property,wchar_t c ); + virtual bool addString( const Property& property,const wchar_t* s , unsigned int len); + virtual bool addBytes( const Property& property,const char* s , unsigned int len); + virtual bool addShort( const Property& property,short s ); + virtual bool addInteger( const Property& property,long i ); + virtual bool addLong( const Property& property,int64_t l ); + virtual bool addFloat( const Property& property,float f ); + virtual bool addDouble( const Property& property,long double d ); + virtual bool addDate( const Property& property,const SDODate t ); + virtual bool addDataObject(const Property& property,DataObjectPtr d ); + virtual bool addSDOValue(const Property& property, const SDOValue& sval); + + + /////////////////////////////////////////////////////////////////////////// + // adds a new entry with the specified property name and value + // at the specified entry index. + // @param index the index at which to add the entry. + // @param propertyName the name of the entry's property. + // @param value the value for the entry. + /////////////////////////////////////////////////////////////////////////// + virtual bool addCString( unsigned int index,const char* propertyName,const char* s ); + virtual bool addBoolean( unsigned int index,const char* propertyName,bool b ); + virtual bool addByte( unsigned int index,const char* propertyName,char c ); + virtual bool addCharacter( unsigned int index,const char* propertyName,wchar_t c ); + virtual bool addString( unsigned int index,const char* propertyName,const wchar_t* s , unsigned int len); + virtual bool addBytes( unsigned int index,const char* propertyName,const char* s , unsigned int len); + virtual bool addShort( unsigned int index,const char* propertyName,short s ); + virtual bool addInteger( unsigned int index,const char* propertyName,long i ); + virtual bool addLong( unsigned int index,const char* propertyName,int64_t l ); + virtual bool addFloat( unsigned int index,const char* propertyName,float f ); + virtual bool addDouble( unsigned int index,const char* propertyName,long double d ); + virtual bool addDate( unsigned int index,const char* propertyName,const SDODate t ); + virtual bool addDataObject(unsigned int index,const char* propertyName,DataObjectPtr d ); + virtual bool addSDOValue(unsigned int index, const char* propertyName, const SDOValue& sval); + + /////////////////////////////////////////////////////////////////////////// + // adds a new entry with the specified property index and value + // at the specified entry index. + // @param index the index at which to add the entry. + // @param propertyIndex the index of the entry's property. + // @param value the value for the entry. + /////////////////////////////////////////////////////////////////////////// + virtual bool addCString( unsigned int index,unsigned int propertyIndex,const char* s ); + virtual bool addBoolean( unsigned int index,unsigned int propertyIndex,bool b ); + virtual bool addByte( unsigned int index,unsigned int propertyIndex,char c ); + virtual bool addCharacter( unsigned int index,unsigned int propertyIndex,wchar_t c ); + virtual bool addString( unsigned int index,unsigned int propertyIndex,const wchar_t* s , unsigned int len); + virtual bool addBytes( unsigned int index,unsigned int propertyIndex,const char* s , unsigned int len); + virtual bool addShort( unsigned int index,unsigned int propertyIndex,short s ); + virtual bool addInteger( unsigned int index,unsigned int propertyIndex,long i ); + virtual bool addLong( unsigned int index,unsigned int propertyIndex,int64_t l ); + virtual bool addFloat( unsigned int index,unsigned int propertyIndex,float f ); + virtual bool addDouble( unsigned int index,unsigned int propertyIndex,long double d ); + virtual bool addDate( unsigned int index,unsigned int propertyIndex,const SDODate t ); + virtual bool addDataObject(unsigned int index,unsigned int propertyIndex,DataObjectPtr d ); + virtual bool addSDOValue(unsigned int index, unsigned int propertyIndex, const SDOValue& sval); + + /////////////////////////////////////////////////////////////////////////// + // adds a new entry with the specified property and value + // at the specified entry index. + // @param index the index at which to add the entry. + // @param property the property of the entry. + // @param value the value for the entry. + /////////////////////////////////////////////////////////////////////////// + virtual bool addCString( unsigned int index,const Property& property,const char* s ); + virtual bool addBoolean( unsigned int index,const Property& property,bool b ); + virtual bool addByte( unsigned int index,const Property& property,char c ); + virtual bool addCharacter( unsigned int index,const Property& property,wchar_t c ); + virtual bool addString( unsigned int index,const Property& property,const wchar_t* s , unsigned int len); + virtual bool addBytes( unsigned int index,const Property& property,const char* s , unsigned int len); + virtual bool addShort( unsigned int index,const Property& property,short s ); + virtual bool addInteger( unsigned int index,const Property& property,long i ); + virtual bool addLong( unsigned int index,const Property& property,int64_t l ); + virtual bool addFloat( unsigned int index,const Property& property,float f ); + virtual bool addDouble( unsigned int index,const Property& property,long double d ); + virtual bool addDate( unsigned int index,const Property& property,const SDODate t ); + virtual bool addDataObject(unsigned int index,const Property& property,DataObjectPtr d ); + virtual bool addSDOValue(unsigned int index, const Property& property, const SDOValue& sval); + + /////////////////////////////////////////////////////////////////////////// + // removes the entry at the given entry index. + // @param index the index of the entry + /////////////////////////////////////////////////////////////////////////// + virtual void remove(unsigned int index); + virtual void removeAll(const Property& p); + + /////////////////////////////////////////////////////////////////////////// + // pushes a new entry without setting the property. + // @param index the index of the entry + /////////////////////////////////////////////////////////////////////////// + virtual void push(const Property& p, unsigned int index); + + /////////////////////////////////////////////////////////////////////////// + // Moves the entry at fromIndex to toIndex. + // @param toIndex the index of the entry destination. + // @param fromIndex the index of the entry to move. + /////////////////////////////////////////////////////////////////////////// + virtual void move(unsigned int toIndex, unsigned int fromIndex); + + /////////////////////////////////////////////////////////////////////////// + // adds a new Setting with the SDO text Property + // to the end of the Settings. + // @param text value of the Setting. + /////////////////////////////////////////////////////////////////////////// + virtual bool addText(const char* text); + + /////////////////////////////////////////////////////////////////////////// + // adds a new Setting with the SDO text Property + // to the Settings. + // @param index the index at which to add the entry. + // @param text value of the Setting. + /////////////////////////////////////////////////////////////////////////// + virtual bool addText(unsigned int index, const char* text); + + /////////////////////////////////////////////////////////////////////////// + // sets a text Property + // @param index the index at which to set the entry. + // @param text value of the Setting. + /////////////////////////////////////////////////////////////////////////// + bool setText(unsigned int index, const char* text); + + /////////////////////////////////////////////////////////////////////////// + // Checks if an entry is text or a setting. + /////////////////////////////////////////////////////////////////////////// + virtual bool isText(unsigned int index); + + SequenceImpl(DataObject* the_do); + SequenceImpl(SequenceImpl* s); + + private: + + SequenceImpl(); + + DataObjectImpl* the_do; + + class seq_item { + public: + // Constructors + seq_item(const Property* p, unsigned int i): + the_prop(p), index(i), freeText(0) + { + } + seq_item(const char* t) : + the_prop(0) + { + freeText = new SDOValue(t); + } + // Copy constructor + seq_item(const seq_item& sin) : + index(sin.index), freeText(0), the_prop(sin.the_prop) + { + if (sin.freeText != 0) + { + freeText = new SDOValue(*sin.freeText); + } + } + + // Copy assignment + seq_item& operator=(const seq_item& sin) + { + if (this != &sin) + { + if (freeText) + { + delete freeText; + } + if (sin.freeText != 0) + { + freeText = new SDOValue(*sin.freeText); + } + } + return *this; + } + + // Destructor + ~seq_item() + { + if (freeText) + { + delete freeText; + } + } + + + const Property* getProp() {return the_prop;} + unsigned int getIndex() { return index;} + + const char* getText() + { + return freeText->getCString(); + } + + const SDOValue* getFreeText() + { + return freeText; + } + + void setProp(Property* p) { the_prop = p;} + + void setText(const char* intext) + { + if (intext != 0) + { + if (freeText != 0) + { + delete freeText; + } + freeText = new SDOValue(intext); + } + } + void setIndex(unsigned int i) + { + index = i; + } + private: + const Property* the_prop; + unsigned int index; + SDOValue* freeText; + }; + + typedef std::list SEQUENCE_ITEM_LIST; + virtual void checkRange(unsigned int index, SEQUENCE_ITEM_LIST::iterator& i); + + SEQUENCE_ITEM_LIST the_list; + +}; +}; +}; + +#endif //_SEQUENCE_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Setting.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Setting.cpp new file mode 100644 index 0000000000..9e0251fec4 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Setting.cpp @@ -0,0 +1,308 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/Setting.h" +#include "commonj/sdo/TypeImpl.h" + +namespace commonj{ +namespace sdo { + + Setting::Setting(bool set, bool nul, void* invalue, unsigned int len, const Property& p, unsigned int inindex) + : bisSet(set), bisNull(nul) , value(invalue),theProp(&p) + { + index = inindex; + length = len; + strbuf = 0; + } + + void Setting::copy(const Setting& s) + { + bisSet = s.isSet(); + bisNull = s.isNull(); + index = s.getIndex(); + length = s.getLength(); + theProp = &(s.getProperty()); + strbuf = 0; + switch (theProp->getTypeEnum()) + { + case Type::BooleanType: + value = new long; + *(long*)value = (long)s.getBooleanValue(); + break; + case Type::ByteType: + value = new long; + *(long*)value = (long)s.getByteValue(); + break; + case Type::CharacterType: + value = new long; + *(long*)value = (long)s.getCharacterValue(); + break; + case Type::IntegerType: + value = new long; + *(long*)value = (long)s.getIntegerValue(); + break; + case Type::ShortType: + value = new long; + *(long*)value = (long)s.getShortValue(); + break; + case Type::DoubleType: + value = new long double; + *(long double*)value = s.getDoubleValue(); + break; + case Type::FloatType: + value = new float; + *(float*)value = s.getFloatValue(); + break; + case Type::LongType: + value = new int64_t; + *(int64_t*)value = s.getLongValue(); + break; + case Type::DateType: + value = new long; + *(long*)value = long(s.getDateValue().getTime()); + break; + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::StringType: + case Type::UriType: + value = new wchar_t[length]; + s.getStringValue((wchar_t*)value,length); + break; + case Type::BytesType: + value = new char[length]; + s.getBytesValue((char*)value,length); + break; + case Type::OtherTypes: + case Type::DataObjectType: + case Type::ChangeSummaryType: + value = s.getDataObjectValue(); + default: + break; + } + } + + Setting& Setting::operator=(const Setting& s) + { + if (this == &s) return *this; + copy(s); + return *this; + } + + Setting::Setting(const Setting& s) + { + copy(s); + } + + Setting::~Setting() + { + // The value has been allocated for everything except data objects + + switch (theProp->getTypeEnum()) + { + case Type::BooleanType: + case Type::ByteType: + case Type::CharacterType: + case Type::IntegerType: + case Type::ShortType: + delete (long*)value; + break; + case Type::DoubleType: + delete (long double*)value; + break; + case Type::FloatType: + delete (float*)value; + break; + case Type::LongType: + delete (int64_t*)value; + break; + case Type::DateType: + delete (long*)value; + break; + case Type::BigDecimalType: + case Type::BigIntegerType: + case Type::StringType: + case Type::UriType: + delete[] (wchar_t*) value; + break; + case Type::BytesType: + delete[] (char*) value; + break; + case Type::OtherTypes: + case Type::DataObjectType: + case Type::ChangeSummaryType: + default: + break; + } + if (strbuf != 0) + { + delete[] strbuf; + } + } + + const Property& Setting::getProperty() const + { + return *theProp; + } + + const Type& Setting::getType() const + { + return theProp->getType(); + } + + bool Setting::getBooleanValue() const + { + TypeImpl* t = (TypeImpl*)&(getType()); + return t->convertToBoolean(value, length); + //if (value == 0) return false; + //if (*(long*)value != 0) { + // return true; + //} + //return false; + } + + char Setting::getByteValue() const + { + TypeImpl* t = (TypeImpl*)&(getType()); + return t->convertToByte(value, length); + //if (value == 0) return 0; + //return (char)*(long*)value; + } + + wchar_t Setting::getCharacterValue() const + { + TypeImpl* t = (TypeImpl*)&(getType()); + return t->convertToCharacter(value, length); + //if (value == 0) return 0; + //return (wchar_t)*(long*)value; + } + + unsigned int Setting::getBytesValue(char* buffer, unsigned int max) const + { + if (buffer == 0 && max == 0) return length; + + TypeImpl* t = (TypeImpl*)&(getType()); + return t->convertToBytes(value, buffer,length, max); + //int i; + //char* c = (char*)value; + //for (i=0;i < max && i < length;i++) + //{ + // buffer[i] = (char)*c; + // c++; + //} + //return i; + } + + unsigned int Setting::getStringValue(wchar_t* buffer, unsigned int max) const + { + if (buffer == 0 && max == 0) return length; + + TypeImpl* t = (TypeImpl*)&(getType()); + return t->convertToString(value, buffer,length, max); + //int i; + //wchar_t* c = (wchar_t*)value; + //for (i=0;i < max && i < length;i++) + //{ + // buffer[i] = (wchar_t)*c; + // c++; + //} + //return i; + } + + short Setting::getShortValue() const + { + TypeImpl* t = (TypeImpl*)&(getType()); + return t->convertToShort(value,length); + //return (short)*(long*)value; + } + + long Setting::getIntegerValue() const + { + TypeImpl* t = (TypeImpl*)&(getType()); + return t->convertToInteger(value, length); + //return *(long*)value; + } + + + int64_t Setting::getLongValue() const + { + TypeImpl* t = (TypeImpl*)&(getType()); + return t->convertToLong(value, length); + //return (int64_t)*(int64_t*)value; + } + + float Setting::getFloatValue() const + { + TypeImpl* t = (TypeImpl*)&(getType()); + return t->convertToFloat(value, length); + //return (float)*(float*)value; + } + + const SDODate Setting::getDateValue() const + { + TypeImpl* t = (TypeImpl*)&(getType()); + return t->convertToDate(value, length); + } + + + long double Setting::getDoubleValue() const + { + TypeImpl* t = (TypeImpl*)&(getType()); + return t->convertToDouble(value, length); + //return (long double)*(long double*)value; + } + + const char* Setting::getCStringValue() + { + TypeImpl* t = (TypeImpl*)&(getType()); + return t->convertToCString(value, &strbuf, length); + //return (const char*)value; + } + + RefCountingPointer Setting::getDataObjectValue() const + { + DataObject *dob = (DataObject*)value; + return RefCountingPointer(dob); + } + + + unsigned int Setting::getLength() const + { + return length; + } + + unsigned int Setting::getIndex() const + { + return index; + } + + bool Setting::isSet() const + { + return bisSet; + } + + bool Setting::isNull() const + { + return bisNull; + } + +}; +}; + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Setting.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Setting.h new file mode 100644 index 0000000000..19980d7b04 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Setting.h @@ -0,0 +1,151 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef SETTING_H +#define SETTING_H + +#include "commonj/sdo/export.h" + +#include "commonj/sdo/Type.h" +#include "commonj/sdo/DataObject.h" +#include "commonj/sdo/SDODate.h" + +namespace commonj{ +namespace sdo { + + class Property; + + /** + * A Setting encapsulates a property and a corresponding single value of + * the property's type. + */ + + class Setting + { + public: + + Setting(bool set, bool nul, void* invalue, unsigned int len, const Property& p, + unsigned int inindex); + + Setting(const Setting& s); + + void copy(const Setting& s); + + Setting& operator=(const Setting& s); + + + virtual ~Setting(); + + + /** getProperty returns the property set. + * + * Returns the property of the Setting. + * @return the Setting property. + */ + + SDO_API const Property& getProperty() const; + + /** getType returns the type of the property + * + * Returns the type of this property. This is the same as + * getProperty().getType() + */ + + SDO_API const Type& getType() const; + + /** getTypeEnum returns the type enumerator + * + * Returns the enum for the type of this property + */ + + SDO_API Type::Types getTypeEnum() const; + + + /** get methods get the right type of value from the setting + * + * + * Returns the value of the Setting. This must be of the right type for + * Setting value. + */ + + SDO_API bool getBooleanValue() const; + SDO_API char getByteValue() const; + SDO_API wchar_t getCharacterValue() const; + SDO_API unsigned int getBytesValue(char* buffer, unsigned int max) const; + SDO_API unsigned int getStringValue(wchar_t* buffer, unsigned int max) const; + SDO_API short getShortValue() const; + SDO_API long getIntegerValue() const; + SDO_API int64_t getLongValue() const; + SDO_API float getFloatValue() const; + SDO_API long double getDoubleValue() const; + SDO_API const SDODate getDateValue() const; + SDO_API const char* getCStringValue() ; + SDO_API DataObjectPtr getDataObjectValue() const; + + + + /** getIndex returns the index in a many-valued property + * + * Returns the index of the Setting, if this is many valued + */ + + SDO_API unsigned int getIndex() const; + + + /** getLength gives the length of a string or bytes + * + * Returns the length of the setting, if this is a String or + * Bytes type + */ + + SDO_API unsigned int getLength() const ; + + /** isSet returns whether the property WAS set. + * + * Returns whether or not the property is set. This value comes from the + * setting, and tells us whether the property was set before the change + * occurred. + */ + + SDO_API bool isSet() const; + + /** isNull is true if the property value WAS null + * + * Returns whether or not the property was null beforfe the setting + * happened. + */ + + SDO_API bool isNull() const; + + private: + + bool bisSet; + bool bisNull; + void* value; + const Property* theProp; + unsigned int length; + unsigned int index; + char* strbuf; + }; +}; +}; + +#endif diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SettingList.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SettingList.cpp new file mode 100644 index 0000000000..c966c4fc6f --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SettingList.cpp @@ -0,0 +1,115 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SDORuntimeException.h" + +#include "commonj/sdo/SettingList.h" +#include "commonj/sdo/Logger.h" +#include "commonj/sdo/Setting.h" + +namespace commonj{ +namespace sdo { + + +//SettingList::SettingList(SETTING_VECTOR p) : slist (p) +//{ +//} + +/*SettingList::SettingList(const SettingList &pin) +{ + Logger::log("SettingList copy constructor\n"); + slist = std::vector(pin.getVec()); +} +*/ + +SettingList::SettingList() +{ +} + +SettingList::~SettingList() +{ + while (slist.size() > 0) + { + Setting* s = slist[0]; + slist.erase(slist.begin()); + delete s; + } + +} + + +Setting& SettingList::operator[] (int pos) const +{ + validateIndex(pos); + return (*slist[pos]); +} + +Setting* SettingList::get(int pos) +{ + validateIndex(pos); + return (slist[pos]); +} + +int SettingList::size () const +{ + return slist.size(); +} + +//SETTING_VECTOR SettingList::getVec() const +//{ +// return slist; +//} + +void SettingList::insert (unsigned int index, Setting* d) +{ + slist.insert(slist.begin()+index, d); +} + +void SettingList::append ( Setting* d) +{ + slist.push_back(d); +} + +void SettingList::remove(unsigned int index) +{ + validateIndex(index); + const Setting* s = slist[index]; + slist.erase(slist.begin()+index); + delete s; + return; +} + +void SettingList::validateIndex(int index) const +{ + if ((index < 0) || (index > size())) + { + std::string msg("Index out of range:"); + msg += index; + SDO_THROW_EXCEPTION("ValidateIndex", SDOIndexOutOfRangeException, + msg.c_str()); + + } + +} + +}; +}; + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SettingList.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SettingList.h new file mode 100644 index 0000000000..1f34acea72 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SettingList.h @@ -0,0 +1,77 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef SETTINGLIST_H +#define SETTINGLIST_H + + + +#include +#include "commonj/sdo/Setting.h" + +namespace commonj{ +namespace sdo{ + +typedef std::vector< Setting*> SETTING_VECTOR; + +/** SettingList is a list of settings returned by a change summary + */ + +class SettingList +{ + +public: + //SettingList(SETTING_VECTOR sl); + SettingList(); + + virtual ~SettingList(); + + /** [] is the index operator + * + * This gives access to elements of the list + */ + + SDO_API virtual Setting& operator[] (int pos) const; + + /** size() returns the number of settings + * + * This method returns the size of the list os settings found. + * These may be creations, deletions or changes. + */ + + SDO_API virtual int size () const; + + virtual void insert (unsigned int index, Setting* d); + virtual void append ( Setting* d); + virtual void remove (unsigned int index); + virtual Setting* get (int pos); + + +private: + SETTING_VECTOR slist; + + void validateIndex(int index) const; +}; + +}; +}; + +#endif diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Type.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Type.cpp new file mode 100644 index 0000000000..d63a9ed7d2 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Type.cpp @@ -0,0 +1,38 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/Type.h" + +namespace commonj{ +namespace sdo{ + + + Type::~Type() + { + } + + const SDOString Type::SDOTypeNamespaceURI = "commonj.sdo"; + +}; +}; +// end - namespace sdo + + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Type.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Type.h new file mode 100644 index 0000000000..e0b56a12b9 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/Type.h @@ -0,0 +1,233 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _SDO_TYPE_H_ +#define _SDO_TYPE_H_ + + +#include "commonj/sdo/export.h" + +#include "commonj/sdo/PropertyList.h" +#include "commonj/sdo/SDOString.h" + + +namespace commonj{ +namespace sdo{ + + + + +class Property; + + /** + * + * Type is a representation of the type of a property of a data object. + */ + +class Type +{ + +public: + + +/** \enum Types + * + * This is the enumerator for all DataType types. All DataObjectType types + * appear as a Type::Types of DataObjectType. + * otherTypes, ChangeSumamryType and TextType are not used by client code. + */ + + + SDO_API enum Types + { + // Zero is a value for 'unknown type; - all data objects' + OtherTypes = 0, + BigDecimalType, + BigIntegerType, + BooleanType, + ByteType, + BytesType, + CharacterType, + DateType, + DoubleType, + FloatType, + IntegerType, + LongType, + ShortType, + StringType, + UriType, + DataObjectType, + ChangeSummaryType, + TextType, + OpenDataObjectType, + num_types + }; + + virtual SDO_API ~Type(); + + /** getName returns the name of the type + * + * This method returns a const char* name of the type. + */ + + virtual SDO_API const char* getName() const = 0; + + /** getAlias returns the n'th alias + * + * This method returns a const char* corresponding to the + * alias at index n of the list of aliases. Use getAliasCount to + * discover the size of the list. + */ + + virtual SDO_API const char* getAlias(unsigned int index = 0) const = 0; + + /** getAliasCount returns the number of aliases + * + * This method returns the number of aliases for this type + */ + + virtual SDO_API unsigned int getAliasCount() const = 0; + + /** getBaseType returns the base if there is one + * + * This method returns a const Type* corresponding to the + * base Type for this type. The base type is the one which + * this type inherits from. + */ + + virtual SDO_API const Type* getBaseType() const = 0; + + /** getURI returns the URI for this type + * + * This method returns the URI for this type. The URI may be + * null. + */ + + virtual SDO_API const char* getURI() const = 0; + + + + /** getProperties returns a list of properties for this type + * + * This method returns the list of properties for this type. + * Instances of open types may have more properties than appear + * in this list. + * See the propertylist API. + */ + + virtual SDO_API PropertyList getProperties() const = 0; + virtual SDO_API const std::list& getPropertyListReference() const = 0; + + + /** getProperty returns a property for this type + * + * This method returns a property, by index or by name + */ + + virtual SDO_API const Property& getProperty(const char* propertyName) const = 0; + virtual SDO_API const Property& getProperty(const SDOString& propertyName) const = 0; + virtual SDO_API const Property& getProperty(unsigned int index) const = 0; + + /** getPropertyIndex returns an index + * + * This method returns a property index for a named property + */ + + virtual SDO_API unsigned int getPropertyIndex(const char* propertyName) const = 0; + virtual SDO_API unsigned int getPropertyIndex(const SDOString& propertyName) const = 0; + + /** isDataObjectType true if not a DataType + * + * This method returns true if the type is not a DataType, and is therefore + * a DataObjectType with properties. + */ + + virtual SDO_API bool isDataObjectType() const = 0; + + + /** isSequencedType true if the type is sequenced + * + * This method returns true if the type is sequenced, and is therefore + * objects of this type can be manipulate via their sequence interface. + */ + + virtual SDO_API bool isSequencedType() const = 0; + + + /** isOpenType true if the type is open + * + * Normal types have a predefined list of properties. Trying to set + * properties which do not exist will cause an exception to be thrown. + * Open types, on the other hand, may have properties added to their + * instances runtime. These properties get added silently when setting a + * property value for a property which does not exist. + * Different instances of these objects may have different lists of + * open properties. + */ + + virtual SDO_API bool isOpenType() const = 0; + + /** isAbstractType true if the type is not instantiable. + * + * An abstract type may not be instantiated. It is useful only as + * a base type to some other non-abstract type. + */ + + virtual SDO_API bool isAbstractType() const = 0; + + /** isDataType true if the type is not an object. + * + * A DataType is anything which is not a DataObjectType. This method + * is the opposite of isDataObjectType(). + */ + + virtual SDO_API bool isDataType() const = 0; + + + /** isChangeSummaryType true if the type is a change summary. + * + * There is only one type called ChangeSummary. This method serves + * no purpose in the C++ implementation. + */ + + virtual SDO_API bool isChangeSummaryType() const = 0; + + /** getTypeEnum gets the enum for this type. + * + * Each DataType has a defined value in the list of Types. + */ + + virtual SDO_API Type::Types getTypeEnum() const = 0; + + /** equals compares uri and name. + * + * The types are equal if the URI and Name are equal. + */ + + virtual SDO_API bool equals(const Type& tother) const = 0; + + static SDO_API const SDOString SDOTypeNamespaceURI; +}; + +}; +}; +#endif //_SDO_TYPE_H_ + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinition.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinition.cpp new file mode 100644 index 0000000000..876dfbce29 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinition.cpp @@ -0,0 +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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/TypeDefinition.h" +#include "commonj/sdo/TypeDefinitionImpl.h" + +namespace commonj +{ + namespace sdo + { + TypeDefinition::TypeDefinition() + { + typedefinition = new TypeDefinitionImpl(); + } + + TypeDefinition::~TypeDefinition() + { + if (typedefinition != 0) delete typedefinition; + } + + void TypeDefinition::copy (const TypeDefinition& td) + { + if (typedefinition != 0) delete typedefinition; + typedefinition = new TypeDefinitionImpl(*(td.typedefinition)); + } + + TypeDefinition::TypeDefinition(const TypeDefinition& td) + { + copy(td); + } + + TypeDefinition& TypeDefinition::operator=(const TypeDefinition& td) + { + if (this != &td) + { + copy(td); + } + return *this; + } + + TypeDefinitionImpl* TypeDefinition::getTypeDefinition() + { + return typedefinition; + } + + void TypeDefinition::setUri(const char * inuri) + { + typedefinition->uri = inuri; + } + void TypeDefinition::setUri(const SDOString& inuri) + { + typedefinition->uri = inuri.c_str(); + } + + const char * TypeDefinition::getUri() const + { + return (const char *)typedefinition->uri; + } + + + void TypeDefinition::setName(const char * inname) + { + typedefinition->name = inname; + } + void TypeDefinition::setName(const SDOString& inname) + { + typedefinition->name = inname.c_str(); + } + + const char * TypeDefinition::getName() const + { + return (const char *)typedefinition->name; + } + + + void TypeDefinition::setLocalName(const char * inname) + { + typedefinition->localname = inname; + } + void TypeDefinition::setLocalName(const SDOString& inname) + { + typedefinition->localname = inname.c_str(); + } + + const char * TypeDefinition::getLocalName() const + { + return (const char *)typedefinition->localname; + } + + + void TypeDefinition::setAliases(const char * inaliases) + { + typedefinition->aliases = inaliases; + } + void TypeDefinition::setAliases(const SDOString& inaliases) + { + typedefinition->aliases = inaliases.c_str(); + } + + const char * TypeDefinition::getAliases() const + { + return (const char*)typedefinition->aliases; + } + + void TypeDefinition::setParentType(const char* uri, const char* name, + bool isrestriction) + { + typedefinition->parentTypeUri = uri; + typedefinition->parentTypeName = name; + typedefinition->isRestriction = isrestriction; + } + void TypeDefinition::setParentType(const SDOString& uri, + const SDOString& name, + bool isrestriction) + { + typedefinition->parentTypeUri = uri.c_str(); + typedefinition->parentTypeName = name.c_str(); + typedefinition->isRestriction = isrestriction; + } + + const char * TypeDefinition::getParentTypeUri() const + { + return (const char *)typedefinition->parentTypeUri; + } + + const char * TypeDefinition::getParentTypeName() const + { + return (const char *)typedefinition->parentTypeName; + } + + void TypeDefinition::setIDPropertyName(const char * idpropname) + { + typedefinition->IDPropertyName = idpropname; + } + void TypeDefinition::setIDPropertyName(const SDOString& idpropname) + { + typedefinition->IDPropertyName = idpropname.c_str(); + } + + const char * TypeDefinition::getIDPropertyName() const + { + return (const char *)typedefinition->IDPropertyName; + } + + void TypeDefinition::addPropertyDefinition(PropertyDefinition& p) + { + typedefinition->properties.push_back((PropertyDefinitionImpl&)(*(p.getPropertyDefinition()))); + } + + bool TypeDefinition::getIsDataType() const + { + return typedefinition->dataType; + } + + bool TypeDefinition::getIsOpen() const + { + return typedefinition->isOpen; + } + + bool TypeDefinition::getIsSequenced() const + { + return typedefinition->isSequenced; + } + + bool TypeDefinition::getIsAbstract() const + { + return typedefinition->isAbstract; + } + + bool TypeDefinition::getIsExtendedPrimitive() const + { + return typedefinition->isExtendedPrimitive; + } + + bool TypeDefinition::getIsFromList() const + { + return typedefinition->isFromList; + } + + bool TypeDefinition::getIsQName() const + { + return typedefinition->isQName; + } + + bool TypeDefinition::getIsMany() const + { + return typedefinition->isMany; + } + + void TypeDefinition::setIsDataType(bool value) + { + typedefinition->dataType = value; + } + + void TypeDefinition::setIsOpen(bool value) + { + typedefinition->isOpen = value; + } + + void TypeDefinition::setIsSequenced(bool value) + { + typedefinition->isSequenced = value; + } + + void TypeDefinition::setIsAbstract(bool value) + { + typedefinition->isAbstract = value; + } + + void TypeDefinition::setIsExtendedPrimitive(bool value) + { + typedefinition->isExtendedPrimitive = value; + } + + void TypeDefinition::setIsFromList(bool value) + { + typedefinition->isFromList = value; + } + + void TypeDefinition::setIsQName(bool value) + { + typedefinition->isQName = value; + } + + void TypeDefinition::setIsMany(bool value) + { + typedefinition->isMany = value; + } + + + int TypeDefinition::getGroupElementCount() const + { + return typedefinition->groupElementCount; + } + + + } // End - namespace sdo +} // End - namespace commonj diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinition.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinition.h new file mode 100644 index 0000000000..6e52e7bbf0 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinition.h @@ -0,0 +1,121 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _TYPEDefinition_H_ +#define _TYPEDefinition_H_ + +#include "export.h" + + +#include "commonj/sdo/PropertyDefinition.h" +#include "commonj/sdo/SDOString.h" +#include "list" + + +namespace commonj +{ + namespace sdo + { + + class TypeDefinitionImpl; + + +/** + * TypeDefinitionImpl holds information gathered from parsing the + * XSD and used for creating Types + */ + class SDO_API TypeDefinition + { + + public: + + + /*SDO_API*/ TypeDefinition(); + TypeDefinition(const TypeDefinition& td); + TypeDefinition& operator=(const TypeDefinition& td); + + /*SDO_API*/ virtual ~TypeDefinition(); + + + TypeDefinitionImpl* getTypeDefinition(); + + /*SDO_API*/ void setUri(const char * inuri) ; + /*SDO_API*/ void setUri(const SDOString& inuri) ; + + /*SDO_API*/ const char * getUri() const; + + /*SDO_API*/ void setName(const char * inname) ; + /*SDO_API*/ void setName(const SDOString& inname) ; + /*SDO_API*/ const char * getName() const; + + /*SDO_API*/ void setLocalName(const char * inname) ; + /*SDO_API*/ void setLocalName(const SDOString& inname) ; + /*SDO_API*/ const char * getLocalName() const; + + /*SDO_API*/ void setAliases(const char * inaliases) ; + /*SDO_API*/ void setAliases(const SDOString& inaliases) ; + /*SDO_API*/ const char * getAliases() const; + + + /*SDO_API*/ void setParentType(const char* uri, const char* name, + bool isrestriction); + /*SDO_API*/ void setParentType(const SDOString& uri, + const SDOString& name, + bool isrestriction); + /*SDO_API*/ const char * getParentTypeUri() const; + /*SDO_API*/ const char * getParentTypeName() const; + + /*SDO_API*/ void setIDPropertyName(const char * idpropname) ; + /*SDO_API*/ void setIDPropertyName(const SDOString& idpropname) ; + /*SDO_API*/ const char * getIDPropertyName() const; + + + /*SDO_API*/ void addPropertyDefinition(PropertyDefinition& p); + + /*SDO_API*/ bool getIsDataType() const; + /*SDO_API*/ bool getIsOpen() const; + /*SDO_API*/ bool getIsSequenced() const; + /*SDO_API*/ bool getIsAbstract() const; + /*SDO_API*/ bool getIsExtendedPrimitive() const; + /*SDO_API*/ bool getIsFromList() const; + /*SDO_API*/ bool getIsQName() const; + /*SDO_API*/ bool getIsMany() const; + + /*SDO_API*/ void setIsDataType(bool value); + /*SDO_API*/ void setIsOpen(bool value); + /*SDO_API*/ void setIsSequenced(bool value); + /*SDO_API*/ void setIsAbstract(bool value); + /*SDO_API*/ void setIsExtendedPrimitive(bool value); + /*SDO_API*/ void setIsFromList(bool value); + /*SDO_API*/ void setIsQName(bool value); + /*SDO_API*/ void setIsMany(bool value); + + /*SDO_API*/ int getGroupElementCount() const; + + private : + TypeDefinitionImpl *typedefinition; + void copy(const TypeDefinition& td); + }; + } // End - namespace sdo +} // End - namespace commonj + + +#endif //_TYPEDefinition_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitionImpl.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitionImpl.cpp new file mode 100644 index 0000000000..d593473ade --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitionImpl.cpp @@ -0,0 +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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/TypeDefinitionImpl.h" +namespace commonj +{ + namespace sdo + { + TypeDefinitionImpl::TypeDefinitionImpl() + : dataType(false), + isOpen(false), + isSequenced(false), + isMany(false), + isQName(false), + isAbstract(false), + groupElementCount(0), + isExtendedPrimitive(false), + isFromList(false) + { + } + + TypeDefinitionImpl::~TypeDefinitionImpl() + { + } + + } // End - namespace sdo +} // End - namespace commonj diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitionImpl.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitionImpl.h new file mode 100644 index 0000000000..2b608ad5ba --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitionImpl.h @@ -0,0 +1,83 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _TYPEDefinitionImpl_H_ +#define _TYPEDefinitionImpl_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/PropertyDefinitionImpl.h" +#include "list" + + +namespace commonj +{ + namespace sdo + { + + typedef std::list XmlDasPropertyDefs; + +/** + * TypeDefinitionImpl holds information gathered from parsing the + * XSD and used for creating Types + */ + class TypeDefinitionImpl + { + + public: + TypeDefinitionImpl(); + virtual ~TypeDefinitionImpl(); + + + SDOXMLString uri; + SDOXMLString name; + SDOXMLString localname; + + SDOXMLString aliases; + + SDOXMLString parentTypeUri; + SDOXMLString parentTypeName; + bool isRestriction; + + SDOXMLString IDPropertyName; + + bool dataType; + XmlDasPropertyDefs properties; + + bool isOpen; + bool isSequenced; + bool isAbstract; + + bool isExtendedPrimitive; + + bool isFromList; + + + bool isMany; + int groupElementCount; + + bool isQName; + }; + } // End - namespace sdo +} // End - namespace commonj + + +#endif //_TYPEDefinitionImpl_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitions.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitions.cpp new file mode 100644 index 0000000000..18cac60840 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitions.cpp @@ -0,0 +1,82 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + + +#include "commonj/sdo/TypeDefinitions.h" +#include "commonj/sdo/TypeDefinitionsImpl.h" + +namespace commonj +{ + namespace sdo + { + TypeDefinitions::TypeDefinitions() + { + typedefinitions = new TypeDefinitionsImpl(); + } + + TypeDefinitions::~TypeDefinitions() + { + if (typedefinitions != 0) delete typedefinitions; + } + + void TypeDefinitions::copy (const TypeDefinitions& tds) + { + if (typedefinitions != 0) delete typedefinitions; + typedefinitions = new TypeDefinitionsImpl(*(tds.typedefinitions)); + } + + TypeDefinitions::TypeDefinitions(const TypeDefinitions& tds) + { + copy(tds); + } + + TypeDefinitions::TypeDefinitions(const TypeDefinitionsImpl& tds) + { + typedefinitions = new TypeDefinitionsImpl(tds); + } + + void TypeDefinitions::addTypeDefinition(TypeDefinition& t) + { + if (typedefinitions == 0) + { + typedefinitions = new TypeDefinitionsImpl(); + } + + typedefinitions->types[ + typedefinitions->getTypeQName( + t.getUri(),t.getName())] = (TypeDefinitionImpl&)(*t.getTypeDefinition()); + } + + TypeDefinitionsImpl& TypeDefinitions::getTypeDefinitions() + { + if (typedefinitions == 0) + { + typedefinitions = new TypeDefinitionsImpl(); + } + return *typedefinitions; + } + + unsigned int TypeDefinitions::size() + { + return typedefinitions->types.size(); + } + } // End - namespace sdo +} // End - namespace commonj diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitions.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitions.h new file mode 100644 index 0000000000..1f5779044f --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitions.h @@ -0,0 +1,68 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _TYPEDefinitions_H_ +#define _TYPEDefinitions_H_ + + +#include "commonj/sdo/TypeDefinition.h" + +namespace commonj +{ + namespace sdo + { + + class TypeDefinitionsImpl; + +/** + * TypeDefinitionsImpl holds a list information gathered from parsing the + * XSD and used for creating Types + */ + class SDO_API TypeDefinitions + { + + public: + TypeDefinitions(); + TypeDefinitions(const TypeDefinitions& tds); + TypeDefinitions& operator=(const TypeDefinitions& tds); + + TypeDefinitions(const TypeDefinitionsImpl& tds); + + virtual ~TypeDefinitions(); + + void addTypeDefinition(TypeDefinition& t); + + TypeDefinitionsImpl& getTypeDefinitions(); + + unsigned int size(); + + protected: + TypeDefinitionsImpl* typedefinitions; + void copy(const TypeDefinitions& tds); + + friend class XSDHelperImpl; + + }; + } // End - namespace sdo +} // End - namespace commonj + + +#endif //_TYPEDefinitions_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitionsImpl.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitionsImpl.cpp new file mode 100644 index 0000000000..ae48c29f2c --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitionsImpl.cpp @@ -0,0 +1,51 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/TypeDefinitionsImpl.h" +namespace commonj +{ + namespace sdo + { + TypeDefinitionsImpl::TypeDefinitionsImpl() + { + } + + TypeDefinitionsImpl::~TypeDefinitionsImpl() + { + } + + void TypeDefinitionsImpl::addTypeDefinitions(const TypeDefinitionsImpl& typedefs) + { + XMLDAS_TypeDefs::const_iterator iter; + for (iter=typedefs.types.begin(); iter != typedefs.types.end(); iter++) + { + types.insert(*iter); + } + + } + + SDOXMLString TypeDefinitionsImpl::getTypeQName(const SDOXMLString& typeUri, const SDOXMLString& typeName) + { + return typeUri + "#" + typeName; + } + + } // End - namespace sdo +} // End - namespace commonj diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitionsImpl.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitionsImpl.h new file mode 100644 index 0000000000..c75c50db66 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeDefinitionsImpl.h @@ -0,0 +1,57 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _TYPEDefinitionsImpl_H_ +#define _TYPEDefinitionsImpl_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/TypeDefinitionImpl.h" +#include + +namespace commonj +{ + namespace sdo + { + typedef std::map XMLDAS_TypeDefs; + +/** + * TypeDefinitionsImpl holds a list information gathered from parsing the + * XSD and used for creating Types + */ + class TypeDefinitionsImpl + { + + public: + TypeDefinitionsImpl(); + virtual ~TypeDefinitionsImpl(); + void addTypeDefinitions(const TypeDefinitionsImpl& types); + static SDOXMLString getTypeQName(const SDOXMLString& typeUri, const SDOXMLString& typeName); + + + XMLDAS_TypeDefs types; + + }; + } // End - namespace sdo +} // End - namespace commonj + + +#endif //_TYPEDefinitionsImpl_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeImpl.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeImpl.cpp new file mode 100644 index 0000000000..3ac561f1b4 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeImpl.cpp @@ -0,0 +1,4077 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/Logger.h" + +#include "commonj/sdo/PropertyImpl.h" +#include "commonj/sdo/TypeImpl.h" + +#include +#include +#include +#include +using namespace std; + +#include +#include +using namespace std; + +#include "commonj/sdo/SDORuntimeException.h" + +namespace commonj{ +namespace sdo{ + + + + char* TypeImpl::types[num_types] = { + "Other Types", + "BigDecimal", + "BigInteger", + "Boolean" , + "Byte", + "Bytes", + "Character", + "Date" , + "Double" , + "Float" , + "Integer" , + "Long" , + "Short" , + "String" , + "URI" , + "DataObject", + "ChangeSummary", + "Text", + "OpenDataObject" + }; + + + /////////////////////////////////////////////////////////////////////////// + // + /////////////////////////////////////////////////////////////////////////// + + void TypeImpl::addChangeSummary(void) + { + changeSummaryType = true; + } + + bool TypeImpl::isChangeSummaryType() const + { + return changeSummaryType; + } + + + /////////////////////////////////////////////////////////////////////////// + // + /////////////////////////////////////////////////////////////////////////// + + bool TypeImpl::isFromList() const + { + return bFromList; + } + /////////////////////////////////////////////////////////////////////////// + // + /////////////////////////////////////////////////////////////////////////// + + bool TypeImpl::isDataType(void) const + { + return isPrimitive; + } + + /////////////////////////////////////////////////////////////////////////// + // + /////////////////////////////////////////////////////////////////////////// + + TypeImpl::TypeImpl(const TypeImpl& t) + { + isResolving = false; + isResolved = false; + brestriction = t.brestriction; + bFromList = t.bFromList; + } + + TypeImpl::TypeImpl(const Type* base, const char* uri, + const char* inname, + bool isSeq, + bool isOp, + bool isAbs, + bool isData, + bool isRestriction) + { + init(uri,inname,isSeq,isOp, isAbs, isData); + setBaseType(base, isRestriction); + bFromList = false; + } + + TypeImpl::TypeImpl(const char* uri, const char* inname, + bool isSeq, + bool isOp, + bool isAbs, + bool isData, + bool isFromList) + + { + init(uri,inname,isSeq,isOp,isAbs, isData); + baseType = 0; + brestriction = false; + bFromList= false; + bFromList = isFromList; + } + + void TypeImpl::init(const char* uri, const char* inname, + bool isSeq, + bool isOp, + bool isAbs, + bool isData) + { + isResolving = false; + isResolved = false; + localPropsSize = 0; + changeSummaryType = false; + isSequenced = isSeq; + isOpen = isOp; + isOpenImplicitly = false; + isAbstract = isAbs; + isPrimitive = isData; + name = new char[strlen(inname)+1]; + strcpy(name,inname); + + if (uri == 0) + { + typeURI = new char[1]; + typeURI[0] = 0; + typeEnum = DataObjectType; + return; + } + + typeURI = new char[strlen(uri)+1]; + strcpy(typeURI,uri); + + if (!strcmp(uri,Type::SDOTypeNamespaceURI.c_str())) { + for (int i = 0; i < num_types ; i++) { + if (!strcmp(inname,types[i])) { + typeEnum = (Types)i; + if (i <= UriType) isPrimitive = true; + // Note - you could create Text, but it would + // not be recognised as primitive. + return; + } + } + } + + // All other types are data object types - for now + typeEnum = DataObjectType; + } + + + /////////////////////////////////////////////////////////////////////////// + // + /////////////////////////////////////////////////////////////////////////// + TypeImpl::TypeImpl() + { + } + + /////////////////////////////////////////////////////////////////////////// + // + /////////////////////////////////////////////////////////////////////////// + + TypeImpl::~TypeImpl() + { + // Types free their corresponding properties, but not the types + // of those properties + // Need to free only those we allocated + unsigned int count = 0, start = props.size() - localPropsSize; + std::list::iterator i; + for (i= props.begin(); i != props.end() ; ++i) + { + if (count >= start) { + delete(*i); + } + count++; + } + if (name != 0) + { + delete[] name; + } + + if (typeURI != 0) + { + delete[] typeURI; + } + for (unsigned int j = 0; j < aliases.size();j++) + { + delete[] aliases[j]; + } + } + + /////////////////////////////////////////////////////////////////////////// + // Sets a data type as sequenced. + /////////////////////////////////////////////////////////////////////////// + + void TypeImpl::setSequenced(bool set) + { + isSequenced = set; + } + + /////////////////////////////////////////////////////////////////////////// + // Sets a data type as open. + /////////////////////////////////////////////////////////////////////////// + + void TypeImpl::setOpen(bool set) + { + isOpen = set; + isOpenImplicitly = false; // explicitly set as open + } + + bool TypeImpl::isBaseTypeOf(const Type* type) const + { + return type + && (this == type || isBaseTypeOf(type->getBaseType())); + } + + /////////////////////////////////////////////////////////////////////////// + // Sets a data type as open. + /////////////////////////////////////////////////////////////////////////// + + void TypeImpl::setBaseType(const Type* bt, bool isRestriction) + { + if (isBaseTypeOf(bt)) + { + SDOString stringBuffer = getName(); + stringBuffer += "\tis base type of\t"; + stringBuffer += bt->getName(); + SDO_THROW_EXCEPTION(setBaseType, SDOIllegalArgumentException, stringBuffer.c_str()) + } + + baseType = (TypeImpl*)bt; + brestriction = isRestriction; + + // DataType and Sequenced must be the same as the base Type + isPrimitive = baseType->isPrimitive; + if (isPrimitive) + { + typeEnum = baseType->typeEnum; + } + + // Removing the following and allowing "sequenced" to be inherited from base type + /* + if (isSequenced && !baseType->isSequenced) + { + // Its an error to be sequenced and inherit from a + // non-sequenced type + string msg("Cannot be sequenced and inherit from a non-sequenced base type:"); + msg += getURI(); + msg += " "; + msg += getName(); + SDO_THROW_EXCEPTION("setBaseType", + SDOUnsupportedOperationException, + msg.c_str()); + } + */ + + isSequenced = baseType->isSequenced; + + // if the base is open then this type must be open too. + if (baseType->isOpenType() && !isOpen) + { + isOpen = true; + isOpenImplicitly = true; + } + } + + bool TypeImpl::equals(const Type& tother) const + { + if (strcmp(typeURI,tother.getURI())) return false; + // TODO - aliases + if (strcmp(name, tother.getName())) return false; + return true; + } + + + const Type* TypeImpl::getBaseType() const + { + return (Type*)baseType; + } + + const TypeImpl* TypeImpl::getBaseTypeImpl() const + { + return baseType; + } + + /////////////////////////////////////////////////////////////////////////// + // Returns the name of the type. + /////////////////////////////////////////////////////////////////////////// + + const char* TypeImpl::getName() const + { + return name; + } + + void TypeImpl::setAlias(const char* alias) + { + char* tmp = new char[strlen(alias)+1]; + strcpy(tmp,alias); + aliases.push_back(tmp); + } + + + + + const char* TypeImpl::getAlias(unsigned int index) const + { + if (index < aliases.size()) + { + return aliases[index]; + } + return name; + } + + unsigned int TypeImpl::getAliasCount() const + { + return aliases.size(); + } + /////////////////////////////////////////////////////////////////////////// + // Returns the namespace URI of the type. + /////////////////////////////////////////////////////////////////////////// + const char* TypeImpl::getURI() const + { + return typeURI; + } + + void TypeImpl::throwIfNestedChangeSummary() const + { + PROPERTY_LIST::const_iterator i; + for (i = props.begin(); i != props.end(); ++i) + { + + const TypeImpl *t = ((*i)->getTypeImpl()); + if (t != 0) + { + if (t->isDataObjectType()) + { + if (t->isChangeSummaryType()) + { + string msg(" Nested change summary type:"); + msg += t->getURI(); + msg += " "; + msg += t->getName(); + SDO_THROW_EXCEPTION("resolve", + SDOUnsupportedOperationException, + msg.c_str()); + } + t->throwIfNestedChangeSummary(); + } + } + } + } + + void TypeImpl::validateChangeSummary() + { + if (!isChangeSummaryType()) return; + throwIfNestedChangeSummary(); + } + + PROPERTY_LIST TypeImpl::getCompoundProperties() + { + return props; + } + + void TypeImpl::initCompoundProperties() + { + // We have already met this type in the resolution heirarchy + if (isResolving) + { + string msg(" circular type dependency on:"); + msg += getURI(); + msg += " "; + msg += getName(); + + SDO_THROW_EXCEPTION("initCompoundProperties", + SDOUnsupportedOperationException, + msg.c_str()); + } + + if (isResolved) + { + return; + } + + isResolving = true; + + + if (baseType != 0) + { + baseType->initCompoundProperties(); + PROPERTY_LIST pl = baseType->getCompoundProperties(); + localPropsSize = props.size(); + + // spec says the properties which are common are taken from + // the superclass. I imagine this will change , and only the + // ones taken from the subclass will be used. + + if (brestriction) + { + // restrict the properties to only those which + // appear in the parent + std::list::iterator p1,p; + for (p=pl.begin();p!=pl.end();++p) + { + for (p1=props.begin();p1!=props.end();++p1) + { + if (!strcmp((*p1)->getName(), + (*p)->getName())) + { + props.erase(p1); + localPropsSize = props.size(); + break; + } + } + } + + } + + props.insert(props.begin(),pl.begin(), pl.end()); + + isPrimitive = !(baseType->isDataObjectType()); + } + if (isPrimitive && (props.size() > 0)) + { + string msg("Add property to data type:"); + msg += getURI(); + msg += " "; + msg += getName(); + SDO_THROW_EXCEPTION("initCompoundProperties", + SDOUnsupportedOperationException, + msg.c_str()); + } + isResolved = true; + isResolving = false; + return; + } + + + /////////////////////////////////////////////////////////////////////////// + // Returns the list of the properties of this type. + /////////////////////////////////////////////////////////////////////////// + PropertyList TypeImpl::getProperties() const + { + return props; + } + + const std::list& TypeImpl::getPropertyListReference() const + { + return props; + } + + unsigned int TypeImpl::getPropertiesSize() const + { + return props.size(); + } + + /////////////////////////////////////////////////////////////////////////// + // Returns the property with the specified name. + /////////////////////////////////////////////////////////////////////////// + const Property& TypeImpl::getProperty(const char* propertyName) const + { + PropertyImpl* pi = getPropertyImpl(propertyName); + if (pi == 0) + { + string msg("Property not found:"); + msg += propertyName; + SDO_THROW_EXCEPTION("getProperty", + SDOPropertyNotFoundException, msg.c_str()); + } + return (Property&)*pi; + } + const Property& TypeImpl::getProperty(const SDOString& propertyName) const + { + PropertyImpl* pi = getPropertyImpl(propertyName); + if (pi == 0) + { + string msg("Property not found:"); + msg += propertyName; + SDO_THROW_EXCEPTION("getProperty", + SDOPropertyNotFoundException, msg.c_str()); + } + return (Property&)*pi; + } + + + /////////////////////////////////////////////////////////////////////////// + // Substitute Support - get the real underlying type + /////////////////////////////////////////////////////////////////////////// + + const Type& TypeImpl::getRealPropertyType(const std::string& propertyName) const + { + const TypeImpl* ti = getRealPropertyTypeImpl(propertyName); + if (ti != 0)return (Type&)*ti; + + string msg("Property not found:"); + msg += propertyName; + SDO_THROW_EXCEPTION("getProperty", + SDOPropertyNotFoundException, msg.c_str()); + + } + + + const TypeImpl* TypeImpl::getRealPropertyTypeImpl(const std::string& propertyName) const + { + + std::list::const_iterator i; + for (i = props.begin(); i != props.end(); ++i) + { + if (propertyName == (*i)->getName()) + { + return ((*i)->getTypeImpl()); + } + for (unsigned int k=0;k < (*i)->getAliasCount(); k++) + { + if (propertyName == (*i)->getAlias(k)) + { + return ((*i)->getTypeImpl()); + } + } + for (unsigned int j=0;j < (*i)->getSubstitutionCount(); j++) + { + if (propertyName == (*i)->getSubstitutionName(j)) + { + return (TypeImpl*)(*i)->getSubstitutionType(j); + } + } + } + return 0; + } + + /////////////////////////////////////////////////////////////////////////// + // Returns the property with the specified name. + /////////////////////////////////////////////////////////////////////////// + + PropertyImpl* TypeImpl::getPropertyImpl(const SDOString& propertyName) const + { + + // Extension - find the property from an xpath + // you should not be able to have both "." and "[" before a "/" - this is assumed. + + if (propertyName.length() == 0) return 0; + + // strchr returns NULL if target not found + // find_first_of returns string::npos in that case + // find_first_of returns the subscript of the character found eg 0 if it is the first + size_t tokenend = propertyName.find_first_of('/'); + size_t bracket = propertyName.find_first_of('['); + size_t dot = propertyName.find_first_of('.'); + size_t dotOrBracketOrSlash = propertyName.find_first_of(".[/"); + SDOString copy; + // char* copy; + + int len = propertyName.length(); + if (dotOrBracketOrSlash != string::npos) + { + len = dotOrBracketOrSlash; + } + + if (len != 0) + { + copy.assign(propertyName, 0, len); + } + else + { + copy = propertyName; + } + + std::list::const_iterator i; + for (i = props.begin(); i != props.end(); ++i) + { + if (!strcmp(copy.c_str(),(*i)->getName())) // ie the two strings are the same + { + // delete copy; + if ((tokenend != string::npos) && (propertyName.length() - tokenend) > 1) + { + // There is someting to the right of the "/" + const TypeImpl* ti = (*i)->getTypeImpl(); + if (ti != 0) + { + PropertyImpl* p = ti->getPropertyImpl(SDOString(propertyName, tokenend + 1, string::npos)); + return p; + } + else + { + return (PropertyImpl*)(*i); + } + } + else { + return (PropertyImpl*)(*i); + } + } + + for (unsigned int j = 0; j < (*i)->getSubstitutionCount(); j++) + { + if (!strcmp(copy.c_str(), (*i)->getSubstitutionName(j))) // ie the two strings are the same + { + // delete copy; + if ((tokenend != string::npos) && (propertyName.length() - tokenend) > 1) + { + // There is someting to the right of the "/" + const TypeImpl* ti = (*i)->getTypeImpl(); + if (ti != 0) + { + // PropertyImpl* p = ti->getPropertyImpl((const char *)(tokenend+1)); + PropertyImpl* p = ti->getPropertyImpl(SDOString(propertyName, tokenend + 1, string::npos)); + return p; + } + else + { + return (PropertyImpl*)(*i); + } + } + else { + return (PropertyImpl*)(*i); + } + } + } + for (unsigned int k = 0; k < (*i)->getAliasCount(); k++) + { + if (!strcmp(copy.c_str(), (*i)->getAlias(k))) // ie the two strings are the same + { + // delete copy; + if ((tokenend != string::npos) && (propertyName.length() - tokenend) > 1) + { + const TypeImpl* ti = (*i)->getTypeImpl(); + if (ti != 0) + { + // PropertyImpl* p = ti->getPropertyImpl((const char *)(tokenend+1)); + PropertyImpl* p = ti->getPropertyImpl(SDOString(propertyName, tokenend + 1, string::npos)); + return p; + } + else + { + return (PropertyImpl*)(*i); + } + } + else { + return (PropertyImpl*)(*i); + } + } + } + } + return 0; + } + + /////////////////////////////////////////////////////////////////////////// + // Returns the property with the specified name. + /////////////////////////////////////////////////////////////////////////// + PropertyImpl* TypeImpl::getPropertyImplPure(const char* propertyName) const + { + + + std::list::const_iterator i; + for (i = props.begin(); i != props.end(); ++i) + { + if (!strcmp(propertyName,(*i)->getName())) + { + return (PropertyImpl*)(*i); + } + for (unsigned int k=0;k < (*i)->getAliasCount(); k++) + { + if (!strcmp(propertyName,(*i)->getAlias(k))) + { + return (PropertyImpl*)(*i); + } + } + } + return 0; + } + + + /////////////////////////////////////////////////////////////////////////// + // Returns the property index with the specified name. + /////////////////////////////////////////////////////////////////////////// + unsigned int TypeImpl::getPropertyIndex(const char* propertyName) const + { + return getPropertyIndex(SDOString(propertyName)); + } + unsigned int TypeImpl::getPropertyIndex(const SDOString& propertyName) const + { + std::list::const_iterator i; + int j = 0; + for (i = props.begin(); i != props.end(); ++i) + { + if (!strcmp(propertyName.c_str(), (*i)->getName())) + { + return j; + } + j++; + } + string msg("Property not found:"); + msg += propertyName; + SDO_THROW_EXCEPTION("getPropertyIndex", + SDOPropertyNotFoundException, msg.c_str()); + } + + /////////////////////////////////////////////////////////////////////////// + // Returns the property with the specified name. + /////////////////////////////////////////////////////////////////////////// + const Property& TypeImpl::getProperty(unsigned int index) const + { + PropertyImpl* pi = getPropertyImpl(index); + if (pi == 0) + { + string msg("Property not found for index:"); + msg += index; + SDO_THROW_EXCEPTION("getProperty" , + SDOPropertyNotFoundException, msg.c_str()); + } + return (Property&)*pi; + } + + /////////////////////////////////////////////////////////////////////////// + // Returns the property with the specified index. + /////////////////////////////////////////////////////////////////////////// + PropertyImpl* TypeImpl::getPropertyImpl(unsigned int index) const + { + std::list::const_iterator i; + int count = 0; + for (i = props.begin() ; i != props.end() ; ++i) + { + if (count == index)return (PropertyImpl*)(*i); + count++; + } + return 0; + } + + + /////////////////////////////////////////////////////////////////////////// + // Returns the property with the specified name. + /////////////////////////////////////////////////////////////////////////// + void TypeImpl::addProperty(const char* propname, + const TypeImpl& t, + bool many, bool rdonly, bool cont) + { + // do not add duplicate properties + if (!getPropertyImplPure(propname)) + { + props.push_back(new PropertyImpl(*this, + propname, + t, + many, + rdonly, + cont)); + localPropsSize++; + } + } + + /////////////////////////////////////////////////////////////////////////// + // Indicates if this Type specifies DataObjects.. + /////////////////////////////////////////////////////////////////////////// + bool TypeImpl::isDataObjectType() const + { + return !isPrimitive; + } + + /////////////////////////////////////////////////////////////////////////// + // Indicates if this Type specifies Sequenced DataObjects. + /////////////////////////////////////////////////////////////////////////// + bool TypeImpl::isSequencedType() const + { + return isSequenced; + } + + /////////////////////////////////////////////////////////////////////////// + // Indicates if this Type allows any form of open content. + /////////////////////////////////////////////////////////////////////////// + bool TypeImpl::isOpenType() const + { + /* TODO - handle open types */ + return isOpen; + } + + bool TypeImpl::isOpenTypeImplicitly() const + { + return isOpenImplicitly; + } + + /////////////////////////////////////////////////////////////////////////// + // Indicates if this type may not be instantiated. + /////////////////////////////////////////////////////////////////////////// + bool TypeImpl::isAbstractType() const + { + return isAbstract; + } + + void TypeImpl::setAbstract(bool set) + { + isAbstract = set; + } + + /////////////////////////////////////////////////////////////////////////// + // TODO - override ==. + /////////////////////////////////////////////////////////////////////////// + bool TypeImpl::equals(const Type& t) + { + return ( strcmp(getName(),t.getName()) == 0 + && strcmp(getURI (),t.getURI ()) == 0 ); + } + + /////////////////////////////////////////////////////////////////////////// + // getTypeEnum. + /////////////////////////////////////////////////////////////////////////// + Type::Types TypeImpl::getTypeEnum(void) const + { + return typeEnum; + } + + + /////////////////////////////////////////////////////////////////////////// + // Conversions. + // convert is used in the process of setting a value. The input is the + // result of a setXXX, so in the first case setBoolean. The typeEnum is the + // type of the value being set and governs the expected final result in + // the value* buffer. + /////////////////////////////////////////////////////////////////////////// + + unsigned int TypeImpl::convert(void** value,const bool b) const + { + switch (typeEnum) + { + case BooleanType: + case ByteType: + case CharacterType: + case IntegerType: + case ShortType: + if (*value != 0)delete (char*)(*value); + *value = new char[sizeof(long)]; + *(long*)*value = (long)b; + return sizeof(long); + + case LongType: + if (*value != 0)delete (char*)(*value); + *value = new char[sizeof(int64_t)]; + *(int64_t*)*value = (int64_t)b; + return sizeof(int64_t); + + case BigDecimalType: + case BigIntegerType: + case StringType: + case UriType: + if (*value != 0)delete (char*)(*value); + // spec change - types + *value = new wchar_t[6]; + if (b) + { + ((wchar_t*)(*value))[0] = (wchar_t)'t'; + ((wchar_t*)(*value))[1] = (wchar_t)'r'; + ((wchar_t*)(*value))[2] = (wchar_t)'u'; + ((wchar_t*)(*value))[3] = (wchar_t)'e'; + ((wchar_t*)(*value))[4] = 0; + return 4; + } + else + { + ((wchar_t*)(*value))[0] = (wchar_t)'f'; + ((wchar_t*)(*value))[1] = (wchar_t)'a'; + ((wchar_t*)(*value))[2] = (wchar_t)'l'; + ((wchar_t*)(*value))[3] = (wchar_t)'s'; + ((wchar_t*)(*value))[4] = (wchar_t)'e'; + ((wchar_t*)(*value))[5] = 0; + return 5; + } + break; + + + case BytesType: + { + if (*value != 0)delete (char*)(*value); + // spec change - types + *value = new char[6]; + if (b) + { + strcpy((char*)*value, "true"); + return 4; + } + else + { + strcpy((char*)*value, "false"); + return 5; + } + break; + + } + + case DoubleType: + case FloatType: + case DateType: + case OtherTypes: + case DataObjectType: + case ChangeSummaryType: + default: + { + string msg("Cannot set Boolean on object of type:"); + msg += getName(); + SDO_THROW_EXCEPTION("setBoolean" , + SDOInvalidConversionException, msg.c_str()); + break; + } + } + return 0; + } + + unsigned int TypeImpl::convert(void** value,const char c) const + { +#if __WORDSIZE ==64 + return convert(value,(int64_t)c); +#else + return convert(value,(long)c); +#endif + } + + unsigned int TypeImpl::convert(void** value,const wchar_t c) const + { +#if __WORDSIZE ==64 + return convert(value,(int64_t)c); +#else + return convert(value,(long)c); +#endif + } + + // This is set CString... + unsigned int TypeImpl::convert(void** value,const char* c) const + { + + switch (typeEnum) + { + case BooleanType: + if (*value != 0)delete ((char*)*value); + *value = new char[sizeof(long)]; + if ((c == 0) || strcmp(c,"true")) + { + *(long*)*value = 0; + } + else + { + *(long*)*value = 1; + } + return sizeof(long); + + case ByteType: + case CharacterType: + case IntegerType: + case ShortType: + if (*value != 0) delete ((char*)*value); + *value = new char[sizeof(long)]; + *(long*)*value = atoi(c); + return sizeof(long); + + case DoubleType: + if (*value != 0) delete ((char*)*value); + *value = new char[sizeof(long double)]; + // TODO - atof not suitable here + *(long double*)*value = (long double)atof(c); + return sizeof(long double); + + case FloatType: + if (*value != 0) delete ((char*)*value); + *value = new char[sizeof(float)]; + *(float*)*value = (float)atof(c); + return sizeof(float); + + case LongType: + if (*value != 0) delete ((char*)*value); + *value = new char[sizeof(int64_t)]; +#if defined(WIN32) || defined (_WINDOWS) + *(int64_t*)*value = (int64_t)_atoi64(c); +#else + *(int64_t*)*value = (int64_t)strtoll(c, NULL, 0); +#endif + return sizeof(int64_t); + + case DateType: + if (*value != 0) delete ((char*)*value); + *value = new char[sizeof(time_t)]; + *(time_t*)*value = (time_t)atoi(c); + return sizeof(time_t); + + case BigDecimalType: + case BigIntegerType: + case StringType: + case UriType: + { + if (*value != 0) delete ((wchar_t*)*value); + wchar_t* vw = new wchar_t[strlen(c)+1]; + for (unsigned int i=0;i< strlen(c);i++) + { + vw[i] = (wchar_t)c[i]; + } + vw[strlen(c)] = 0; + *value = (void*)vw; + return strlen(c); + } + break; + case BytesType: + { + if (*value != 0) delete ((char*)*value); + char* vc = new char[strlen(c)+1]; + for (unsigned int i=0;i< strlen(c);i++) + { + vc[i] = (char)c[i]; + } + vc[strlen(c)] = 0; + *value = (void*)vc; + return strlen(c); + } + break; + + case OtherTypes: + case DataObjectType: + case ChangeSummaryType: + default: + { + string msg("Cannot set CString on object of type:"); + msg += getName(); + SDO_THROW_EXCEPTION("setString" , + SDOInvalidConversionException, msg.c_str()); + break; + } + } + return 0; + } + + // +++ + + // This is set CString... + // The value supplied in s is converted and written to value. + unsigned int TypeImpl::convert(void** value, const SDOString& c) const + { + switch (typeEnum) + { + case BooleanType: + if (*value != 0) delete ((char*) *value); + *value = new char[sizeof(long)]; + + if (c == "true") + { + *(long*)*value = 0; + } + else + { + *(long*)*value = 1; + } + return sizeof(long); + + case ByteType: + case CharacterType: + case IntegerType: + case ShortType: + if (*value != 0) delete ((char*)*value); + + *value = new char[sizeof(long)]; + *(long*)*value = atoi(c.c_str()); + return sizeof(long); + + case DoubleType: + if (*value != 0) delete ((char*)*value); + + *value = new char[sizeof(long double)]; + // TODO - atof not suitable here + *(long double*)*value = (long double)atof(c.c_str()); + return sizeof(long double); + + case FloatType: + if (*value != 0) delete ((char*)*value); + + *value = new char[sizeof(float)]; + *(float*)*value = (float)atof(c.c_str()); + return sizeof(float); + + case LongType: + if (*value != 0) delete ((char*)*value); + + *value = new char[sizeof(int64_t)]; +#if defined(WIN32) || defined (_WINDOWS) + *(int64_t*)*value = (int64_t)_atoi64(c.c_str()); +#else + *(int64_t*)*value = (int64_t)strtoll(c.c_str(), NULL, 0); +#endif + return sizeof(int64_t); + + case DateType: + if (*value != 0) delete ((char*)*value); + *value = new char[sizeof(time_t)]; + *(time_t*)*value = (time_t)atoi(c.c_str()); + return sizeof(time_t); + + case BigDecimalType: + case BigIntegerType: + case StringType: + case UriType: + { + if (*value != 0) delete ((wchar_t*)*value); + wchar_t* vw = new wchar_t[c.length() + 1]; + for (unsigned int i = 0; i < c.length(); i++) + { + vw[i] = (wchar_t)c[i]; + } + vw[c.length()] = 0; + *value = (void*)vw; + return c.length(); + } + break; + case BytesType: + { + if (*value != 0) delete ((char*)*value); + char* vc = new char[c.length() + 1]; + for (unsigned int i = 0; i < c.length(); i++) + { + vc[i] = (char)c[i]; + } + vc[c.length()] = 0; + *value = (void*)vc; + return c.length(); + } + break; + + case OtherTypes: + case DataObjectType: + case ChangeSummaryType: + default: + { + string msg("Cannot set CString on object of type:"); + msg += getName(); + SDO_THROW_EXCEPTION("setString" , + SDOInvalidConversionException, msg.c_str()); + break; + } + } + return 0; + } + + + // --- + + // setString + unsigned int TypeImpl::convert(void** value,const wchar_t* b, unsigned int len) const + { + unsigned int i; + switch (typeEnum) + { + case BigDecimalType: + case BigIntegerType: + case UriType: + case StringType: + { + if (*value != 0) delete ((wchar_t*)*value); + wchar_t* vw = new wchar_t[len+1]; + for (i=0;i 4) + { + *(long*)*value = 0; + } + else + { + if (b[0] == (wchar_t)'t' && + b[1] == (wchar_t)'r' && + b[2] == (wchar_t)'u' && + b[3] == (wchar_t)'e' ) + *(long*)*value = 1; + else *(long*)*value = 0; + } + return sizeof(long); + + case CharacterType: + case ByteType: + if (*value != 0)delete ((char*)*value); + *value = new char[sizeof(long)]; + if (len > 0) + { + *(long*)*value = (long)b[0]; + } + else + { + *(long*)*value = (long)0; + } + return sizeof(long); + + case ShortType: + case IntegerType: + { + if (*value != 0)delete ((char*)*value); + *value = new char[sizeof(long)]; + int val = 0; + for (unsigned int j=0;j 4) + { + *(long*)*value = 0; + } + else + { + if (b[0] == (char)'t' && + b[1] == (char)'r' && + b[2] == (char)'u' && + b[3] == (char)'e' ) + *(long*)*value = 1; + else *(long*)*value = 0; + } + return sizeof(long); + + case ByteType: + case CharacterType: + if (*value != 0)delete ((char*)*value); + *value = new char[sizeof(long)]; + if (len > 0) + { + *(long*)*value = (long)b[0]; + } + else + { + *(long*)*value = (long)0; + } + return sizeof(long); + + case IntegerType: + case ShortType: + { + if (*value != 0)delete ((char*)*value); + *value = new char[sizeof(long)]; + int val = 0; + for (unsigned int j=0;j 4) + { + *(long*)*value = 0; + } + else + { + if (b == "true") + *(long*)*value = 1; + else *(long*)*value = 0; + } + return sizeof(long); + + case ByteType: + case CharacterType: + if (*value != 0)delete ((char*)*value); + *value = new char[sizeof(long)]; + if (len > 0) + { + *(long*)*value = (long)b[0]; + } + else + { + *(long*)*value = (long)0; + } + return sizeof(long); + + case IntegerType: + case ShortType: + { + if (*value != 0)delete ((char*)*value); + *value = new char[sizeof(long)]; + int val = 0; + for (unsigned int j=0;jmax?max:len; + } + case BytesType: + { + if (value == 0) return 0; + char* tmp = (char*)value; + for (i=0;(i < len) && (i < max);i++) + { + outval[i] = (wchar_t)(tmp[i]); + } + return len>max?max:len; + } + + case BooleanType: + { + if (max < 4) return 0; + if (value == 0 || *(long*)value == 0) { + if (max < 5) return 0; + outval[0] = (wchar_t)'f'; + outval[1] = (wchar_t)'a'; + outval[2] = (wchar_t)'l'; + outval[3] = (wchar_t)'s'; + outval[4] = (wchar_t)'e'; + return 5; + } + else + { + outval[0] = (wchar_t)'t'; + outval[1] = (wchar_t)'r'; + outval[2] = (wchar_t)'u'; + outval[3] = (wchar_t)'e'; + return 4; + } + } + + case ByteType: + { + if (value == 0) return 0; + long tmp = *(long*)value; + outval[0] = (wchar_t)(tmp&0xFF); + return 1; + } + + case CharacterType: + { + if (value == 0) return 0; + long tmp = *(long*)value; + outval[0] = (wchar_t)(tmp & 0xFFFF); + return 1; + } + + case ShortType: + case IntegerType: + { + if (value == 0) return 0; + long tmp = *(long*)value; +#if defined(WIN32) || defined (_WINDOWS) + wchar_t* tmpstr = new wchar_t[MAX_LONG_SIZE]; + _ltow(tmp,tmpstr,10); + if (wcslen(tmpstr) > max) return 0; + _ltow(tmp,outval,10); + return wcslen(outval); +#else + sprintf(tmpstr, "%ld", tmp); + if (strlen(tmpstr) > max) return 0; + for (j=0; j< strlen(tmpstr); j++) + { + outval[j] = (wchar_t)tmpstr[j]; + } + delete tmpstr; + return j; +#endif + } + + + case LongType: + { + if (value == 0) return 0; + int64_t tmp = *(int64_t*)value; +#if defined(WIN32) || defined (_WINDOWS) + wchar_t* tmpstr = new wchar_t[MAX_LONG_SIZE]; + _i64tow(tmp,tmpstr,10); + if (wcslen(tmpstr) > max) + { + delete tmpstr; + return 0; + } + _i64tow(tmp,outval,10); + return wcslen(outval); +#else + sprintf(tmpstr, "%lld", tmp); + if (strlen(tmpstr) > max) return 0; + for (j=0; j< strlen(tmpstr); j++) + { + outval[j] = (wchar_t)tmpstr[j]; + } + delete tmpstr; + return j; +#endif + } + + case DateType: + { + + if (value == 0) return 0; + string msg("Conversion to string not implemented from type:"); + msg += getName(); + SDO_THROW_EXCEPTION("getString" , + SDOInvalidConversionException, msg.c_str()); + break; + } + + case DoubleType: + { + if (value == 0) return 0; + if (max < MAX_DOUBLE_SIZE) return 0; + wchar_t* fmt = new wchar_t[5]; + fmt[0] = (wchar_t)'%'; + fmt[1] = (wchar_t)'.'; + fmt[2] = (wchar_t)'3'; + fmt[3] = (wchar_t)'e'; + fmt[4] = (wchar_t)0; +#if defined(WIN32) || defined (_WINDOWS) + swprintf((wchar_t*)outval,fmt,*(long double*)value); +#else +#if defined(NO_SWPRINTF) + { + int k; + char *tmpbuf = new char[50]; + wchar_t *tmpw = (wchar_t*)outval; + sprintf(tmpbuf,"%.3Le",*(long double*)value); + for (k=0;kmax?max:len; + } + + case BigDecimalType: + case BigIntegerType: + case UriType: + case StringType: + { + if (value == 0) return 0; + wchar_t* tmp = (wchar_t*)value; + for (i=0;(i < max) && (i < len);i++) + { + outval[i] = (char)(tmp[i]); + } + return len>max?max:len; + } + + case BooleanType: + { + if (value == 0 || *(long*)value == 0) { + if (max < 5) return 0; + outval[0] = 'f'; + outval[1] = 'a'; + outval[2] = 'l'; + outval[3] = 's'; + outval[4] = 'e'; + return 5; + } + else { + if (max < 4) return 0; + outval[0] = 't'; + outval[1] = 'r'; + outval[2] = 'u'; + outval[3] = 'e'; + return 4; + } + return 0; + } + + case CharacterType: + case ByteType: + { + if (value == 0) return 0; + long tmp = *(long*)value; + outval[0] = (char)(tmp&0xFF); + return 1; + } + + case ShortType: + case IntegerType: + { + if (value == 0) return 0; + long tmp = *(long*)value; + char* tmpstr = new char[MAX_LONG_SIZE]; + sprintf(tmpstr, "%ld", tmp); + if (strlen(tmpstr) > max) + { + delete tmpstr; + return 0; + } + delete tmpstr; + sprintf(outval, "%ld", tmp); + return strlen(outval); + } + + + case LongType: + { + if (value == 0) return 0; + int64_t tmp = *(int64_t*)value; + char * tmpstr = new char[MAX_LONG_SIZE]; + sprintf(tmpstr, "%lld", tmp); + if (strlen(tmpstr) > max) + { + delete tmpstr; + return 0; + } + delete tmpstr; + sprintf(outval, "%lld", tmp); + return strlen(outval); + } + case DateType: + { + if (value == 0) return 0; + string msg("Conversion to string not implemented from type:"); + msg += getName(); + SDO_THROW_EXCEPTION("getBytes" , + SDOInvalidConversionException, msg.c_str()); + break; + } + + case DoubleType: + if (value == 0) return 0; + if (max < MAX_DOUBLE_SIZE) return 0; + sprintf(outval,"%.3Le",*(long double*)value); + return strlen(outval); + + case FloatType: + if (value == 0) return 0; + if (max < MAX_FLOAT_SIZE) return 0; + sprintf(outval,"%.3e",*(float*)value); + return strlen(outval); + + case OtherTypes: + case DataObjectType: + default: + { + if (max < 9) return 0; + sprintf(outval,"%08x",value); + //string msg("Cannot get Bytes from object of type:"); + //msg += getName(); + //SDO_THROW_EXCEPTION("getBytes" , + // SDOInvalidConversionException, msg.c_str()); + return strlen(outval); + } + } + return 0; + } + + unsigned int TypeImpl::convertToBytes(const SDOValue& sdoValue, char* outptr, unsigned int max) const + { + switch (typeEnum) + { + case BytesType: + case BigDecimalType: + case BigIntegerType: + case UriType: + case StringType: + case BooleanType: + case CharacterType: + case ByteType: + case ShortType: + case IntegerType: + case LongType: + case DateType: + case DoubleType: + case FloatType: + return sdoValue.getBytes(outptr, max); + + case DataObjectType: + case OtherTypes: + default: + string msg("Cannot get Bytes from object of type:"); + msg += getName(); + SDO_THROW_EXCEPTION("getBytes" , + SDOInvalidConversionException, + msg.c_str()); + } + return 0; + } + + + // +++ + + // value is a pointer to the byte stream that is the value to convert + // outval is the resulting string representation of value + // len is the length of the input byte stream, it is used only when the length cannot be inferred from other information. + // max is the maximum size allowed for the output byte stream. (Not strictly needed when the output is an std::string but we maintain the behaviour from the earlier method. + + // Questions + // 1. Why isn't value const? + // + unsigned int TypeImpl::convertToBytes(const void* value, + SDOString& outval, + unsigned int len, + unsigned int max) const + { + unsigned int i; + outval.erase(); + switch (typeEnum) + { + case BytesType: + { + if (value == 0) return 0; + + const char* tempPtr = (const char*) value; + unsigned int count = (len > max) ? max : len; + outval.assign(tempPtr, count); + + return count; + } + + case BigDecimalType: + case BigIntegerType: + case UriType: + case StringType: + { + if (value == 0) return 0; + + const wchar_t* tempPtr = (const wchar_t*) value; + unsigned int count = (len > max) ? max : len; + + // The following loop copies the low byte from each 2 byte wchar_t + // into one byte of the target array eg H_E_L_P -> HELP + for (i = 0; (i < count); i++) + { + outval += (char)(tempPtr[i]); + } + return count; + } + + case BooleanType: + { + if (value == 0 || *(const long*)value == 0) { + if (max < 5) return 0; + outval = "false"; + return 5; + } + else { + if (max < 4) return 0; + outval = "true"; + return 4; + } + return 0; + } + + case CharacterType: + case ByteType: + { + if (value == 0) return 0; + + const long tmp = *(const long*)value; + outval += (char)(tmp&0xFF); + return 1; + } + + case ShortType: + case IntegerType: + { + if (value == 0) return 0; + + const long tmp = *(const long*) value; + char* tmpstr = new char[MAX_LONG_SIZE + 1]; + sprintf(tmpstr, "%ld", tmp); + if (strlen(tmpstr) > max) + { + delete tmpstr; + return 0; + } + outval = tmpstr; + delete tmpstr; + return outval.length(); + } + + case LongType: + { + if (value == 0) return 0; + + const int64_t tmp = *(const int64_t*)value; + char* tmpstr = new char[MAX_LONG_SIZE + 1]; + sprintf(tmpstr, "%lld", tmp); + if (strlen(tmpstr) > max) + { + delete tmpstr; + return 0; + } + outval = tmpstr; + delete tmpstr; + return outval.length(); + } + case DateType: + { + if (value == 0) return 0; + + string msg("Conversion to string not implemented from type:"); + msg += getName(); + SDO_THROW_EXCEPTION("getBytes" , + SDOInvalidConversionException, msg.c_str()); + break; + } + + case DoubleType: + { + if (value == 0) return 0; + + if (max < MAX_DOUBLE_SIZE) return 0; + + char* tmpstr = new char[MAX_DOUBLE_SIZE + 1]; + sprintf(tmpstr, "%.3Le", *(const long double*)value); + outval = tmpstr; + delete tmpstr; + return outval.length(); + } + + case FloatType: + { + if (value == 0) return 0; + + if (max < MAX_FLOAT_SIZE) return 0; + + char* tmpstr = new char[MAX_FLOAT_SIZE + 1]; + sprintf(tmpstr, "%.3Le", *(const float*)value); + outval = tmpstr; + delete tmpstr; + return outval.length(); + } + + case OtherTypes: + case DataObjectType: + default: + { + if (max < 9) return 0; + + char tmpstr[9]; + sprintf(tmpstr, "%08x", value); + outval = tmpstr; + //string msg("Cannot get Bytes from object of type:"); + //msg += getName(); + //SDO_THROW_EXCEPTION("getBytes" , + // SDOInvalidConversionException, msg.c_str()); + return outval.length(); + } + } + return 0; + } + + // --- + + const char* TypeImpl::convertToCString(void* value, char** asstringbuf, unsigned int len) const + { + unsigned int i; + + switch (typeEnum) + { + case BooleanType: + if (value == 0 || *(long*)value == 0) { + *asstringbuf = new char[6]; + strcpy(*asstringbuf,"false"); + } + else { + *asstringbuf = new char[5]; + strcpy(*asstringbuf,"true"); + } + return *asstringbuf; + + case ByteType: + *asstringbuf = new char[MAX_LONG_SIZE]; + if (value == 0){ + sprintf(*asstringbuf,"%ld",0); + } + else { + sprintf(*asstringbuf,"%ld",*(long*)value); + } + return *asstringbuf; + + case CharacterType: + *asstringbuf = new char[MAX_LONG_SIZE]; + if (value == 0){ + sprintf(*asstringbuf,"%ld",0); + } + else { + sprintf(*asstringbuf,"%ld", *(long*)value); + } + return *asstringbuf; + + case IntegerType: + *asstringbuf = new char[MAX_LONG_SIZE]; + if (value == 0){ + sprintf(*asstringbuf,"%ld",0); + } + else { + sprintf(*asstringbuf,"%ld", *(long*)value); + } + return *asstringbuf; + + case ShortType: + *asstringbuf = new char[MAX_LONG_SIZE]; + if (value == 0){ + sprintf(*asstringbuf,"%ld",0); + } + else { + sprintf(*asstringbuf,"%ld", *(long*)value); + } + return *asstringbuf; + + case DoubleType: + *asstringbuf = new char[MAX_DOUBLE_SIZE]; + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + (*asstringbuf)[0] = 0; + return *asstringbuf; + } + sprintf(*asstringbuf,"%.3Le",*(long double*)value); + return *asstringbuf; + + case FloatType: + *asstringbuf = new char[MAX_FLOAT_SIZE]; + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + (*asstringbuf)[0] = 0; + return *asstringbuf; + } + sprintf(*asstringbuf,"%.3e", *(float*)value); + return *asstringbuf; + + case LongType: + { + *asstringbuf = new char[MAX_LONG_SIZE]; + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + (*asstringbuf)[0] = 0; + return *asstringbuf; + } + int64_t temp = *(int64_t*)value; +#if defined(WIN32) || defined (_WINDOWS) + sprintf(*asstringbuf,"%I64d", temp); +#else + sprintf(*asstringbuf,"%lld", temp); +#endif + return *asstringbuf; + } + case DateType: + *asstringbuf = new char[MAX_LONG_SIZE]; + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + (*asstringbuf)[0] = 0; + return *asstringbuf; + } + sprintf(*asstringbuf,"%ld", *(time_t*)value); + return *asstringbuf; + + case BigDecimalType: + case BigIntegerType: + case StringType: + case UriType: + { + if (value == 0 || len == 0) + { + *asstringbuf = new char[1]; + (*asstringbuf)[0] = 0; + return *asstringbuf; + } + *asstringbuf = new char[len + 1]; + wchar_t* tmp = (wchar_t*)value; + for (i=0;i< len;i++) + { + (*asstringbuf)[i] = tmp[i] & 0xFF; + } + (*asstringbuf)[i] = 0; + return *asstringbuf; + } + + case BytesType: + { + if (value == 0 || len == 0) + { + *asstringbuf = new char[1]; + (*asstringbuf)[0] = 0; + return *asstringbuf; + } + *asstringbuf = new char[len + 1]; + char* tmp = (char*)value; + for (i=0;i< len ;i++) + { + (*asstringbuf)[i] = (char)(tmp[i]); + } + (*asstringbuf)[i] = 0; + return *asstringbuf; + } + + + case OtherTypes: + case DataObjectType: + default: + { + *asstringbuf = new char[9]; + sprintf(*asstringbuf,"%08x",value); + //string msg("Cannot get CString from object of type:"); + //msg += getName(); + //SDO_THROW_EXCEPTION("getCString" , + // SDOInvalidConversionException, msg.c_str()); + return *asstringbuf; + } + } + return 0; + } + + const char* TypeImpl::convertToCString(const SDOValue& sdoValue) const + { + + switch (typeEnum) + { + case BooleanType: + case ByteType: + case CharacterType: + case IntegerType: + case ShortType: + case DoubleType: + case FloatType: + case LongType: + case DateType: + case BigDecimalType: + case BigIntegerType: + case StringType: + case UriType: + case BytesType: + return sdoValue.getCString(); + + case OtherTypes: + case DataObjectType: + default: + { + string msg("Cannot get CString from object of type:"); + msg += getName(); + SDO_THROW_EXCEPTION("getCString" , + SDOInvalidConversionException, + msg.c_str()); + } + return 0; + } + } + + + const bool TypeImpl::convertToBoolean(void* value, unsigned int len) const + { + switch (typeEnum) + { + case BooleanType: + case ByteType: + case CharacterType: + case IntegerType: + case ShortType: + if (value == 0) return false; + if (*(long*)value != 0) return true; + return false; + + case DoubleType: + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return false; + } + if (*(long double*)value != 0.0) return true; + return false; + + case FloatType: + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return false; + } + if (*(float*)value != 0.0) return true; + return false; + + case LongType: + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return false; + } + if (*(int64_t*)value != 0)return true; + return false; + + case DateType: + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return false; + } + if (*(time_t*)value != 0)return true; + return false; + + case BigDecimalType: + case BigIntegerType: + case StringType: + case UriType: + if (value == 0 || len < 4) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return false; + } + if ( ((wchar_t*)value)[0] == (wchar_t)'t' && + ((wchar_t*)value)[1] == (wchar_t)'r' && + ((wchar_t*)value)[2] == (wchar_t)'u' && + ((wchar_t*)value)[3] == (wchar_t)'e' ) + return true; + + return false; + + case BytesType: + if (value == 0 || len < 4) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return false; + } + if (!strncmp((char*)value,"true", 4)) return true; + return false; + + case OtherTypes: + case DataObjectType: + default: + { + string msg("Cannot get Boolean from object of type:"); + msg += getName(); + SDO_THROW_EXCEPTION("getBoolean" , + SDOInvalidConversionException, msg.c_str()); + break; + } + } + + } + + const bool TypeImpl::convertToBoolean(const SDOValue& sdoValue) const + { + switch (typeEnum) + { + case BooleanType: + case ByteType: + case CharacterType: + case IntegerType: + case ShortType: + case DoubleType: + case FloatType: + case LongType: + case DateType: + case BigDecimalType: + case BigIntegerType: + case StringType: + case UriType: + case BytesType: + return sdoValue.getBoolean(); + + case OtherTypes: + case DataObjectType: + default: + { + string msg("Cannot get Boolean from object of type:"); + msg += getName(); + SDO_THROW_EXCEPTION("getBoolean" , + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + } + + + const char TypeImpl::convertToByte(void* value , unsigned int len) const + { + switch (typeEnum) + { + case BooleanType: + case ByteType: + case CharacterType: + case IntegerType: + case ShortType: + if (value == 0) return 0; + return (char)(*(long*)value); + + case DoubleType: + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return 0; + } + return (char)(*(long double*)value); + + case FloatType: + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return 0; + } + return (char)(*(float*)value); + + case LongType: + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return 0; + } + return (char)(*(int64_t*)value); + + case DateType: + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return 0; + } + + return (char)(*(time_t*)value); + + case BigDecimalType: + case BigIntegerType: + case StringType: + case UriType: + { + if (value == 0) return 0; + // Assume the string is a number eg "123" and attempt to convert it. + +#if defined(WIN32) || defined(_WINDOWS) + return (char) _wtoi((wchar_t*) value); +#else + char* tmpstr = new char[len + 1]; + short s = 0; + wchar_t* srcptr = (wchar_t*) value; + + for (int j = 0; j < len; j++) + { + tmpstr[j] = (char) srcptr[j]; + } + tmpstr[len] = 0; + s = (char) atoi(tmpstr); + delete tmpstr; + return (char) s; +#endif + } + + case BytesType: + { + if (value == 0) return 0; + return (char)*(char*)value; + } + + + case OtherTypes: + case DataObjectType: + default: + { + string msg("Cannot get Byte from object of type:"); + msg += getName(); + SDO_THROW_EXCEPTION("getByte" , + SDOInvalidConversionException, msg.c_str()); + break; + } + } + } + + const char TypeImpl::convertToByte(const SDOValue& sdoValue) const + { + switch (typeEnum) + { + case BooleanType: + case ByteType: + case CharacterType: + case IntegerType: + case ShortType: + case DoubleType: + case FloatType: + case LongType: + case DateType: + case BigDecimalType: + case BigIntegerType: + case StringType: + case UriType: + case BytesType: + return sdoValue.getByte(); + + case OtherTypes: + case DataObjectType: + default: + { + string msg("Cannot get Byte from object of type:"); + msg += getName(); + SDO_THROW_EXCEPTION("getByte", + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + } + + + const wchar_t TypeImpl::convertToCharacter(void* value, unsigned int len) const + { + switch (typeEnum) + { + case BooleanType: + case ByteType: + case CharacterType: + case IntegerType: + case ShortType: + if (value == 0) return 0; + return (wchar_t)(*(long*)value); + + case DoubleType: + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return 0; + } + return (wchar_t)(*(long double*)value); + + case FloatType: + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return 0; + } + return (wchar_t)(*(float*)value); + + case LongType: + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return 0; + } + return (wchar_t)(*(int64_t*)value); + + case DateType: + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return 0; + } + return (wchar_t)(*(time_t*)value); + + case BigDecimalType: + case BigIntegerType: + case StringType: + case UriType: + { + if (value == 0) return 0; + return *(wchar_t*)value; + } + + case BytesType: + { + if (value == 0) return 0; + return (wchar_t)*(char*)value; + } + + case OtherTypes: + case DataObjectType: + default: + { + string msg("Cannot get Character from object of type:"); + msg += getName(); + SDO_THROW_EXCEPTION("getCharacter" , + SDOInvalidConversionException, msg.c_str()); + break; + } + } + } + + + const wchar_t TypeImpl::convertToCharacter(const SDOValue& sdoValue) const + { + switch (typeEnum) + { + case BooleanType: + case ByteType: + case CharacterType: + case IntegerType: + case ShortType: + case DoubleType: + case FloatType: + case LongType: + case DateType: + case BigDecimalType: + case BigIntegerType: + case StringType: + case UriType: + case BytesType: + return sdoValue.getCharacter(); + + case OtherTypes: + case DataObjectType: + default: + { + string msg("Cannot get Character from object of type:"); + msg += getName(); + SDO_THROW_EXCEPTION("getCharacter" , + SDOInvalidConversionException, msg.c_str()); + break; + } + } + } + + + + const short TypeImpl::convertToShort(void* value, unsigned int len) const + { +#if ! defined(WIN32) && !defined (_WINDOWS) + char* tmpstr = new char[len+1]; + short s = 0; +#endif + switch (typeEnum) + { + case BooleanType: + case ByteType: + case CharacterType: + case IntegerType: + case ShortType: + if (value == 0) return 0; + return (short)(*(long*)value); + + case DoubleType: + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return 0; + } + return (short)(*(long double*)value); + + case FloatType: + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return 0; + } + return (short)(*(float*)value); + + case LongType: + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return 0; + } + return (short)(*(int64_t*)value); + + case DateType: + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return 0; + } + return (short)(*(time_t*)value); + + case BigDecimalType: + case BigIntegerType: + case StringType: + case UriType: + if (value == 0 || len == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return 0; + } +#if defined(WIN32) || defined (_WINDOWS) + return (short)_wtoi((wchar_t*)value); +#else + for (int j=0;j< len;j++) + { + tmpstr[j] = (char)((char *)value)[j]; + } + tmpstr[len] = 0; + s = (short) atoi(tmpstr); + delete tmpstr; + return s; +#endif + + + case BytesType: + case OtherTypes: + case DataObjectType: + default: + { + string msg("Cannot get Short from object of type:"); + msg += getName(); + SDO_THROW_EXCEPTION("getShort" , + SDOInvalidConversionException, msg.c_str()); + break; + } + } + } + + const short TypeImpl::convertToShort(const SDOValue& sdoValue) const + { + switch (typeEnum) + { + case BooleanType: + case ByteType: + case CharacterType: + case IntegerType: + case ShortType: + case DoubleType: + case FloatType: + case LongType: + case DateType: + case BigDecimalType: + case BigIntegerType: + case StringType: + case UriType: + case BytesType: + return sdoValue.getShort(); + + case OtherTypes: + case DataObjectType: + default: + { + string msg("Cannot get Short from object of type:"); + msg += getName(); + SDO_THROW_EXCEPTION("getShort" , + SDOInvalidConversionException, + msg.c_str()); + break; + } + } + } + + +/* const int TypeImpl::convertToInt(void* value, unsigned int len) const + { + switch (typeEnum) + { + case BooleanType: + case ByteType: + case CharacterType: + case IntegerType: + case ShortType: + if (value == 0) return 0; + return (int)(*(long*)value); + + case DoubleType: + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return 0; + } + return (int)(*(long double*)value); + + case FloatType: + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return 0; + } + return (int)(*(float*)value); + + case LongType: + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return 0; + } + return (int)(*(int64_t*)value); + + case DateType: + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return 0; + } + return (int)(*(time_t*)value); + + case BigDecimalType: + case BigIntegerType: + case StringType: + case UriType: + if (value == 0) + { + // Conversions might set from a zero value, as they are used + // by the default Setting code as well + return 0; + } +#if defined(WIN32) || defined (_WINDOWS) + return (int)_wtoi((wchar_t*)value); +#else + char* tmp = new char[len+1]; + int j = 0;; + for (j=0;j +#include +#include +#include "commonj/sdo/DASType.h" +#include "commonj/sdo/PropertyImpl.h" +#include "commonj/sdo/SDODate.h" +#include "commonj/sdo/SDOValue.h" + + +#define MAX_LONG_SIZE 20 +#define MAX_FLOAT_SIZE 32 +#define MAX_DOUBLE_SIZE 32 +#define BOOL_SIZE 5 +#define CHAR_SIZE 1 +#define BYTE_SIZE 1 + + + +namespace commonj{ +namespace sdo{ + +class DataObject; +class PropertyList; +class MetadataGraph; + + +#ifndef PROPERTY_LIST + typedef std::list PROPERTY_LIST; +#endif + +/** + * TypeImpl implements the abstract class Type. + * A representation of the type of property of a data object. + */ + + +class TypeImpl : public DASType +{ + +public: + + + virtual ~TypeImpl(); + + /** convert - converts between types + * + * When a DataObject is queried for the value of one of its + * properties, the method to call varies according to the + * type of the property. + * If the wrong API is called (E.g getBoolean() called on + * an Integer value), then a conversion is attempted. + * Many conversions will succeed and return the value, + * others will throw an InvalidConversionException + */ + + unsigned int convertDate( void ** value, const SDODate i) const; + unsigned int convert( void ** value,const char* s) const; + unsigned int convert(void ** value, const SDOString& s) const; + unsigned int convert( void ** value,const wchar_t* s, unsigned int len) const; + unsigned int convert( void ** value,const char* s, unsigned int len) const; + unsigned int convert(void ** value, const SDOString& s, unsigned int len) const; + unsigned int convert( void ** value,const bool b) const; + unsigned int convert( void ** value,const char c) const; + unsigned int convert( void ** value,const wchar_t c) const; + unsigned int convert( void ** value,const short s) const; +#if __WORDSIZE !=64 + unsigned int convert( void ** value,const long i) const; +#endif + unsigned int convert( void ** value,const int64_t l) const; + unsigned int convert( void ** value,const float f) const; + unsigned int convert( void ** value,const long double d) const; + unsigned int convert( void ** value,DataObject* dob) const; + + const char* convertToCString( void* value , char** inbuf, unsigned int len) const; + const char* convertToCString(const SDOValue& sdoValue) const; + const bool convertToBoolean( void* value, unsigned int len) const; + const bool convertToBoolean(const SDOValue& sdoValue) const; + const char convertToByte( void* value,unsigned int len ) const; + const char convertToByte(const SDOValue& sdoValue) const; + unsigned int convertToString( void* value , wchar_t* val, unsigned int len, + unsigned int max) const; + unsigned int convertToString(const SDOValue& sdoValue, + wchar_t* val, + unsigned int max) const; + unsigned int convertToBytes( void* value , char* val, unsigned int len, + unsigned int max) const; + unsigned int convertToBytes(const SDOValue& sdoValue , char* val, unsigned int max) const; + unsigned int convertToBytes( const void* value , SDOString& val, unsigned int len, + unsigned int max) const; + const wchar_t convertToCharacter( void* value ,unsigned int len) const; + const wchar_t convertToCharacter(const SDOValue& sdoValue) const; + const short convertToShort( void* value ,unsigned int len) const; + const short convertToShort(const SDOValue& sdoValue) const; + const long convertToInteger( void* value ,unsigned int len) const; + const long convertToInteger(const SDOValue& sdoValue) const; + const int64_t convertToLong( void* value ,unsigned int len) const; + const int64_t convertToLong(const SDOValue& sdoValue) const; + const float convertToFloat( void* value ,unsigned int len) const; + const float convertToFloat(const SDOValue& sdoValue) const; + const long double convertToDouble(void* value ,unsigned int len) const; + const long double convertToDouble(const SDOValue& sdoValue) const; + DataObject* convertToDataObject(void* value ,unsigned int len) const; + const SDODate convertToDate (void* value ,unsigned int len) const; + const SDODate convertToDate (const SDOValue& sdoValue) const; + + /** equals - compares + * + * equals returns true if the name and uri are the same + */ + + bool equals(const Type& t); + + /////////////////////////////////////////////////////////////////////////// + // Returns the name of the type. + /////////////////////////////////////////////////////////////////////////// + const char* getName() const; + + /////////////////////////////////////////////////////////////////////////// + // Alias support. + // @return nth alias + /////////////////////////////////////////////////////////////////////////// + virtual const char* getAlias(unsigned int index = 0) const ; + virtual unsigned int getAliasCount() const ; + virtual void setAlias(const char* alias); + + + + /////////////////////////////////////////////////////////////////////////// + // Returns the namespace URI of the type. + /////////////////////////////////////////////////////////////////////////// + const char* getURI() const; + + /////////////////////////////////////////////////////////////////////////// + // Returns the list of the properties of this type. + /////////////////////////////////////////////////////////////////////////// + PropertyList getProperties() const; + const std::list& getPropertyListReference() const; + + /////////////////////////////////////////////////////////////////////////// + // add a property to a Type whilst building - this is for DAS + /////////////////////////////////////////////////////////////////////////// + void addProperty(const char* name, + const TypeImpl& t, bool many, bool rdonly, bool cont); + + /////////////////////////////////////////////////////////////////////////// + // Returns the property with the specified name. + /////////////////////////////////////////////////////////////////////////// + const Property& getProperty(const char* propertyName) const ; + const Property& getProperty(const SDOString& propertyName) const ; + const Property& getProperty(unsigned int index) const ; + + PropertyImpl* getPropertyImpl(const SDOString& propertyName) const ; + PropertyImpl* getPropertyImpl(unsigned int index) const ; + + + /////////////////////////////////////////////////////////////////////////// + // Substitute support + /////////////////////////////////////////////////////////////////////////// + // get the property with no substitute possible. + PropertyImpl* getPropertyImplPure(const char* propertyName) const ; + + // get the type of the property even if its a substitute + const Type& getRealPropertyType(const std::string& propertyName) const ; + const TypeImpl* getRealPropertyTypeImpl(const std::string& propertyName) const ; + + + + unsigned int getPropertyIndex(const char* propertyName) const ; + unsigned int getPropertyIndex(const SDOString& propertyName) const ; + + unsigned int getPropertiesSize() const; + /////////////////////////////////////////////////////////////////////////// + // Indicates if this Type specifies DataObjects. + /////////////////////////////////////////////////////////////////////////// + bool isDataObjectType() const; + + /////////////////////////////////////////////////////////////////////////// + // Indicates if this Type specifies Sequenced DataObjects. + /////////////////////////////////////////////////////////////////////////// + bool isSequencedType() const; + void setSequenced(bool set); + + /////////////////////////////////////////////////////////////////////////// + // Indicates if this Type allows any form of open content. If false, + // dataObject.getInstanceProperties() must be the same as + // DataObject.getType().getProperties(). + /////////////////////////////////////////////////////////////////////////// + bool isOpenType() const; + void setOpen(bool set); + + // Returns true if Type is Open only because it's base Type is open + bool isOpenTypeImplicitly() const; + + /////////////////////////////////////////////////////////////////////////// + // Indicates if this type may not be instantiated. + /////////////////////////////////////////////////////////////////////////// + bool isAbstractType() const; + void setAbstract(bool set); + + /////////////////////////////////////////////////////////////////////////// + // Set the base type for inherited types + /////////////////////////////////////////////////////////////////////////// + void setBaseType(const Type* tb, bool isRestriction = false); + const Type* getBaseType() const; + const TypeImpl* getBaseTypeImpl() const; + + + /////////////////////////////////////////////////////////////////////////// + // Indicates a non-object type + /////////////////////////////////////////////////////////////////////////// + bool isDataType() const; + + /////////////////////////////////////////////////////////////////////////// + // Indicates a non-object type + /////////////////////////////////////////////////////////////////////////// + Type::Types getTypeEnum() const; + + /////////////////////////////////////////////////////////////////////////// + // set this type as a change summary holder + /////////////////////////////////////////////////////////////////////////// + void addChangeSummary(); + + ////////////////////////////////////////////////////////////////////////// + // Say if this type is allowed to have a summary + /////////////////////////////////////////////////////////////////////////// + bool isChangeSummaryType() const; + + /////////////////////////////////////////////////////////////////////////// + // Used by the DAS to resolve the base type properties list + /////////////////////////////////////////////////////////////////////////// + void initCompoundProperties(); + + /////////////////////////////////////////////////////////////////////////// + // Used by the DAS to chack for nested change summaries + /////////////////////////////////////////////////////////////////////////// + void validateChangeSummary(); + + virtual bool equals(const Type& tother) const; + + virtual bool isFromList() const; + + +private: + friend class DataFactoryImpl; + + bool changeSummaryType; + + bool bFromList; + + void* newValue(void* v, int size) const; + + PROPERTY_LIST getCompoundProperties(); + + void throwIfNestedChangeSummary() const; + + TypeImpl(const char* uri,const char* name, + bool isSeq= false, + bool isOp = false, + bool isAbs = false, + bool isData = false, + bool isFromList = false); + + TypeImpl(const Type* base, const char* uri,const char* name, + bool isSeq = false, + bool isOp = false, + bool isAbs = false, + bool isData = false, + bool isRest = false); + + void init(const char* uri, const char* inname, + bool isSeq, + bool isOp, + bool isAbs, + bool isData); + + + + TypeImpl(); + TypeImpl(const TypeImpl& t); + + bool isBaseTypeOf(const Type* type)const; + + char* name; + char* typeURI; + + + bool isPrimitive; + bool isSequenced; + bool isOpen; + bool isOpenImplicitly; + bool isAbstract; + + // baseType properties included + bool isResolved; + // check for circular dependency + bool isResolving; + + Types typeEnum; + + static char* types[num_types]; + + // alias support + + std::vector aliases; + + + PROPERTY_LIST props; + + + // type inheritance + TypeImpl* baseType; + bool brestriction; /* if this is a restriction of the base type + rather than an extension.*/ + // says how many of the props are really in this data object type. + unsigned int localPropsSize; + +}; + +}; +}; + +#endif //_TYPEIMPL_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeList.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeList.cpp new file mode 100644 index 0000000000..86821e1b51 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeList.cpp @@ -0,0 +1,86 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef SDO_EXPORTS + #define SDO_EXPORTS +#endif + +#include "commonj/sdo/export.h" +#include +#include "commonj/sdo/Property.h" +#include "commonj/sdo/Type.h" +#include "commonj/sdo/TypeList.h" +#include "commonj/sdo/Logger.h" + +using namespace std; + +namespace commonj{ +namespace sdo { + + +/** TypeList provides access to a list of Types. + * + * The data factory can return a list of types available. This + * class wraps that list and provides access to Types by + * iteration + */ + +SDO_API TypeList::TypeList(std::vector p) : plist (p) +{ +} + +SDO_API TypeList::TypeList(const TypeList &pin) +{ + plist = std::vector(pin.getVec()); +} + +SDO_API TypeList::TypeList() +{ +} + +SDO_API TypeList::~TypeList() +{ +} + + +SDO_API const Type& TypeList::operator[] (unsigned int pos) const +{ + return *plist[pos]; +} + +SDO_API unsigned int TypeList::size () const +{ + return plist.size(); +} + +std::vector TypeList::getVec() const +{ + return plist; +} + +SDO_API void TypeList::insert (const Type* t) +{ + plist.push_back(t); +} + +}; +}; + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeList.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeList.h new file mode 100644 index 0000000000..cd19d0bf3d --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeList.h @@ -0,0 +1,58 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _TYPELIST_H_ +#define _TYPELIST_H_ +#include "commonj/sdo/export.h" + +#include +#include "commonj/sdo/Type.h" + +namespace commonj{ +namespace sdo +{ +class Type; + +/** TypeList - provides access to a list of Types + * + * The data factory can return a list of types available. This + * class wraps that list and provides access to Types by + * iteration + */ + +class TypeList +{ +private: + std::vector plist; + std::vector getVec() const; +public: + SDO_API TypeList(const TypeList &pin); + SDO_API TypeList(std::vector p); + SDO_API TypeList(); + virtual SDO_API ~TypeList(); + SDO_API const Type& operator[] (unsigned int pos) const; + SDO_API unsigned int size () const; + SDO_API void insert (const Type* t); +}; +}; +}; + +#endif diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLDocument.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLDocument.cpp new file mode 100644 index 0000000000..d6dfd02c8e --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLDocument.cpp @@ -0,0 +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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/XMLDocument.h" +namespace commonj +{ + namespace sdo + { + + XMLDocument::~XMLDocument() + { + } + + } // End - namespace sdo +} // End - namespace commonj diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLDocument.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLDocument.h new file mode 100644 index 0000000000..757ba2113a --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLDocument.h @@ -0,0 +1,151 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _XMLDOCUMENT_H_ +#define _XMLDOCUMENT_H_ + + +#include "commonj/sdo/export.h" + +#include "commonj/sdo/DataObject.h" + +namespace commonj +{ + namespace sdo + { + /** XMLDocument - place for holding a graph + * + * The XMLDocument class provides a place to hold a loaded + * graph of data. The root element name is maintained here so that + * the graph can be serialized to the same name later. + */ + + + class XMLDocument : public RefCountingObject + { + + public: + + SDO_API virtual ~XMLDocument(); + + /** getRootDataObject- return the topmost data object + * + * When XML data is loaded, there is one base element which becomes + * the root data object. As this data object is not a property of any + * other data object, it has no name + * The XMLDocument stores the name which was in the XML file. + * This root data object has a URI and a Name only within this + * XMLDocument + */ + + SDO_API virtual DataObjectPtr getRootDataObject() const = 0; + + /** getRootElementName- return the topmost data objects name + * + * When XML data is loaded, there is one base element which becomes + * the root data object. As this data object is not a property of any + * other data object, it has no name + * The XMLDocument stores the name/uri which was in the XML file. + */ + SDO_API virtual const char* getRootElementURI() const = 0; + + /** getRootElementURI- return the topmost data objects uri + * + * When XML data is loaded, there is one base element which becomes + * the root data object. As this data object is not a property of any + * other data object, it has no name + * The XMLDocument stores the name/uri which was in the XML file. + */ + SDO_API virtual const char* getRootElementName() const = 0; + + /** getEncoding- return the encoding for this document + * + * NOT IMPLEMENTED + * This returns the encoding specified in the original XML. + */ + SDO_API virtual const char* getEncoding() const = 0; + + /** setEncoding- set the encoding to save this document + * + * This sets the encoding to save this data to XML. + */ + SDO_API virtual void setEncoding(const char* encoding) = 0; + SDO_API virtual void setEncoding(const SDOString& encoding) = 0; + + /** getXMLDeclaration + * + * NOT IMPLEMENTED + */ + SDO_API virtual bool getXMLDeclaration() const = 0; + + /** setXMLDeclaration + * + * Sets the XMLDeclaration + */ + SDO_API virtual void setXMLDeclaration(bool xmlDeclaration) = 0; + + /** getXMLVersion- return the xml version for this document + * + * NOT IMPLEMENTED + */ + SDO_API virtual const char* getXMLVersion() const = 0; + + /** setXMLVersion- sets the version for this document + * + * NOT IMPLEMENTED + */ + SDO_API virtual void setXMLVersion(const char* xmlVersion) = 0; + SDO_API virtual void setXMLVersion(const SDOString& xmlVersion) = 0; + + /** getSchemaLocation- return the schema location + * + * NOT IMPLEMENTED + */ + SDO_API virtual const char* getSchemaLocation() const = 0; + + /** setSchemaLocation + * + * Sets the XML Schema location. + */ + SDO_API virtual void setSchemaLocation(const char* schemaLocation) = 0; + SDO_API virtual void setSchemaLocation(const SDOString& schemaLocation) = 0; + + /** getNoNamespaceSchemaLocation + * + * NOT IMPLEMENTED + */ + SDO_API virtual const char* getNoNamespaceSchemaLocation() const = 0; + + /** setNoNamespaceSchemaLocation + * + * Sets the nonamespace schema location + */ + SDO_API virtual void setNoNamespaceSchemaLocation(const char* noNamespaceSchemaLocation) = 0; + SDO_API virtual void setNoNamespaceSchemaLocation(const SDOString& noNamespaceSchemaLocation) = 0; + + SDO_API friend std::istream& operator>>(std::istream& input, XMLDocument& doc); + + }; + } // End - namespace sdo +} // End - namespace commonj + + +#endif //_XMLDOCUMENT_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLDocumentImpl.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLDocumentImpl.cpp new file mode 100644 index 0000000000..1a97f26765 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLDocumentImpl.cpp @@ -0,0 +1,87 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/XMLDocumentImpl.h" + +namespace commonj +{ + namespace sdo + { + XMLDocumentImpl::XMLDocumentImpl( + DataObjectPtr dob, + const char* rootURI, + const char* rootName) + : dataObject(dob), + rootElementURI(rootURI), + rootElementName(rootName), + xmlDeclaration(true), + encoding("UTF-8"), + xmlVersion("1.0") + { + } + + XMLDocumentImpl::~XMLDocumentImpl() + { + } + + void XMLDocumentImpl::setEncoding(const char* enc) + { + encoding = enc; + } + void XMLDocumentImpl::setEncoding(const SDOString& enc) + { + encoding = enc.c_str(); + } + + void XMLDocumentImpl::setXMLDeclaration(bool xmlDecl) + { + xmlDeclaration = xmlDecl; + } + + void XMLDocumentImpl::setXMLVersion(const char* xmlVer) + { + xmlVersion = xmlVer; + } + void XMLDocumentImpl::setXMLVersion(const SDOString& xmlVer) + { + xmlVersion = xmlVer.c_str(); + } + + void XMLDocumentImpl::setSchemaLocation(const char* schemaLoc) + { + schemaLocation = schemaLoc; + } + void XMLDocumentImpl::setSchemaLocation(const SDOString& schemaLoc) + { + schemaLocation = schemaLoc.c_str(); + } + + void XMLDocumentImpl::setNoNamespaceSchemaLocation(const char* noNamespaceSchemaLoc) + { + noNamespaceSchemaLocation = noNamespaceSchemaLoc; + } + void XMLDocumentImpl::setNoNamespaceSchemaLocation(const SDOString& noNamespaceSchemaLoc) + { + noNamespaceSchemaLocation = noNamespaceSchemaLoc.c_str(); + } + + } // End - namespace sdo +} // End - namespace commonj diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLDocumentImpl.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLDocumentImpl.h new file mode 100644 index 0000000000..f7726a449c --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLDocumentImpl.h @@ -0,0 +1,102 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _XMLDocumentImpl_H_ +#define _XMLDocumentImpl_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/XMLDocument.h" +#include "commonj/sdo/DataObject.h" +#include "commonj/sdo/SDOXMLString.h" +#include "commonj/sdo/SDOString.h" + + +namespace commonj +{ + namespace sdo + { + +/** XMLDocumentImpl place for holding a graph + * + * The XMLDocumentImpl class implements the abstract XMLDocument. + * Provides a place to hold a loaded + * graph of data. The root element name is maintained here so that + * the graph can be serialized to the same name later. + */ + + class XMLDocumentImpl : public XMLDocument + { + + public: + XMLDocumentImpl(); + + XMLDocumentImpl( + DataObjectPtr dataObject); + + XMLDocumentImpl( + DataObjectPtr dataObject, + const char* rootElementURI, + const char* rootElementName); + + virtual ~XMLDocumentImpl(); + + virtual DataObjectPtr getRootDataObject() const {return dataObject;} + virtual const char* getRootElementURI() const {return rootElementURI;} + virtual const char* getRootElementName() const {return rootElementName;} + virtual const char* getEncoding() const {return encoding;} + virtual void setEncoding(const char* enc); + virtual void setEncoding(const SDOString& enc); + + virtual bool getXMLDeclaration() const {return xmlDeclaration;} + virtual void setXMLDeclaration(bool xmlDecl); + + virtual const char* getXMLVersion() const {return xmlVersion;} + virtual void setXMLVersion(const char* xmlVer); + virtual void setXMLVersion(const SDOString& xmlVer); + + virtual const char* getSchemaLocation() const {return schemaLocation;} + virtual void setSchemaLocation(const char* schemaLoc); + virtual void setSchemaLocation(const SDOString& schemaLoc); + + virtual const char* getNoNamespaceSchemaLocation() const { return noNamespaceSchemaLocation;} + virtual void setNoNamespaceSchemaLocation(const char* noNamespaceSchemaLoc); + virtual void setNoNamespaceSchemaLocation(const SDOString& noNamespaceSchemaLoc); + + + friend std::istream& operator>>(std::istream& input, XMLDocumentImpl& doc); + private: + DataObjectPtr dataObject; + SDOXMLString rootElementURI; + SDOXMLString rootElementName; + SDOXMLString encoding; + bool xmlDeclaration; + SDOXMLString xmlVersion; + SDOXMLString schemaLocation; + SDOXMLString noNamespaceSchemaLocation; + + + }; + } // End - namespace sdo +} // End - namespace commonj + + +#endif //_XMLDocumentImpl_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLHelper.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLHelper.cpp new file mode 100644 index 0000000000..0e1018ac99 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLHelper.cpp @@ -0,0 +1,36 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + + +#include "commonj/sdo/XMLHelper.h" +namespace commonj +{ + namespace sdo + { + ////////////////////////////////////////////////////////////////////// + // Construction/Destruction + ////////////////////////////////////////////////////////////////////// + XMLHelper::~XMLHelper() + { + } + + } // End - namespace sdo +} // End - namespace commonj diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLHelper.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLHelper.h new file mode 100644 index 0000000000..79e821ebd1 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLHelper.h @@ -0,0 +1,184 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _XMLHELPER_H_ +#define _XMLHELPER_H_ + + +#include "commonj/sdo/export.h" +#include "commonj/sdo/XMLDocument.h" +#include "commonj/sdo/RefCountingObject.h" + +namespace commonj +{ + namespace sdo + { + /** + * + * XMLHelper provides the ability to load XML data into + * a data object graph, according to a schema + */ + + class XMLHelper : public RefCountingObject + { + public: + + /** load/loadFile - loads xml data + * + * De-serializes the specified XML file building a graph of DataObjects. + * Returns a pointer to the root data object + */ + + SDO_API virtual XMLDocumentPtr createDocument( + const char* elementname = 0, + const char* rootElementURI=0) = 0; + SDO_API virtual XMLDocumentPtr createDocument( + const SDOString& elementname, + const SDOString& rootElementURI) = 0; + + SDO_API virtual XMLDocumentPtr loadFile( + const char* xmlFile, + const char* targetNamespaceURI=0) = 0; + SDO_API virtual XMLDocumentPtr loadFile( + const SDOString& xmlFile, + const SDOString& targetNamespaceURI = "") = 0; + + SDO_API virtual XMLDocumentPtr load( + std::istream& inXml, + const char* targetNamespaceURI=0) = 0; + SDO_API virtual XMLDocumentPtr load( + std::istream& inXml, + const SDOString& targetNamespaceURI = "") = 0; + + SDO_API virtual XMLDocumentPtr load( + const char* inXml, + const char* targetNamespaceURI=0) = 0; + SDO_API virtual XMLDocumentPtr load( + const SDOString& inXml, + const SDOString& targetNamespaceURI = "") = 0; + + /** save saves the graph to XML + * + * save - Serializes the datagraph to the XML file + */ + + SDO_API virtual void save(XMLDocumentPtr doc, + const char* xmlFile, + int indent = -1) = 0; + SDO_API virtual void save(XMLDocumentPtr doc, + const SDOString& xmlFile, + int indent = -1) = 0; + + SDO_API virtual void save( + DataObjectPtr dataObject, + const char* rootElementURI, + const char* rootElementName, + const char* xmlFile, + int indent = -1) = 0; + SDO_API virtual void save( + DataObjectPtr dataObject, + const SDOString& rootElementURI, + const SDOString& rootElementName, + const SDOString& xmlFile, + int indent = -1) = 0; + + /** save saves the graph to XML + * + * save - Serializes the datagraph to the XML stream + */ + + SDO_API virtual void save(XMLDocumentPtr doc, std::ostream& outXml, + int indent = -1) = 0; + + SDO_API virtual void save( + DataObjectPtr dataObject, + const char* rootElementURI, + const char* rootElementName, + std::ostream& outXml, + int indent = -1) = 0; + SDO_API virtual void save( + DataObjectPtr dataObject, + const SDOString& rootElementURI, + const SDOString& rootElementName, + std::ostream& outXml, + int indent = -1) = 0; + + /** save saves the graph to XML + * + * save - Serializes the datagraph to a string + */ + + SDO_API virtual char* save(XMLDocumentPtr doc, int indent = -1) = 0; + SDO_API virtual char* save( + DataObjectPtr dataObject, + const char* rootElementURI, + const char* rootElementName, + int indent = -1) = 0; + SDO_API virtual char* save( + DataObjectPtr dataObject, + const SDOString& rootElementURI, + const SDOString& rootElementName, + int indent = -1) = 0; + + /** createDocument creates an XMLDocument + * + * An XMLDocument holds a root data object and all its + * tree of children. This provides the means of storing the + * name to be applied to the root element when serializing + */ + + SDO_API virtual XMLDocumentPtr createDocument( + DataObjectPtr dataObject, + const char* rootElementURI, + const char* rootElementName) = 0; + SDO_API virtual XMLDocumentPtr createDocument( + DataObjectPtr dataObject, + const SDOString& rootElementURI, + const SDOString& rootElementName) = 0; + + /***********************************/ + /* Destructor */ + /***********************************/ + SDO_API virtual ~XMLHelper(); + + /** getErrorCount gets number of parse errors + * + * Parser error count - the parse may have + * succeeded or partially succeeded or failed. There + * may be errors to report or handle. + */ + + virtual unsigned int getErrorCount() const = 0; + + /** getErrorMessage gets the nth error message + * + * Each error has a message, usually giving the line and file + * in which the parser error occurred. + */ + + virtual const char* getErrorMessage(unsigned int errnum) const = 0; + + + }; + } // End - namespace sdo +} // End - namespace commonj + +#endif //_XMLHELPER_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLHelperImpl.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLHelperImpl.cpp new file mode 100644 index 0000000000..c524b24ccc --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLHelperImpl.cpp @@ -0,0 +1,400 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SDOXMLFileWriter.h" // Include first to avoid libxml compile problems! +#include "commonj/sdo/SDOXMLStreamWriter.h" // Include first to avoid libxml compile problems! +#include "commonj/sdo/SDOXMLBufferWriter.h" // Include first to avoid libxml compile problems! +#include "commonj/sdo/XMLHelperImpl.h" +#include "commonj/sdo/XMLDocumentImpl.h" +#include +#include +#include +#include "commonj/sdo/SDOSAX2Parser.h" +#include "commonj/sdo/XSDPropertyInfo.h" +#include "commonj/sdo/XSDTypeInfo.h" +#include "commonj/sdo/SDORuntimeException.h" +#include "commonj/sdo/DataFactoryImpl.h" + + +namespace commonj +{ + namespace sdo + { + + + ////////////////////////////////////////////////////////////////////// + // Construction/Destruction + ////////////////////////////////////////////////////////////////////// + + XMLHelperImpl::XMLHelperImpl(DataFactoryPtr df) + { + dataFactory = (DataFactory*)df; + if (!dataFactory) + { + dataFactory = DataFactory::getDataFactory(); + } + } + + XMLHelperImpl::~XMLHelperImpl() + { + clearErrors(); + } + + DataFactoryPtr XMLHelperImpl::getDataFactory() + { + if (!dataFactory) + { + dataFactory = DataFactory::getDataFactory(); + } + return dataFactory; + } + + + const TypeImpl* XMLHelperImpl::findRoot(DataFactory* df, + const SDOString& rootElementURI) + { + + const TypeImpl* rootTypePtr = ((DataFactoryImpl*)df)->findTypeImpl(rootElementURI.c_str(), + "RootType"); + + if (rootTypePtr != 0) + { + return rootTypePtr; + } + + const TypeList& tl = df->getTypes(); + for (unsigned int i = 0; i < tl.size(); i++) + { + if (!strcmp("RootType", tl[i].getName())) + { + return ((DataFactoryImpl*)df)->findTypeImpl(tl[i].getURI(), "RootType"); + } + } + return 0; + } + + XMLDocumentPtr XMLHelperImpl::createDocument(const char* elementname, + const char* rootElementURI) + { + if (rootElementURI == 0) + { + if (elementname == 0) + { + return createDocument(SDOString(""), SDOString("")); + } + else + { + return createDocument(SDOString(elementname), SDOString("")); + } + } + else + { + if (elementname == 0) + { + return createDocument(SDOString(""), SDOString(rootElementURI)); + } + else + { + return createDocument(SDOString(elementname), SDOString(rootElementURI)); + } + } + } + + + XMLDocumentPtr XMLHelperImpl::createDocument(const SDOString& elementname, + const SDOString& rootElementURI) + { + DataFactory* dp = (DataFactory*)getDataFactory(); + if (dp == 0) return 0; + + const TypeImpl* rType = findRoot(dp, rootElementURI); + if (rType == 0) + { + std::string msg("createDocument - cannot find element "); + msg += elementname; + SDO_THROW_EXCEPTION("createDocument", SDOUnsupportedOperationException, + msg.c_str()); + } + + if (elementname.length() != 0) + { + PropertyImpl* pl = rType->getPropertyImpl(elementname); + if (pl == 0) + { + std::string msg("createDocument - cannot find element "); + msg += elementname; + SDO_THROW_EXCEPTION("createDocument", SDOUnsupportedOperationException, + msg.c_str()); + } + + const Type& tp = pl->getType(); + DataObjectPtr dob = dp->create(tp); + return new XMLDocumentImpl(dob, + tp.getURI(), + elementname.c_str()); + } + else + { + const Property& pl = rType->getProperty((unsigned int)0); + const Type& tp = pl.getType(); + DataObjectPtr dob = dp->create(tp); + return new XMLDocumentImpl(dob, + tp.getURI(), pl.getName()); + } + + std::string msg("createDocument - unable to find root type in namespace "); + msg += " NULL"; + SDO_THROW_EXCEPTION("createDocument", SDOUnsupportedOperationException, + msg.c_str()); + } + + XMLDocumentPtr XMLHelperImpl::createDocument( + DataObjectPtr dataObject, + const char* rootElementURI, + const char* rootElementName) + { + SDOString uri; + SDOString name; + if (0 == rootElementURI) + uri = ""; + else + uri = rootElementURI; + if (0 == rootElementName) + name = ""; + else + name = rootElementName; + + return createDocument(dataObject, uri, name); + } + XMLDocumentPtr XMLHelperImpl::createDocument( + DataObjectPtr dataObject, + const SDOString& rootElementURI, + const SDOString& rootElementName) + { + return new XMLDocumentImpl(dataObject, rootElementURI.c_str(), rootElementName.c_str()); + } + + XMLDocumentPtr XMLHelperImpl::loadFile( + const char* xmlFile, + const char* targetNamespaceURI) + { + DataObjectPtr rootDataObject; + clearErrors(); + SDOSAX2Parser sdoParser(getDataFactory(), + targetNamespaceURI, + rootDataObject, + this); + if (sdoParser.parse(xmlFile) == 0) + { + return createDocument(rootDataObject, (const char*)sdoParser.getRootElementURI(), sdoParser.getRootElementName()); + } + return 0; + } + + XMLDocumentPtr XMLHelperImpl::loadFile( + const SDOString& xmlFile, + const SDOString& targetNamespaceURI) + { + DataObjectPtr rootDataObject; + clearErrors(); + SDOSAX2Parser sdoParser(getDataFactory(), + targetNamespaceURI.c_str(), + rootDataObject, + this); + if (sdoParser.parse(xmlFile.c_str()) == 0) + { + return createDocument(rootDataObject, (const char*)sdoParser.getRootElementURI(), sdoParser.getRootElementName()); + } + return 0; + } + + + XMLDocumentPtr XMLHelperImpl::load( + std::istream& inXml, + const char* targetNamespaceURI) + { + DataObjectPtr rootDataObject; + SDOSAX2Parser sdoParser(getDataFactory(), + targetNamespaceURI, + rootDataObject, + this); + clearErrors(); + inXml>>sdoParser; + return createDocument(rootDataObject, (const char*)sdoParser.getRootElementURI(), sdoParser.getRootElementName()); + } + + XMLDocumentPtr XMLHelperImpl::load( + std::istream& inXml, + const SDOString& targetNamespaceURI) + { + DataObjectPtr rootDataObject; + SDOSAX2Parser sdoParser(getDataFactory(), + targetNamespaceURI.c_str(), + rootDataObject, + this); + clearErrors(); + inXml>>sdoParser; + return createDocument(rootDataObject, (const char*)sdoParser.getRootElementURI(), sdoParser.getRootElementName()); + } + + XMLDocumentPtr XMLHelperImpl::load( + const char* inXml, + const char* targetNamespaceURI) + { + std::istringstream str(inXml); + return load(str, targetNamespaceURI); + } + XMLDocumentPtr XMLHelperImpl::load( + const SDOString& inXml, + const SDOString& targetNamespaceURI) + { + std::istringstream str(inXml); + return load(str, targetNamespaceURI); + } + + void XMLHelperImpl::save(XMLDocumentPtr doc, const char* xmlFile, int indent) + { + SDOXMLFileWriter writer(xmlFile, dataFactory); + writer.write(doc, indent); + } + void XMLHelperImpl::save(XMLDocumentPtr doc, const SDOString& xmlFile, int indent) + { + SDOXMLFileWriter writer(xmlFile.c_str(), dataFactory); + writer.write(doc, indent); + } + + void XMLHelperImpl::save( + DataObjectPtr dataObject, + const char* rootElementURI, + const char* rootElementName, + const char* xmlFile, + int indent) + { + save(createDocument(dataObject,rootElementURI, rootElementName), xmlFile, + indent); + } + void XMLHelperImpl::save( + DataObjectPtr dataObject, + const SDOString& rootElementURI, + const SDOString& rootElementName, + const SDOString& xmlFile, + int indent) + { + save(createDocument(dataObject,rootElementURI, rootElementName), xmlFile, + indent); + } + + + // Serializes the datagraph to a stream + void XMLHelperImpl::save(XMLDocumentPtr doc, std::ostream& outXml, + int indent) + { + SDOXMLStreamWriter writer(outXml, dataFactory); + writer.write(doc, indent); + } + + void XMLHelperImpl::save( + DataObjectPtr dataObject, + const char* rootElementURI, + const char* rootElementName, + std::ostream& outXml, + int indent ) + { + save(createDocument(dataObject,rootElementURI, rootElementName), outXml, indent); + } + void XMLHelperImpl::save( + DataObjectPtr dataObject, + const SDOString& rootElementURI, + const SDOString& rootElementName, + std::ostream& outXml, + int indent ) + { + save(createDocument(dataObject,rootElementURI, rootElementName), outXml, indent); + } + + // Serializes the datagraph to a std::string + char* XMLHelperImpl::save(XMLDocumentPtr doc, + int indent) + { + SDOXMLBufferWriter writer(dataFactory); + writer.write(doc, indent); + SDOXMLString ret = writer.getBuffer(); + char* retString = new char[strlen(ret) +1]; + strcpy(retString, ret); + return retString; + } + char* XMLHelperImpl::save( + DataObjectPtr dataObject, + const char* rootElementURI, + const char* rootElementName, + int indent) + { + return save(createDocument(dataObject,rootElementURI, rootElementName), + indent); + } + char* XMLHelperImpl::save( + DataObjectPtr dataObject, + const SDOString& rootElementURI, + const SDOString& rootElementName, + int indent) + { + return save(createDocument(dataObject,rootElementURI, rootElementName), + indent); + } + + unsigned int XMLHelperImpl::getErrorCount() const + { + return parseErrors.size(); + } + + + const char* XMLHelperImpl::getErrorMessage(unsigned int errnum) const + { + if (errnum >= 0 && errnum < parseErrors.size()) + { + return parseErrors[errnum]; + } + return 0; + } + + void XMLHelperImpl::setError(const char* message) + { + if (message == 0) return; + char * m = new char[strlen(message) + 1]; + strcpy(m,message); + m[strlen(message)] = 0; + parseErrors.push_back(m); + } + + void XMLHelperImpl::clearErrors() + { + while (!parseErrors.empty()) + { + if (*parseErrors.begin() != 0) + { + delete[] (char*)(*parseErrors.begin()); + } + parseErrors.erase(parseErrors.begin()); + } + } + + } // End - namespace sdo +} // End - namespace commonj diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLHelperImpl.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLHelperImpl.h new file mode 100644 index 0000000000..49768e2566 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLHelperImpl.h @@ -0,0 +1,184 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _XMLHELPERIMPL_H_ +#define _XMLHELPERIMPL_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/XMLHelper.h" +#include "commonj/sdo/export.h" +#include "commonj/sdo/SDOXMLString.h" +#include "commonj/sdo/SAX2Namespaces.h" +#include "commonj/sdo/SchemaInfo.h" +#include "commonj/sdo/TypeDefinitionsImpl.h" +#include "commonj/sdo/ParserErrorSetter.h" + +namespace commonj +{ + namespace sdo + { + + /** + * + * XMLHelperImpl is the implementation of the abstract class + * XMLHelper. + * Provides the ability to load XML data into + * a data object graph, according to a schema + */ + + class XMLHelperImpl : public XMLHelper, ParserErrorSetter + { + public: + // Constructor + XMLHelperImpl(DataFactoryPtr dataFactory); + + // Destructor + virtual ~XMLHelperImpl(); + + virtual unsigned int getErrorCount() const; + virtual const char* getErrorMessage(unsigned int errnum) const; + virtual void setError(const char* error); + + + /** load/loadFile - loads xml data + * + * De-serializes the specified XML file building a graph of DataObjects. + * Returns a pointer to the root data object + */ + + virtual XMLDocumentPtr createDocument( + const char* elementname= 0, + const char* rootElementURI=0); + + virtual XMLDocumentPtr createDocument( + const SDOString& elementname, + const SDOString& rootElementURI); + + virtual XMLDocumentPtr loadFile( + const char* xmlFile, + const char* targetNamespaceURI = 0); + virtual XMLDocumentPtr loadFile( + const SDOString& xmlFile, + const SDOString& targetNamespaceURI = ""); + + virtual XMLDocumentPtr load( + std::istream& inXml, + const char* targetNamespaceURI = 0); + virtual XMLDocumentPtr load( + std::istream& inXml, + const SDOString& targetNamespaceURI = ""); + + virtual XMLDocumentPtr load( + const char* inXml, + const char* targetNamespaceURI = 0); + virtual XMLDocumentPtr load( + const SDOString& inXml, + const SDOString& targetNamespaceURI = ""); + + virtual XMLDocumentPtr createDocument( + DataObjectPtr dataObject, + const char* rootElementURI, + const char* rootElementName); + virtual XMLDocumentPtr createDocument( + DataObjectPtr dataObject, + const SDOString& rootElementURI, + const SDOString& rootElementName); + + /** save saves the graph to XML + * + * save - Serializes the datagraph to the XML file + */ + + void save(XMLDocumentPtr doc, + const char* xmlFile, + int indent = -1); + void save(XMLDocumentPtr doc, + const SDOString& xmlFile, + int indent = -1); + + void save( + DataObjectPtr dataObject, + const char* rootElementURI, + const char* rootElementName, + const char* xmlFile, int indent = -1); + void save( + DataObjectPtr dataObject, + const SDOString& rootElementURI, + const SDOString& rootElementName, + const SDOString& xmlFile, int indent = -1); + + /** save saves the graph to XML + * + * save - Serializes the datagraph to a stream + */ + + void save(XMLDocumentPtr doc, std::ostream& outXml, + int indent = -1); + void save( + DataObjectPtr dataObject, + const char* rootElementURI, + const char* rootElementName, + std::ostream& outXml, + int indent = -1); + void save( + DataObjectPtr dataObject, + const SDOString& rootElementURI, + const SDOString& rootElementName, + std::ostream& outXml, + int indent = -1); + + /** save saves the graph to XML + * + * save - Serializes the datagraph to a string + */ + char* save(XMLDocumentPtr doc,int indent = -1); + char* save( + DataObjectPtr dataObject, + const char* rootElementURI, + const char* rootElementName, + int indent = -1); + char* save( + DataObjectPtr dataObject, + const SDOString& rootElementURI, + const SDOString& rootElementName, + int indent = -1); + + private: + int parse(const char* source); + void clearErrors(); + + std::vector parseErrors; + + // Instance variables + DataFactoryPtr dataFactory; + SDOXMLString targetNamespaceURI; + + const TypeImpl* findRoot(DataFactory* df, + const SDOString& rootElementURI); + + DataFactoryPtr getDataFactory(); + }; + + } // End - namespace sdo +} // End - namespace commonj + +#endif // _XMLHELPERIMPL_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLQName.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLQName.cpp new file mode 100644 index 0000000000..9f897a8525 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLQName.cpp @@ -0,0 +1,86 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/XMLQName.h" +namespace commonj +{ + namespace sdo + { + + + XMLQName::XMLQName() + { + } + + XMLQName::XMLQName(const SDOXMLString& sdouri) + { + int index = sdouri.lastIndexOf('#'); + if (index < 0) + { + localName = sdouri; + } + else + { + uri = sdouri.substring(0, index); + localName = sdouri.substring(index+1); + } + } + + XMLQName::XMLQName( + const SDOXMLString& qname, + const SAX2Namespaces& globalNamespaces, + const SAX2Namespaces& localNamespaces) + { + SDOXMLString prefix; + + int index = qname.firstIndexOf(':'); + if (index < 0) + { + localName = qname; + } + else + { + prefix = qname.substring(0, index); + localName = qname.substring(index+1); + } + + const SDOXMLString* namespaceURI = localNamespaces.find(prefix); + if (namespaceURI == 0) + { + namespaceURI = globalNamespaces.find(prefix); + } + if (namespaceURI != 0) + { + uri = *namespaceURI; + } + + } + + XMLQName::~XMLQName() + { + } + + SDOXMLString XMLQName::getSDOName() const + { + return uri + "#" + localName; + } + } // End - namespace sdo +} // End - namespace commonj diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLQName.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLQName.h new file mode 100644 index 0000000000..4efeb15bc5 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XMLQName.h @@ -0,0 +1,68 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _XMLQName_H_ +#define _XMLQName_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/SAX2Namespaces.h" +#include "commonj/sdo/SDOXMLString.h" +#include "commonj/sdo/DataObject.h" + +namespace commonj +{ + namespace sdo + { + +/** XMLQname wraps a qualified name + * + * This class holds a QName and provides access to its + * members + */ + + class XMLQName + { + + public: + XMLQName(); + XMLQName(const SDOXMLString& sdoUri); + XMLQName( + const SDOXMLString& qname, + const SAX2Namespaces& globalNamespaces, + const SAX2Namespaces& localNamespaces = SAX2Namespaces()); + + SDOXMLString getSDOName() const ; + const SDOXMLString& getURI() const {return uri;} + const SDOXMLString& getLocalName() const {return localName;} + virtual ~XMLQName(); + + private: + SDOXMLString uri; + SDOXMLString localName; + + + }; + } // End - namespace sdo +} // End - namespace commonj + + +#endif //_XMLQName_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDHelper.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDHelper.cpp new file mode 100644 index 0000000000..310716cc8c --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDHelper.cpp @@ -0,0 +1,37 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/XSDHelper.h" + +namespace commonj +{ + namespace sdo + { + + + XSDHelper::~XSDHelper() + { + } + + + + } // End - namespace sdo +} // End - namespace commonj diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDHelper.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDHelper.h new file mode 100644 index 0000000000..254afa236c --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDHelper.h @@ -0,0 +1,152 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _XSDHELPER_H_ +#define _XSDHELPER_H_ + + +#include "commonj/sdo/export.h" +#include "commonj/sdo/RefCountingObject.h" +#include "commonj/sdo/DataFactory.h" +#include "commonj/sdo/TypeDefinitions.h" + +namespace commonj +{ + namespace sdo + { + + /** + * + * XSDHelper provides the means of loading and saving XSD information + * from/to the metadata (Types and properties) + */ + + class XSDHelper : public RefCountingObject + { + public: + + /** define builds types/properties from file or stream + * + * define/defineFile + * + * Populates the data factory with Types and Properties from the schema + * Loads from file, stream or char* buffer. + * The return value is the URI of the root Type + * + */ + + SDO_API virtual const char* defineFile(const char* schemaFile) = 0; + SDO_API virtual const char* defineFile(const SDOString& schemaFile) = 0; + SDO_API virtual const char* define(std::istream& schema) = 0; + SDO_API virtual const char* define(const char* schema) = 0; + SDO_API virtual const char* define(const SDOString& schema) = 0; + + /** generate buildsXSD from types/properties + * + * generate/generateFile + * + * Saves the types/properties to an XSD stream or file + * + */ + + SDO_API virtual char* generate( + const TypeList& types, + const char* targetNamespaceURI = "", + int indent = -1) = 0; + SDO_API virtual char* generate( + const TypeList& types, + const SDOString& targetNamespaceURI = "", + int indent = -1) = 0; + SDO_API virtual void generate( + const TypeList& types, + std::ostream& outXsd, + const char* targetNamespaceURI = "", + int indent = -1) = 0; + SDO_API virtual void generate( + const TypeList& types, + std::ostream& outXsd, + const SDOString& targetNamespaceURI = "", + int indent = -1) = 0; + SDO_API virtual void generateFile( + const TypeList& types, + const char* fileName, + const char* targetNamespaceURI = "", + int indent = -1) = 0; + SDO_API virtual void generateFile( + const TypeList& types, + const SDOString& fileName, + const SDOString& targetNamespaceURI = "", + int indent = -1) = 0; + + /***********************************/ + /* Destructor */ + /***********************************/ + SDO_API virtual ~XSDHelper(); + + /** getDataFactory() + * + * Return the DataFactory + */ + + SDO_API virtual DataFactoryPtr getDataFactory() = 0; + + /** getRootTypeURI + * + * Return the URI for the root Type + */ + + SDO_API virtual const char* getRootTypeURI() = 0; + + /** getErrorCount gets number of parse errors + * + * Parser error count - the parse may have + * succeeded or partially succeeded or failed. There + * may be errors to report or handle. + */ + + virtual unsigned int getErrorCount() const = 0; + + /** getErrorMessage gets the nth error message + * + * Each error has a message, usually giving the line and file + * in which the parser error occurred. + */ + + virtual const char* getErrorMessage(unsigned int errnum) const = 0; + + /** + * + * used for defining types from type definitions + */ + + SDO_API virtual void defineTypes(TypeDefinitions& types) = 0; + + /** + * + * returns the types parsed from the schemas + */ + SDO_API virtual TypeDefinitions& getDefinedTypes() = 0; + + }; + }//End - namespace sdo +} // End - namespace commonj + +#endif //_XSDHELPER_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDHelperImpl.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDHelperImpl.cpp new file mode 100644 index 0000000000..752ad493de --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDHelperImpl.cpp @@ -0,0 +1,665 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/SDOXMLFileWriter.h" // Include first to avoid libxml compile problems! +#include "commonj/sdo/SDOXMLStreamWriter.h" // Include first to avoid libxml compile problems! +#include "commonj/sdo/SDOXMLBufferWriter.h" // Include first to avoid libxml compile problems! +#include "commonj/sdo/SDOXSDFileWriter.h" +#include "commonj/sdo/SDOXSDStreamWriter.h" +#include "commonj/sdo/SDOXSDBufferWriter.h" +#include "commonj/sdo/XSDHelperImpl.h" +#include "commonj/sdo/XMLDocumentImpl.h" +#include +#include +#include +#include +#include "commonj/sdo/SDOSchemaSAX2Parser.h" +#include "commonj/sdo/SDOSAX2Parser.h" +#include "commonj/sdo/XSDPropertyInfo.h" +#include "commonj/sdo/XSDTypeInfo.h" + +#include "commonj/sdo/SDORuntimeException.h" +#include "commonj/sdo/DASProperty.h" +#include "commonj/sdo/Logging.h" +#include "commonj/sdo/Type.h" + +namespace commonj +{ + namespace sdo + { + + /** XSDHelperImpl + * + * XSDHelperImpl is the implementation of the abstract class + * XSDHelper. + * Provides the means of loading and saving XSD information + * from/to the metadata (Types and properties) + */ + + XSDHelperImpl::XSDHelperImpl(DataFactoryPtr df) + { + dataFactory = df; + if (!dataFactory) + { + dataFactory = DataFactory::getDataFactory(); + } + } + + XSDHelperImpl::~XSDHelperImpl() + { + clearErrors(); + } + + /** define builds types/properties from file or stream + * + * define/defineFile + * + * Populates the data factory with Types and Properties from the schema + * Loads from file, stream or char* buffer. + * The return value is the URI of the root Type + * + */ + + const char* XSDHelperImpl::defineFile(const char* schema) + { + clearErrors(); + SDOSchemaSAX2Parser schemaParser(schemaInfo, this, parsedLocations, definedNamespaces); + + // Build URI allowing for Windows path + xmlChar* uri = xmlCanonicPath((xmlChar*)schema); + SDOXMLString schemaUri(uri); + if (uri) + { + xmlFree(uri); + } + + if (0 != schemaParser.parseURI(schemaUri, SDOXMLString())) + return 0; + defineTypes(schemaParser.getTypeDefinitions()); + return schemaInfo.getTargetNamespaceURI(); + } + + const char* XSDHelperImpl::defineFile(const SDOString& schema) + { + return defineFile(schema.c_str()); + } + + const char* XSDHelperImpl::define(std::istream& schema) + { + SDOSchemaSAX2Parser schemaParser(schemaInfo, this, parsedLocations, definedNamespaces); + clearErrors(); + schema >> schemaParser; + defineTypes(schemaParser.getTypeDefinitions()); + return schemaInfo.getTargetNamespaceURI(); + } + + const char* XSDHelperImpl::define(const char* schema) + { + std::istringstream str(schema); + SDOSchemaSAX2Parser schemaParser(schemaInfo, this, parsedLocations, definedNamespaces); + clearErrors(); + str >> schemaParser; + defineTypes(schemaParser.getTypeDefinitions()); + return schemaInfo.getTargetNamespaceURI(); + return define(str); + } + const char* XSDHelperImpl::define(const SDOString& schema) + { + std::istringstream str(schema); + SDOSchemaSAX2Parser schemaParser(schemaInfo, this, parsedLocations, definedNamespaces); + clearErrors(); + str >> schemaParser; + defineTypes(schemaParser.getTypeDefinitions()); + return schemaInfo.getTargetNamespaceURI(); + return define(str); + } + + void XSDHelperImpl::newSubstitute(const char* entryName, + PropertyDefinitionImpl& prop) + { + try + { + const char* typeUri = prop.substituteUri.isNull() ? + prop.typeUri : prop.substituteUri; + const Type& rootType = dataFactory->getType(typeUri, entryName); + const std::list& pl = rootType.getPropertyListReference(); + + for (std::list::const_iterator j = pl.begin(); + j != pl.end(); + j++) + { + if (!(*j)->getType().isDataType() + && strcmp((*j)->getType().getURI(),Type::SDOTypeNamespaceURI.c_str())) + { + // recurse the tree.. + newSubstitute((*j)->getType().getName(), prop); + + if (!strcmp((*j)->getName(), prop.substituteName)) + { + dataFactory->setPropertySubstitute(rootType.getURI(), + rootType.getName(), + (*j)->getName(), + prop.name, + typeUri, + prop.typeName); + XSDPropertyInfo* pi = (XSDPropertyInfo*) + ((DASProperty*) (*j))->getDASValue("XMLDAS::PropertyInfo"); + + if (pi) + { + PropertyDefinitionImpl& propdef = (PropertyDefinitionImpl&)pi->getPropertyDefinition(); + propdef.substituteNames.push_back(prop.name); + propdef.substituteLocalNames.push_back(prop.localname); + } + } + } + } + } + catch (const SDORuntimeException&) + { + } + } + + void XSDHelperImpl::addSubstitutes(PropertyDefinitionImpl& prop, + TypeDefinitionImpl& ty) + { + try + { + const char* typeUri = prop.substituteUri.isNull() ? + ty.uri : prop.substituteUri; + DataFactoryImpl* df = (DataFactoryImpl*)(DataFactory*)dataFactory; + const Type* rootType = df->findType(typeUri,"RootType"); + if (rootType == 0) return; + + const std::list& pl = rootType->getPropertyListReference(); + + for (std::list::const_iterator j = pl.begin(); + j != pl.end(); + j++) + { + XSDPropertyInfo* pi = (XSDPropertyInfo*) + ((DASProperty*) (*j))->getDASValue("XMLDAS::PropertyInfo"); + + if (pi) + { + PropertyDefinitionImpl& propdef = (PropertyDefinitionImpl&)pi->getPropertyDefinition(); + if (propdef.isSubstitute && propdef.substituteName.equals(prop.name)) + { + + LOGINFO_1(INFO,"XSDHelper adding substitute for property %s", (const char*)prop.name); + + dataFactory->setPropertySubstitute(typeUri,ty.name, + prop.name, propdef.name, + (*j)->getType().getURI(), + (*j)->getType().getName()); + prop.substituteNames.push_back(propdef.name); + prop.substituteLocalNames.push_back(propdef.localname); + } + } + } + } + catch (const SDORuntimeException&) + { + } + } + + + /** defineTypes + * + * This method works through all the data gathered during parsing + * and defines all the types using the data factory. + */ + + void XSDHelperImpl::defineTypes(TypeDefinitions& types) + { + defineTypes(types.getTypeDefinitions()); + } + + + /** defineTypes + * + * This method works through all the data gathered during parsing + * and defines all the types using the data factory. + */ + + void XSDHelperImpl::defineTypes(TypeDefinitionsImpl& typedefs) + { + DataFactoryImpl* df = (DataFactoryImpl*)(DataFactory*)dataFactory; + + XMLDAS_TypeDefs::iterator iter; + for (iter=typedefs.types.begin(); iter != typedefs.types.end(); iter++) + { + TypeDefinitionImpl& ty = iter->second; + try + { + /* + string isSeqCode = "false"; + if (ty.isSequenced) + isSeqCode = "true"; + string isOpenCode = "false"; + if (ty.isOpen) + isOpenCode = "true"; + string isAbstractCode = "false"; + if (ty.isAbstract) + isAbstractCode = "true"; + string uriCode = "0"; + if (!ty.uri.isNull()) + { + uriCode = "\"" + string(ty.uri) + "\""; + } + + string addTypeCode = "dataFactory->addType(\n" + + uriCode + ", \"" + string(ty.name) + "\", \n" + + isSeqCode + ", " + isOpenCode + ", " + isAbstractCode +");"; + cout << addTypeCode.c_str() <addType((const char*)ty.uri, (const char*)ty.name, ty.isSequenced, + ty.isOpen, ty.isAbstract, ty.dataType, ty.isFromList); + df->setDASValue( + (const char*)ty.uri, (const char*)ty.name, + "XMLDAS::TypeInfo", + new XSDTypeInfo(ty)); + + // add aliases + if (!ty.aliases.isNull()) + { + SDOXMLString al = ty.aliases; + SDOXMLString al1 = ""; + int index; + while (!al.isNull() && !al.equals("")) + { + index = al.lastIndexOf(' '); + if (index < 0) + { + al1 = al; + al = ""; + } + else + { + al1 = al.substring(index + 1); + al = al.substring(0,index); + } + if (!al1.isNull() && !al1.equals("")) + { + df->setAlias( + ty.uri, + ty.name, + (const char*)al1); + } + } + } + + } + catch (SDORuntimeException& e) + { + SDO_RETHROW_EXCEPTION("defineTypes", e); + } + } + for (iter=typedefs.types.begin(); iter != typedefs.types.end(); iter++) + { + TypeDefinitionImpl& ty = iter->second; + if (!ty.parentTypeName.isNull()) + { + try + { + /* + string uriCode = "0"; + if (!ty.uri.isNull()) + { + uriCode = "\"" + string(ty.uri) + "\""; + } + string parentUriCode = "0"; + if (!ty.uri.isNull()) + { + parentUriCode = "\"" + string(ty.parentTypeUri) + "\""; + } + + string addTypeCode = "dataFactory->setBaseType(\n" + + uriCode + ", \"" + string(ty.name) + "\", \n" + + parentUriCode + ", \"" + string(ty.parentTypeName) + "\");"; + + cout << addTypeCode.c_str() <setBaseType( + (const char*)ty.uri, + (const char*)ty.name, + (const char*)ty.parentTypeUri, + (const char*)ty.parentTypeName, + ty.isRestriction); + } + catch (SDORuntimeException& e) + { + SDO_RETHROW_EXCEPTION("defineTypes", e); + } + } + + XmlDasPropertyDefs::iterator propsIter; + for (propsIter = ty.properties.begin(); propsIter != ty.properties.end(); propsIter++) + { + PropertyDefinitionImpl& prop = *propsIter; + + // For a refence we need to determine the type from the + // global element declaration + if(prop.isReference) + { + + bool refFound = false; + + if (prop.name.isNull()) + prop.name = prop.typeName; + + + XMLDAS_TypeDefs::iterator refTypeIter = + typedefs.types.find(TypeDefinitionsImpl::getTypeQName(prop.typeUri, "RootType")); + if(refTypeIter != typedefs.types.end()) + { + + TypeDefinitionImpl& rootTy = refTypeIter->second; + + // find the property on the root type + XmlDasPropertyDefs::iterator refPropsIter; + for (refPropsIter = rootTy.properties.begin(); refPropsIter != rootTy.properties.end(); refPropsIter++) + { + + if (refPropsIter->localname.equals(prop.typeName)) + { + prop.typeUri = refPropsIter->typeUri; + prop.typeName = refPropsIter->typeName; + refFound = true; + } + } + } + if (!refFound) + { + + // Check if this type is already defined to the data factory + try + { + const Type& rootType = dataFactory->getType(prop.typeUri, "RootType"); + + const std::list pl = rootType.getPropertyListReference(); + + for (std::list::const_iterator j = pl.begin(); + j != pl.end(); + j++) + { + + XSDPropertyInfo* pi = (XSDPropertyInfo*) + ((DASProperty*) (*j))->getDASValue("XMLDAS::PropertyInfo"); + + if (prop.typeName.equals((*j)->getName()) + || (pi && prop.typeName.equals(pi->getPropertyDefinition().localname))) + { + prop.typeUri = (*j)->getType().getURI(); + prop.typeName = (*j)->getType().getName(); + refFound = true; + break; + } + } + } + catch (const SDORuntimeException&) + { + } + } + // If we haven't been able to resolve this reference we should ignore it + if (!refFound) + { + LOGINFO_1(INFO,"XsdHelper:no matching reference for %s", + (const char *)prop.name); + continue; + } + } + + if (prop.name.isNull()) + { + continue; + } + XMLDAS_TypeDefs::iterator propTypeIter = + typedefs.types.find(TypeDefinitionsImpl::getTypeQName(prop.typeUri, prop.typeName)); + if(propTypeIter != typedefs.types.end()) + { + prop.typeName = propTypeIter->second.name; + } + + try + { + + df->addPropertyToType((const char*)ty.uri, (const char*)ty.name, + (const char*)prop.name, + (const char*)prop.typeUri, + (const char*)prop.typeName, + prop.isMany, + prop.isReadOnly, + prop.isContainment); + + LOGINFO_1(INFO,"XSDHelper adds property %s",(const char*)(prop.name)); + + if (!prop.aliases.isNull()) + { + SDOXMLString al = prop.aliases; + SDOXMLString al1 = ""; + int index; + while (!al.isNull() && !al.equals("")) + { + index = al.lastIndexOf(' '); + if (index < 0) + { + al1 = al; + al = ""; + } + else + { + al1 = al.substring(index + 1); + al = al.substring(0,index); + } + if (!al1.isNull() && !al1.equals("")) + { + df->setAlias( + (const char*)ty.uri, + (const char*)ty.name, + (const char*)prop.name, + (const char*)al1); + } + } + } + if (prop.isSubstitute) + { + // we have a new substitute - so will check the existing graph for + // substitutions to insert + + LOGINFO_1(INFO,"XSDHelper: Found new substitute %s",(const char*)(prop.name)); + + newSubstitute( "RootType",prop); + } + else + { + // subtitutes can only reference global types + if (ty.name.equals("RootType")) + { + addSubstitutes(prop,ty); + } + } + + // Do not add DASValue to ChangeSummary + if (!(prop.typeUri.equals(Type::SDOTypeNamespaceURI.c_str()) + && prop.typeName.equals("ChangeSummary"))) + { + df->setDASValue( + ty.uri, ty.name, + prop.name, + "XMLDAS::PropertyInfo", + new XSDPropertyInfo(prop)); + } + } + catch (SDORuntimeException& e) + { + SDO_RETHROW_EXCEPTION("defineTypes", e); + } + } + + } + + // The addition of the new types was succesful so adding these + // types to the defined types should succeed (no duplicates) + definedTypes.getTypeDefinitions().addTypeDefinitions(typedefs); + + } // End - defineTypes + + /** getDataFactory returns the factory + * + */ + + DataFactoryPtr XSDHelperImpl::getDataFactory() + { + return dataFactory; + } + + + /** generate buildsXSD from types/properties + * + * generate/generateFile + * + * Saves the types/properties to an XSD stream or file + * + */ + + void XSDHelperImpl::generateFile( + const TypeList& types, + const char* fileName, + const char* targetNamespaceURI, + int indent + ) + { + SDOXSDFileWriter writer(fileName); + DataFactory* fac = dataFactory; + writer.write(types, targetNamespaceURI, + ((DataFactoryImpl*)fac)->getOpenProperties(), indent); + } + void XSDHelperImpl::generateFile( + const TypeList& types, + const SDOString& fileName, + const SDOString& targetNamespaceURI, + int indent + ) + { + SDOXSDFileWriter writer(fileName.c_str()); + DataFactory* fac = dataFactory; + writer.write(types, targetNamespaceURI.c_str(), + ((DataFactoryImpl*)fac)->getOpenProperties(), indent); + } + + void XSDHelperImpl::generate( + const TypeList& types, + std::ostream& outXml, + const char* targetNamespaceURI, + int indent + ) + { + SDOXSDStreamWriter writer(outXml); + DataFactory* fac = dataFactory; + writer.write(types, targetNamespaceURI, + ((DataFactoryImpl*)fac)->getOpenProperties(), indent); + } + void XSDHelperImpl::generate( + const TypeList& types, + std::ostream& outXml, + const SDOString& targetNamespaceURI, + int indent + ) + { + SDOXSDStreamWriter writer(outXml); + DataFactory* fac = dataFactory; + writer.write(types, targetNamespaceURI.c_str(), + ((DataFactoryImpl*)fac)->getOpenProperties(), indent); + } + + char* XSDHelperImpl::generate( + const TypeList& types, + const char* targetNamespaceURI, + int indent + ) + { + SDOXSDBufferWriter writer; + DataFactory* fac = dataFactory; + writer.write(types, targetNamespaceURI, + ((DataFactoryImpl*)fac)->getOpenProperties(), indent); + SDOXMLString ret = writer.getBuffer(); + char* retString = new char[strlen(ret) +1]; + strcpy(retString, ret); + return retString; + } + char* XSDHelperImpl::generate( + const TypeList& types, + const SDOString& targetNamespaceURI, + int indent + ) + { + SDOXSDBufferWriter writer; + DataFactory* fac = dataFactory; + writer.write(types, targetNamespaceURI.c_str(), + ((DataFactoryImpl*)fac)->getOpenProperties(), indent); + SDOXMLString ret = writer.getBuffer(); + char* retString = new char[strlen(ret) +1]; + strcpy(retString, ret); + return retString; + } + + unsigned int XSDHelperImpl::getErrorCount() const + { + return parseErrors.size(); + } + + + const char* XSDHelperImpl::getErrorMessage(unsigned int errnum) const + { + if (errnum >= 0 && errnum < parseErrors.size()) + { + return parseErrors[errnum]; + } + return 0; + } + + void XSDHelperImpl::setError(const char* message) + { + if (message == 0) return; + char * m = new char[strlen(message) + 1]; + strcpy(m,message); + m[strlen(message)] = 0; + parseErrors.push_back(m); + } + + void XSDHelperImpl::clearErrors() + { + while (!parseErrors.empty()) + { + if (*parseErrors.begin() != 0) + { + delete[] (char*)(*parseErrors.begin()); + } + parseErrors.erase(parseErrors.begin()); + } + } + + + } // End - namespace sdo +} // End - namespace commonj diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDHelperImpl.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDHelperImpl.h new file mode 100644 index 0000000000..a8cb561ccf --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDHelperImpl.h @@ -0,0 +1,172 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _XSDHELPERIMPL_H_ +#define _XSDHELPERIMPL_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/XSDHelper.h" +#include "commonj/sdo/export.h" +#include "commonj/sdo/SDOXMLString.h" +#include "commonj/sdo/SAX2Namespaces.h" +#include "commonj/sdo/SchemaInfo.h" +#include "commonj/sdo/TypeDefinitionsImpl.h" +#include "commonj/sdo/ParserErrorSetter.h" +#include "commonj/sdo/SDOSchemaSAX2Parser.h" + +namespace commonj +{ + namespace sdo + { + + /** + * + * XSDHelperImpl is the implementation of the abstract class + * XSDHelper. + * Provides the means of loading and saving XSD information + * from/to the metadata (Types and properties) + */ + + class XSDHelperImpl : public XSDHelper, ParserErrorSetter + { + public: + + // Constructor + XSDHelperImpl(DataFactoryPtr dataFactory); + + // Destructor + virtual ~XSDHelperImpl(); + + /** define builds types/properties from file or stream + * + * define/defineFile + * + * Populates the data factory with Types and Properties from the schema + * Loads from file, stream or char* buffer. + * The return value is the URI of the root Type + * + */ + virtual const char* defineFile(const char* schemaFile); + virtual const char* defineFile(const SDOString& schemaFile); + virtual const char* define(std::istream& schema); + virtual const char* define(const char* schema); + virtual const char* define(const SDOString& schema); + + /** getErrorCount gets number of parse errors + * + * Parser error count - the parse may have + * succeeded or partially succeeded or failed. There + * may be errors to report or handle. + */ + + virtual unsigned int getErrorCount() const; + + /** getErrorMessage gets the nth error message + * + * Each error has a message, usually giving the line and file + * in which the parser error occurred. + */ + + virtual const char* getErrorMessage(unsigned int errnum) const; + virtual void setError(const char* error); + + /** generate buildsXSD from types/properties + * + * generate/generateFile + * + * Saves the types/properties to an XSD stream or file + * + */ + + virtual char* generate( + const TypeList& types, + const char* targetNamespaceURI = "", + int indent = -1 + ); + virtual char* generate( + const TypeList& types, + const SDOString& targetNamespaceURI = "", + int indent = -1 + ); + void generate( + const TypeList& types, + std::ostream& outXsd, + const char* targetNamespaceURI = "", + int indent = -1 + ); + void generate( + const TypeList& types, + std::ostream& outXsd, + const SDOString& targetNamespaceURI = "", + int indent = -1 + ); + virtual void generateFile( + const TypeList& types, + const char* fileName, + const char* targetNamespaceURI = "", + int indent = -1); + virtual void generateFile( + const TypeList& types, + const SDOString& fileName, + const SDOString& targetNamespaceURI = "", + int indent = -1); + + virtual DataFactoryPtr getDataFactory(); + + // Return the URI for the root Type + virtual const char* getRootTypeURI() + { + return schemaInfo.getTargetNamespaceURI(); + } + + virtual void defineTypes(TypeDefinitions& types); + + virtual TypeDefinitions& getDefinedTypes() {return definedTypes;} + + private: + virtual void clearErrors(); + + void newSubstitute(const char* entryName, + PropertyDefinitionImpl& prop); + + void addSubstitutes(PropertyDefinitionImpl& prop, + TypeDefinitionImpl& ty); + + void defineTypes(TypeDefinitionsImpl& types); + int parse(const char* source); + + // Instance variables + DataFactoryPtr dataFactory; // metadata + SchemaInfo schemaInfo; + + std::vector parseErrors; + + TypeDefinitions definedTypes; + SDOSchemaSAX2Parser::PARSED_LOCATIONS parsedLocations; + + SDOSchemaSAX2Parser::DEFINED_NAMESPACES definedNamespaces; + }; + + } // End - namespace sdo +} // End - namespace commonj + +#endif // _XSDHELPERIMPL_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDPropertyInfo.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDPropertyInfo.cpp new file mode 100644 index 0000000000..c1124b648a --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDPropertyInfo.cpp @@ -0,0 +1,55 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/XSDPropertyInfo.h" + +namespace commonj +{ + namespace sdo + { + + /** + * + * This holds a property definition during the parsing process + * when all properties need to be read and stored prior to creation + * within the data facttory. + */ + + XSDPropertyInfo::XSDPropertyInfo() + { + } + + XSDPropertyInfo::XSDPropertyInfo(const PropertyDefinitionImpl& prop) + : property(prop) + { + } + + + XSDPropertyInfo::~XSDPropertyInfo() + { + } + + + } +} +// end - namespace sdo + + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDPropertyInfo.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDPropertyInfo.h new file mode 100644 index 0000000000..d6ebad81e0 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDPropertyInfo.h @@ -0,0 +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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _XSDPropertyInfo_H_ +#define _XSDPropertyInfo_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/DASValue.h" +#include "commonj/sdo/PropertyDefinitionImpl.h" +#include "commonj/sdo/SDOXMLString.h" + +namespace commonj +{ + namespace sdo + { + + /** + * + * This holds a property definition during the parsing process. + * This holds a property definition during the parsing process + * when all properties need to be read and stored prior to creation + * within the data facttory. + */ + + class XSDPropertyInfo : public DASValue + { + public: + + XSDPropertyInfo(); + XSDPropertyInfo(const PropertyDefinitionImpl& prop); + + virtual ~XSDPropertyInfo(); + + const PropertyDefinitionImpl& getPropertyDefinition() {return property;} + + + private: + PropertyDefinitionImpl property; + }; + } +} +#endif //_XSDPropertyInfo_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDTypeInfo.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDTypeInfo.cpp new file mode 100644 index 0000000000..214027fcb6 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDTypeInfo.cpp @@ -0,0 +1,54 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/XSDTypeInfo.h" + +namespace commonj +{ + namespace sdo + { + + /** XSDTypeInfo + * + * This holds a type definition during the parsing process + * when all types need to be read and stored prior to creation + * within the data facttory. + */ + + XSDTypeInfo::XSDTypeInfo() + { + } + + XSDTypeInfo::XSDTypeInfo(const TypeDefinitionImpl& typeDef) + : typeDefinition(typeDef) + { + } + + + XSDTypeInfo::~XSDTypeInfo() + { + + } + } +} +// end - namespace sdo + + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDTypeInfo.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDTypeInfo.h new file mode 100644 index 0000000000..16dd8c6eb8 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XSDTypeInfo.h @@ -0,0 +1,54 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _XSDTypeInfo_H_ +#define _XSDTypeInfo_H_ + +#include "commonj/sdo/disable_warn.h" + +#include "commonj/sdo/DASValue.h" +#include "commonj/sdo/TypeDefinitionImpl.h" + +namespace commonj +{ + namespace sdo + { + /** + * + * This holds a type definition during the parsing process + * when all types need to be read and stored prior to creation + * within the data factory. + */ + + class XSDTypeInfo : public DASValue + { + public: + XSDTypeInfo(); + XSDTypeInfo(const TypeDefinitionImpl& typeDef); + virtual ~XSDTypeInfo(); + const TypeDefinitionImpl& getTypeDefinition() {return typeDefinition;} + + private: + TypeDefinitionImpl typeDefinition; + }; + } +} +#endif //_XSDTypeInfo_H_ diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XpathHelper.cpp b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XpathHelper.cpp new file mode 100644 index 0000000000..de5aff341b --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XpathHelper.cpp @@ -0,0 +1,88 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#include "commonj/sdo/XpathHelper.h" + +#include +using std::string; + +namespace commonj{ +namespace sdo{ + +/** + * + * will provide utilities to help with xpath parsing + */ + +/** isIndexed - true if [] or . + * + * Returns true if the path has an index, indicating a many valued + * property at the end of the path. + */ + + +const bool XpathHelper::isIndexed(const char* path) +{ + if (path == 0) + { + return false; + } + else + { + return isIndexed(SDOString(path)); + } +} + +const bool XpathHelper::isIndexed(const SDOString& path) +{ + size_t lastSlash = path.rfind('/'); + + if (lastSlash == string::npos) + { + // Search from start of path + if (path.find('[') != string::npos) + { + return true; + } + if (path.find('.') != string::npos) + { + return true; + } + } + else + { + // Search from lastSlash + if (path.find('[', lastSlash) != string::npos) + { + return true; + } + if (path.find('.', lastSlash) != string::npos) + { + return true; + } + } + + return false; +} + +}; +}; + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XpathHelper.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XpathHelper.h new file mode 100644 index 0000000000..1e02ea1dd3 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/XpathHelper.h @@ -0,0 +1,57 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef XPATH_HELPER_H +#define XPATH_HELPER_H + +#include "commonj/sdo/export.h" +#include "commonj/sdo/SDOString.h" + +namespace commonj{ +namespace sdo{ + +/** + * + * XpathHelper provides utilities to help with xpath parsing + */ + +class XpathHelper +{ + public: + + virtual ~XpathHelper(); + + /** isIndexed - true if [] or . + * + * Returns true if the path has an index, indicating a many valued + * property at the end of the path. + */ + + static SDO_API const bool isIndexed(const char * path); + static SDO_API const bool isIndexed(const SDOString& path); + +}; +}; +}; + + +#endif + diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/disable_warn.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/disable_warn.h new file mode 100644 index 0000000000..b02bb5bd81 --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/disable_warn.h @@ -0,0 +1,29 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#ifndef _DISABLE_WARN_H_ +#define _DISABLE_WARN_H_ + +#if defined(WIN32) || defined (_WINDOWS) +#pragma warning(disable: 4786) +#endif + +#endif diff --git a/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/export.h b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/export.h new file mode 100644 index 0000000000..4a2d5f49ce --- /dev/null +++ b/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/export.h @@ -0,0 +1,49 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +#define SDO4CPP_VERSION 20051202 + +#if defined(WIN32) || defined (_WINDOWS) + +#define int64_t __int64 + +#ifdef SDO_EXPORTS +#include "commonj/sdo/disable_warn.h" +# define SDO_API __declspec(dllexport) +# define SDO_SPI __declspec(dllexport) +# define EXPIMP +#else +# define SDO_API __declspec(dllimport) +# define SDO_SPI __declspec(dllimport) +# define EXPIMP extern +#endif + +#else +#include +#include +#include +#include +#include +# define SDO_API +# define SDO_SPI +# define EXPIMP +#endif + -- cgit v1.2.3