00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "schemaparser/ContentModel.h"
00022 #include "schemaparser/Element.h"
00023 #include "schemaparser/Group.h"
00024
00025 namespace Schema {
00026 void
00027 ContentModel::addElement(const Element & elem)
00028 {
00029 ContentType ct;
00030
00031 if(m_compositor==Schema::All){
00032 if(elem.getMax()>1)
00033 {
00034 SchemaParserException spe("<all> MUST not have multiple occurrences of an element "+
00035 elem.getName());
00036 throw spe;
00037 }
00038
00039 }
00040 ct.e=new Element(elem);
00041 ContentHolder c(ct,ContentModel::Particle);
00042 contents_.push_back(c);
00043 if (elem.getType() == Schema::XSD_ANY) {
00044
00045 anyContent_ = true;
00046 }
00047 nParticles++;
00048 }
00049
00050 void
00051 ContentModel::addGroup(const Group & g,bool isRef)
00052 {
00053 ContentType ct;
00054 if(m_compositor==Schema::All){
00055
00056 SchemaParserException spe("<all> MUST have only element ");
00057 throw spe;
00058 }
00059 ct.g=new Group(g);
00060 ct.g->setContents(g.getContents (),isRef);
00061 ContentHolder c(ct,ContentModel::ParticleGroup);
00062 contents_.push_back(c);
00063 }
00064
00065 void
00066 ContentModel::addContentModel(const ContentModel * container)
00067 {
00068 if(m_compositor==Schema::All){
00069 SchemaParserException spe("<all> MUST have only elements within");
00070 throw spe;
00071 }
00072
00073 ContentType ct;
00074 ct.c=const_cast<ContentModel*> (container);
00075 ContentHolder c(ct,ContentModel::Container);
00076 contents_.push_back(c);
00077 }
00078
00079 ContentModel::ContentModel(Schema::Compositor c)
00080 :m_compositor(c),
00081 nParticles(0),
00082 anyContent_(false)
00083 {
00084 contents_.clear();
00085
00086 }
00087
00088
00089 ContentModel::~ContentModel()
00090 {
00091 for(ContentsIterator ci=begin();ci!=end();ci++){
00092
00093 if(ci->second==ContentModel::Container)
00094 delete (ci->first).c;
00095 else if(ci->second==ContentModel::Particle)
00096 delete (ci->first).e;
00097 else if(ci->second==ContentModel::ParticleGroup)
00098 delete (ci->first).g;
00099 }
00100 }
00101
00102 void
00103 ContentModel::matchforwardRef(const std::string &name,Element &e)
00104 {
00105 for(ContentsIterator ci=begin();ci!=end();ci++){
00106 if(ci->second==ContentModel::Particle)
00107 if((ci->first).e->getName()==name){
00108 *((ci->first).e)=e;
00109 }
00110 }
00111 }
00112 }