00001 #include "stdafx.h"
00002
00003 #include "BON.h"
00004 #include "BONImpl.h"
00005
00006 #include "Any.h"
00007 #include "ConstraintRep.h"
00008 #include "Broker.h"
00009 #include "Dumper.h"
00010
00011 #include "algorithm"
00012
00013 #include "globals.h"
00014 extern Globals global_vars;
00015
00016 bool AnyLexicographicSort::operator()( Any * op1, Any * op2) const
00017 {
00018 std::string s1 = op1->getName();
00019 std::string s2 = op2->getName();
00020 int k = s1.compare(s2);
00021
00022 return ( k < 0);
00023 }
00024
00025 const std::string Any::NamespaceDelimiter_str = "::";
00026 const std::string Any::InRootFolder_str = "InRootFolder";
00027 const std::string Any::DisplayedName_str = "DisplayedName";
00028 const std::string Any::NameSelectorNode_str = "myNameIs";
00029 const std::string Any::DisplayedNameSelectorNode_str = "myDisplayedNameIs";
00030 const std::string Any::GeneralPreferences_str = "GeneralPreferences";
00031
00032 const std::string Any::KIND_TYPE_STR[] =
00033 {
00034 "ATOM",
00035 "MODEL",
00036 "CONN",
00037 "SET",
00038 "REF",
00039 "FCO",
00040 "ASPECT",
00041 "FOLDER",
00042 "CONSTRAINT",
00043 "CONSTRAINFUNC",
00044 "ATTRIBUTE"
00045 };
00046
00047
00048 Any::Any( BON::FCO& ptr)
00049 : m_ptr( ptr)
00050 , m_isInRootFolder( false)
00051 , m_equivs()
00052 , m_initialConstraintList()
00053 , m_finalConstraintList()
00054 {
00055 }
00056
00057
00058 Any::~Any()
00059 {
00060 m_equivs.clear();
00061 m_initialConstraintList.clear();
00062 m_finalConstraintList.clear();
00063 }
00064
00065 void Any::initNamespace()
00066 {
00067
00068 if( m_ptr->isInLibrary())
00069 {
00070 bool all_equivs_in_lib = true;
00071 for ( std::set< BON::FCO >::const_iterator it = m_equivs.begin()
00072 ; all_equivs_in_lib && it != m_equivs.end()
00073 ; ++it)
00074 {
00075 if ( *it == m_ptr) continue;
00076 if ((*it)->getObjectMeta().name().find("Proxy") != std::string::npos) continue;
00077 all_equivs_in_lib = (*it)->isInLibrary();
00078 }
00079
00080 if( !all_equivs_in_lib)
00081 resetNamespace();
00082 else
00083 {
00084
00085
00086 BON::RegistryNode rn = m_nmspRootFolder->getRegistry()->getChild( "Namespace");
00087
00088 if( rn) m_namespace = rn->getValue();
00089 else m_namespace = "";
00090
00091 }
00092 }
00093 else
00094 {
00095 resetNamespace();
00096 }
00097 }
00098
00099 void Any::resetNamespace()
00100 {
00101 m_namespace = Dumper::getInstance()->getNamespace();
00102 }
00103
00104 std::string Any::getNamespace() const
00105 {
00106 return m_namespace;
00107 }
00108
00109 void FolderRep::initAttributes()
00110 {
00111
00112
00113
00114 m_isInRootFolder = m_ptr->getAttribute( InRootFolder_str)->getBooleanValue();
00115
00116 std::set< BON::FCO >::const_iterator it = m_equivs.begin();
00117 for ( ; !m_isInRootFolder && it != m_equivs.end(); ++it)
00118 {
00119 if ( *it == m_ptr) continue;
00120 if ((*it)->getObjectMeta().name().find("Proxy") != std::string::npos) continue;
00121 m_isInRootFolder = m_isInRootFolder || (*it)->getAttribute( InRootFolder_str)->getBooleanValue();
00122 }
00123 auto attr = m_ptr->getAttribute(GeneralPreferences_str);
00124 if (attr)
00125 {
00126 m_sAttrGenPref = attr->getStringValue();
00127 }
00128 }
00129
00130
00131 bool Any::isInRootFolder()
00132 {
00133 return m_isInRootFolder;
00134 }
00135
00136
00137 bool Any::isFCO() const
00138 {
00139 bool fco = false;
00140 fco = (getMyKind() == ATOM ||
00141 getMyKind() == MODEL ||
00142 getMyKind() == CONN ||
00143 getMyKind() == SET ||
00144 getMyKind() == REF ||
00145 getMyKind() == FCO_REP);
00146 return fco;
00147 }
00148
00149
00150 std::string Any::getName() const
00151 {
00152 if ( this->m_ptr)
00153 {
00154 return m_namespace + (m_namespace.empty()?"":Any::NamespaceDelimiter_str) + m_ptr->getName();
00155 }
00156 return "NullPtrError";
00157 }
00158
00159
00160 std::string Any::getDispName() const
00161 {
00162 if ( this->m_ptr)
00163 {
00164 return m_ptr->getAttribute( DisplayedName_str)->getStringValue();
00165 }
00166 return "NullPtrError";
00167 }
00168
00169
00170 std::string Any::dumpDispName() const
00171 {
00172 std::string mmm;
00173 std::string disp = getDispName();
00174 if ( !disp.empty())
00175 mmm += indStr() + "<dispname>" + Dumper::xmlFilter(disp) +"</dispname>\n";
00176 return mmm;
00177 }
00178
00179
00180 std::string Any::getMyKindStr() const
00181 {
00182 return KIND_TYPE_STR[ getMyKind()];
00183 }
00184
00185
00186 std::string Any::getMyPrefix() const
00187 {
00188
00189
00190 if ( this->m_ptr)
00191 return Broker::getRegistryTokenName( m_ptr);
00192
00193 throw "Error: inquiring prefix for a null object\n";
00194 }
00195
00196
00197 BON::RegistryNode Any::getMyRegistry() const
00198 {
00199
00200
00201 if ( this->m_ptr && this->m_parentFolder)
00202 return m_parentFolder->getRegistry()->getChild( getMyPrefix());
00203
00204 throw 1;
00205 }
00206
00207
00208 BON::RegistryNode Any::getMyRegistryOld() const
00209 {
00210 if ( this->m_ptr && this->m_parentFolder)
00211 {
00212 std::string kind = m_ptr->getObjectMeta().name();
00213 std::string name = m_ptr->getPath();
00214
00215 BON::ObjectPtr p = m_ptr->getObjectI();
00216 long relid = 0;
00217 BONCOMTHROW( p->get_RelID(&relid));
00218 char t[16];
00219 sprintf( t, "%x", relid);
00220
00221 std::string child_name = kind + "s" + name + t;
00222 return m_parentFolder->getRegistry()->getChild( child_name);
00223 }
00224
00225 throw 1;
00226 }
00227
00228 std::string Any::getMyPrefix( BON::FCO& fco, BON::Folder& f)
00229 {
00230 ASSERT( fco);
00231 ASSERT( f);
00232 return Broker::getRegistryTokenName( fco);
00233 }
00234
00235
00236 BON::RegistryNode Any::getMyRegistry( BON::FCO& fco, BON::Folder& f)
00237 {
00238 ASSERT( fco);
00239 ASSERT( f);
00240 return f->getRegistry()->getChild( Any::getMyPrefix(fco, f));
00241 }
00242
00243
00244 std::string Any::askMetaRef(const std::string& in_token ) const
00245 {
00246
00247
00248
00249
00250
00251 std::string token = "/MetaRef" + in_token;
00252 std::string meta_ref = "";
00253 if ( this->m_ptr && this->m_parentFolder)
00254 {
00255
00256 meta_ref = getMyRegistry()->getValueByPath( token);
00257
00258 if (meta_ref == "")
00259 {
00260 int meta_ref_int = Broker::getNextMetaRefId();
00261 char n_meta_ref[64];
00262 sprintf( n_meta_ref, "%d", meta_ref_int);
00263
00264 getMyRegistry()->setValueByPath( token, n_meta_ref);
00265 meta_ref = n_meta_ref;
00266 }
00267 return meta_ref;
00268 }
00269 else
00270 {
00271 int meta_ref_int = Broker::getNextMetaRefId();
00272 char n_meta_ref[64];
00273 sprintf( n_meta_ref, "%d", meta_ref_int);
00274
00275 meta_ref = n_meta_ref;
00276 return meta_ref;
00277 }
00278 return "NullPtrError";
00279 }
00280
00281
00282 void Any::addInitialConstraintRep( ConstraintRep * constraint)
00283 {
00284 ConstraintRepPtrList_ConstIterator it =
00285 std::find( m_initialConstraintList.begin(), m_initialConstraintList.end(), constraint);
00286
00287 if ( it == m_initialConstraintList.end())
00288 m_initialConstraintList.push_back( constraint);
00289 else
00290 global_vars.err << MSG_ERROR << constraint->getName() << " constraint owned by " << m_ptr << " twice\n";
00291 }
00292
00293
00294 const Any::ConstraintRepPtrList& Any::getInitialConstraintRepPtrList() const
00295 {
00296 return m_initialConstraintList;
00297 }
00298
00299
00300 void Any::addFinalConstraint( ConstraintRep * constraint)
00301 {
00302 ConstraintRepPtrList_ConstIterator c_it =
00303 std::find( m_finalConstraintList.begin(), m_finalConstraintList.end(), constraint);
00304
00305 if ( c_it == m_finalConstraintList.end())
00306 m_finalConstraintList.push_back( constraint);
00307
00308
00309 }
00310
00311
00312 void Any::addFinalConstraintList( const ConstraintRepPtrList & list)
00313 {
00314 ConstraintRepPtrList_ConstIterator it = list.begin();
00315 for( ; it != list.end(); ++it)
00316 addFinalConstraint( *it);
00317 }
00318
00319
00320 std::string Any::dumpConstraints()
00321 {
00322 std::string mmm = "";
00323
00324 AnyLexicographicSort lex;
00325 std::string last_name = "";
00326 std::sort( m_finalConstraintList.begin(), m_finalConstraintList.end(), lex );
00327
00328 ConstraintRepPtrList_ConstIterator c_i = m_finalConstraintList.begin();
00329 for( ; c_i != m_finalConstraintList.end(); ++c_i)
00330 {
00331 mmm += ( *c_i)->doDump();
00332 if ( last_name != "" && last_name == (*c_i)->getName())
00333 global_vars.err << MSG_ERROR << "Duplicate constraint name " << (*c_i)->getName() << " found for " << m_ptr << "\n";
00334 last_name = (*c_i)->getName();
00335 }
00336 return mmm;
00337 }
00338
00339