|
From: Frank V. C. <fr...@us...> - 2001-04-26 10:22:38
|
Update of /cvsroot/corelinux/clfw/src/testdrivers/exf2
In directory usw-pr-cvs1:/tmp/cvs-serv6603/src/testdrivers/exf2
Modified Files:
examp2.cpp
Log Message:
Complete schema management and example
Index: examp2.cpp
===================================================================
RCS file: /cvsroot/corelinux/clfw/src/testdrivers/exf2/examp2.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** examp2.cpp 2001/04/25 03:27:22 1.9
--- examp2.cpp 2001/04/26 10:22:35 1.10
***************
*** 105,111 ****
//
! Int showMenuGetCommand( void );
void commandLoop( StoreCatalogPtr ) throw();
//
// Functions for catalog
--- 105,113 ----
//
! Int catalogMenuGetCommand( void );
void commandLoop( StoreCatalogPtr ) throw();
+ Int schemaMenuGetCommand( void );
+
//
// Functions for catalog
***************
*** 123,128 ****
void editSchema( StoreCatalogPtr ) throw ();
- void createConcepts( SchemaPtr ) throw ();
void initializeConcept( ConceptPtr, CharCptr, CharCptr ) throw ();
void assignCollection( ConceptPtr, CharCptr ) throw ();
--- 125,133 ----
void editSchema( StoreCatalogPtr ) throw ();
+
+ void displayConcepts( SchemaPtr ) throw ();
+ void createConcept( SchemaPtr ) throw ();
+ void deleteConcept( SchemaPtr ) throw ();
void initializeConcept( ConceptPtr, CharCptr, CharCptr ) throw ();
void assignCollection( ConceptPtr, CharCptr ) throw ();
***************
*** 133,136 ****
--- 138,142 ----
FrameworkEntityPtr getInstanceOf( CharCptr, CharCptr domain=NULLPTR );
+ void resolveAndDestroy( FrameworkEntityPtr );
AttributePtr buildStringAttribute( CharCptr, CharCptr );
AttributePtr buildStringAttribute( CharCptr, UniversalIdentifierCref );
***************
*** 144,147 ****
--- 150,160 ----
void handleException( ExceptionCref );
+ //
+ // Global flags because I'm lazy and don't want to take the
+ // opportunity away for someone to CONTRIBUTE and do a better
+ // job :)
+ //
+
+ bool DIRTYSCHEMASABOUND( false );
int main( void )
***************
*** 194,198 ****
}
! Int showMenuGetCommand( void )
{
Int results(-1);
--- 207,211 ----
}
! Int catalogMenuGetCommand( void )
{
Int results(-1);
***************
*** 204,211 ****
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;
--- 217,234 ----
cout << "\t2 - Create Schema " << endl;
cout << "\t3 - Edit Schema " << endl;
! cout << "\t4 - Save Schemas " << endl;
! cout << "\t5 - Close Schemas " << endl;
! cout << "\t6 - Delete Schema " << endl;
cout << "\t9 - Quit " << endl;
cout << endl;
+ if( DIRTYSCHEMASABOUND == true )
+ {
+ cout << "CAUTION: Work has been done that merits a save." <<
+ endl << endl;
+ }
+ else
+ {
+ ; // do nothing
+ }
cout << "Enter command option : ";
cin >> results;
***************
*** 223,227 ****
while( results != -1 )
{
! results = showMenuGetCommand();
if( results > 9 || results < 0 )
{
--- 246,250 ----
while( results != -1 )
{
! results = catalogMenuGetCommand();
if( results > 9 || results < 0 )
{
***************
*** 247,254 ****
case 4:
saveOpen( aSCPtr );
- closeOpen( aSCPtr );
break;
case 5:
deleteSchema( aSCPtr );
break;
--- 270,281 ----
case 4:
saveOpen( aSCPtr );
break;
case 5:
+ saveOpen( aSCPtr );
+ closeOpen( aSCPtr );
+ break;
+
+ case 6:
deleteSchema( aSCPtr );
break;
***************
*** 267,270 ****
--- 294,316 ----
}
+ Int schemaMenuGetCommand( FrameworkStringPtr aSchema )
+ {
+ Int results(-1);
+
+ cout << endl;
+ cout << "Schema edit command options..active schema ["<<aSchema->getValue()<<"]" << endl;
+ cout << endl << endl;
+ cout << "\t1 - List Concepts " << endl;
+ cout << "\t2 - Create Concept " << endl;
+ cout << "\t3 - Delete Concept " << endl;
+ cout << "\t9 - Quit " << endl;
+ cout << endl;
+ cout << "Enter command option : ";
+ cin >> results;
+ cout << endl;
+
+ return results;
+ }
+
void displayCatalog( StoreCatalogPtr aSCPtr )
{
***************
*** 305,315 ****
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;
--- 351,362 ----
cout << endl << endl <<
! "Schema creation requires at least two attributes " << endl <<
! "which are fundementally name value pairs. The attributes are: " << endl <<
! "\tName - no spaces, have fun. " << endl <<
! "\tCollection - no spaces..choices are Array and SetCollection. " << endl <<
! "Other Stores may require user id and password as well." <<
! endl << endl;
! cout << "Input the Name for the schema : ";
cin >> inputBuffer;
***************
*** 317,321 ****
*aName = inputBuffer;
! cout << "Enter the collection type (Array or SetCollection) ";
cin >> inputBuffer;
--- 364,368 ----
*aName = inputBuffer;
! cout << "Enter the collection type (Array or SetCollection) : ";
cin >> inputBuffer;
***************
*** 337,350 ****
//
AttributePtr aPtr = Attribute::castDown( args.getElementAt(0) );
! FrameworkString::destroy( (FrameworkStringPtr)aPtr->getKey() );
! Attribute::destroy( aPtr );
aPtr = Attribute::castDown( args.getElementAt(1) );
! FrameworkString::destroy( (FrameworkStringPtr)aPtr->getKey() );
! FrameworkString::destroy( (FrameworkStringPtr)aPtr->getValue() );
aPtr->setKey( aName );
aPtr->setValue( aSchema );
liveSchemas.put( aPtr );
}
--- 384,400 ----
//
AttributePtr aPtr = Attribute::castDown( args.getElementAt(0) );
! resolveAndDestroy( aPtr->getKey() );
! resolveAndDestroy( aPtr );
+
aPtr = Attribute::castDown( args.getElementAt(1) );
! resolveAndDestroy( aPtr->getKey() );
! resolveAndDestroy( aPtr->getValue() );
aPtr->setKey( aName );
aPtr->setValue( aSchema );
liveSchemas.put( aPtr );
+
+ DIRTYSCHEMASABOUND = true;
}
***************
*** 368,372 ****
if( args.getSize() > 0 )
{
! aSCPtr->saveEntries( &args );
}
else
--- 418,430 ----
if( args.getSize() > 0 )
{
! if( DIRTYSCHEMASABOUND == true )
! {
! aSCPtr->saveEntries( &args );
! DIRTYSCHEMASABOUND = false;
! }
! else
! {
! ; // do nothing
! }
}
else
***************
*** 404,409 ****
liveSchemas.remove( aPtr );
AttributePtr aAtt( Attribute::castDown(aPtr) );
! FrameworkString::destroy( FrameworkString::castDown(aAtt->getKey()) );
! Attribute::destroy( aAtt );
}
--- 462,467 ----
liveSchemas.remove( aPtr );
AttributePtr aAtt( Attribute::castDown(aPtr) );
! resolveAndDestroy( aAtt->getKey() );
! resolveAndDestroy( aAtt );
}
***************
*** 419,428 ****
{
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;
--- 477,487 ----
{
displayCatalog( aSCPtr );
+
cout << endl << endl <<
! "Schema delete requires at least one attribute " << endl <<
! "which is fundementally a name value pair. The attribute is: " << endl <<
! "\tName - no spaces, select from above list. " << endl << endl;
! cout << "Input the schema name to be deleted : ";
cin >> inputBuffer;
***************
*** 446,451 ****
{
AttributePtr aAPtr(Attribute::castDown( liveSchemas.getElementAt(hit) ) );
! FrameworkString::destroy( FrameworkString::castDown(aAPtr->getKey()) );
! Attribute::destroy( aAPtr );
}
else
--- 505,510 ----
{
AttributePtr aAPtr(Attribute::castDown( liveSchemas.getElementAt(hit) ) );
! resolveAndDestroy( aAPtr->getKey() );
! resolveAndDestroy( aAPtr );
}
else
***************
*** 462,477 ****
//
//
// Then present the options in regards to concepts
//
}
! void createConcepts( SchemaPtr aSchmPtr ) throw ()
{
ConceptPtr aConcept =
Concept::castDown(getInstanceOf("Concept"));
! initializeConcept( aConcept, "AppString","SetCollection" );
//
--- 521,697 ----
//
+ displayCatalog( aSCPtr );
+ cout << endl << endl <<
+ "Select a Schema from this list to work with" << endl << endl;
+
+ cout << "Enter name of schema : ";
+ cin >> inputBuffer;
+
+ FrameworkString aName;
+ aName = inputBuffer;
+
+ // Check the liveSchemas first before going to the catalog
+
+ SchemaPtr aSchema;
+ Attribute anAtt;
+ anAtt.setKey( &aName );
+
+ ElementIndex index(-1);
+
+ if( ( index = liveSchemas.indexOf( &anAtt ) ) != -1 )
+ {
+ AttributePtr anAP( Attribute::castDown( liveSchemas.getElementAt(index) ) );
+ aSchema = Schema::castDown( anAP->getValue() );
+ }
+ else
+ {
+ Array anArray;
+
+ anAtt.setKey( FrameworkStringPtr(&Store::getNameKey()) );
+ anAtt.setValue( &aName );
+ anArray.put( &anAtt );
+
+ aSchema = Schema::castDown( aSCPtr->getEntry( &anArray ) );
+ liveSchemas.put( buildStringAttribute(aName.getValue(),aSchema) );
+ }
+
//
// Then present the options in regards to concepts
//
+ if( aSchema != NULLPTR )
+ {
+ Int results(0);
+
+ while( results != -1 )
+ {
+ results = schemaMenuGetCommand(&aName);
+ if( results > 9 || results < 0 )
+ {
+ cout << "Invalid command option, exiting" << endl;
+ results = -1;
+ }
+ else
+ {
+ switch( results )
+ {
+ case 1:
+ displayConcepts( aSchema );
+ break;
+
+ case 2:
+ createConcept( aSchema );
+ break;
+
+ case 3:
+ deleteConcept( aSchema );
+ break;
+
+ case 9:
+ results = -1;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ }
+
+ }
+
+ }
+
+ void displayConcepts( SchemaPtr aSchmPtr ) throw ()
+ {
+ REQUIRE( aSchmPtr != NULLPTR );
+ CollectionPtr aCollection( aSchmPtr->getProperties() );
+ Counter maxCnt( aCollection->getSize() );
+
+ AttributePtr anAtt( NULLPTR );
+ ConceptPtr aConcept( NULLPTR );
+ FrameworkStringPtr aKey( NULLPTR );
+ FrameworkStringPtr aClassName( NULLPTR );
+
+ cout << endl <<
+ "********************" << endl <<
+ "Schema dump display" << endl <<
+ "********************" << endl << endl;
+
+ for( Counter x = 0; x < maxCnt; ++x )
+ {
+ anAtt =( Attribute::castDown( aCollection->getElementAt(x) ) );
+
+ aKey = FrameworkString::castDown( anAtt->getKey() );
+
+ aConcept = Concept::castDown( anAtt->getValue() );
+
+ CHECK( aConcept );
+
+ aClassName = Store::resolveValueAssignment
+ (
+ aConcept->getProperties(),
+ FrameworkStringPtr(&Store::getClassIdKey())
+ );
+
+ CHECK( aClassName );
+
+ UniversalIdentifier aCID( aClassName->getValue() );
+ MetaClassPtr aClass( Ontology::getClassFor( aCID ) );
+
+ CHECK( aClass );
+
+ cout << "Entry [" << aKey->getValue() <<
+ "] is a schema concept for " << aClass->getInstanceTypeName() <<
+ "[" << aClassName->getValue() << "]" << endl;
+
+ }
+ cout << endl << "********************" << endl ;
+
}
! void createConcept( SchemaPtr aSchmPtr ) throw ()
{
+ SetCollection args;
+
+ cout << endl << endl <<
+ "Concept creation requires at least three attributes " << endl <<
+ "which are fundementally name value pairs. The attributes are: " << endl <<
+ "\tName - no spaces" << endl <<
+ "\tCollection - no spaces..choices are Array and SetCollection. " << endl <<
+ "\tClass - no spaces..the Class that this concept defines for persist. " << endl <<
+ "Other Stores may require user id and password as well." <<
+ endl << endl;
+
+ cout << "Enter the Name for the concept : ";
+ cin >> inputBuffer;
+
+ FrameworkString aName;
+ aName = inputBuffer;
+
+ cout << "Enter the collection type (Array or SetCollection) : ";
+ cin >> inputBuffer;
+
+ FrameworkString aCollection;
+ aCollection = inputBuffer;
+
+ cout << "Enter the Class name for the concept to manager : ";
+ cin >> inputBuffer;
+
+ FrameworkString aClassName;
+ aClassName = inputBuffer;
+
+ cout << endl << "Creating " << aName.getValue() <<
+ " with collection " << aCollection.getValue() <<
+ " to manage " << aClassName.getValue() << endl;
+
ConceptPtr aConcept =
Concept::castDown(getInstanceOf("Concept"));
+
+ initializeConcept( aConcept, aName.getValue(), aCollection.getValue() );
+
+ MetaClassPtr aClass( Ontology::getClassFor( aClassName.getValue() ) );
! ENSURE( aClass != NULLPTR );
//
***************
*** 479,493 ****
//
! AttributePtr aClass
(
buildStringAttribute
(
"Class",
! FrameworkString::getTypeDescriptor()->getIdentifier()
)
);
! aConcept->addAttribute( aClass );
! aSchmPtr->addAttribute( buildStringAttribute("AppString",aConcept) );
}
--- 699,797 ----
//
! AttributePtr aClassAtt
(
buildStringAttribute
(
"Class",
! aClass->getIdentifier()
)
);
+
+ aConcept->addAttribute( aClassAtt );
+ aSchmPtr->addAttribute( buildStringAttribute(aName.getValue(),aConcept) );
+ DIRTYSCHEMASABOUND = true;
+ }
+
+ void deleteConcept( SchemaPtr aSchmPtr ) throw ()
+ {
+ displayConcepts( aSchmPtr );
+
+ cout << endl << endl <<
+ "Concept deletion requires the name of the concept " << endl <<
+ "to be deleted. " <<
+ endl << endl;
+
+ cout << "Enter the Name for the concept : ";
+ cin >> inputBuffer;
+
+ FrameworkString aName;
+ aName = inputBuffer;
+
+ Attribute srchAtt;
+ srchAtt.setKey( &aName );
+
+ ElementIndex cIndex(-1);
+
+ //
+ // Find, and iterate through the concepts properties deleting
+ // as you go
+ //
+
+ if( ( cIndex = aSchmPtr->getProperties()->indexOf(&srchAtt) ) != -1 )
+ {
+ AttributePtr aCncAtt
+ (
+ Attribute::castDown
+ (
+ aSchmPtr->getProperties()->getElementAt(cIndex)
+ )
+ );
+
+ CHECK( aCncAtt );
+
+ ConceptPtr aConcept( Concept::castDown(aCncAtt->getValue()) );
+
+ CHECK( aConcept );
+
+ aSchmPtr->getProperties()->remove( aCncAtt );
+ resolveAndDestroy( aCncAtt->getKey() );
+
+ CollectionPtr aCol( aConcept->getProperties() );
+ for( Counter x = 0; x < aCol->getSize() ; ++x )
+ {
+ AttributePtr aAtt( Attribute::castDown(aCol->getElementAt(x)) );
+ FrameworkEntityPtr aKey( aAtt->getKey() );
+ FrameworkEntityPtr aValue( aAtt->getValue() );
+ if( aValue != NULLPTR )
+ {
+ resolveAndDestroy( aValue );
+ }
+ else
+ {
+ cout << FrameworkString::castDown(aKey)->getValue() << " has no value" << endl;
+
+ }
+ if( aKey != NULLPTR )
+ {
+ resolveAndDestroy( aKey );
+ }
+ else
+ {
+ cout << "Key has no value" << endl;
+ }
+
+ resolveAndDestroy( aAtt );
! }
!
! resolveAndDestroy( aCol );
! resolveAndDestroy( aCncAtt );
! DIRTYSCHEMASABOUND = true;
!
! }
! else
! {
! cout << inputBuffer << " concept not found " << endl;
! }
}
***************
*** 563,566 ****
--- 867,884 ----
return aPtr;
+ }
+
+ void resolveAndDestroy( FrameworkEntityPtr aPtr )
+ {
+ REQUIRE( aPtr != NULLPTR );
+ MetaClassPtr aClass
+ (
+ Ontology::getClassFor( aPtr->getType()->getIdentifier() )
+ );
+
+ CHECK( aClass );
+
+ aClass->dispatch(aPtr,"Destruct",NULLPTR,NULLPTR);
+
}
|