Leaked source code of windows server 2003
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.

1978 lines
61 KiB

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