Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improved region creation code.

Added pre-SAX validation. See tracker item 2892.

--HG--
rename : src/fieldml_library_0.3.cpp => src/String_InternalLibrary.cpp
rename : src/fieldml_library_0.3.h => src/String_InternalLibrary.h
  • Loading branch information...
commit 9ded2b751816bee32c0a7ab254e5a76f53d40964 1 parent 82c3bc8
caton.little@gmail.com authored
View
15 Fieldml.xsd
@@ -1,14 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="fieldml"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:fmlmeta="http://www.fieldml.org/metadata/0.3#"
>
- <xs:import schemaLocation="Fieldml_0.3_meta.xsd" namespace="http://www.fieldml.org/metadata/0.3#"/>
+ <xs:complexType name="FieldmlRdfTargetType">
+ <xs:attribute name="id" type="xs:string" form="qualified"/>
+ </xs:complexType>
<xs:complexType name="FieldmlObject_Type">
<xs:complexContent >
- <xs:extension base="fmlmeta:FieldmlRdfTargetType">
+ <xs:extension base="FieldmlRdfTargetType">
<xs:attribute name="name" type="xs:string" />
</xs:extension>
</xs:complexContent>
@@ -189,8 +190,8 @@
<xs:complexType name="EnsembleMembers_Type">
<xs:choice minOccurs="1" maxOccurs="1">
<xs:element name="MemberListData" type="MemberData_Type" />
- <xs:element name="MemberRangesData" type="MemberData_Type" />
- <xs:element name="MemberStrideRangesData" type="MemberData_Type" />
+ <xs:element name="MemberRangeData" type="MemberData_Type" />
+ <xs:element name="MemberStrideRangeData" type="MemberData_Type" />
<xs:element name="MemberRange" type="MemberRange_Type" />
</xs:choice>
</xs:complexType>
@@ -303,7 +304,7 @@
<xs:complexType name="Region_Type">
<xs:complexContent >
- <xs:extension base="fmlmeta:FieldmlRdfTargetType">
+ <xs:extension base="FieldmlRdfTargetType">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Import" type="Import_Type" />
<xs:element name="DataObject" type="DataObject_Type" />
@@ -325,7 +326,7 @@
<xs:complexType name="Fieldml_Type">
<xs:complexContent >
- <xs:extension base="fmlmeta:FieldmlRdfTargetType">
+ <xs:extension base="FieldmlRdfTargetType">
<xs:choice minOccurs="1" maxOccurs="1">
<xs:element name="Region" type="Region_Type" />
</xs:choice>
View
13 Fieldml_0.3.xsd
@@ -1,14 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="fieldml"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:fmlmeta="http://www.fieldml.org/metadata/0.3#"
>
-
- <xs:import schemaLocation="Fieldml_0.3_meta.xsd" namespace="http://www.fieldml.org/metadata/0.3#"/>
+
+ <xs:complexType name="FieldmlRdfTargetType">
+ <xs:attribute name="id" type="xs:string" form="qualified"/>
+ </xs:complexType>
<xs:complexType name="FieldmlObject_Type">
<xs:complexContent >
- <xs:extension base="fmlmeta:FieldmlRdfTargetType">
+ <xs:extension base="FieldmlRdfTargetType">
<xs:attribute name="name" type="xs:string" />
</xs:extension>
</xs:complexContent>
@@ -268,7 +269,7 @@
<xs:complexType name="Region_Type">
<xs:complexContent >
- <xs:extension base="fmlmeta:FieldmlRdfTargetType">
+ <xs:extension base="FieldmlRdfTargetType">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Import" type="Import_Type" />
<xs:element name="EnsembleType" type="EnsembleType_Type" />
@@ -289,7 +290,7 @@
<xs:complexType name="Fieldml_Type">
<xs:complexContent >
- <xs:extension base="fmlmeta:FieldmlRdfTargetType">
+ <xs:extension base="FieldmlRdfTargetType">
<xs:choice minOccurs="1" maxOccurs="1">
<xs:element name="Region" type="Region_Type" />
</xs:choice>
View
1  src/FieldmlRegion.h
@@ -67,6 +67,7 @@ class FieldmlRegion
public:
FieldmlRegion( const std::string location, const std::string name, const std::string root, ObjectStore *_store );
+
virtual ~FieldmlRegion();
void addLocalObject( FmlObjectHandle handle );
View
63 src/FieldmlSession.cpp
@@ -44,7 +44,7 @@
#include "string_const.h"
#include "fieldml_structs.h"
#include "fieldml_sax.h"
-#include "fieldml_library_0.3.h"
+#include "String_InternalLibrary.h"
using namespace std;
@@ -87,7 +87,7 @@ FieldmlSession::~FieldmlSession()
}
-FieldmlRegion *FieldmlSession::addRegion( string location, string name )
+FieldmlRegion *FieldmlSession::getRegion( string location, string name )
{
for( vector<FieldmlRegion*>::iterator i = regions.begin(); i != regions.end(); i++ )
{
@@ -98,10 +98,16 @@ FieldmlRegion *FieldmlSession::addRegion( string location, string name )
}
}
- FieldmlRegion *r = new FieldmlRegion( location, name, "", objects );
- regions.push_back( r );
+ return NULL;
+}
+
+
+FieldmlRegion *FieldmlSession::addNewRegion( string location, string name )
+{
+ FieldmlRegion *region = new FieldmlRegion( location, name, "", objects );
+ regions.push_back( region );
- return r;
+ return region;
}
@@ -131,30 +137,41 @@ FieldmlRegion *FieldmlSession::getRegion( int index )
}
-int FieldmlSession::readRegion( FieldmlRegion *readRegion )
+FieldmlRegion *FieldmlSession::addResourceRegion( string location, string name )
{
+ if( location.length() == 0 )
+ {
+ return NULL;
+ }
+
+ FieldmlRegion *resourceRegion = new FieldmlRegion( location, name, "", objects );
+ FieldmlRegion *currentRegion = region;
+ region = resourceRegion;
+
int result = 0;
- string location = readRegion->getLocation();
+ if( location == FML_INTERNAL_LIBRARY_NAME )
+ {
+ result = parseFieldmlString( FML_STRING_INTERNAL_LIBRARY, "Internal library", this );
+ }
+ else
+ {
+ string libraryFile = makeFilename( region->getRoot(), location );
+ result = parseFieldmlFile( libraryFile.c_str(), this );
+ }
- if( location.length() != 0 )
+ region = currentRegion;
+
+ if( result != 0 )
{
- FieldmlRegion *currentRegion = region;
- region = readRegion;
-
- if( location == FML_LIBRARY_0_3_NAME )
- {
- result = parseFieldmlString( FML_LIBRARY_0_3_STRING, "Internal library 0.3", this );
- }
- else
- {
- string libraryFile = makeFilename( region->getRoot(), location );
- result = parseFieldmlFile( libraryFile.c_str(), this );
- }
-
- region = currentRegion;
+ delete resourceRegion;
+ resourceRegion = NULL;
+ }
+ else
+ {
+ regions.push_back( resourceRegion );
}
- return result;
+ return resourceRegion;
}
View
8 src/FieldmlSession.h
@@ -85,14 +85,16 @@ class FieldmlSession :
FieldmlObject *getObject( const FmlObjectHandle handle );
- FieldmlRegion *addRegion( std::string location, std::string name );
+ FieldmlRegion *addResourceRegion( std::string location, std::string name );
+
+ FieldmlRegion *addNewRegion( std::string location, std::string name );
+
+ FieldmlRegion *getRegion( std::string location, std::string name );
int getRegionIndex( std::string location, std::string name );
FieldmlRegion *getRegion( int index );
- int readRegion( FieldmlRegion *region );
-
FieldmlRegion *region;
ObjectStore * const objects;
View
6 src/fieldml_library_0.3.cpp → src/String_InternalLibrary.cpp
@@ -39,11 +39,11 @@
*
*/
-#include "fieldml_library_0.3.h"
+#include "String_InternalLibrary.h"
-const char * const FML_LIBRARY_0_3_NAME = "library_0.3.xml";
+const char * const FML_INTERNAL_LIBRARY_NAME = "library_0.3.xml";
-const char * const FML_LIBRARY_0_3_STRING = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> \
+const char * const FML_STRING_INTERNAL_LIBRARY = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> \
<Fieldml version=\"0.3_alpha\" xsi:noNamespaceSchemaLocation=\"Fieldml_0.3.xsd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"> \
<Region name=\"library\"> \
<ContinuousType name=\"library.real.1d\"/> \
View
48 src/String_InternalLibrary.h
@@ -0,0 +1,48 @@
+/* \file
+ * $Id$
+ * \author Caton Little
+ * \brief
+ *
+ * \section LICENSE
+ *
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (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.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is FieldML
+ *
+ * The Initial Developer of the Original Code is Auckland Uniservices Ltd,
+ * Auckland, New Zealand. Portions created by the Initial Developer are
+ * Copyright (C) 2010 the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ */
+
+#ifndef H_STRING_INTERNAL_LIBRARY_H
+#define H_STRING_INTERNAL_LIBRARY_H
+
+extern const char * const FML_INTERNAL_LIBRARY_NAME;
+extern const char * const FML_STRING_INTERNAL_LIBRARY;
+
+#endif // H_STRING_INTERNAL_LIBRARY_H
View
384 src/String_InternalXSD.cpp
@@ -0,0 +1,384 @@
+/* \file
+ * $Id$
+ * \author Caton Little
+ * \brief
+ *
+ * \section LICENSE
+ *
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (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.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an \"AS IS\"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is FieldML
+ *
+ * The Initial Developer of the Original Code is Auckland Uniservices Ltd,
+ * Auckland, New Zealand. Portions created by the Initial Developer are
+ * Copyright (C) 2010 the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the \"GPL\"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the \"LGPL\"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ */
+
+#include "String_InternalXSD.h"
+
+const char * const FML_STRING_FIELDML_XSD = "<?xml version=\"1.0\" encoding=\"utf-8\"?> \
+<xs:schema id=\"fieldml\" \
+ xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" \
+ > \
+ \
+ <xs:complexType name=\"FieldmlRdfTargetType\"> \
+ <xs:attribute name=\"id\" type=\"xs:string\" form=\"qualified\"/> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"FieldmlObject_Type\"> \
+ <xs:complexContent > \
+ <xs:extension base=\"FieldmlRdfTargetType\"> \
+ <xs:attribute name=\"name\" type=\"xs:string\" /> \
+ </xs:extension> \
+ </xs:complexContent> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"TextFileSource_Type\"> \
+ <xs:attribute name=\"filename\" type=\"xs:string\" /> \
+ <xs:attribute name=\"firstLine\" type=\"xs:positiveInteger\" use=\"optional\" /> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"InlineSource_Type\"> \
+ <xs:simpleContent> \
+ <xs:extension base=\"xs:string\"> \
+ </xs:extension> \
+ </xs:simpleContent> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"DataSource_Type\"> \
+ <xs:choice minOccurs=\"1\" maxOccurs=\"1\"> \
+ <xs:element name=\"TextFileSource\" type=\"TextFileSource_Type\" /> \
+ <xs:element name=\"InlineSource\" type=\"InlineSource_Type\" /> \
+ </xs:choice> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"DataEntries_Type\"> \
+ <xs:attribute name=\"count\" type=\"xs:nonNegativeInteger\" /> \
+ <xs:attribute name=\"length\" type=\"xs:positiveInteger\" /> \
+ <xs:attribute name=\"head\" type=\"xs:nonNegativeInteger\" use=\"optional\" /> \
+ <xs:attribute name=\"tail\" type=\"xs:nonNegativeInteger\" use=\"optional\" /> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"DataObject_Type\"> \
+ <xs:choice minOccurs=\"2\" maxOccurs=\"2\"> \
+ <xs:element name=\"Source\" type=\"DataSource_Type\" maxOccurs=\"1\" minOccurs=\"1\"/> \
+ <xs:element name=\"Entries\" type=\"DataEntries_Type\" maxOccurs=\"1\" minOccurs=\"1\"/> \
+ </xs:choice> \
+ <xs:attribute name=\"name\" type=\"xs:string\" /> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"ImportTypeEntry_Type\"> \
+ <xs:attribute name=\"localName\" type=\"xs:string\" /> \
+ <xs:attribute name=\"remoteName\" type=\"xs:string\" /> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"ImportEvaluatorEntry_Type\"> \
+ <xs:attribute name=\"localName\" type=\"xs:string\" /> \
+ <xs:attribute name=\"remoteName\" type=\"xs:string\" /> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"Import_Type\"> \
+ <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\"> \
+ <xs:element name=\"ImportType\" type=\"ImportTypeEntry_Type\" /> \
+ <xs:element name=\"ImportEvaluator\" type=\"ImportEvaluatorEntry_Type\" /> \
+ </xs:choice> \
+ <xs:attribute name=\"location\" type=\"xs:string\" /> \
+ <xs:attribute name=\"region\" type=\"xs:string\" /> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"NumberedIndexEvaluator_Type\"> \
+ <xs:attribute name=\"evaluator\" type=\"xs:string\" /> \
+ <xs:attribute name=\"indexNumber\" type=\"xs:positiveInteger\" /> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"NumberedIndexEvaluatorList_Type\"> \
+ <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\"> \
+ <xs:element name=\"IndexEvaluator\" type=\"NumberedIndexEvaluator_Type\" /> \
+ </xs:choice> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"BindMapEntry_Type\"> \
+ <xs:attribute name=\"variable\" type=\"xs:string\" /> \
+ <xs:attribute name=\"source\" type=\"xs:string\" /> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"BindMapIndexEntry_Type\"> \
+ <xs:attribute name=\"variable\" type=\"xs:string\" /> \
+ <xs:attribute name=\"indexNumber\" type=\"xs:positiveInteger\" /> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"BindMapWithIndexes_Type\"> \
+ <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\"> \
+ <xs:element name=\"BindIndex\" type=\"BindMapIndexEntry_Type\" /> \
+ <xs:element name=\"Bind\" type=\"BindMapEntry_Type\" /> \
+ </xs:choice> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"BindMap_Type\"> \
+ <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\"> \
+ <xs:element name=\"Bind\" type=\"BindMapEntry_Type\" /> \
+ </xs:choice> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"ComponentEvaluatorsEntry_Type\"> \
+ <xs:attribute name=\"number\" type=\"xs:positiveInteger\" /> \
+ <xs:attribute name=\"evaluator\" type=\"xs:string\" /> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"ComponentEvaluators_Type\"> \
+ <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\"> \
+ <xs:element name=\"ComponentEvaluator\" type=\"ComponentEvaluatorsEntry_Type\" /> \
+ </xs:choice> \
+ <xs:attribute name=\"default\" type=\"xs:string\" /> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"SimpleMapEntry_Type\"> \
+ <xs:attribute name=\"key\" type=\"xs:string\" /> \
+ <xs:attribute name=\"value\" type=\"xs:string\" /> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"SimpleMap_Type\"> \
+ <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\"> \
+ <xs:element name=\"SimpleMapEntry\" type=\"SimpleMapEntry_Type\" /> \
+ </xs:choice> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"ElementMapEntry_Type\"> \
+ <xs:attribute name=\"number\" type=\"xs:string\" /> \
+ <xs:attribute name=\"evaluator\" type=\"xs:string\" /> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"ElementMap_Type\"> \
+ <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\"> \
+ <xs:element name=\"ElementEvaluator\" type=\"ElementMapEntry_Type\" /> \
+ </xs:choice> \
+ <xs:attribute name=\"default\" type=\"xs:string\" use=\"optional\"/> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"DefaultSimpleMap_Type\"> \
+ <xs:complexContent> \
+ <xs:extension base=\"SimpleMap_Type\"> \
+ <xs:attribute name=\"default\" type=\"xs:string\" use=\"optional\"/> \
+ </xs:extension> \
+ </xs:complexContent> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"VariableListEntry_Type\"> \
+ <xs:attribute name=\"name\" type=\"xs:string\" /> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"VariableList_Type\"> \
+ <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\"> \
+ <xs:element name=\"Variable\" type=\"VariableListEntry_Type\" /> \
+ </xs:choice> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"EvaluatorListEntry_Type\"> \
+ <xs:attribute name=\"evaluator\" type=\"xs:string\" /> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"IndexEvaluatorList_Type\"> \
+ <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\"> \
+ <xs:element name=\"IndexEvaluator\" type=\"EvaluatorListEntry_Type\" /> \
+ </xs:choice> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"OrderedEvaluatorListEntry_Type\"> \
+ <xs:attribute name=\"evaluator\" type=\"xs:string\" /> \
+ <xs:attribute name=\"order\" type=\"xs:string\" /> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"OrderedIndexEvaluatorList_Type\"> \
+ <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\"> \
+ <xs:element name=\"IndexEvaluator\" type=\"OrderedEvaluatorListEntry_Type\" /> \
+ </xs:choice> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"MemberRange_Type\"> \
+ <xs:attribute name=\"min\" type=\"xs:nonNegativeInteger\" /> \
+ <xs:attribute name=\"max\" type=\"xs:nonNegativeInteger\" /> \
+ <xs:attribute name=\"stride\" type=\"xs:positiveInteger\" use=\"optional\"/> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"MemberData_Type\"> \
+ <xs:attribute name=\"count\" type=\"xs:positiveInteger\" /> \
+ <xs:attribute name=\"data\" type=\"xs:string\" /> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"EnsembleMembers_Type\"> \
+ <xs:choice minOccurs=\"1\" maxOccurs=\"1\"> \
+ <xs:element name=\"MemberListData\" type=\"MemberData_Type\" /> \
+ <xs:element name=\"MemberRangeData\" type=\"MemberData_Type\" /> \
+ <xs:element name=\"MemberStrideRangeData\" type=\"MemberData_Type\" /> \
+ <xs:element name=\"MemberRange\" type=\"MemberRange_Type\" /> \
+ </xs:choice> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"EnsembleType_Type\"> \
+ <xs:complexContent> \
+ <xs:extension base=\"FieldmlObject_Type\"> \
+ <xs:sequence> \
+ <xs:element name=\"Members\" type=\"EnsembleMembers_Type\" minOccurs=\"1\" maxOccurs=\"1\" /> \
+ </xs:sequence> \
+ <xs:attribute name=\"isComponentEnsemble\" type=\"xs:boolean\" use=\"optional\" /> \
+ </xs:extension> \
+ </xs:complexContent> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"ContinuousType_Type\"> \
+ <xs:complexContent> \
+ <xs:extension base=\"FieldmlObject_Type\"> \
+ <xs:attribute name=\"componentEnsemble\" type=\"xs:string\" use=\"optional\" /> \
+ </xs:extension> \
+ </xs:complexContent> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"MeshType_Type\"> \
+ <xs:complexContent> \
+ <xs:extension base=\"FieldmlObject_Type\"> \
+ <xs:sequence> \
+ <xs:element name=\"Elements\" type=\"EnsembleMembers_Type\" minOccurs=\"1\" maxOccurs=\"1\" /> \
+ <xs:element name=\"Shapes\" type=\"DefaultSimpleMap_Type\" minOccurs=\"1\" maxOccurs=\"1\" /> \
+ </xs:sequence> \
+ <xs:attribute name=\"xiComponent\" type=\"xs:string\" /> \
+ </xs:extension> \
+ </xs:complexContent> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"FieldmlEvaluator_Type\"> \
+ <xs:complexContent> \
+ <xs:extension base=\"FieldmlObject_Type\"> \
+ <xs:sequence> \
+ <xs:element name=\"Variables\" type=\"VariableList_Type\" minOccurs=\"0\" maxOccurs=\"1\" /> \
+ </xs:sequence> \
+ <xs:attribute name=\"valueType\" type=\"xs:string\" /> \
+ </xs:extension> \
+ </xs:complexContent> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"AbstractEvaluator_Type\"> \
+ <xs:complexContent> \
+ <xs:extension base=\"FieldmlEvaluator_Type\" /> \
+ </xs:complexContent> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"ExternalEvaluator_Type\"> \
+ <xs:complexContent> \
+ <xs:extension base=\"FieldmlEvaluator_Type\" /> \
+ </xs:complexContent> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"ReferenceEvaluator_Type\"> \
+ <xs:complexContent> \
+ <xs:extension base=\"FieldmlEvaluator_Type\"> \
+ <xs:sequence> \
+ <xs:element name=\"Bindings\" type=\"BindMap_Type\" minOccurs=\"0\" maxOccurs=\"1\" /> \
+ </xs:sequence> \
+ <xs:attribute name=\"evaluator\" type=\"xs:string\" /> \
+ </xs:extension> \
+ </xs:complexContent> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"PiecewiseEvaluator_Type\"> \
+ <xs:complexContent> \
+ <xs:extension base=\"FieldmlEvaluator_Type\"> \
+ <xs:sequence> \
+ <xs:element name=\"Bindings\" type=\"BindMap_Type\" minOccurs=\"0\" maxOccurs=\"1\" /> \
+ <xs:element name=\"IndexEvaluators\" type=\"NumberedIndexEvaluatorList_Type\" minOccurs=\"0\" maxOccurs=\"1\" /> \
+ <xs:element name=\"ElementEvaluators\" type=\"ElementMap_Type\" minOccurs=\"0\" maxOccurs=\"1\" /> \
+ </xs:sequence> \
+ </xs:extension> \
+ </xs:complexContent> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"SemidenseData_Type\"> \
+ <xs:sequence> \
+ <xs:element name=\"DenseIndexes\" type=\"OrderedIndexEvaluatorList_Type\" minOccurs=\"0\" maxOccurs=\"1\" /> \
+ <xs:element name=\"SparseIndexes\" type=\"IndexEvaluatorList_Type\" minOccurs=\"0\" maxOccurs=\"1\" /> \
+ </xs:sequence> \
+ <xs:attribute name=\"data\" type=\"xs:string\" /> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"ParameterEvaluator_Type\"> \
+ <xs:complexContent> \
+ <xs:extension base=\"FieldmlEvaluator_Type\"> \
+ <xs:choice> \
+ <xs:element name=\"SemidenseData\" type=\"SemidenseData_Type\" minOccurs=\"1\" maxOccurs=\"1\" /> \
+ </xs:choice> \
+ </xs:extension> \
+ </xs:complexContent> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"AggregateEvaluator_Type\"> \
+ <xs:complexContent> \
+ <xs:extension base=\"FieldmlEvaluator_Type\"> \
+ <xs:sequence> \
+ <xs:element name=\"Bindings\" type=\"BindMapWithIndexes_Type\" minOccurs=\"0\" maxOccurs=\"1\" /> \
+ <xs:element name=\"ComponentEvaluators\" type=\"ComponentEvaluators_Type\" minOccurs=\"1\" maxOccurs=\"1\" /> \
+ </xs:sequence> \
+ </xs:extension> \
+ </xs:complexContent> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"Region_Type\"> \
+ <xs:complexContent > \
+ <xs:extension base=\"FieldmlRdfTargetType\"> \
+ <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\"> \
+ <xs:element name=\"Import\" type=\"Import_Type\" /> \
+ <xs:element name=\"DataObject\" type=\"DataObject_Type\" /> \
+ <xs:element name=\"EnsembleType\" type=\"EnsembleType_Type\" /> \
+ <xs:element name=\"ContinuousType\" type=\"ContinuousType_Type\" /> \
+ <xs:element name=\"MeshType\" type=\"MeshType_Type\" /> \
+ <xs:element name=\"AbstractEvaluator\" type=\"AbstractEvaluator_Type\" /> \
+ <xs:element name=\"ExternalEvaluator\" type=\"ExternalEvaluator_Type\" /> \
+ <xs:element name=\"ReferenceEvaluator\" type=\"ReferenceEvaluator_Type\" /> \
+ <xs:element name=\"PiecewiseEvaluator\" type=\"PiecewiseEvaluator_Type\" /> \
+ <xs:element name=\"ParametersEvaluator\" type=\"ParameterEvaluator_Type\" /> \
+ <xs:element name=\"AggregateEvaluator\" type=\"AggregateEvaluator_Type\" /> \
+ </xs:choice> \
+ <xs:attribute name=\"name\" type=\"xs:string\" /> \
+ <xs:attribute name=\"library\" type=\"xs:string\" /> \
+ </xs:extension> \
+ </xs:complexContent> \
+ </xs:complexType> \
+ \
+ <xs:complexType name=\"Fieldml_Type\"> \
+ <xs:complexContent > \
+ <xs:extension base=\"FieldmlRdfTargetType\"> \
+ <xs:choice minOccurs=\"1\" maxOccurs=\"1\"> \
+ <xs:element name=\"Region\" type=\"Region_Type\" /> \
+ </xs:choice> \
+ <xs:attribute name=\"version\" type=\"xs:string\" /> \
+ </xs:extension> \
+ </xs:complexContent> \
+ </xs:complexType> \
+ \
+ <xs:element name=\"Fieldml\" type=\"Fieldml_Type\"/> \
+ \
+</xs:schema> \
+";
View
9 src/fieldml_library_0.3.h → src/String_InternalXSD.h
@@ -39,10 +39,9 @@
*
*/
-#ifndef H_FIELDML_LIBRARY_0_3_H
-#define H_FIELDML_LIBRARY_0_3_H
+#ifndef H_STRING_INTERNAL_XSD_H
+#define H_STRING_INTERNAL_XSD_H
-extern const char * const FML_LIBRARY_0_3_NAME;
-extern const char * const FML_LIBRARY_0_3_STRING;
+extern const char * const FML_STRING_FIELDML_XSD;
-#endif // H_FIELDML_LIBRARY_0_3_H
+#endif // H_STRING_INTERNAL_XSD_H
View
28 src/fieldml_api.cpp
@@ -43,7 +43,7 @@
#include <string.h>
-#include "fieldml_library_0.3.h"
+#include "String_InternalLibrary.h"
#include "fieldml_api.h"
#include "fieldml_sax.h"
@@ -474,15 +474,13 @@ FmlHandle Fieldml_CreateFromFile( const char *filename )
{
FieldmlSession *session = new FieldmlSession();
- session->region = session->addRegion( filename, "" );
- int err = session->readRegion( session->region );
- session->region->setRoot( getDirectory( filename ) );
-
- if( err != 0 )
+ session->region = session->addResourceRegion( filename, "" );
+ if( session->region == NULL )
{
- delete session;
- return FML_INVALID_HANDLE;
+ session->setError( FML_ERR_IO_READ_ERR );
}
+
+ session->region->setRoot( getDirectory( filename ) );
session->region->finalize();
return session->getHandle();
@@ -493,7 +491,7 @@ FmlHandle Fieldml_Create( const char *location, const char *name )
{
FieldmlSession *session = new FieldmlSession();
- session->region = session->addRegion( location, name );
+ session->region = session->addNewRegion( location, name );
return session->getHandle();
}
@@ -2674,12 +2672,14 @@ int Fieldml_AddImportSource( FmlHandle handle, const char *location, const char
return -1;
}
- FieldmlRegion *importedRegion = session->addRegion( location, name );
- int err = session->readRegion( importedRegion );
- if( err != 0 )
+ FieldmlRegion *importedRegion = session->getRegion( location, name );
+ if( importedRegion == NULL )
{
- delete importedRegion;
- return -1;
+ importedRegion = session->addResourceRegion( location, name );
+ if( importedRegion == NULL )
+ {
+ return -1;
+ }
}
int index = session->getRegionIndex( location, name );
View
93 src/fieldml_sax.cpp
@@ -39,6 +39,9 @@
*
*/
+#include <string>
+#include <stdio.h>
+
#include <libxml/SAX.h>
#include <libxml/globals.h>
#include <libxml/xmlerror.h>
@@ -46,7 +49,8 @@
#include <libxml/xmlmemory.h>
#include <libxml/xmlschemas.h>
-#include "fieldml_library_0.3.h"
+#include "String_InternalLibrary.h"
+#include "String_InternalXSD.h"
#include "string_const.h"
#include "fieldml_sax.h"
@@ -57,14 +61,77 @@ using namespace std;
//========================================================================
+void addSaxContextError( void *context, const char *msg, ... )
+{
+ SaxContext *saxContext = (SaxContext*)context;
+
+ char message[256];
+
+ va_list vargs;
+ va_start( vargs, msg );
+ int retval = vsnprintf( message, 255, msg, vargs );
+ va_end( vargs);
+
+ if( retval > 0 )
+ {
+ //libxml likes to put \n at the end of its error messages
+ if( message[retval-1] == '\n' )
+ {
+ message[retval-1] = 0;
+ }
+ saxContext->session->addError( message );
+ }
+}
+
+//========================================================================
+
class SaxParser
{
public:
virtual int parse( xmlSAXHandlerPtr saxHandler, SaxContext *context ) = 0;
+ virtual int validate( SaxContext *context, xmlParserInputBufferPtr buffer, const char *resourceName );
+
virtual const char *getSource() = 0;
};
+
+int SaxParser::validate( SaxContext *context, xmlParserInputBufferPtr buffer, const char *resourceName )
+{
+ xmlSchemaPtr schemas = NULL;
+ xmlSchemaParserCtxtPtr sctxt;
+ xmlSchemaValidCtxtPtr vctxt;
+
+ LIBXML_TEST_VERSION
+
+ xmlSubstituteEntitiesDefault( 1 );
+
+ if( buffer == NULL )
+ {
+ return false;
+ }
+
+ sctxt = xmlSchemaNewMemParserCtxt( FML_STRING_FIELDML_XSD, strlen( FML_STRING_FIELDML_XSD ) );
+ xmlSchemaSetParserErrors( sctxt, (xmlSchemaValidityErrorFunc)addSaxContextError, (xmlSchemaValidityWarningFunc)addSaxContextError, context );
+ schemas = xmlSchemaParse( sctxt );
+ if( schemas == NULL )
+ {
+ xmlGenericError( xmlGenericErrorContext, "Internal schema failed to compile\n" );
+ }
+ xmlSchemaFreeParserCtxt( sctxt );
+
+ vctxt = xmlSchemaNewValidCtxt( schemas );
+ xmlSchemaSetValidErrors( vctxt, (xmlSchemaValidityErrorFunc)addSaxContextError, (xmlSchemaValidityWarningFunc)addSaxContextError, context );
+
+ int result = xmlSchemaValidateStream( vctxt, buffer, (xmlCharEncoding)0, NULL, NULL );
+
+ xmlSchemaFreeValidCtxt( vctxt );
+
+ xmlSchemaFree( schemas );
+
+ return result;
+}
+
//========================================================================
class SaxFileParser :
@@ -90,6 +157,18 @@ SaxFileParser::SaxFileParser( const char *_filename ) :
int SaxFileParser::parse( xmlSAXHandlerPtr saxHandler, SaxContext *context )
{
+ xmlParserInputBufferPtr buffer = xmlParserInputBufferCreateFilename( filename, XML_CHAR_ENCODING_NONE );
+
+ int res = validate( context, buffer, filename );
+
+ if( res != 0 )
+ {
+ string error = filename;
+ error += " failed to validate";
+ context->session->addError( error );
+ return res;
+ }
+
return xmlSAXUserParseFile( saxHandler, context, filename );
}
@@ -127,6 +206,18 @@ SaxStringParser::SaxStringParser( const char *_string, const char *_stringDescri
int SaxStringParser::parse( xmlSAXHandlerPtr saxHandler, SaxContext *context )
{
+ xmlParserInputBufferPtr buffer = xmlParserInputBufferCreateMem( string, strlen( string ), XML_CHAR_ENCODING_NONE );
+
+ int res = validate( context, buffer, stringDescription );
+
+ if( res != 0 )
+ {
+ std::string error = stringDescription;
+ error += " failed to validate";
+ context->session->addError( error );
+ return res;
+ }
+
return xmlSAXUserParseMemory( saxHandler, context, string, strlen( string ) );
}
Please sign in to comment.
Something went wrong with that request. Please try again.