Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1983 lines
50 KiB

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright(C) 1997-1998 Microsoft Corporation all rights reserved.
  4. //
  5. // Module: sdoschema.cpp
  6. //
  7. // Project: Everest
  8. //
  9. // Description: IAS Server Data Object - Schema Implementation
  10. //
  11. // Author: TLP 9/6/98
  12. //
  13. ///////////////////////////////////////////////////////////////////////////
  14. #include "stdafx.h"
  15. #include "sdoschema.h"
  16. #include "sdohelperfuncs.h"
  17. #include "varvec.h"
  18. #include <vector>
  19. using namespace std;
  20. //////////////////////////////////////////////////////////////////////////////
  21. // SCHEMA IMPLEMENTATION
  22. //////////////////////////////////////////////////////////////////////////////
  23. //////////////////////////////////////////////////////////////////////////////
  24. static WCHAR PropertyIdClass[] = L"{46557889-4DB8-11d2-8ECE-00C04FC2F519}";
  25. static WCHAR PropertyIdName[] = L"{46557888-4DB8-11d2-8ECE-00C04FC2F519}";
  26. static LPCWSTR RequiredProperties[] =
  27. {
  28. PropertyIdClass,
  29. PropertyIdName,
  30. NULL
  31. };
  32. //////////////////////////////////////////////////////////////////////////////
  33. static WCHAR PropertyIdCallingStationId[] = L"{EFE7FCD3-4D26-11d2-A8C8-00AA00A71DCA}";
  34. static WCHAR PropertyIdSavedCallingStationId[] = L"{EFE7FCD4-4D26-11d2-A8C8-00AA00A71DCA}";
  35. static WCHAR PropertyIdRADIUSCallbackNumber[] = L"{EFE7FCD5-4D26-11d2-A8C8-00AA00A71DCA}";
  36. static WCHAR PropertyIdRADIUSFramedRoute[] = L"{EFE7FCD6-4D26-11d2-A8C8-00AA00A71DCA}";
  37. static WCHAR PropertyIdRADIUSFramedIPAddress[] = L"{EFE7FCD7-4D26-11d2-A8C8-00AA00A71DCA}";
  38. static WCHAR PropertyIdRASCallbackNumber[] = L"{EFE7FCD8-4D26-11d2-A8C8-00AA00A71DCA}";
  39. static WCHAR PropertyIdRASFramedRoute[] = L"{EFE7FCD9-4D26-11d2-A8C8-00AA00A71DCA}";
  40. static WCHAR PropertyIdRASFramedIPAddress[] = L"{EFE7FCDA-4D26-11d2-A8C8-00AA00A71DCA}";
  41. static WCHAR PropertyIdAllowDialin[] = L"{EFE7FCDB-4D26-11d2-A8C8-00AA00A71DCA}";
  42. static WCHAR PropertyIdRADIUSServiceType[] = L"{EFE7FCDC-4D26-11d2-A8C8-00AA00A71DCA}";
  43. static LPCWSTR UserOptionalProperties[] =
  44. {
  45. PropertyIdCallingStationId,
  46. PropertyIdSavedCallingStationId,
  47. PropertyIdRADIUSCallbackNumber,
  48. PropertyIdRADIUSFramedRoute,
  49. PropertyIdRADIUSFramedIPAddress,
  50. PropertyIdRASCallbackNumber,
  51. PropertyIdRASFramedRoute,
  52. PropertyIdRASFramedIPAddress,
  53. PropertyIdAllowDialin,
  54. PropertyIdRADIUSServiceType,
  55. NULL
  56. };
  57. //////////////////////////////////////////////////////////////////////////////
  58. // Internal SDO Properties
  59. //
  60. BEGIN_SCHEMA_PROPERTY_MAP(InternalProperties)
  61. DEFINE_SCHEMA_PROPERTY(
  62. SDO_STOCK_PROPERTY_CLASS, // Name
  63. PropertyIdClass, // Id
  64. (LONG)VT_BSTR, // Syntax
  65. (LONG)PROPERTY_SDO_CLASS, // Alias
  66. 496, // Flas
  67. 1, // MinLength
  68. 255, // MaxLength
  69. SDO_STOCK_PROPERTY_CLASS // DisplayName
  70. )
  71. DEFINE_SCHEMA_PROPERTY(
  72. SDO_STOCK_PROPERTY_NAME,
  73. PropertyIdName,
  74. (LONG)VT_BSTR,
  75. (LONG)PROPERTY_SDO_NAME,
  76. 112,
  77. 1,
  78. 255,
  79. SDO_STOCK_PROPERTY_NAME
  80. )
  81. DEFINE_SCHEMA_PROPERTY(
  82. L"Calling Station Id",
  83. PropertyIdCallingStationId,
  84. (LONG)VT_BSTR,
  85. PROPERTY_USER_CALLING_STATION_ID,
  86. 0x210,
  87. 1,
  88. 0,
  89. L"msNPCallingStationID"
  90. )
  91. DEFINE_SCHEMA_PROPERTY(
  92. L"Saved Calling Station Id",
  93. PropertyIdSavedCallingStationId,
  94. (LONG)VT_BSTR,
  95. PROPERTY_USER_SAVED_CALLING_STATION_ID,
  96. 0x210,
  97. 1,
  98. 0,
  99. L"msNPSavedCallingStationID"
  100. )
  101. DEFINE_SCHEMA_PROPERTY(
  102. L"RADIUS Callback Number",
  103. PropertyIdRADIUSCallbackNumber,
  104. (LONG)VT_BSTR,
  105. PROPERTY_USER_RADIUS_CALLBACK_NUMBER,
  106. 48,
  107. 1,
  108. 255,
  109. L"msRADIUSCallbackNumber"
  110. )
  111. DEFINE_SCHEMA_PROPERTY(
  112. L"RADIUS Framed Route",
  113. PropertyIdRADIUSFramedRoute,
  114. (LONG)VT_BSTR,
  115. PROPERTY_USER_RADIUS_FRAMED_ROUTE,
  116. 560,
  117. 1,
  118. 255,
  119. L"msRADIUSFramedRoute"
  120. )
  121. DEFINE_SCHEMA_PROPERTY(
  122. L"RADIUS Framed IP Address",
  123. PropertyIdRADIUSFramedIPAddress,
  124. (LONG)VT_I4,
  125. PROPERTY_USER_RADIUS_FRAMED_IP_ADDRESS,
  126. 0,
  127. 0,
  128. 0,
  129. L"msRADIUSFramedIPAddress"
  130. )
  131. DEFINE_SCHEMA_PROPERTY(
  132. L"RAS Saved Callback Number",
  133. PropertyIdRASCallbackNumber,
  134. (LONG)VT_BSTR,
  135. PROPERTY_USER_SAVED_RADIUS_CALLBACK_NUMBER,
  136. 48,
  137. 1,
  138. 255,
  139. L"msRASSavedCallbackNumber"
  140. )
  141. DEFINE_SCHEMA_PROPERTY(
  142. L"RAS Saved Framed Route",
  143. PropertyIdRASFramedRoute,
  144. (LONG)VT_BSTR,
  145. PROPERTY_USER_SAVED_RADIUS_FRAMED_ROUTE,
  146. 560,
  147. 1,
  148. 255,
  149. L"msRASSavedFramedRoute"
  150. )
  151. DEFINE_SCHEMA_PROPERTY(
  152. L"RAS Saved Framed IP Address",
  153. PropertyIdRASFramedIPAddress,
  154. (LONG)VT_I4,
  155. PROPERTY_USER_SAVED_RADIUS_FRAMED_IP_ADDRESS,
  156. 0,
  157. 0,
  158. 0,
  159. L"msRASSavedFramedIPAddress"
  160. )
  161. DEFINE_SCHEMA_PROPERTY(
  162. L"Allow Dial-In",
  163. PropertyIdAllowDialin,
  164. (LONG)VT_BOOL,
  165. PROPERTY_USER_ALLOW_DIALIN,
  166. 0,
  167. 0,
  168. 0,
  169. L"msNPAllowDialin"
  170. )
  171. DEFINE_SCHEMA_PROPERTY(
  172. L"Service Type",
  173. PropertyIdRADIUSServiceType,
  174. (LONG)VT_I4,
  175. PROPERTY_USER_SERVICE_TYPE,
  176. 0,
  177. 0,
  178. 0,
  179. L"msRADIUSServiceType"
  180. )
  181. END_SCHEMA_PROPERTY_MAP
  182. //////////////////////////////////////////////////////////////////////////////
  183. // Internal SDO Classes
  184. //
  185. BEGIN_SCHEMA_CLASS_MAP(InternalClasses)
  186. DEFINE_SCHEMA_CLASS(
  187. SDO_PROG_ID_USER,
  188. RequiredProperties,
  189. UserOptionalProperties
  190. )
  191. END_SCHEMA_CLASS_MAP
  192. //////////////////////////////////////////////////////////////////////////////
  193. CSdoSchema::CSdoSchema()
  194. : m_state(SCHEMA_OBJECT_SHUTDOWN),
  195. m_fInternalObjsInitialized(false),
  196. m_fSchemaObjsInitialized(false)
  197. {
  198. InitializeCriticalSection(&m_critSec);
  199. InternalAddRef();
  200. }
  201. //////////////////////////////////////////////////////////////////////////////
  202. CSdoSchema::~CSdoSchema()
  203. {
  204. if ( SCHEMA_OBJECT_INITIALIZED == m_state )
  205. {
  206. DestroyClasses();
  207. DestroyProperties();
  208. }
  209. DeleteCriticalSection(&m_critSec);
  210. }
  211. ///////////////////
  212. // Public Iterface
  213. /////////////////////////////////////////////////////////////////////////////
  214. STDMETHODIMP CSdoSchema::GetVersion(
  215. /*[in]*/ BSTR* version
  216. )
  217. {
  218. _ASSERT( NULL != version );
  219. _ASSERT( SCHEMA_OBJECT_INITIALIZED == m_state );
  220. if ( SCHEMA_OBJECT_INITIALIZED == m_state )
  221. {
  222. BSTR theStr = ::SysAllocString( m_version.c_str() );
  223. if ( theStr )
  224. {
  225. *version = theStr;
  226. return S_OK;
  227. }
  228. }
  229. return E_FAIL;
  230. }
  231. //////////////////////////////////////////////////////////////////////////////
  232. STDMETHODIMP CSdoSchema::GetClass(
  233. /*[in]*/ BSTR id,
  234. /*[out]*/ IUnknown** ppSdoClassInfo
  235. )
  236. {
  237. _ASSERT( NULL != id && NULL != ppSdoClassInfo );
  238. HRESULT hr = E_FAIL;
  239. try
  240. {
  241. ClassMapIterator p = m_classMap.find(id);
  242. _ASSERT( p != m_classMap.end() );
  243. if ( p != m_classMap.end() )
  244. {
  245. ((*p).second)->AddRef();
  246. *ppSdoClassInfo = (*p).second;
  247. hr = S_OK;
  248. }
  249. else
  250. {
  251. IASTracePrintf("Error in SDO Schema - GetClass() - Unknown class id...");
  252. }
  253. }
  254. catch(...)
  255. {
  256. IASTracePrintf("Error in SDO Schema - GetClass() - Caught unknown exception...");
  257. }
  258. return hr;
  259. }
  260. //////////////////////////////////////////////////////////////////////////////
  261. STDMETHODIMP CSdoSchema::GetProperty(
  262. /*[in]*/ BSTR id,
  263. /*[out]*/ IUnknown** ppSdoPropertyInfo
  264. )
  265. {
  266. _ASSERT( NULL != id && NULL != ppSdoPropertyInfo );
  267. HRESULT hr = E_FAIL;
  268. try
  269. {
  270. PropertyMapIterator p = m_propertyMap.find(id);
  271. _ASSERT( p != m_propertyMap.end() );
  272. if ( p != m_propertyMap.end() )
  273. {
  274. ((*p).second)->AddRef();
  275. *ppSdoPropertyInfo = (*p).second;
  276. hr = S_OK;
  277. }
  278. else
  279. {
  280. IASTracePrintf("Error in SDO Schema - GetProperty() - Unknown property id...");
  281. }
  282. }
  283. catch(...)
  284. {
  285. IASTracePrintf("Error in SDO Schema - GetProperty() - Caught unknown exception...");
  286. }
  287. return hr;
  288. }
  289. ////////////////////
  290. // Private Functions
  291. //////////////////////////////////////////////////////////////////////////////
  292. HRESULT CSdoSchema::Initialize(
  293. /*[in]*/ IDataStoreObject* pSchemaDataStore
  294. )
  295. {
  296. HRESULT hr = S_OK;
  297. EnterCriticalSection(&m_critSec);
  298. try
  299. {
  300. do
  301. {
  302. if ( ! m_fInternalObjsInitialized )
  303. {
  304. hr = BuildInternalProperties();
  305. if (FAILED(hr) )
  306. break;
  307. hr = BuildInternalClasses();
  308. if ( FAILED(hr) )
  309. {
  310. DestroyProperties();
  311. break;
  312. }
  313. m_fInternalObjsInitialized = true;
  314. m_state = SCHEMA_OBJECT_INITIALIZED;
  315. }
  316. if ( pSchemaDataStore )
  317. {
  318. if ( ! m_fSchemaObjsInitialized )
  319. {
  320. hr = BuildSchemaProperties(pSchemaDataStore);
  321. if ( SUCCEEDED(hr) )
  322. hr = BuildSchemaClasses(pSchemaDataStore);
  323. if ( FAILED(hr) )
  324. {
  325. DestroyProperties();
  326. DestroyClasses();
  327. m_fInternalObjsInitialized = false;
  328. m_state = SCHEMA_OBJECT_SHUTDOWN;
  329. break;
  330. }
  331. m_fSchemaObjsInitialized = true;
  332. }
  333. }
  334. } while ( FALSE );
  335. }
  336. catch(...)
  337. {
  338. IASTracePrintf("Error in SDO Schema - Initialize() - Caught unknown exception...");
  339. DestroyClasses();
  340. DestroyProperties();
  341. m_fInternalObjsInitialized = false;
  342. m_state = SCHEMA_OBJECT_SHUTDOWN;
  343. hr = E_FAIL;
  344. }
  345. LeaveCriticalSection(&m_critSec);
  346. return hr;
  347. }
  348. //////////////////////////////////////////////////////////////////////////////
  349. HRESULT CSdoSchema::AddProperty(
  350. /*[in]*/ PSDO_PROPERTY_OBJ pPropertyObj
  351. )
  352. {
  353. HRESULT hr = E_FAIL;
  354. BSTR propertyId = NULL;
  355. try {
  356. hr = pPropertyObj->get_Id(&propertyId);
  357. if ( FAILED(hr) )
  358. {
  359. IASTracePrintf("Error in SDO Schema - AddProperty() - CSdoPropertyClass::get_Id() failed...");
  360. return hr;
  361. }
  362. PropertyMapIterator p = m_propertyMap.find(propertyId);
  363. _ASSERT( p == m_propertyMap.end() );
  364. if ( p == m_propertyMap.end() )
  365. {
  366. pair<PropertyMapIterator, bool> thePair = m_propertyMap.insert(PropertyMap::value_type(propertyId, static_cast<ISdoPropertyInfo*>(pPropertyObj)));
  367. if ( true == thePair.second )
  368. hr = S_OK;
  369. }
  370. else
  371. {
  372. IASTracePrintf("Error in SDO Schema - AddProperty() - Property was already defined...");
  373. }
  374. SysFreeString(propertyId);
  375. }
  376. catch(...)
  377. {
  378. if ( NULL != propertyId )
  379. SysFreeString(propertyId);
  380. throw;
  381. }
  382. return hr;
  383. }
  384. //////////////////////////////////////////////////////////////////////////////
  385. HRESULT CSdoSchema::AddClass(
  386. /*[in]*/ PSDO_CLASS_OBJ pClassObj
  387. )
  388. {
  389. HRESULT hr = E_FAIL;
  390. BSTR classId = NULL;
  391. try {
  392. hr = pClassObj->get_Id(&classId);
  393. if ( FAILED(hr) )
  394. {
  395. IASTracePrintf("Error in SDO Schema - AddClass() - CSdoSchemaClass::get_Id() failed...");
  396. return hr;
  397. }
  398. ClassMapIterator p = m_classMap.find(classId);
  399. _ASSERT( p == m_classMap.end() );
  400. if ( p == m_classMap.end() )
  401. {
  402. pair<ClassMapIterator, bool> thePair = m_classMap.insert(ClassMap::value_type(classId, static_cast<ISdoClassInfo*>(pClassObj)));
  403. if ( true == thePair.second )
  404. hr = S_OK;
  405. }
  406. else
  407. {
  408. IASTracePrintf("Error in SDO Schema - AddClass() - Class was already defined...");
  409. }
  410. SysFreeString(classId);
  411. }
  412. catch(...)
  413. {
  414. if ( NULL != classId )
  415. SysFreeString(classId);
  416. throw;
  417. }
  418. return hr;
  419. }
  420. //////////////////////////////////////////////////////////////////////////////
  421. HRESULT CSdoSchema::InitializeClasses()
  422. {
  423. HRESULT hr = S_OK;
  424. ClassMapIterator p = m_classMap.begin();
  425. while ( p != m_classMap.end() )
  426. {
  427. hr = (static_cast<CSdoSchemaClass*>((*p).second))->Initialize(static_cast<ISdoSchema*>(this));
  428. if ( FAILED(hr) )
  429. {
  430. IASTracePrintf("Error in SDO Schema - InitializeClasses() - CSdoSchema::Initialize() failed...");
  431. break;
  432. }
  433. p++;
  434. }
  435. return hr;
  436. }
  437. //////////////////////////////////////////////////////////////////////////////
  438. void CSdoSchema::DestroyClasses()
  439. {
  440. ClassMapIterator p = m_classMap.begin();
  441. while ( p != m_classMap.end() )
  442. {
  443. ((*p).second)->Release();
  444. p = m_classMap.erase(p);
  445. }
  446. }
  447. //////////////////////////////////////////////////////////////////////////////
  448. void CSdoSchema::DestroyProperties()
  449. {
  450. PropertyMapIterator p = m_propertyMap.begin();
  451. while ( p != m_propertyMap.end() )
  452. {
  453. ((*p).second)->Release();
  454. p = m_propertyMap.erase(p);
  455. }
  456. }
  457. //////////////////////////////////////////////////////////////////////////////
  458. HRESULT CSdoSchema::BuildInternalProperties()
  459. {
  460. HRESULT hr = S_OK;
  461. PSCHEMA_PROPERTY_INFO pPropertyInfo = InternalProperties;
  462. while ( NULL != pPropertyInfo->lpszName )
  463. {
  464. auto_ptr <SDO_PROPERTY_OBJ> pPropertyObj (new SDO_PROPERTY_OBJ);
  465. if ( NULL == pPropertyObj.get())
  466. {
  467. IASTracePrintf("Error in SDO Schema - BuildInternalProperties() - Could not alloc memory for property...");
  468. hr = E_FAIL;
  469. break;
  470. }
  471. hr = pPropertyObj->Initialize(pPropertyInfo);
  472. if ( FAILED(hr) )
  473. {
  474. IASTracePrintf("Error in SDO Schema - BuildInternalProperties() - property initialization failed...");
  475. break;
  476. }
  477. hr = AddProperty(pPropertyObj.get());
  478. if ( FAILED(hr) )
  479. {
  480. IASTracePrintf("Error in SDO Schema - BuildInternalProperties() - AddProperty() failed...");
  481. break;
  482. }
  483. pPropertyObj.release ();
  484. pPropertyInfo++;
  485. }
  486. return hr;
  487. }
  488. //////////////////////////////////////////////////////////////////////////////
  489. HRESULT CSdoSchema::BuildInternalClasses()
  490. {
  491. HRESULT hr = S_OK;
  492. PSCHEMA_CLASS_INFO pClassInfo = InternalClasses;
  493. while ( NULL != pClassInfo->lpszClassId )
  494. {
  495. auto_ptr <SDO_CLASS_OBJ> pClassObj (new SDO_CLASS_OBJ);
  496. if ( NULL == pClassObj.get())
  497. {
  498. IASTracePrintf("Error in SDO Schema - BuildInternalClasses() - Could not alloc memory for class...");
  499. hr = E_FAIL;
  500. break;
  501. }
  502. hr = pClassObj->Initialize(pClassInfo, static_cast<ISdoSchema*>(this));
  503. if ( FAILED(hr) )
  504. {
  505. IASTracePrintf("Error in SDO Schema - BuildInternalClasses() - Class initialization failed...");
  506. break;
  507. }
  508. hr = AddClass(pClassObj.get());
  509. if ( FAILED(hr) )
  510. {
  511. IASTracePrintf("Error in SDO Schema - BuildInternalClasses() - AddClass() failed...");
  512. break;
  513. }
  514. pClassObj.release ();
  515. pClassInfo++;
  516. }
  517. return hr;
  518. }
  519. //////////////////////////////////////////////////////////////////////////////
  520. HRESULT CSdoSchema::BuildSchemaProperties(
  521. /*[in]*/ IDataStoreObject* pSchema
  522. )
  523. {
  524. HRESULT hr = E_FAIL;
  525. do
  526. {
  527. SDO_TRACE_VERBOSE_0("Building SDO Schema Properties...");
  528. CComPtr<IDataStoreObject> pProperties;
  529. _bstr_t bstrName = SDO_SCHEMA_PROPERTIES_CONTAINER;
  530. hr = ::SDOGetContainedObject(bstrName, pSchema, &pProperties);
  531. if ( FAILED(hr) )
  532. break;
  533. CComPtr<IEnumVARIANT> pPropertiesEnum;
  534. hr = ::SDOGetContainerEnumerator(pProperties, &pPropertiesEnum);
  535. if ( FAILED(hr) )
  536. break;
  537. CComPtr<IDataStoreObject> pPropertyDataStore;
  538. hr = ::SDONextObjectFromContainer(pPropertiesEnum, &pPropertyDataStore);
  539. while ( S_OK == hr )
  540. {
  541. auto_ptr <SDO_PROPERTY_OBJ> pPropertyObj (new SDO_PROPERTY_OBJ);
  542. if ( NULL == pPropertyObj.get())
  543. {
  544. IASTracePrintf("Error in SDO Schema - BuildProperties() - Could not alloc memory for property...");
  545. hr = E_FAIL;
  546. break;
  547. }
  548. hr = pPropertyObj->Initialize(pPropertyDataStore);
  549. if ( FAILED(hr) )
  550. {
  551. IASTracePrintf("Error in SDO Schema - BuildProperties() - InitNew() failed...");
  552. break;
  553. }
  554. hr = AddProperty(pPropertyObj.get());
  555. if ( FAILED(hr) )
  556. {
  557. IASTracePrintf("Error in SDO Schema - BuildProperties() - AddProperty() failed...");
  558. break;
  559. }
  560. pPropertyObj.release ();
  561. pPropertyDataStore.Release();
  562. hr = ::SDONextObjectFromContainer(pPropertiesEnum, &pPropertyDataStore);
  563. }
  564. if ( S_FALSE == hr )
  565. hr = S_OK;
  566. } while (FALSE);
  567. if ( FAILED(hr) )
  568. DestroyProperties();
  569. return hr;
  570. }
  571. //////////////////////////////////////////////////////////////////////////////
  572. HRESULT CSdoSchema::BuildSchemaClasses(
  573. /*[in]*/ IDataStoreObject* pSchema
  574. )
  575. {
  576. HRESULT hr = E_FAIL;
  577. do
  578. {
  579. SDO_TRACE_VERBOSE_0("Building SDO Schema Classes...");
  580. CComPtr<IDataStoreObject> pClasses;
  581. _bstr_t bstrName = SDO_SCHEMA_CLASSES_CONTAINER;
  582. hr = ::SDOGetContainedObject(bstrName, pSchema, &pClasses);
  583. if ( FAILED(hr) )
  584. break;
  585. CComPtr<IEnumVARIANT> pClassesEnum;
  586. hr = ::SDOGetContainerEnumerator(pClasses, &pClassesEnum);
  587. if ( FAILED(hr) )
  588. break;
  589. CComPtr<IDataStoreObject> pClassDataStore;
  590. hr = ::SDONextObjectFromContainer(pClassesEnum, &pClassDataStore);
  591. while ( S_OK == hr )
  592. {
  593. auto_ptr <SDO_CLASS_OBJ> pClassObj (new SDO_CLASS_OBJ);
  594. if ( NULL == pClassObj.get())
  595. {
  596. IASTracePrintf("Error in SDO Schema - BuildSchemaClasses() - Could not alloc memory for class...");
  597. hr = E_FAIL;
  598. break;
  599. }
  600. hr = pClassObj->InitNew(pClassDataStore, static_cast<ISdoSchema*>(this));
  601. if ( FAILED(hr) )
  602. {
  603. IASTracePrintf("Error in SDO Schema - BuildSchemaClasses() - InitNew() failed...");
  604. break;
  605. }
  606. hr = AddClass(pClassObj.get());
  607. if ( FAILED(hr) )
  608. {
  609. IASTracePrintf("Error in SDO Schema - BuildSchemaClasses() - AddClass() failed...");
  610. break;
  611. }
  612. pClassObj.release ();
  613. pClassDataStore.Release();
  614. hr = ::SDONextObjectFromContainer(pClassesEnum, &pClassDataStore);
  615. }
  616. if ( S_FALSE == hr )
  617. hr = InitializeClasses();
  618. } while (FALSE);
  619. if ( FAILED(hr) )
  620. DestroyClasses();
  621. return hr;
  622. }
  623. //////////////////////////////////////////////////////////////////////////////
  624. // SCHEMA CLASS IMPLEMENTATION
  625. //////////////////////////////////////////////////////////////////////////////
  626. //////////////////////////////////////////////////////////////////////////////
  627. CSdoSchemaClass::CSdoSchemaClass()
  628. : m_state(SCHEMA_OBJECT_SHUTDOWN)
  629. {
  630. InternalAddRef();
  631. }
  632. //////////////////////////////////////////////////////////////////////////////
  633. CSdoSchemaClass::~CSdoSchemaClass()
  634. {
  635. FreeProperties();
  636. }
  637. //////////////////////////
  638. // ISdoClassInfo Functions
  639. //////////////////////////////////////////////////////////////////////////////
  640. STDMETHODIMP CSdoSchemaClass::get_Id(
  641. /*[in]*/ BSTR* Id
  642. )
  643. {
  644. _ASSERT( NULL != Id && SCHEMA_OBJECT_SHUTDOWN != m_state );
  645. if ( NULL != Id && SCHEMA_OBJECT_SHUTDOWN != m_state )
  646. {
  647. BSTR retVal = SysAllocString(m_id.c_str());
  648. if ( NULL != retVal )
  649. {
  650. *Id = retVal;
  651. return S_OK;
  652. }
  653. }
  654. return E_FAIL;
  655. }
  656. //////////////////////////////////////////////////////////////////////////////
  657. STDMETHODIMP CSdoSchemaClass::GetProperty(
  658. /*[in]*/ LONG alias,
  659. /*[in]*/ IUnknown** ppSdoPropertyInfo
  660. )
  661. {
  662. _ASSERT( NULL != ppSdoPropertyInfo && SCHEMA_OBJECT_INITIALIZED == m_state );
  663. HRESULT hr = E_FAIL;
  664. if ( NULL != ppSdoPropertyInfo && SCHEMA_OBJECT_INITIALIZED == m_state )
  665. {
  666. try
  667. {
  668. ClassPropertyMapIterator p;
  669. p = m_requiredProperties.find(alias);
  670. if ( p != m_requiredProperties.end() )
  671. {
  672. (*ppSdoPropertyInfo = (*p).second)->AddRef();
  673. hr = S_OK;
  674. }
  675. else
  676. {
  677. p = m_optionalProperties.find(alias);
  678. _ASSERT ( p != m_optionalProperties.end() );
  679. if ( p != m_optionalProperties.end() )
  680. {
  681. (*ppSdoPropertyInfo = (*p).second)->AddRef();
  682. hr = S_OK;
  683. }
  684. else
  685. {
  686. IASTracePrintf("Error in SDO Schema Class - get_Property() - Unknown property alias...");
  687. }
  688. }
  689. }
  690. catch(...)
  691. {
  692. IASTracePrintf("Error in SDO Schema Class - get_Property() - Caught unknown exception...");
  693. }
  694. }
  695. return hr;
  696. }
  697. //////////////////////////////////////////////////////////////////////////////
  698. STDMETHODIMP CSdoSchemaClass::get_RequiredPropertyCount(
  699. /*[in]*/ LONG* count
  700. )
  701. {
  702. _ASSERT( NULL != count && SCHEMA_OBJECT_INITIALIZED == m_state );
  703. HRESULT hr = E_FAIL;
  704. if ( NULL != count && SCHEMA_OBJECT_INITIALIZED == m_state )
  705. {
  706. *count = m_requiredProperties.size();
  707. return S_OK;
  708. }
  709. return E_FAIL;
  710. }
  711. //////////////////////////////////////////////////////////////////////////////
  712. STDMETHODIMP CSdoSchemaClass::get_RequiredProperties(
  713. /*[in]*/ IUnknown** ppPropertyInfo
  714. )
  715. {
  716. _ASSERT( NULL != ppPropertyInfo && SCHEMA_OBJECT_INITIALIZED == m_state );
  717. HRESULT hr = E_FAIL;
  718. EnumVARIANT* newEnum = NULL;
  719. if ( NULL != ppPropertyInfo && SCHEMA_OBJECT_INITIALIZED == m_state )
  720. {
  721. try
  722. {
  723. VARIANT property;
  724. vector<_variant_t> properties;
  725. VariantInit(&property);
  726. ClassPropertyMapIterator p = m_requiredProperties.begin();
  727. while ( p != m_requiredProperties.end() )
  728. {
  729. V_VT(&property) = VT_DISPATCH;
  730. V_DISPATCH(&property) = dynamic_cast<IDispatch*>((*p).second);
  731. properties.push_back(property);
  732. p++;
  733. }
  734. newEnum = new (std::nothrow) CComObject<EnumVARIANT>;
  735. if (newEnum == NULL)
  736. {
  737. IASTracePrintf("Error in SDO Schema Class - get__NewEnum() - Out of memory...");
  738. return E_OUTOFMEMORY;
  739. }
  740. hr = newEnum->Init(
  741. properties.begin(),
  742. properties.end(),
  743. static_cast<IUnknown*>(this),
  744. AtlFlagCopy
  745. );
  746. if ( SUCCEEDED(hr) )
  747. {
  748. (*ppPropertyInfo = newEnum)->AddRef();
  749. return S_OK;
  750. }
  751. }
  752. catch(...)
  753. {
  754. IASTracePrintf("Error in SDO Schema Class - get__NewEnum() - Caught unknown exception...");
  755. hr = E_FAIL;
  756. }
  757. if ( newEnum )
  758. delete newEnum;
  759. }
  760. return hr;
  761. }
  762. //////////////////////////////////////////////////////////////////////////////
  763. STDMETHODIMP CSdoSchemaClass::get_OptionalPropertyCount(
  764. /*[in]*/ LONG* count
  765. )
  766. {
  767. _ASSERT( NULL != count && SCHEMA_OBJECT_INITIALIZED == m_state );
  768. HRESULT hr = E_FAIL;
  769. if ( NULL != count && SCHEMA_OBJECT_INITIALIZED == m_state )
  770. {
  771. *count = m_optionalProperties.size();
  772. return S_OK;
  773. }
  774. return E_FAIL;
  775. }
  776. //////////////////////////////////////////////////////////////////////////////
  777. STDMETHODIMP CSdoSchemaClass::get_OptionalProperties(
  778. /*[in]*/ IUnknown** ppPropertyInfo
  779. )
  780. {
  781. _ASSERT( NULL != ppPropertyInfo && SCHEMA_OBJECT_INITIALIZED == m_state );
  782. HRESULT hr = E_FAIL;
  783. EnumVARIANT* newEnum = NULL;
  784. if ( NULL != ppPropertyInfo && SCHEMA_OBJECT_INITIALIZED == m_state )
  785. {
  786. try
  787. {
  788. VARIANT property;
  789. vector<_variant_t> properties;
  790. VariantInit(&property);
  791. ClassPropertyMapIterator p = m_optionalProperties.begin();
  792. while ( p != m_optionalProperties.end() )
  793. {
  794. V_VT(&property) = VT_DISPATCH;
  795. V_DISPATCH(&property) = dynamic_cast<IDispatch*>((*p).second);
  796. properties.push_back(property);
  797. p++;
  798. }
  799. newEnum = new (std::nothrow) CComObject<EnumVARIANT>;
  800. if (newEnum == NULL)
  801. {
  802. IASTracePrintf("Error in SDO Schema Class - get__NewEnum() - Out of memory...");
  803. return E_OUTOFMEMORY;
  804. }
  805. hr = newEnum->Init(
  806. properties.begin(),
  807. properties.end(),
  808. static_cast<IUnknown*>(this),
  809. AtlFlagCopy
  810. );
  811. if ( SUCCEEDED(hr) )
  812. {
  813. (*ppPropertyInfo = newEnum)->AddRef();
  814. return S_OK;
  815. }
  816. }
  817. catch(...)
  818. {
  819. IASTracePrintf("Error in SDO Schema Class - get__NewEnum() - Caught unknown exception...");
  820. hr = E_FAIL;
  821. }
  822. if ( newEnum )
  823. delete newEnum;
  824. }
  825. return hr;
  826. }
  827. /////////////////////
  828. // Private Functions
  829. //////////////////////////////////////////////////////////////////////////////
  830. void CSdoSchemaClass::FreeProperties()
  831. {
  832. ClassPropertyMapIterator p;
  833. p = m_requiredProperties.begin();
  834. while ( p != m_requiredProperties.end() )
  835. {
  836. ((*p).second)->Release();
  837. p = m_requiredProperties.erase(p);
  838. }
  839. p = m_optionalProperties.begin();
  840. while ( p != m_optionalProperties.end() )
  841. {
  842. ((*p).second)->Release();
  843. p = m_optionalProperties.erase(p);
  844. }
  845. }
  846. //////////////////////////////////////////////////////////////////////////////
  847. HRESULT CSdoSchemaClass::ReadClassProperties(
  848. /*[in]*/ IDataStoreObject* pDSClass
  849. )
  850. {
  851. HRESULT hr = E_FAIL;
  852. do
  853. {
  854. _variant_t vtValue;
  855. _variant_t vtName = SDO_SCHEMA_CLASS_ID;
  856. hr = pDSClass->GetValue(V_BSTR(&vtName), &vtValue);
  857. if ( FAILED(hr) )
  858. {
  859. IASTracePrintf("Error in SDO Schema Class - InitNew() - IDataStoreObject::GetValue(Name) failed...");
  860. break;
  861. }
  862. m_id = V_BSTR(&vtValue);
  863. SDO_TRACE_VERBOSE_1("Initializing Schema Class: '%ls'...",m_id.c_str());
  864. vtName = SDO_SCHEMA_CLASS_BASE_CLASSES;
  865. hr = pDSClass->GetValueEx(V_BSTR(&vtName), &m_variants[VARIANT_BASES]);
  866. if ( FAILED(hr) )
  867. {
  868. if ( DISP_E_MEMBERNOTFOUND != hr )
  869. {
  870. IASTracePrintf("Error in SDO Schema Class - InitNew() - IDataStoreObject::GetValueEx(BASE_CLASSES) failed...");
  871. break;
  872. }
  873. }
  874. else
  875. {
  876. _ASSERT( (VT_ARRAY | VT_VARIANT) == V_VT(&m_variants[VARIANT_BASES]) );
  877. if ( (VT_ARRAY | VT_VARIANT) != V_VT(&m_variants[VARIANT_BASES]) )
  878. {
  879. IASTracePrintf("Error in SDO Schema Class - InitNew() - Invalid data type (BASE_CLASSES)...");
  880. hr = E_FAIL;
  881. break;
  882. }
  883. #ifdef DEBUG
  884. CVariantVector<VARIANT> properties(&m_variants[VARIANT_BASES]);
  885. DWORD count = 0;
  886. while ( count < properties.size() )
  887. {
  888. _ASSERT( VT_BSTR == properties[count].vt );
  889. count++;
  890. }
  891. #endif
  892. }
  893. vtName = SDO_SCHEMA_CLASS_REQUIRED_PROPERTIES;
  894. hr = pDSClass->GetValueEx(V_BSTR(&vtName), &m_variants[VARIANT_REQUIRED]);
  895. if ( FAILED(hr) )
  896. {
  897. if ( DISP_E_MEMBERNOTFOUND != hr )
  898. {
  899. IASTracePrintf("Error in SDO Schema Class - InitNew() - IDataStoreObject::GetValueEx(REQUIRED_PROPERTIES) failed...");
  900. break;
  901. }
  902. }
  903. else
  904. {
  905. _ASSERT( (VT_ARRAY | VT_VARIANT) == V_VT(&m_variants[VARIANT_REQUIRED]) );
  906. if ( (VT_ARRAY | VT_VARIANT) != V_VT(&m_variants[VARIANT_REQUIRED]) )
  907. {
  908. IASTracePrintf("Error in SDO Schema Class - InitNew() - Invalid data type (REQUIRED_PROPERTIES)...");
  909. hr = E_FAIL;
  910. break;
  911. }
  912. #ifdef DEBUG
  913. CVariantVector<VARIANT> properties(&m_variants[VARIANT_REQUIRED]);
  914. DWORD count = 0;
  915. while ( count < properties.size() )
  916. {
  917. _ASSERT( VT_BSTR == properties[count].vt );
  918. count++;
  919. }
  920. #endif
  921. }
  922. vtName = SDO_SCHEMA_CLASS_OPTIONAL_PROPERTIES;
  923. hr = pDSClass->GetValueEx(V_BSTR(&vtName), &m_variants[VARIANT_OPTIONAL]);
  924. if ( FAILED(hr) )
  925. {
  926. if ( DISP_E_MEMBERNOTFOUND != hr )
  927. {
  928. IASTracePrintf("Error in SDO Schema Class - InitNew() - IDataStoreObject::GetValueEx(OPTIONAL_PROPERTIES) failed...");
  929. break;
  930. }
  931. hr = S_OK; // Class has no optional properties
  932. }
  933. else
  934. {
  935. _ASSERT( (VT_ARRAY | VT_VARIANT) == V_VT(&m_variants[VARIANT_OPTIONAL]) );
  936. if ( (VT_ARRAY | VT_VARIANT) != V_VT(&m_variants[VARIANT_OPTIONAL]) )
  937. {
  938. IASTracePrintf("Error in SDO Schema Class - InitNew() - Invalid data type (OPTIONAL_PROPERTIES)...");
  939. hr = E_FAIL;
  940. }
  941. #ifdef DEBUG
  942. CVariantVector<VARIANT> properties(&m_variants[VARIANT_OPTIONAL]);
  943. DWORD count = 0;
  944. while ( count < properties.size() )
  945. {
  946. _ASSERT( VT_BSTR == properties[count].vt );
  947. count++;
  948. }
  949. #endif
  950. }
  951. } while (FALSE);
  952. return hr;
  953. }
  954. //////////////////////////////////////////////////////////////////////////////
  955. HRESULT CSdoSchemaClass::AddProperty(
  956. /*[in]*/ CLASSPROPERTYSET ePropertySet,
  957. /*[in]*/ ISdoPropertyInfo* pSdoPropertyInfo
  958. )
  959. {
  960. LONG alias;
  961. HRESULT hr = pSdoPropertyInfo->get_Alias(&alias);
  962. if ( FAILED(hr) )
  963. {
  964. IASTracePrintf("Error in SDO Schema Class - InitNew() - get_Alias() failed...");
  965. return hr;
  966. }
  967. ClassPropertyMapIterator p, q;
  968. if ( PROPERTY_SET_REQUIRED == ePropertySet )
  969. {
  970. p = m_requiredProperties.find(alias);
  971. q = m_requiredProperties.end();
  972. }
  973. else
  974. {
  975. _ASSERT( PROPERTY_SET_OPTIONAL == ePropertySet );
  976. p = m_optionalProperties.find(alias);
  977. q = m_optionalProperties.end();
  978. }
  979. _ASSERT( p == q );
  980. if ( p == q )
  981. {
  982. pair<ClassPropertyMapIterator, bool> thePair;
  983. if ( PROPERTY_SET_REQUIRED == ePropertySet )
  984. thePair = m_requiredProperties.insert(ClassPropertyMap::value_type(alias, pSdoPropertyInfo));
  985. else
  986. thePair = m_optionalProperties.insert(ClassPropertyMap::value_type(alias, pSdoPropertyInfo));
  987. if ( true == thePair.second )
  988. {
  989. pSdoPropertyInfo->AddRef(); // AddRef() AFTER item has been added to the property map...
  990. hr = S_OK;
  991. }
  992. }
  993. else
  994. {
  995. IASTracePrintf("Error in SDO Schema Class - AddProperty() - Property was already defined...");
  996. }
  997. return hr;
  998. }
  999. //////////////////////////////////////////////////////////////////////////////
  1000. HRESULT CSdoSchemaClass::AddBaseClassProperties(
  1001. /*[in]*/ ISdoClassInfo* pSdoClassInfo
  1002. )
  1003. {
  1004. CComPtr<IEnumVARIANT> pPropertyEnum;
  1005. HRESULT hr = ::SDOGetClassPropertyEnumerator(PROPERTY_SET_REQUIRED, pSdoClassInfo, &pPropertyEnum);
  1006. if ( FAILED(hr) )
  1007. return hr;
  1008. CComPtr<ISdoPropertyInfo> pSdoPropertyInfo;
  1009. hr = ::SDONextPropertyFromClass(pPropertyEnum, &pSdoPropertyInfo);
  1010. while ( S_OK == hr )
  1011. {
  1012. hr = AddProperty(PROPERTY_SET_REQUIRED, pSdoPropertyInfo);
  1013. if ( FAILED(hr) )
  1014. break;
  1015. pSdoPropertyInfo.Release();
  1016. hr = ::SDONextPropertyFromClass(pPropertyEnum, &pSdoPropertyInfo);
  1017. }
  1018. if ( S_FALSE == hr )
  1019. {
  1020. pPropertyEnum.Release();
  1021. hr = ::SDOGetClassPropertyEnumerator(PROPERTY_SET_OPTIONAL, pSdoClassInfo, &pPropertyEnum);
  1022. if ( FAILED(hr) )
  1023. return hr;
  1024. hr = ::SDONextPropertyFromClass(pPropertyEnum, &pSdoPropertyInfo);
  1025. while ( S_OK == hr )
  1026. {
  1027. hr = AddProperty(PROPERTY_SET_OPTIONAL, pSdoPropertyInfo);
  1028. if ( FAILED(hr) )
  1029. break;
  1030. pSdoPropertyInfo.Release();
  1031. hr = ::SDONextPropertyFromClass(pPropertyEnum, &pSdoPropertyInfo);
  1032. }
  1033. if ( S_FALSE == hr )
  1034. return S_OK;
  1035. }
  1036. return hr;
  1037. }
  1038. //////////////////////////////////////////////////////////////////////////////
  1039. HRESULT CSdoSchemaClass::InitNew(
  1040. /*[in]*/ IDataStoreObject* pDSClass,
  1041. /*[in]*/ ISdoSchema* pSchema
  1042. )
  1043. {
  1044. HRESULT hr = E_FAIL;
  1045. do
  1046. {
  1047. _ASSERT( SCHEMA_OBJECT_SHUTDOWN == m_state );
  1048. hr = ReadClassProperties(pDSClass);
  1049. if ( FAILED(hr) )
  1050. break;
  1051. CComPtr<IUnknown> pUnknown;
  1052. CComPtr<ISdoPropertyInfo> pSdoPropertyInfo;
  1053. DWORD count = 0;
  1054. if ( VT_EMPTY != V_VT(&m_variants[VARIANT_REQUIRED]) )
  1055. {
  1056. CVariantVector<VARIANT> properties(&m_variants[VARIANT_REQUIRED]);
  1057. while ( count < properties.size() )
  1058. {
  1059. hr = pSchema->GetProperty(properties[count].bstrVal, &pUnknown);
  1060. if ( FAILED(hr) )
  1061. {
  1062. IASTracePrintf("Error in SDO Schema Class - InitNew() - GetProperty(REQUIRED) failed...");
  1063. break;
  1064. }
  1065. hr = pUnknown->QueryInterface(IID_ISdoPropertyInfo, (void**)&pSdoPropertyInfo);
  1066. if ( FAILED(hr) )
  1067. {
  1068. IASTracePrintf("Error in SDO Schema Class - InitNew() - QueryInterface(REQUIRED) failed...");
  1069. break;
  1070. }
  1071. hr = AddProperty(PROPERTY_SET_REQUIRED, pSdoPropertyInfo);
  1072. if ( FAILED(hr) )
  1073. {
  1074. IASTracePrintf("Error in SDO Schema Class - InitNew() - AddProperty(REQUIRED) failed...");
  1075. break;
  1076. }
  1077. pUnknown.Release();
  1078. pSdoPropertyInfo.Release();
  1079. count++;
  1080. }
  1081. }
  1082. if ( SUCCEEDED(hr) )
  1083. {
  1084. if ( VT_EMPTY != V_VT(&m_variants[VARIANT_OPTIONAL]) )
  1085. {
  1086. count = 0;
  1087. CVariantVector<VARIANT> properties(&m_variants[VARIANT_OPTIONAL]);
  1088. while ( count < properties.size() )
  1089. {
  1090. hr = pSchema->GetProperty(properties[count].bstrVal, &pUnknown);
  1091. if ( FAILED(hr) )
  1092. {
  1093. IASTracePrintf("Error in SDO Schema Class - InitNew() - GetProperty(OPTIONAL) failed...");
  1094. break;
  1095. }
  1096. hr = pUnknown->QueryInterface(IID_ISdoPropertyInfo, (void**)&pSdoPropertyInfo);
  1097. if ( FAILED(hr) )
  1098. {
  1099. IASTracePrintf("Error in SDO Schema Class - InitNew() - QueryInterface(OPTIONAL) failed...");
  1100. break;
  1101. }
  1102. hr = AddProperty(PROPERTY_SET_OPTIONAL, pSdoPropertyInfo);
  1103. if ( FAILED(hr) )
  1104. {
  1105. IASTracePrintf("Error in SDO Schema Class - InitNew() - AddProperty(OPTIONAL) failed...");
  1106. break;
  1107. }
  1108. pUnknown.Release();
  1109. pSdoPropertyInfo.Release();
  1110. count++;
  1111. }
  1112. }
  1113. if ( SUCCEEDED(hr) )
  1114. m_state = SCHEMA_OBJECT_UNINITIALIZED;
  1115. }
  1116. } while (FALSE);
  1117. return hr;
  1118. }
  1119. //////////////////////////////////////////////////////////////////////////////
  1120. HRESULT CSdoSchemaClass::Initialize(
  1121. /*[in]*/ ISdoSchema* pSchema
  1122. )
  1123. {
  1124. HRESULT hr = S_OK;
  1125. _ASSERT( SCHEMA_OBJECT_SHUTDOWN != m_state );
  1126. if ( SCHEMA_OBJECT_UNINITIALIZED == m_state )
  1127. {
  1128. if ( VT_EMPTY != V_VT(&m_variants[VARIANT_BASES]) )
  1129. {
  1130. hr = E_FAIL;
  1131. CVariantVector<VARIANT> classes(&m_variants[VARIANT_BASES]);
  1132. CComPtr<ISdoClassInfo> pSdoClassInfo;
  1133. CComPtr<IUnknown> pUnknown;
  1134. DWORD count = 0;
  1135. while ( count < classes.size() )
  1136. {
  1137. hr = pSchema->GetClass(classes[count].bstrVal, &pUnknown);
  1138. if ( FAILED(hr) )
  1139. {
  1140. IASTracePrintf("Error in SDO Schema Class - Inititalize() - GetClass() failed...");
  1141. break;
  1142. }
  1143. hr = pUnknown->QueryInterface(IID_ISdoClassInfo, (void**)&pSdoClassInfo);
  1144. if ( FAILED(hr) )
  1145. {
  1146. IASTracePrintf("Error in SDO Schema Class - Inititalize() - QueryInterface() failed...");
  1147. break;
  1148. }
  1149. hr = AddBaseClassProperties(pSdoClassInfo);
  1150. if ( FAILED(hr) )
  1151. {
  1152. IASTracePrintf("Error in SDO Schema Class - Inititalize() - AddBaseClassProperties() failed...");
  1153. break;
  1154. }
  1155. pUnknown.Release();
  1156. pSdoClassInfo.Release();
  1157. count++;
  1158. }
  1159. }
  1160. if ( SUCCEEDED(hr) )
  1161. m_state = SCHEMA_OBJECT_INITIALIZED;
  1162. }
  1163. return hr;
  1164. }
  1165. //////////////////////////////////////////////////////////////////////////////
  1166. HRESULT CSdoSchemaClass::Initialize(
  1167. /*[in]*/ PSCHEMA_CLASS_INFO pClassInfo,
  1168. /*[in]*/ ISdoSchema* pSchema
  1169. )
  1170. {
  1171. _ASSERT( SCHEMA_OBJECT_SHUTDOWN == m_state );
  1172. HRESULT hr = S_OK;
  1173. CComPtr<IUnknown> pUnknown;
  1174. CComPtr<ISdoPropertyInfo> pSdoPropertyInfo;
  1175. m_id = pClassInfo->lpszClassId;
  1176. PCLASSPROPERTIES pRequiredProperties = pClassInfo->pRequiredProperties;
  1177. while ( NULL != pRequiredProperties[0] )
  1178. {
  1179. hr = pSchema->GetProperty((LPWSTR)pRequiredProperties[0], &pUnknown);
  1180. if ( FAILED(hr) )
  1181. {
  1182. IASTracePrintf("Error in SDO Schema Class - Inititialize() - GetProperty(REQUIRED) failed...");
  1183. break;
  1184. }
  1185. hr = pUnknown->QueryInterface(IID_ISdoPropertyInfo, (void**)&pSdoPropertyInfo);
  1186. if ( FAILED(hr) )
  1187. {
  1188. IASTracePrintf("Error in SDO Schema Class - Initialize() - QueryInterface(REQUIRED) failed...");
  1189. break;
  1190. }
  1191. hr = AddProperty(PROPERTY_SET_REQUIRED, pSdoPropertyInfo);
  1192. if ( FAILED(hr) )
  1193. {
  1194. IASTracePrintf("Error in SDO Schema Class - Initialize() - AddProperty(REQUIRED) failed...");
  1195. break;
  1196. }
  1197. pUnknown.Release();
  1198. pSdoPropertyInfo.Release();
  1199. pRequiredProperties++;
  1200. }
  1201. if ( SUCCEEDED(hr) )
  1202. {
  1203. PCLASSPROPERTIES pOptionalProperties = pClassInfo->pOptionalProperties;
  1204. while ( NULL != pOptionalProperties[0] )
  1205. {
  1206. hr = pSchema->GetProperty((LPWSTR)pOptionalProperties[0], &pUnknown);
  1207. if ( FAILED(hr) )
  1208. {
  1209. IASTracePrintf("Error in SDO Schema Class - Inititialize() - GetProperty(OPTIONAL) failed...");
  1210. break;
  1211. }
  1212. hr = pUnknown->QueryInterface(IID_ISdoPropertyInfo, (void**)&pSdoPropertyInfo);
  1213. if ( FAILED(hr) )
  1214. {
  1215. IASTracePrintf("Error in SDO Schema Class - Initialize() - QueryInterface(OPTIONAL) failed...");
  1216. break;
  1217. }
  1218. hr = AddProperty(PROPERTY_SET_OPTIONAL, pSdoPropertyInfo);
  1219. if ( FAILED(hr) )
  1220. {
  1221. IASTracePrintf("Error in SDO Schema Class - Initialize() - AddProperty(OPTIONAL) failed...");
  1222. break;
  1223. }
  1224. pUnknown.Release();
  1225. pSdoPropertyInfo.Release();
  1226. pOptionalProperties++;
  1227. }
  1228. if ( SUCCEEDED(hr) )
  1229. m_state = SCHEMA_OBJECT_INITIALIZED;
  1230. }
  1231. return hr;
  1232. }
  1233. //////////////////////////////////////////////////////////////////////////////
  1234. // SCHEMA PROPERTY IMPLEMENTATION
  1235. //////////////////////////////////////////////////////////////////////////////
  1236. //////////////////////////////////////////////////////////////////////////////
  1237. CSdoSchemaProperty::CSdoSchemaProperty()
  1238. : m_state(SCHEMA_OBJECT_SHUTDOWN),
  1239. m_type(0),
  1240. m_alias(0),
  1241. m_flags(0),
  1242. m_minLength(0),
  1243. m_maxLength(0)
  1244. {
  1245. InternalAddRef();
  1246. }
  1247. //////////////////////////////////////////////////////////////////////////////
  1248. CSdoSchemaProperty::~CSdoSchemaProperty()
  1249. {
  1250. }
  1251. /////////////////////////////
  1252. // ISdoPropertyInfo Functions
  1253. //////////////////////////////////////////////////////////////////////////////
  1254. STDMETHODIMP CSdoSchemaProperty::get_Name(
  1255. /*[out]*/ BSTR* name
  1256. )
  1257. {
  1258. _ASSERT( NULL != name && SCHEMA_OBJECT_INITIALIZED == m_state );
  1259. if ( NULL != name && SCHEMA_OBJECT_INITIALIZED == m_state )
  1260. {
  1261. BSTR retVal = SysAllocString(m_name.c_str());
  1262. if ( NULL != retVal )
  1263. {
  1264. *name = retVal;
  1265. return S_OK;
  1266. }
  1267. }
  1268. return E_FAIL;
  1269. }
  1270. //////////////////////////////////////////////////////////////////////////////
  1271. STDMETHODIMP CSdoSchemaProperty::get_Id(
  1272. /*[out]*/ BSTR* id
  1273. )
  1274. {
  1275. _ASSERT( NULL != id && SCHEMA_OBJECT_INITIALIZED == m_state );
  1276. if ( NULL != id && SCHEMA_OBJECT_INITIALIZED == m_state )
  1277. {
  1278. BSTR retVal = SysAllocString(m_id.c_str());
  1279. if ( NULL != retVal )
  1280. {
  1281. *id = retVal;
  1282. return S_OK;
  1283. }
  1284. }
  1285. return E_FAIL;
  1286. }
  1287. //////////////////////////////////////////////////////////////////////////////
  1288. STDMETHODIMP CSdoSchemaProperty::get_Type(
  1289. /*[out]*/ LONG* type
  1290. )
  1291. {
  1292. _ASSERT( NULL != type && SCHEMA_OBJECT_INITIALIZED == m_state );
  1293. if ( NULL != type && SCHEMA_OBJECT_INITIALIZED == m_state )
  1294. {
  1295. *type = m_type;
  1296. return S_OK;
  1297. }
  1298. return E_FAIL;
  1299. }
  1300. //////////////////////////////////////////////////////////////////////////////
  1301. STDMETHODIMP CSdoSchemaProperty::get_Alias(
  1302. /*[out]*/ LONG* alias
  1303. )
  1304. {
  1305. _ASSERT( NULL != alias && SCHEMA_OBJECT_INITIALIZED == m_state );
  1306. if ( NULL != alias && SCHEMA_OBJECT_INITIALIZED == m_state )
  1307. {
  1308. *alias = m_alias;
  1309. return S_OK;
  1310. }
  1311. return E_FAIL;
  1312. }
  1313. //////////////////////////////////////////////////////////////////////////////
  1314. STDMETHODIMP CSdoSchemaProperty::get_Flags(
  1315. /*[out]*/ LONG* flags
  1316. )
  1317. {
  1318. _ASSERT( NULL != flags && SCHEMA_OBJECT_INITIALIZED == m_state );
  1319. if ( NULL != flags && SCHEMA_OBJECT_INITIALIZED == m_state )
  1320. {
  1321. *flags = m_flags;
  1322. return S_OK;
  1323. }
  1324. return E_FAIL;
  1325. }
  1326. //////////////////////////////////////////////////////////////////////////////
  1327. STDMETHODIMP CSdoSchemaProperty::get_DisplayName(
  1328. /*[out]*/ BSTR* displayName
  1329. )
  1330. {
  1331. _ASSERT( NULL != displayName && SCHEMA_OBJECT_INITIALIZED == m_state );
  1332. if ( NULL != displayName && SCHEMA_OBJECT_INITIALIZED == m_state )
  1333. {
  1334. BSTR retVal = SysAllocString(m_displayName.c_str());
  1335. if ( NULL != retVal )
  1336. {
  1337. *displayName = retVal;
  1338. return S_OK;
  1339. }
  1340. }
  1341. return E_FAIL;
  1342. }
  1343. //////////////////////////////////////////////////////////////////////////////
  1344. STDMETHODIMP CSdoSchemaProperty::HasMinLength(
  1345. /*[out]*/ VARIANT_BOOL* pBool
  1346. )
  1347. {
  1348. _ASSERT( NULL != pBool && SCHEMA_OBJECT_INITIALIZED == m_state );
  1349. if ( NULL != pBool && SCHEMA_OBJECT_INITIALIZED == m_state )
  1350. {
  1351. if ( SDO_PROPERTY_MAX_VALUE & m_flags )
  1352. *pBool = VARIANT_TRUE;
  1353. else
  1354. *pBool = VARIANT_FALSE;
  1355. return S_OK;
  1356. }
  1357. return E_FAIL;
  1358. }
  1359. //////////////////////////////////////////////////////////////////////////////
  1360. STDMETHODIMP CSdoSchemaProperty::get_MinLength(
  1361. /*[out]*/ LONG* length
  1362. )
  1363. {
  1364. _ASSERT( NULL != length && SCHEMA_OBJECT_INITIALIZED == m_state );
  1365. if ( NULL != length && SCHEMA_OBJECT_INITIALIZED == m_state )
  1366. {
  1367. if ( SDO_PROPERTY_MIN_LENGTH & m_flags )
  1368. {
  1369. *length = m_minLength;
  1370. return S_OK;
  1371. }
  1372. }
  1373. return E_FAIL;
  1374. }
  1375. //////////////////////////////////////////////////////////////////////////////
  1376. STDMETHODIMP CSdoSchemaProperty::HasMaxLength(
  1377. /*[out]*/ VARIANT_BOOL* pBool
  1378. )
  1379. {
  1380. _ASSERT( NULL != pBool && SCHEMA_OBJECT_INITIALIZED == m_state );
  1381. if ( NULL != pBool && SCHEMA_OBJECT_INITIALIZED == m_state )
  1382. {
  1383. if ( SDO_PROPERTY_MAX_LENGTH & m_flags )
  1384. *pBool = VARIANT_TRUE;
  1385. else
  1386. *pBool = VARIANT_FALSE;
  1387. return S_OK;
  1388. }
  1389. return E_FAIL;
  1390. }
  1391. //////////////////////////////////////////////////////////////////////////////
  1392. STDMETHODIMP CSdoSchemaProperty::get_MaxLength(
  1393. /*[out]*/ LONG* length
  1394. )
  1395. {
  1396. _ASSERT( NULL != length && SCHEMA_OBJECT_INITIALIZED == m_state );
  1397. if ( NULL != length && SCHEMA_OBJECT_INITIALIZED == m_state )
  1398. {
  1399. if ( SDO_PROPERTY_MAX_LENGTH & m_flags )
  1400. {
  1401. *length = m_maxLength;
  1402. return S_OK;
  1403. }
  1404. }
  1405. return E_FAIL;
  1406. }
  1407. //////////////////////////////////////////////////////////////////////////////
  1408. STDMETHODIMP CSdoSchemaProperty::HasMinValue(
  1409. /*[out]*/ VARIANT_BOOL* pBool
  1410. )
  1411. {
  1412. _ASSERT( NULL != pBool && SCHEMA_OBJECT_INITIALIZED == m_state );
  1413. if ( NULL != pBool && SCHEMA_OBJECT_INITIALIZED == m_state )
  1414. {
  1415. if ( SDO_PROPERTY_MIN_VALUE & m_flags )
  1416. *pBool = VARIANT_TRUE;
  1417. else
  1418. *pBool = VARIANT_FALSE;
  1419. return S_OK;
  1420. }
  1421. return E_FAIL;
  1422. }
  1423. //////////////////////////////////////////////////////////////////////////////
  1424. STDMETHODIMP CSdoSchemaProperty::get_MinValue(
  1425. /*[out]*/ VARIANT* value
  1426. )
  1427. {
  1428. _ASSERT( NULL != value && SCHEMA_OBJECT_INITIALIZED == m_state );
  1429. if ( NULL != value && SCHEMA_OBJECT_INITIALIZED == m_state )
  1430. {
  1431. if ( SDO_PROPERTY_MIN_VALUE & m_flags )
  1432. {
  1433. VariantInit(value);
  1434. VariantCopy(value, &m_minValue);
  1435. return S_OK;
  1436. }
  1437. }
  1438. return E_FAIL;
  1439. }
  1440. //////////////////////////////////////////////////////////////////////////////
  1441. STDMETHODIMP CSdoSchemaProperty::HasMaxValue(
  1442. /*[out]*/ VARIANT_BOOL* pBool
  1443. )
  1444. {
  1445. _ASSERT( NULL != pBool && SCHEMA_OBJECT_INITIALIZED == m_state );
  1446. if ( NULL != pBool && SCHEMA_OBJECT_INITIALIZED == m_state )
  1447. {
  1448. if ( SDO_PROPERTY_MAX_VALUE & m_flags )
  1449. *pBool = VARIANT_TRUE;
  1450. else
  1451. *pBool = VARIANT_FALSE;
  1452. return S_OK;
  1453. }
  1454. return E_FAIL;
  1455. }
  1456. //////////////////////////////////////////////////////////////////////////////
  1457. STDMETHODIMP CSdoSchemaProperty::get_MaxValue(
  1458. /*[out]*/ VARIANT* value
  1459. )
  1460. {
  1461. _ASSERT( NULL != value && SCHEMA_OBJECT_INITIALIZED == m_state );
  1462. if ( NULL != value && SCHEMA_OBJECT_INITIALIZED == m_state )
  1463. {
  1464. if ( SDO_PROPERTY_MAX_VALUE & m_flags )
  1465. {
  1466. VariantInit(value);
  1467. VariantCopy(value, &m_maxValue);
  1468. return S_OK;
  1469. }
  1470. }
  1471. return E_FAIL;
  1472. }
  1473. //////////////////////////////////////////////////////////////////////////////
  1474. STDMETHODIMP CSdoSchemaProperty::HasDefaultValue(
  1475. /*[out]*/ VARIANT_BOOL* pBool
  1476. )
  1477. {
  1478. _ASSERT( NULL != pBool && SCHEMA_OBJECT_INITIALIZED == m_state );
  1479. if ( NULL != pBool && SCHEMA_OBJECT_INITIALIZED == m_state )
  1480. {
  1481. if ( SDO_PROPERTY_HAS_DEFAULT & m_flags )
  1482. *pBool = VARIANT_TRUE;
  1483. else
  1484. *pBool = VARIANT_FALSE;
  1485. return S_OK;
  1486. }
  1487. return E_FAIL;
  1488. }
  1489. //////////////////////////////////////////////////////////////////////////////
  1490. STDMETHODIMP CSdoSchemaProperty::get_DefaultValue(
  1491. /*[out]*/ VARIANT* value
  1492. )
  1493. {
  1494. _ASSERT( NULL != value && SCHEMA_OBJECT_INITIALIZED == m_state );
  1495. if ( NULL != value && SCHEMA_OBJECT_INITIALIZED == m_state )
  1496. {
  1497. if ( SDO_PROPERTY_HAS_DEFAULT & m_flags )
  1498. {
  1499. VariantInit(value);
  1500. VariantCopy(value, &m_defaultValue);
  1501. return S_OK;
  1502. }
  1503. }
  1504. return E_FAIL;
  1505. }
  1506. //////////////////////////////////////////////////////////////////////////////
  1507. STDMETHODIMP CSdoSchemaProperty::HasFormat(
  1508. /*[out]*/ VARIANT_BOOL* pBool
  1509. )
  1510. {
  1511. _ASSERT( NULL != pBool && SCHEMA_OBJECT_INITIALIZED == m_state );
  1512. if ( NULL != pBool && SCHEMA_OBJECT_INITIALIZED == m_state )
  1513. {
  1514. if ( SDO_PROPERTY_FORMAT & m_flags )
  1515. *pBool = VARIANT_TRUE;
  1516. else
  1517. *pBool = VARIANT_FALSE;
  1518. return S_OK;
  1519. }
  1520. return E_FAIL;
  1521. }
  1522. //////////////////////////////////////////////////////////////////////////////
  1523. STDMETHODIMP CSdoSchemaProperty::get_Format(
  1524. /*[out]*/ BSTR* Format
  1525. )
  1526. {
  1527. _ASSERT( NULL != Format && SCHEMA_OBJECT_INITIALIZED == m_state );
  1528. if ( NULL != Format && SCHEMA_OBJECT_INITIALIZED == m_state )
  1529. {
  1530. if ( SDO_PROPERTY_FORMAT & m_flags )
  1531. {
  1532. BSTR retVal = SysAllocString(m_format.c_str());
  1533. if ( NULL != retVal )
  1534. {
  1535. *Format = retVal;
  1536. return S_OK;
  1537. }
  1538. }
  1539. }
  1540. return E_FAIL;
  1541. }
  1542. //////////////////////////////////////////////////////////////////////////////
  1543. STDMETHODIMP CSdoSchemaProperty::IsRequired(
  1544. /*[out]*/ VARIANT_BOOL* pBool
  1545. )
  1546. {
  1547. _ASSERT( NULL != pBool && SCHEMA_OBJECT_INITIALIZED == m_state );
  1548. if ( NULL != pBool && SCHEMA_OBJECT_INITIALIZED == m_state )
  1549. {
  1550. if ( SDO_PROPERTY_MANDATORY & m_flags )
  1551. *pBool = VARIANT_TRUE;
  1552. else
  1553. *pBool = VARIANT_FALSE;
  1554. return S_OK;
  1555. }
  1556. return E_FAIL;
  1557. }
  1558. //////////////////////////////////////////////////////////////////////////////
  1559. STDMETHODIMP CSdoSchemaProperty::IsReadOnly(
  1560. /*[out]*/ VARIANT_BOOL* pBool
  1561. )
  1562. {
  1563. _ASSERT( NULL != pBool && SCHEMA_OBJECT_INITIALIZED == m_state );
  1564. if ( NULL != pBool && SCHEMA_OBJECT_INITIALIZED == m_state )
  1565. {
  1566. if ( SDO_PROPERTY_READ_ONLY & m_flags )
  1567. *pBool = VARIANT_TRUE;
  1568. else
  1569. *pBool = VARIANT_FALSE;
  1570. return S_OK;
  1571. }
  1572. return E_FAIL;
  1573. }
  1574. //////////////////////////////////////////////////////////////////////////////
  1575. STDMETHODIMP CSdoSchemaProperty::IsMultiValued(
  1576. /*[out]*/ VARIANT_BOOL* pBool
  1577. )
  1578. {
  1579. _ASSERT( NULL != pBool && SCHEMA_OBJECT_INITIALIZED == m_state );
  1580. if ( NULL != pBool && SCHEMA_OBJECT_INITIALIZED == m_state )
  1581. {
  1582. if ( SDO_PROPERTY_MULTIVALUED & m_flags )
  1583. *pBool = VARIANT_TRUE;
  1584. else
  1585. *pBool = VARIANT_FALSE;
  1586. return S_OK;
  1587. }
  1588. return E_FAIL;
  1589. }
  1590. //////////////////////////////////////////////////////////////////////////////
  1591. STDMETHODIMP CSdoSchemaProperty::IsCollection(
  1592. /*[out]*/ VARIANT_BOOL* pBool
  1593. )
  1594. {
  1595. _ASSERT( NULL != pBool && SCHEMA_OBJECT_INITIALIZED == m_state );
  1596. if ( NULL != pBool && SCHEMA_OBJECT_INITIALIZED == m_state )
  1597. {
  1598. if ( SDO_PROPERTY_COLLECTION & m_flags )
  1599. *pBool = VARIANT_TRUE;
  1600. else
  1601. *pBool = VARIANT_FALSE;
  1602. return S_OK;
  1603. }
  1604. return E_FAIL;
  1605. }
  1606. //////////////////
  1607. // Private methods
  1608. //////////////////////////////////////////////////////////////////////////////
  1609. HRESULT CSdoSchemaProperty::Initialize(
  1610. /*[in]*/ IDataStoreObject* pDSObject
  1611. )
  1612. {
  1613. HRESULT hr = E_FAIL;
  1614. _ASSERT ( SCHEMA_OBJECT_SHUTDOWN == m_state );
  1615. do
  1616. {
  1617. _variant_t vtValue;
  1618. _variant_t vtName;
  1619. vtName = SDO_SCHEMA_PROPERTY_NAME;
  1620. hr = pDSObject->GetValue(V_BSTR(&vtName), &vtValue);
  1621. if ( FAILED(hr) )
  1622. {
  1623. IASTracePrintf("Error in SDO Schema Property - Initialize() - Could not read property name...");
  1624. break;
  1625. }
  1626. m_name = V_BSTR(&vtValue);
  1627. SDO_TRACE_VERBOSE_1("Initializing Schema Property: '%ls'...", m_name.c_str());
  1628. vtName = SDO_SCHEMA_PROPERTY_ID;
  1629. vtValue.Clear();
  1630. hr = pDSObject->GetValue(V_BSTR(&vtName), &vtValue);
  1631. if ( SUCCEEDED(hr) )
  1632. {
  1633. m_id = V_BSTR(&vtValue);
  1634. }
  1635. else
  1636. {
  1637. m_id = m_name;
  1638. }
  1639. vtName = SDO_SCHEMA_PROPERTY_TYPE;
  1640. vtValue.Clear();
  1641. hr = pDSObject->GetValue(V_BSTR(&vtName), &vtValue);
  1642. if ( FAILED(hr) )
  1643. {
  1644. IASTracePrintf("Error in SDO Schema Property - Initialize() - Could not read property type...");
  1645. break;
  1646. }
  1647. m_type = V_I4(&vtValue);
  1648. vtName = SDO_SCHEMA_PROPERTY_ALIAS;
  1649. vtValue.Clear();
  1650. hr = pDSObject->GetValue(V_BSTR(&vtName), &vtValue);
  1651. if ( FAILED(hr) )
  1652. {
  1653. IASTracePrintf("Error in SDO Schema Property - Initialize() - Could not read property alias...");
  1654. break;
  1655. }
  1656. m_alias = V_I4(&vtValue);
  1657. vtName = SDO_SCHEMA_PROPERTY_FLAGS;
  1658. vtValue.Clear();
  1659. hr = pDSObject->GetValue(V_BSTR(&vtName), &vtValue);
  1660. if ( SUCCEEDED(hr) )
  1661. {
  1662. m_flags = V_I4(&vtValue);
  1663. }
  1664. else
  1665. {
  1666. m_flags = 0;
  1667. }
  1668. vtName = SDO_SCHEMA_PROPERTY_DISPLAYNAME;
  1669. vtValue.Clear();
  1670. hr = pDSObject->GetValue(V_BSTR(&vtName), &vtValue);
  1671. if ( SUCCEEDED(hr) )
  1672. {
  1673. m_displayName = V_BSTR(&vtValue);
  1674. }
  1675. else
  1676. {
  1677. m_displayName = m_name;
  1678. }
  1679. hr = S_OK;
  1680. if ( m_flags & SDO_PROPERTY_MIN_VALUE )
  1681. {
  1682. vtName = SDO_SCHEMA_PROPERTY_MINVAL;
  1683. vtValue.Clear();
  1684. hr = pDSObject->GetValue(V_BSTR(&vtName), &vtValue);
  1685. if ( FAILED(hr) )
  1686. {
  1687. IASTracePrintf("Error in SDO Schema Property - Initialize() - Could not read min value for property %ls...", m_name.c_str());
  1688. break;
  1689. }
  1690. m_minValue = vtValue;
  1691. }
  1692. if ( m_flags & SDO_PROPERTY_MIN_VALUE )
  1693. {
  1694. vtName = SDO_SCHEMA_PROPERTY_MAXVAL;
  1695. vtValue.Clear();
  1696. hr = pDSObject->GetValue(V_BSTR(&vtName), &vtValue);
  1697. if ( FAILED(hr) )
  1698. {
  1699. IASTracePrintf("Error in SDO Schema Property - Initialize() - Could not read max value for property %ls...", m_name.c_str());
  1700. break;
  1701. }
  1702. m_maxValue = vtValue;
  1703. }
  1704. if ( m_flags & SDO_PROPERTY_MIN_LENGTH )
  1705. {
  1706. vtName = SDO_SCHEMA_PROPERTY_MINLENGTH;
  1707. vtValue.Clear();
  1708. hr = pDSObject->GetValue(V_BSTR(&vtName), &vtValue);
  1709. if ( FAILED(hr) )
  1710. {
  1711. IASTracePrintf("Error in SDO Schema Property - Initialize() - Could not read min length for property %ls...", m_name.c_str());
  1712. break;
  1713. }
  1714. m_minLength = V_I4(&vtValue);
  1715. }
  1716. if ( m_flags & SDO_PROPERTY_MAX_LENGTH )
  1717. {
  1718. vtName = SDO_SCHEMA_PROPERTY_MAXLENGTH;
  1719. vtValue.Clear();
  1720. hr = pDSObject->GetValue(V_BSTR(&vtName), &vtValue);
  1721. if ( FAILED(hr) )
  1722. {
  1723. IASTracePrintf("Error in SDO Schema Property - Initialize() - Could not read max length for property %ls...", m_name.c_str());
  1724. break;
  1725. }
  1726. m_maxLength = V_I4(&vtValue);
  1727. }
  1728. _ASSERT ( m_minLength <= m_maxLength );
  1729. if ( m_flags & SDO_PROPERTY_HAS_DEFAULT )
  1730. {
  1731. vtName = SDO_SCHEMA_PROPERTY_DEFAULTVAL;
  1732. vtValue.Clear();
  1733. if ( m_flags & SDO_PROPERTY_MULTIVALUED )
  1734. hr = pDSObject->GetValueEx(V_BSTR(&vtName), &vtValue);
  1735. else
  1736. hr = pDSObject->GetValue(V_BSTR(&vtName), &vtValue);
  1737. if ( FAILED(hr) )
  1738. {
  1739. IASTracePrintf("Error in SDO Schema Property - Initialize() - Could not read default value for property %ls...", m_name.c_str());
  1740. break;
  1741. }
  1742. m_defaultValue = vtValue;
  1743. }
  1744. if ( m_flags & SDO_PROPERTY_FORMAT )
  1745. {
  1746. vtName = SDO_SCHEMA_PROPERTY_FORMAT;
  1747. vtValue.Clear();
  1748. hr = pDSObject->GetValue(V_BSTR(&vtName), &vtValue);
  1749. if ( FAILED(hr) )
  1750. {
  1751. IASTracePrintf("Error in SDO Schema Property - Initialize() - Could not read format string for property %ls...", m_name.c_str());
  1752. break;
  1753. }
  1754. m_format = V_BSTR(&vtValue);
  1755. }
  1756. m_state = SCHEMA_OBJECT_INITIALIZED;
  1757. } while ( FALSE );
  1758. return hr;
  1759. }
  1760. //////////////////////////////////////////////////////////////////////////////
  1761. HRESULT CSdoSchemaProperty::Initialize(
  1762. /*[in]*/ PSCHEMA_PROPERTY_INFO pPropertyInfo
  1763. )
  1764. {
  1765. _ASSERT ( SCHEMA_OBJECT_SHUTDOWN == m_state );
  1766. _ASSERT( pPropertyInfo->lpszName );
  1767. m_name = pPropertyInfo->lpszName;
  1768. _ASSERT( pPropertyInfo->Id );
  1769. m_id = pPropertyInfo->Id;
  1770. m_type = pPropertyInfo->Syntax;
  1771. m_alias = pPropertyInfo->Alias;
  1772. m_flags = pPropertyInfo->Flags;
  1773. m_minLength = pPropertyInfo->MinLength;
  1774. m_maxLength = pPropertyInfo->MaxLength;
  1775. _ASSERT( m_minLength <= m_maxLength );
  1776. _ASSERT( pPropertyInfo->lpszDisplayName );
  1777. m_displayName = pPropertyInfo->lpszDisplayName;
  1778. m_state = SCHEMA_OBJECT_INITIALIZED;
  1779. return S_OK;
  1780. }