|
From: Frank V. C. <fr...@us...> - 2001-04-25 03:27:25
|
Update of /cvsroot/corelinux/clfw/src/testdrivers/exf2
In directory usw-pr-cvs1:/tmp/cvs-serv12882/src/testdrivers/exf2
Modified Files:
examp2.cpp
Log Message:
Fully functional schema management, work continues on cleanup and example completion
Index: examp2.cpp
===================================================================
RCS file: /cvsroot/corelinux/clfw/src/testdrivers/exf2/examp2.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** examp2.cpp 2001/04/22 14:30:51 1.8
--- examp2.cpp 2001/04/25 03:27:22 1.9
***************
*** 23,27 ****
This may be the begining of the schema management stuff, who knows?
! Maybe that guy over there...no?...over there?
Anyway, for this example we make a number of assertions:
--- 23,27 ----
This may be the begining of the schema management stuff, who knows?
! Maybe that guy over there does...no?...over there?
Anyway, for this example we make a number of assertions:
***************
*** 76,85 ****
#endif
#if !defined(__STORECATALOG_HPP)
#include INCL_StoreCatalog
#endif
! #if !defined(__STORESPONSOR_HPP)
! #include INCL_StoreSponsor
#endif
--- 76,89 ----
#endif
+ #if !defined(__STORESPONSOR_HPP)
+ #include INCL_StoreSponsor
+ #endif
+
#if !defined(__STORECATALOG_HPP)
#include INCL_StoreCatalog
#endif
! #if !defined(__STORE_HPP)
! #include INCL_Store
#endif
***************
*** 87,98 ****
//
// Main entry prototype
//
int main( void );
! SchemaPtr createSchemaAndPopulate( StoreCatalogPtr ) throw ();
! void initializeConcept( ConceptPtr, CharCptr, CharCptr ) throw ();
! void assignCollection( ConceptPtr, CharCptr ) throw ();
//
--- 91,130 ----
//
+ // Data Declarations
+ //
+
+
+ //
// Main entry prototype
//
int main( void );
+
+ //
+ // Menu management
+ //
+
+ Int showMenuGetCommand( void );
+ void commandLoop( StoreCatalogPtr ) throw();
+
+ //
+ // Functions for catalog
+ //
+
+ void displayCatalog( StoreCatalogPtr );
+ void createSchema( StoreCatalogPtr ) throw ();
+ void saveOpen( StoreCatalogPtr ) throw ();
+ void closeOpen( StoreCatalogPtr ) throw ();
+ void deleteSchema( StoreCatalogPtr ) throw ();
+
+ //
+ // Functions for schemas
+ //
+
+ void editSchema( StoreCatalogPtr ) throw ();
! void createConcepts( SchemaPtr ) throw ();
! void initializeConcept( ConceptPtr, CharCptr, CharCptr ) throw ();
! void assignCollection( ConceptPtr, CharCptr ) throw ();
//
***************
*** 103,106 ****
--- 135,139 ----
AttributePtr buildStringAttribute( CharCptr, CharCptr );
AttributePtr buildStringAttribute( CharCptr, UniversalIdentifierCref );
+ AttributePtr buildStringAttribute( CharCptr, FrameworkEntityPtr );
//
***************
*** 133,153 ****
StoreCatalogPtr aCatalog = aSponsor->getCatalog();
-
- // list existing schemas
-
- Iterator<FrameworkEntityPtr> *aItr( aCatalog->createCatalogIterator() );
! while( aItr->isValid() )
! {
! FrameworkStringPtr aName( FrameworkString::castDown(aItr->getElement()));
! cout << "Have entry for " << aName->getValue() << endl;
! aItr->setNext();
! }
!
! aCatalog->destroyIterator( aItr );
!
! // load a schema -or-
! SchemaPtr aSchema( createSchemaAndPopulate(aCatalog) );
}
--- 166,175 ----
StoreCatalogPtr aCatalog = aSponsor->getCatalog();
! //
! // Enter command loop
! //
! commandLoop( aCatalog );
}
***************
*** 172,188 ****
}
//
// Create the empty vessel then populate
// with concepts
//
! SchemaPtr createSchemaAndPopulate( StoreCatalog *aCatalog ) throw ()
{
SetCollection args;
! args.put( buildStringAttribute("Name","SchemaTest") );
! args.put( buildStringAttribute("Collection","SetCollection") );
aCatalog->createEntry(&args);
--- 194,332 ----
}
+ Int showMenuGetCommand( void )
+ {
+ Int results(-1);
+
+ cout << endl;
+ cout << "Schema management command options" << endl;
+ cout << endl << endl;
+ cout << "\t1 - List Catalog " << endl;
+ cout << "\t2 - Create Schema " << endl;
+ cout << "\t3 - Edit Schema " << endl;
+ cout << "\t4 - Close Schemas " << endl;
+ cout << "\t5 - Delete Schema " << endl;
+ cout << "\t9 - Quit " << endl;
+ cout << endl;
+ cout << "Enter command option : ";
+ cin >> results;
+ cout << endl;
+
+ return results;
+ }
+
+ SetCollection liveSchemas;
+
+ void commandLoop( StoreCatalogPtr aSCPtr ) throw ()
+ {
+ Int results(0);
+ while( results != -1 )
+ {
+ results = showMenuGetCommand();
+ if( results > 9 || results < 0 )
+ {
+ cout << "Invalid command option, exiting" << endl;
+ results = -1;
+ }
+ else
+ {
+ switch( results )
+ {
+ case 1:
+ displayCatalog( aSCPtr );
+ break;
+
+ case 2:
+ createSchema( aSCPtr );
+ break;
+
+ case 3:
+ editSchema( aSCPtr );
+ break;
+
+ case 4:
+ saveOpen( aSCPtr );
+ closeOpen( aSCPtr );
+ break;
+
+ case 5:
+ deleteSchema( aSCPtr );
+ break;
+
+ case 9:
+ results = -1;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ }
+
+ }
+
+ void displayCatalog( StoreCatalogPtr aSCPtr )
+ {
+ // list existing schemas
+
+ Iterator<FrameworkEntityPtr> *aItr( aSCPtr->createCatalogIterator() );
+
+ cout << endl <<
+ "********************" << endl <<
+ "Catalog dump display" << endl <<
+ "********************" << endl << endl;
+
+ Counter entCount(0);
+
+ while( aItr->isValid() )
+ {
+ FrameworkStringPtr aName( FrameworkString::castDown(aItr->getElement()));
+ cout << "Entry [" << entCount << "] = " << aName->getValue() << endl;
+ aItr->setNext();
+ ++entCount;
+ }
+
+ aSCPtr->destroyIterator( aItr );
+ cout << endl << "********************" << endl ;
+
+ }
+
//
// Create the empty vessel then populate
// with concepts
//
+
+ char inputBuffer[256];
! void createSchema( StoreCatalog *aCatalog ) throw ()
{
SetCollection args;
+
+ cout << endl << endl <<
+ "Schema creation requires at least two attributes " <<
+ "which are fundementally name value pairs. The attributes are: " <<
+ "Name - no spaces, have fun. " << endl <<
+ "Collection - no spaces..choices are Array and SetCollection " << endl <<
+ endl;
+
+ cout << "Input the Name for the schema ";
+ cin >> inputBuffer;
+
+ FrameworkStringPtr aName( FrameworkString::create() );
+ *aName = inputBuffer;
+
+ cout << "Enter the collection type (Array or SetCollection) ";
+ cin >> inputBuffer;
+
+ FrameworkStringPtr aCollection( FrameworkString::create() );
+ *aCollection = inputBuffer;
! cout << endl << "Creating " << aName->getValue() <<
! " with collection " << aCollection->getValue() << endl;
+ args.put( buildStringAttribute("Name",aName) );
+ args.put( buildStringAttribute("Collection",aCollection) );
+
aCatalog->createEntry(&args);
***************
*** 194,198 ****
AttributePtr aPtr = Attribute::castDown( args.getElementAt(0) );
FrameworkString::destroy( (FrameworkStringPtr)aPtr->getKey() );
- FrameworkString::destroy( (FrameworkStringPtr)aPtr->getValue() );
Attribute::destroy( aPtr );
--- 338,341 ----
***************
*** 200,208 ****
FrameworkString::destroy( (FrameworkStringPtr)aPtr->getKey() );
FrameworkString::destroy( (FrameworkStringPtr)aPtr->getValue() );
- Attribute::destroy( aPtr );
! return aSchema;
}
//
// Constructs a new concept, gives it a name, and
--- 343,495 ----
FrameworkString::destroy( (FrameworkStringPtr)aPtr->getKey() );
FrameworkString::destroy( (FrameworkStringPtr)aPtr->getValue() );
! aPtr->setKey( aName );
! aPtr->setValue( aSchema );
! liveSchemas.put( aPtr );
}
+ void saveOpen( StoreCatalogPtr aSCPtr ) throw ()
+ {
+ Array args;
+
+ //
+ // Loop for gather
+ //
+
+ for( Counter x = 0; x < liveSchemas.getSize(); ++x )
+ {
+ AttributePtr aAtt( Attribute::castDown( liveSchemas.getElementAt(x) ) );
+ args.put( aAtt->getValue() );
+ }
+
+ //
+ // Save
+ //
+ if( args.getSize() > 0 )
+ {
+ aSCPtr->saveEntries( &args );
+ }
+ else
+ {
+ ; // do nothing
+ }
+ }
+
+ void closeOpen( StoreCatalogPtr aSCPtr ) throw ()
+ {
+ Array args;
+ Array indexes;
+
+ //
+ // Loop for gather
+ //
+
+ for( Counter x = 0; x < liveSchemas.getSize(); ++x )
+ {
+ AttributePtr aAtt( Attribute::castDown( liveSchemas.getElementAt(x) ) );
+ args.put( aAtt->getValue() );
+ indexes.put( aAtt );
+ }
+
+ //
+ // Close and remove from live list
+ //
+
+ if( args.getSize() > 0 )
+ {
+ aSCPtr->closeEntries( &args );
+ for( Counter r = 0; r < args.getSize(); ++r )
+ {
+ FrameworkEntityPtr aPtr( indexes.getElementAt(r) );
+ liveSchemas.remove( aPtr );
+ AttributePtr aAtt( Attribute::castDown(aPtr) );
+ FrameworkString::destroy( FrameworkString::castDown(aAtt->getKey()) );
+ Attribute::destroy( aAtt );
+ }
+
+ }
+ else
+ {
+ ; // do nothing
+ }
+
+ }
+
+ void deleteSchema( StoreCatalogPtr aSCPtr ) throw ()
+ {
+ displayCatalog( aSCPtr );
+ cout << endl << endl <<
+ "Schema delete requires at least one attribute " <<
+ "which is fundementally a name value pair. The attribute is: " <<
+ "Name - no spaces, from list displayed. " << endl << endl;
+
+ cout << "Input the schema name to be deleted ";
+ cin >> inputBuffer;
+
+ FrameworkString aName;
+ aName = inputBuffer;
+
+ Attribute anAtt;
+ anAtt.setKey( FrameworkStringPtr(&Store::getNameKey()) );
+ anAtt.setValue( &aName );
+
+ Array args;
+ args.put( &anAtt );
+
+ aSCPtr->deleteEntry( &args );
+
+ anAtt.setKey( anAtt.getValue() );
+
+ ElementIndex hit( liveSchemas.indexOf( &anAtt ) );
+
+ if( hit >= 0 )
+ {
+ AttributePtr aAPtr(Attribute::castDown( liveSchemas.getElementAt(hit) ) );
+ FrameworkString::destroy( FrameworkString::castDown(aAPtr->getKey()) );
+ Attribute::destroy( aAPtr );
+ }
+ else
+ {
+ ; // do nothing
+ }
+
+ }
+
+ void editSchema( StoreCatalogPtr aSCPtr ) throw ()
+ {
+ //
+ // First get the schema to use in editing
+ //
+
+ //
+ // Then present the options in regards to concepts
+ //
+
+ }
+
+ void createConcepts( SchemaPtr aSchmPtr ) throw ()
+ {
+ ConceptPtr aConcept =
+ Concept::castDown(getInstanceOf("Concept"));
+
+ initializeConcept( aConcept, "AppString","SetCollection" );
+
+ //
+ // Now add what class this concept represents
+ //
+
+ AttributePtr aClass
+ (
+ buildStringAttribute
+ (
+ "Class",
+ FrameworkString::getTypeDescriptor()->getIdentifier()
+ )
+ );
+
+ aConcept->addAttribute( aClass );
+ aSchmPtr->addAttribute( buildStringAttribute("AppString",aConcept) );
+ }
+
//
// Constructs a new concept, gives it a name, and
***************
*** 284,288 ****
)
{
! AttributePtr aAtr( new Attribute );
aAtr->setKey( new FrameworkString(aKey) );
aAtr->setValue( new FrameworkString(aValue) );
--- 571,575 ----
)
{
! AttributePtr aAtr( Attribute::create() );
aAtr->setKey( new FrameworkString(aKey) );
aAtr->setValue( new FrameworkString(aValue) );
***************
*** 302,305 ****
--- 589,601 ----
return buildStringAttribute(aKey,buffer);
}
+
+ AttributePtr buildStringAttribute( CharCptr aKey, FrameworkEntityPtr aValue )
+ {
+ AttributePtr aAtr( Attribute::create() );
+ aAtr->setKey( new FrameworkString(aKey) );
+ aAtr->setValue( aValue );
+ return aAtr;
+ }
+
//
|