BBjAPI::getNamespace

Description

In BBj 3.0 and higher, this method retrieves a BBjNamespace.

Syntax

Return Value

Method

BBjNamespace

getNamespace(string prefixName, string baseName, int createIfNeeded)

Parameters

Variable

Description

prefixName

This name is prefixed to baseName to create the actual name of a BBjNamespace.

baseName

This name is suffixed to prefixName to create the actual name of a BBjNamespace.

createIfNeeded

Indication of whether a new Variable Domain should be created if one does not already exist.

0 = An error will be generated if the Variable Domain does not already exist.

1 = A new Variable Domain will be created if one does not already exist.

Return Value

Returns a generic BBjNamespace that has the name prefixName + "." + baseName.

Remarks

The name of a BBjNamespace consists of two parts: the prefix and the suffix. The full name of a BBjNamespace is prefix + "." + suffix. The prefix and the suffix may be any non-empty string consisting of printable characters that begins with a letter and contains no white space. A prefix that is not likely to be used by others should be used. For example, BASIS often uses the prefix "basis.eng.test"

If a program makes multiple calls to getNamespace() using the same prefixName and baseName, then each call returns the same BBjNamespace.

Executing the getName() method on the returned BBjNamespace returns the Namespace name that can be subsequently used with the getNamespace and getExistingNamespace methods.

Example

sysgui=unt
open (sysgui)"X0"
api! = BBjAPI()
sysgui!=api!.getSysGui()


REM retrieve a namespace, get value of count

switch argc
     case 1
          REM run from command line with no namespace name
          prefix$ = "basis.eng.test.namespace"
          sharedNSName$ = "test"
          sharedNS! = api!.getNamespace(prefix$, sharedNSName$, 1)
          break

     case 2
          REM run from command line with a namespace name
          prefix$ = argv(1)
          sharedNSName$ = "test"
          sharedNS! = api!.getNamespace(prefix$, sharedNSName$, 1)
          break

     case 3
          REM run from within MDI
          prefix$ = "basis.eng.test"
          sharedNSName$ = argv(1)
          sharedNS! = api!.getExistingNamespace(sharedNSName$)
          break

swend

count = sharedNS!.getValue("count", err=setCount)
privateNS! = api!.getNewNamespace(prefix$)
privateNS!.setValue("count",0)
name$ = "client-" + privateNS!.getName()

REM
REM retrieve position
REM

x = sharedNS!.getValue("x", err = setXY)
y = sharedNS!.getValue("y", err = setXY)

REM
REM increment position
REM

sharedNS!.setValue("x", x+50)
sharedNS!.setValue("y", y+50)

REM
REM create window
REM


window! = sysgui!.addWindow(x,y,300,200,name$)
plus! = window!.addButton(1,5,10,90,30,"Increment")
minus! = window!.addButton(2,105,10,90,30,"Decrement")
window!.addStaticText(101,5,50,290,30,"sharedCount:   ")
window!.addStaticText(102,5,70,290,30,"privateCount: ")
sharedCount! = window!.addStaticText(103,200,50,290,15,str(count))
privateCount! = window!.addStaticText(104,200,70,290,15,str(0))


break! = window!.addButton(3,5,110,90,30,"Break")
break!.setCallback(break!.ON_BUTTON_PUSH,"onBreak")


REM
REM set callback for controls
REM
plus!.setCallback(plus!.ON_BUTTON_PUSH, "onPlus")
minus!.setCallback(plus!.ON_BUTTON_PUSH, "onMinus")
window!.setCallback(window!.ON_ACTIVATE, "onActivate")

REM set callback that is to be called when count changes
sharedNS!.setCallbackForVariable("count", "showCount")
privateNS!.setCallbackForVariable("count", "showCount")

REM call onActivate to set tell others we have activated
gosub onActivate

callback(ON_CLOSE,done,sysgui!.getContext())

process_events

onPlus:
sharedNS!.setValue("count", 1 + sharedNS!.getValue("count"))
privateNS!.setValue("count", 1 + privateNS!.getValue("count"))
return


onMinus:
sharedNS!.setValue("count", -1 + sharedNS!.getValue("count"))
privateNS!.setValue("count", -1 + privateNS!.getValue("count"))
count = count - 1
return

onActivate:
print "onActivate called"
sharedNS!.setValue("activeClientNS", privateNS!.getName())
sharedNS!.setValue("activeClientName",name$)
return

showCount:
sharedcount!.setText(str(sharedNS!.getValue("count")))
privatecount!.setText(str(privateNS!.getValue("count")))
return

onBreak:
escape
return


done:
release

setXY:
x = 100
y = 100
sharedNS!.setValue("x", x)
sharedNS!.setValue("y", y)
retry

setCount:
count = 0
sharedNS!.setValue("count", count)
retry

See Also

BBjAPI

Object Variables

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.