Enterprise Architecture with Protégé 
by David Houlding

Example 1:

(a)

class Service ( Component ) :
 def __init__( self, _service ) :
   self._service = _service
   Component.__init__( self, _service )
 def getInterfaces( self ) :
   return getCollection( self._service, "Interfaces_of_Service", "Interface" )
 def setInterfaces( self, interfaces ) :
   setCollection( self._service, interfaces, 
                                       "Interfaces_of_Service", "_interface" )

(b)

def createService( name ) :
  _service = kb.createInstance( "Service_" + name, kb.getCls( "Service" ) )
  service = Service( _service )
  service.setName( name )
  return service


Example 2:

(a)

def exampleQuery() :
  services = findAllServices()
  for service in services :
    if( service.getOwner().getName() == "Joe Soap" ) :
      print service.getName() + ' Service: Requirements'
      requirements = service.getRequirements()
      for requirement in requirements :
        print '  ' + requirement.getName()

(b)

>>> exampleQuery()
Security Service: Requirements
  Username / Password Login
  Logout
  Get Access Control Lists


Example 3:

owner = findOrCreatePerson( r'Joe Soap' )

implementation = findOrCreateImplementation( r'Security Service' )
implementation.setClassName( r'com.xyz.security.SecurityServiceImpl' )

interface = findOrCreateInterface( r'Security Service' )
interface.setClassName( r'com.xyz.security.SecurityService' )
interface.setImplementations( [ implementation ] )

service = findOrCreateService( r'Security' )
service.setInterfaces( [ interface ] )
service.setOwner( owner )


Example 4:

services = findAllServices()
for service in services :
  if( service.getOwner() == None ) :
    print service.getName()  






2


