GME  13
IC_Field.cpp
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  * 
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  * 
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 /*
00019  * $Id: IC_Field.cpp 471747 2006-11-06 14:31:56Z amassari $
00020  */
00021 
00022 // ---------------------------------------------------------------------------
00023 //  Includes
00024 // ---------------------------------------------------------------------------
00025 #include <xercesc/validators/schema/identity/FieldActivator.hpp>
00026 #include <xercesc/validators/schema/identity/IC_Field.hpp>
00027 #include <xercesc/validators/schema/identity/ValueStore.hpp>
00028 #include <xercesc/validators/schema/identity/XercesXPath.hpp>
00029 #include <xercesc/validators/schema/identity/IdentityConstraint.hpp>
00030 
00031 XERCES_CPP_NAMESPACE_BEGIN
00032 
00033 // ---------------------------------------------------------------------------
00034 //  FieldMatcher: Constructors and Destructor
00035 // ---------------------------------------------------------------------------
00036 FieldMatcher::FieldMatcher(XercesXPath* const xpath,
00037                            IC_Field* const aField,
00038                            ValueStore* const valueStore,
00039                            FieldActivator* const fieldActivator,
00040                            MemoryManager* const manager)
00041     : XPathMatcher(xpath, (IdentityConstraint*) 0, manager)
00042     , fValueStore(valueStore)
00043     , fField(aField)    
00044     , fFieldActivator(fieldActivator)
00045 {
00046 }
00047 
00048 // ---------------------------------------------------------------------------
00049 //  FieldMatcher: Match methods
00050 // ---------------------------------------------------------------------------
00051 void FieldMatcher::matched(const XMLCh* const content,
00052                            DatatypeValidator* const dv,
00053                            const bool isNil) {
00054 
00055     if(isNil) {
00056         fValueStore->reportNilError(fField->getIdentityConstraint());
00057     }
00058 
00059     fValueStore->addValue(fFieldActivator, fField, dv, content);
00060 
00061     // once we've stored the value for this field, we set the mayMatch
00062     // member to false so that, in the same scope, we don't match any more
00063     // values (and throw an error instead).
00064     fFieldActivator->setMayMatch(fField, false);
00065 }
00066 
00067 // ---------------------------------------------------------------------------
00068 //  IC_Field: Constructors and Destructor
00069 // ---------------------------------------------------------------------------
00070 IC_Field::IC_Field(XercesXPath* const xpath,
00071                    IdentityConstraint* const identityConstraint)
00072     : fXPath(xpath)
00073     , fIdentityConstraint(identityConstraint)
00074 {
00075 }
00076 
00077 
00078 IC_Field::~IC_Field()
00079 {
00080     delete fXPath;
00081 }
00082 
00083 // ---------------------------------------------------------------------------
00084 //  IC_Field: operators
00085 // ---------------------------------------------------------------------------
00086 bool IC_Field::operator== (const IC_Field& other) const {
00087 
00088     return (*fXPath == *(other.fXPath));
00089 }
00090 
00091 bool IC_Field::operator!= (const IC_Field& other) const {
00092 
00093     return !operator==(other);
00094 }
00095 
00096 // ---------------------------------------------------------------------------
00097 //  IC_Field: Factory methods
00098 // ---------------------------------------------------------------------------
00099 XPathMatcher* IC_Field::createMatcher(FieldActivator* const fieldActivator,
00100                                       ValueStore* const valueStore,
00101                                       MemoryManager* const manager)
00102 {
00103     return new (manager) FieldMatcher(fXPath, this, valueStore, fieldActivator, manager);
00104 }
00105 
00106 /***
00107  * Support for Serialization/De-serialization
00108  ***/
00109 
00110 IMPL_XSERIALIZABLE_TOCREATE(IC_Field)
00111 
00112 void IC_Field::serialize(XSerializeEngine& serEng)
00113 {
00114 
00115     if (serEng.isStoring())
00116     {
00117         serEng<<fXPath;
00118         
00119         IdentityConstraint::storeIC(serEng, fIdentityConstraint);
00120     }
00121     else
00122     {
00123         serEng>>fXPath;
00124 
00125         fIdentityConstraint = IdentityConstraint::loadIC(serEng);
00126     }
00127 
00128 }
00129 
00130 IC_Field::IC_Field(MemoryManager* const )
00131 :fXPath(0)
00132 ,fIdentityConstraint(0)
00133 {
00134 }
00135 
00136 XERCES_CPP_NAMESPACE_END
00137