summaryrefslogtreecommitdiffstats
path: root/ponder2
diff options
context:
space:
mode:
authorpikusa <pikusa@man.poznan.pl>2013-04-03 13:18:17 (GMT)
committer pikusa <pikusa@man.poznan.pl>2013-04-03 13:18:17 (GMT)
commit2f2a3a129c91de540e66c3bfbe30b0df1942cd4b (patch)
tree2d313cdf0068af368d4de6067d676be16f6a6464 /ponder2
parentff8aa232b071a9b54dff833714a870fd0aec0b30 (diff)
downloadnovi-public-2f2a3a129c91de540e66c3bfbe30b0df1942cd4b.zip
novi-public-2f2a3a129c91de540e66c3bfbe30b0df1942cd4b.tar.gz
novi-public-2f2a3a129c91de540e66c3bfbe30b0df1942cd4b.tar.bz2
project commit and dir tree change
Diffstat (limited to 'ponder2')
-rw-r--r--ponder2/lib/2p.jarbin0 -> 302869 bytes
-rw-r--r--ponder2/lib/ANTLR3Licence.txt31
-rw-r--r--ponder2/lib/antlr-runtime.jarbin0 -> 150774 bytes
-rw-r--r--ponder2/lib/ponder2.jarbin0 -> 432077 bytes
-rw-r--r--ponder2/lib/ponder2.jardesc20
-rw-r--r--ponder2/lib/ponder2aptfactory.jarbin0 -> 16818 bytes
-rw-r--r--ponder2/lib/ponder2aptfactory.jardesc18
-rw-r--r--ponder2/lib/ponder2aptfactory.old.jarbin0 -> 15979 bytes
-rw-r--r--ponder2/lib/qdparser.jarbin0 -> 80846 bytes
-rw-r--r--ponder2/lib/srcBuild.xml12
-rw-r--r--ponder2/lib/tools.jarbin0 -> 12618948 bytes
-rw-r--r--ponder2/lib/topBuild.xml148
-rw-r--r--ponder2/lib/tuPrologLicence.txt8
-rw-r--r--ponder2/pom.xml254
-rw-r--r--ponder2/src/.DS_Storebin0 -> 6148 bytes
-rw-r--r--ponder2/src/main/.DS_Storebin0 -> 6148 bytes
-rw-r--r--ponder2/src/main/java/.DS_Storebin0 -> 6148 bytes
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/.DS_Storebin0 -> 6148 bytes
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/ArgumentList.java129
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/Domain.java453
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/EventForwarder.java177
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/EventTemplate.java254
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/ExternalManagedObject.java316
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/FactoryObject.java138
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/HashInspector.java162
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/ManagedObject.java37
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/OID.java483
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/P2ManagedObject.java422
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/P2ObjectAdaptor.java496
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/Path.java344
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/Ponder2Message.java56
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/PonderTalk.java267
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/PonderTalkInterface.java78
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/SMCStartInterface.java26
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/SelfManagedCell.java769
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/Semaphore.java80
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/Shell.java300
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/ShellInstance.java753
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/StartStopPonder2SMC.java181
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/Timer.java234
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/Util.java572
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/apt/DocWriter.java119
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/apt/DocWriterHtml.java222
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/apt/Ponder2Factory.java76
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/apt/Ponder2Processor.java545
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/apt/Ponder2notify.java37
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/apt/Ponder2op.java39
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/HttpProtocol.java52
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/P2Serializable.java53
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/Protocol.java53
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/Receiver.java198
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/RmiProtocol.java113
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/RmistringProtocol.java100
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/RmixmlProtocol.java101
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/SocketProtocol.java172
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/SscProtocol.java125
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/Transmitter.java106
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/TransmitterImpl.java309
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/Utilities.java81
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/XmlblasterProtocol.java169
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/http/HTTPTransmitter.java133
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/http/Ponder2.jws63
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/java.policy3
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/rmi/CheckRMI.java134
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/rmi/RMIReceiveInterface.java88
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/rmi/RMIReceiver.java146
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/rmi/RMITransmitter.java165
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/rmistring/RmiStringReceiveInterface.java69
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/rmistring/RmiStringReceiver.java92
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/rmistring/RmiStringTransmitter.java146
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/rmixml/RmiXmlReceiveInterface.java70
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/rmixml/RmiXmlReceiver.java96
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/rmixml/RmiXmlTransmitter.java140
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/socket/SocketReceiver.java91
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/socket/SocketTransmitter.java146
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/ssc/SscReceiver.java91
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/ssc/SscTransmitter.java98
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/xmlblaster/XmlBlasterReceiver.java116
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/xmlblaster/XmlBlasterSync.java110
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/comms/xmlblaster/XmlBlasterTransmitter.java124
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2ArgumentException.java42
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2AuthorizationException.java45
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2Exception.java106
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2OperationException.java50
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2RemoteException.java45
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2ResolveException.java45
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/inspector/BooleanPanel.java107
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/inspector/InspectorWindow.java256
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/inspector/Value.java44
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/inspector/ValueBoolean.java66
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/inspector/ValueNew.java79
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/inspector/ValueNumber.java71
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/inspector/ValueP2Object.java66
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/inspector/ValuePanel.java85
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/inspector/ValueString.java68
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/interactions/CallstoIRM.java58
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/interactions/CallstoPonder2.java22
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/managedobject/CsvHash.java137
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/managedobject/DateTime.java106
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/managedobject/DynamicString.java98
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/managedobject/LinkMO.java24
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/managedobject/MemoryMO.java7
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/managedobject/NodeMO.java20
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/managedobject/PlatformMO.java117
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/managedobject/ResourceMO.java8
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/managedobject/RoleMO.java39
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/managedobject/SampleObject.java115
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/managedobject/SearhingMO.java21
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/managedobject/TopologyMO.java129
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/managedobject/UserMO.java39
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/managedobject/VirtualNodeMO.java51
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/mission/Interface.java356
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/mission/Mission.java183
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/mission/MissionController.java224
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/objects/P2Array.java379
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/objects/P2Block.java463
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/objects/P2Boolean.java270
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/objects/P2Class.java92
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/objects/P2Error.java154
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/objects/P2Hash.java504
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/objects/P2Null.java67
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/objects/P2Number.java339
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/objects/P2Object.java438
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/objects/P2String.java283
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/objects/P2XML.java311
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/parser/P2Compiler.java655
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/parser/PonderTalkLexer.java2237
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/parser/PonderTalkParser.java2950
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/parser/XMLParser.java316
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/policy/AuthPolicyHolder.java65
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/policy/AuthPolicySearch.java287
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/policy/AuthorisationModule.java102
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/policy/AuthorisationPolicy.java407
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/policy/BasicAuthModule.java181
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/policy/Event.java278
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/policy/EventListener.java55
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/policy/FlexAuthPolicySearch.java446
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/policy/ObligationPolicy.java400
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/policy/Pair.java79
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/policy/Policy.java197
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/policy/StaticAuthPolicySearch.java489
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/queue/PolicyQueueProducer.java70
-rw-r--r--ponder2/src/main/java/eu/novi/ponder2/queue/Ponder2QueueListener.java88
-rw-r--r--ponder2/src/main/resources/META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory1
-rw-r--r--ponder2/src/main/resources/OSGI-INF/blueprint/.gitignore1
-rw-r--r--ponder2/src/main/resources/OSGI-INF/blueprint/config.xml36
-rw-r--r--ponder2/src/main/resources/OSGI-INF/blueprint/config.xml~11
-rw-r--r--ponder2/src/main/resources/log4j.properties19
-rw-r--r--ponder2/src/main/resources/net/ponder2/apt/PonderDoc.css29
-rw-r--r--ponder2/src/main/resources/resource/PlSlice.p213
-rw-r--r--ponder2/src/main/resources/resource/SampleObject.p217
-rw-r--r--ponder2/src/main/resources/resource/alarm.p213
-rw-r--r--ponder2/src/main/resources/resource/authpolicy.p2124
-rw-r--r--ponder2/src/main/resources/resource/boot.p222
-rw-r--r--ponder2/src/main/resources/resource/bootmissionNOVI.p2119
-rw-r--r--ponder2/src/main/resources/resource/exit.p23
-rw-r--r--ponder2/src/main/resources/resource/federicamission.p297
-rw-r--r--ponder2/src/main/resources/resource/federicamission2.p2146
-rw-r--r--ponder2/src/main/resources/resource/linkmo.p224
-rw-r--r--ponder2/src/main/resources/resource/nodemo.p2188
-rw-r--r--ponder2/src/main/resources/resource/pl.p214
-rw-r--r--ponder2/src/main/resources/resource/planetlabmission.p2102
-rw-r--r--ponder2/src/main/resources/resource/planetlabmission2.p2118
-rw-r--r--ponder2/src/main/resources/resource/platformmo.p225
-rw-r--r--ponder2/src/main/resources/resource/platformmoFED.p262
-rw-r--r--ponder2/src/main/resources/resource/platformmoPL.p262
-rw-r--r--ponder2/src/main/resources/resource/plnode.p213
-rw-r--r--ponder2/src/main/resources/resource/roles.p219
-rw-r--r--ponder2/src/main/resources/resource/shell-auth.p215
-rw-r--r--ponder2/src/main/resources/resource/talkFED.p26
-rw-r--r--ponder2/src/main/resources/resource/talkPL.p26
-rw-r--r--ponder2/src/main/resources/resource/testsetup.p221
-rw-r--r--ponder2/src/main/resources/resource/topologymo.p237
-rw-r--r--ponder2/src/main/resources/resource/users.p216
-rw-r--r--ponder2/src/main/resources/resource/virtualnodemo.p239
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/ArgumentListTest.java43
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/DomainTest.java404
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/EventTemplateTest.java183
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/EventTest.java130
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/ExternalManagedObjectTest.java207
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/FactoryObjectTest.java67
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/OIDTest.java328
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/P2ManagedObjectTest.java216
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/P2ObjectAdaptorTest.java220
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/PathTest.java238
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/PonderTalkTest.java100
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/SelfManagedCellTest.java111
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/ShellInstanceTest.java192
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/ShellTest.java46
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/StartStopPonder2SMCTest.java45
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/UtilTest.java183
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/apt/DocWriterHtmlTest.java126
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/apt/DocWriterTest.java78
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/apt/Ponder2FactoryTest.java58
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/apt/Ponder2ProcessorTest.java56
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/comms/MyProtocol.java19
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/comms/ReceiverTest.java100
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/exception/Ponder2ArgumentExceptionTest.java99
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/exception/Ponder2AuthorizationExceptionTest.java27
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/exception/Ponder2OperationExceptionTest.java26
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/exception/Ponder2RemoteExceptionTest.java26
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/exception/Ponder2ResolveExceptionTest.java26
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/integrationtests/PolicyManagerIT.java143
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/integrationtests/Ponder2PolicyManagerIT.java212
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/managedobject/MyMO.java72
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/managedobject/SampleObjectTest.java104
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/objects/BlockTest.java67
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/objects/P2ArrayTest.java168
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/objects/P2BlockTest.java203
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/objects/P2BooleanTest.java181
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/objects/P2ClassTest.java36
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/objects/P2HashTest.java399
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/objects/P2NumberTest.java134
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/objects/P2ObjectTest.java270
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/objects/P2StringTest.java114
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/objects/P2XMLTest.java135
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/parser/XMLParserTest.java99
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/policy/AuthPolicyHolderTest.java92
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/policy/AuthPolicySearchTest.java175
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/policy/AuthorisationModuleTest.java26
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/policy/AuthorisationPolicyTest.java274
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/policy/BasicAuthModuleTest.java403
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/policy/ObligationPolicyTest.java230
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/policy/PolicyTest.java71
-rw-r--r--ponder2/src/test/java/eu/novi/ponder2/support/shell/PathTest.java72
-rw-r--r--ponder2/src/test/java/other/TestArgs.java58
-rw-r--r--ponder2/src/test/java/other/TestMemoryDelete.java42
-rw-r--r--ponder2/src/test/resources/OSGI-INF/blueprint/.gitignore1
-rw-r--r--ponder2/src/test/resources/resource/DomainEventTest.xml63
-rw-r--r--ponder2/src/test/resources/resource/EventForwardingA.p265
-rw-r--r--ponder2/src/test/resources/resource/EventForwardingB.p253
-rw-r--r--ponder2/src/test/resources/resource/LocalRemoteTest.xml69
-rw-r--r--ponder2/src/test/resources/resource/ProximityEvent.p267
-rw-r--r--ponder2/src/test/resources/resource/TickTest.xml51
-rw-r--r--ponder2/src/test/resources/resource/args.p211
-rw-r--r--ponder2/src/test/resources/resource/array.p226
-rw-r--r--ponder2/src/test/resources/resource/authpol.p255
-rw-r--r--ponder2/src/test/resources/resource/block.p211
-rw-r--r--ponder2/src/test/resources/resource/bootmission.p2103
-rw-r--r--ponder2/src/test/resources/resource/delete.p211
-rw-r--r--ponder2/src/test/resources/resource/error.p20
-rw-r--r--ponder2/src/test/resources/resource/hashinspector.p229
-rw-r--r--ponder2/src/test/resources/resource/includefile.p26
-rw-r--r--ponder2/src/test/resources/resource/includefile2.p22
-rw-r--r--ponder2/src/test/resources/resource/interface.p232
-rw-r--r--ponder2/src/test/resources/resource/misctests.p226
-rw-r--r--ponder2/src/test/resources/resource/missiontest.p279
-rw-r--r--ponder2/src/test/resources/resource/numbers.p210
-rw-r--r--ponder2/src/test/resources/resource/nurse.p255
-rw-r--r--ponder2/src/test/resources/resource/nursepatienttest.p220
-rw-r--r--ponder2/src/test/resources/resource/patient.p248
-rw-r--r--ponder2/src/test/resources/resource/policy.p2100
-rw-r--r--ponder2/src/test/resources/resource/policy.xml516
-rw-r--r--ponder2/src/test/resources/resource/pondertalk.p28
-rw-r--r--ponder2/src/test/resources/resource/pondertalkremote.p27
-rw-r--r--ponder2/src/test/resources/resource/try.p26
-rw-r--r--ponder2/src/test/resources/resource/voidtest.p25
-rw-r--r--ponder2/src/test/resources/resource/xml.p225
258 files changed, 37652 insertions, 0 deletions
diff --git a/ponder2/lib/2p.jar b/ponder2/lib/2p.jar
new file mode 100644
index 0000000..8bbb0b6
--- /dev/null
+++ b/ponder2/lib/2p.jar
Binary files differ
diff --git a/ponder2/lib/ANTLR3Licence.txt b/ponder2/lib/ANTLR3Licence.txt
new file mode 100644
index 0000000..fb3c2c2
--- /dev/null
+++ b/ponder2/lib/ANTLR3Licence.txt
@@ -0,0 +1,31 @@
+ANTLR home: http://antlr.org/
+The ANTLR Jar file is distributed under the following licence:
+===================================
+ANTLR 3 License
+
+[The BSD License]
+Copyright (c) 2003-2008, Terence Parr
+All rights reserved.
+Redistribution and use in source and binary forms, with or without modification, are
+permitted provided that the following conditions are met:
+
+ o Redistributions of source code must retain the above copyright notice, this list of
+ conditions and the following disclaimer.
+
+ o Redistributions in binary form must reproduce the above copyright notice, this list
+ of conditions and the following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+ o Neither the name of the author nor the names of its contributors may be used to
+ endorse or promote products derived from this software without specific prior
+ written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file
diff --git a/ponder2/lib/antlr-runtime.jar b/ponder2/lib/antlr-runtime.jar
new file mode 100644
index 0000000..b0a9ea6
--- /dev/null
+++ b/ponder2/lib/antlr-runtime.jar
Binary files differ
diff --git a/ponder2/lib/ponder2.jar b/ponder2/lib/ponder2.jar
new file mode 100644
index 0000000..690a555
--- /dev/null
+++ b/ponder2/lib/ponder2.jar
Binary files differ
diff --git a/ponder2/lib/ponder2.jardesc b/ponder2/lib/ponder2.jardesc
new file mode 100644
index 0000000..889ac42
--- /dev/null
+++ b/ponder2/lib/ponder2.jardesc
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="MacRoman"?>
+<jardesc>
+<jar path="Ponder2/lib/ponder2.jar"/>
+<options buildIfNeeded="true" compress="true" descriptionLocation="/Ponder2/lib/ponder2.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="true" overwrite="true" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
+<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
+<selectedProjects/>
+<manifest generateManifest="true" mainClassHandleIdentifier="=Ponder2/src\/main\/java&lt;net.ponder2{SelfManagedCell.java[SelfManagedCell" manifestLocation="" manifestVersion="1.0" reuseManifest="false" saveManifest="false" usesManifest="true">
+<sealing sealJar="false">
+<packagesToSeal/>
+<packagesToUnSeal/>
+</sealing>
+</manifest>
+<selectedElements exportClassFiles="true" exportJavaFiles="false" exportOutputFolder="false">
+<javaElement handleIdentifier="=Ponder2/src\/main\/resources"/>
+<javaElement handleIdentifier="=Ponder2/src\/main\/java"/>
+<folder path="/Ponder2/META-INF"/>
+<javaElement handleIdentifier="=Ponder2/apt_generated"/>
+<javaElement handleIdentifier="=QDParser/src\/main\/java"/>
+</selectedElements>
+</jardesc>
diff --git a/ponder2/lib/ponder2aptfactory.jar b/ponder2/lib/ponder2aptfactory.jar
new file mode 100644
index 0000000..0794ccb
--- /dev/null
+++ b/ponder2/lib/ponder2aptfactory.jar
Binary files differ
diff --git a/ponder2/lib/ponder2aptfactory.jardesc b/ponder2/lib/ponder2aptfactory.jardesc
new file mode 100644
index 0000000..2e99d0c
--- /dev/null
+++ b/ponder2/lib/ponder2aptfactory.jardesc
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="MacRoman"?>
+<jardesc>
+<jar path="Ponder2/lib/ponder2aptfactory.jar"/>
+<options buildIfNeeded="true" compress="true" descriptionLocation="/Ponder2/lib/ponder2aptfactory.jardesc" exportErrors="false" exportWarnings="true" includeDirectoryEntries="true" overwrite="true" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
+<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
+<selectedProjects/>
+<manifest generateManifest="true" manifestLocation="" manifestVersion="1.0" reuseManifest="false" saveManifest="false" usesManifest="true">
+<sealing sealJar="false">
+<packagesToSeal/>
+<packagesToUnSeal/>
+</sealing>
+</manifest>
+<selectedElements exportClassFiles="true" exportJavaFiles="true" exportOutputFolder="false">
+<folder path="/Ponder2/src/main/resources/META-INF"/>
+<javaElement handleIdentifier="=Ponder2/src\/main\/java&lt;net.ponder2.apt"/>
+<javaElement handleIdentifier="=Ponder2/src\/main\/resources&lt;net.ponder2.apt"/>
+</selectedElements>
+</jardesc>
diff --git a/ponder2/lib/ponder2aptfactory.old.jar b/ponder2/lib/ponder2aptfactory.old.jar
new file mode 100644
index 0000000..aaec237
--- /dev/null
+++ b/ponder2/lib/ponder2aptfactory.old.jar
Binary files differ
diff --git a/ponder2/lib/qdparser.jar b/ponder2/lib/qdparser.jar
new file mode 100644
index 0000000..421b745
--- /dev/null
+++ b/ponder2/lib/qdparser.jar
Binary files differ
diff --git a/ponder2/lib/srcBuild.xml b/ponder2/lib/srcBuild.xml
new file mode 100644
index 0000000..4acfaee
--- /dev/null
+++ b/ponder2/lib/srcBuild.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="Ponder2 Install" default="install" basedir=".">
+
+ <!-- =================================
+ target: install
+ ================================= -->
+ <target name="install" description="--> installs all the subdirectory components of Ponder2">
+ <ant dir="Ponder2" target="install" inheritAll="false" />
+ <ant dir="Ponder2Comms" target="install" inheritAll="false" />
+ </target>
+
+</project>
diff --git a/ponder2/lib/tools.jar b/ponder2/lib/tools.jar
new file mode 100644
index 0000000..6ab54b4
--- /dev/null
+++ b/ponder2/lib/tools.jar
Binary files differ
diff --git a/ponder2/lib/topBuild.xml b/ponder2/lib/topBuild.xml
new file mode 100644
index 0000000..9c8e1b6
--- /dev/null
+++ b/ponder2/lib/topBuild.xml
@@ -0,0 +1,148 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- =================================
+ Ponder2 end-user ant file
+ ================================= -->
+<project name="Ponder2" default="run" basedir=".">
+
+ <property name="apt.generated" value=".apt_generated" />
+ <property name="dist" value="dist" />
+ <property name="sources" value="src" />
+ <property name="bin" value=".bin" />
+ <property name="doc" value="doc" />
+ <property name="lib" value="lib" />
+ <property name="antlr-version" value="3.1.3"/>
+ <property name="antlr.jar" value="antlr-runtime.jar" />
+ <property name="2p.zip" value="2p-2.1.zip" />
+ <property name="2p.jar" value="2p.jar" />
+
+ <path id="classpath">
+ <pathelement location="${bin}" />
+ <fileset dir="${lib}">
+ <include name="**/*.jar"/>
+ </fileset>
+ </path>
+
+ <pathconvert property="p2.codebase" targetos="unix">
+ <path path="${basedir}/${lib}/ponder2.jar" />
+ <filtermapper>
+ <replacestring from=" " to="%20" />
+ </filtermapper>
+ </pathconvert>
+
+ <pathconvert property="p2comms.codebase" targetos="unix">
+ <path path="${basedir}/${lib}/ponder2comms.jar" />
+ <filtermapper>
+ <replacestring from=" " to="%20" />
+ </filtermapper>
+ </pathconvert>
+
+ <pathconvert property="qdparser.codebase" targetos="unix">
+ <path path="${basedir}/${lib}/qdparser.jar" />
+ <filtermapper>
+ <replacestring from=" " to="%20" />
+ </filtermapper>
+ </pathconvert>
+
+ <target name="boot" if="boot">
+ <property name="bootarg" value="-boot ${boot}" />
+ </target>
+
+ <target name="address" if="address">
+ <property name="addressarg" value="-address ${address}" />
+ </target>
+
+
+ <!-- =================================
+ target: antlr.exists
+ ================================= -->
+ <target name="antlr.exists">
+ <available property="antlr.exists" file="${lib}/${antlr.jar}" />
+ </target>
+
+ <!-- =================================
+ target: antlr
+ ================================= -->
+ <target name="antlr" depends="antlr.exists" unless="antlr.exists">
+ <echo message="ANTLR is required for the PonderTalk compiler" />
+ <mkdir dir="${lib}" />
+ <get src="http://www.antlr.org/download/antlr-runtime-${antlr-version}.jar" dest="${lib}/${antlr.jar}" usetimestamp="true" />
+ </target>
+
+ <!-- =================================
+ target: tuprolog.exists
+ ================================= -->
+ <target name="tuprolog.exists">
+ <available property="tuprolog.exists" file="${lib}/${2p.jar}" />
+ </target>
+
+ <!-- =================================
+ target: tuprolog
+ ================================= -->
+ <target name="tuprolog" depends="tuprolog.exists" unless="tuprolog.exists">
+ <echo>TUProlog is required for authorisation policies</echo>
+ <echo>to ignore this step use -Dtuprolog=ignore</echo>
+ <mkdir dir="${lib}" />
+ <get src="http://downloads.sourceforge.net/tuprolog/${2p.zip}" dest="${lib}/${2p.zip}" usetimestamp="true" />
+ <unzip src="${lib}/${2p.zip}" dest="${lib}">
+ <patternset>
+ <include name="${lib}/2p.jar" />
+ </patternset>
+ <mapper type="flatten" />
+ </unzip>
+ </target>
+
+ <!-- =================================
+ target: rmiregistry
+ ================================= -->
+ <target name="rmiregistry" if="rmi" description="--> checks that rmiregistry is running or starts it. Invoke with -Drmi=name">
+ <java classname="net.ponder2.comms.rmi.CheckRMI" fork="true">
+ <classpath>
+ <pathelement location="${lib}/ponder2comms.jar" />
+ </classpath>
+ <jvmarg value="-Djava.security.policy=jar:file://${p2comms.codebase}!/net/ponder2/comms/java.policy" />
+ </java>
+ </target>
+
+ <target name="rmi" if="rmi" depends="rmiregistry">
+ <property name="rmiarg" value="-address rmi://localhost/${rmi}" />
+ </target>
+
+ <!-- =================================
+ target: build
+ ================================= -->
+ <target name="build" depends="antlr,tuprolog" description="--> compiles everything and copies documentation to ./doc">
+ <mkdir dir="${apt.generated}" />
+ <mkdir dir="${bin}" />
+ <echo message="== Ignore following multiple creation and Override warnings ==" />
+ <apt compile="true" preprocessdir="${apt.generated}" srcdir="${sources}" destdir="${bin}" classpathref="classpath" />
+ <echo message="== Ignore preceeding multiple creation and Override warnings ==" />
+ <copy todir="${bin}">
+ <fileset dir="${sources}" includes="resource/**" />
+ </copy>
+ <mkdir dir="${doc}/user" />
+ <copy todir="${doc}/user">
+ <fileset dir="${apt.generated}/doc" />
+ </copy>
+ </target>
+
+ <!-- =================================
+ target: run
+ ================================= -->
+ <target name="run" depends="build,boot,rmi" description="--> runs the Ponder2 SMC. Options: -Drmi=name -Dboot=file.p2 -Daddress=proto://address">
+ <java classname="net.ponder2.SelfManagedCell" classpathref="classpath" fork="true">
+ <jvmarg value="-Djava.security.policy=jar:file://${p2comms.codebase}!/net/ponder2/comms/java.policy" />
+ <jvmarg value="-Djava.rmi.server.codebase=file://${p2.codebase} file://${p2comms.codebase} file://${qdparser.codebase}" />
+ <arg line="${bootarg} ${rmiarg} ${addressarg}" />
+ </java>
+ </target>
+
+ <!-- =================================
+ target: empty
+ ================================= -->
+ <target name="empty" depends="boot" description="--> runs the SMC without the bootstrap code">
+ <antcall target="run">
+ <param name="bootarg" value="-boot - ${bootarg}" />
+ </antcall>
+ </target>
+
+</project>
diff --git a/ponder2/lib/tuPrologLicence.txt b/ponder2/lib/tuPrologLicence.txt
new file mode 100644
index 0000000..d97e6b1
--- /dev/null
+++ b/ponder2/lib/tuPrologLicence.txt
@@ -0,0 +1,8 @@
+tuProlog home: http://alice.unibo.it/xwiki/bin/view/Tuprolog/
+The tuProlog Jar file (p2.jar) is distributed under the following licence:
+===================================
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public License
+(http://www.gnu.org/copyleft/lesser.html) as published by the Free
+Software Foundation; either version 2.1 of the License, or (at your
+option) any later version.
diff --git a/ponder2/pom.xml b/ponder2/pom.xml
new file mode 100644
index 0000000..a3ba3c0
--- /dev/null
+++ b/ponder2/pom.xml
@@ -0,0 +1,254 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>eu.novi</groupId>
+ <artifactId>parent</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <relativePath>../parent/</relativePath>
+ </parent>
+
+ <artifactId>ponder2</artifactId>
+ <packaging>bundle</packaging>
+ <name>NOVI Ponder2 implementation</name>
+ <description>Policy manager service</description>
+
+ <developers>
+ <developer>
+ <id>yiannos.kryftis</id>
+ <name>Yiannos Kryftis</name>
+ <email>ykryftis@netmode.ece.ntua.gr</email>
+ <organization>NTUA</organization>
+ <organizationUrl>http://www.ntua.gr/</organizationUrl>
+ <roles>
+ <role>developer</role>
+ </roles>
+ <timezone>+2</timezone>
+ </developer>
+ </developers>
+ <dependencies>
+ <!--<dependency>
+ <groupId>eu.novi</groupId>
+ <artifactId>framework</artifactId>
+ <version>${project.version}</version>
+ </dependency>-->
+
+
+ <!--
+ Removed on 31/1/2013
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jta_1.1_spec</artifactId>
+ <version>1.1.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-j2ee-management_1.1_spec</artifactId>
+ <version>1.0.1</version>
+ <scope>test</scope>
+ </dependency>-->
+
+
+ <!-- <dependency> <groupId>com.tu</groupId> <artifactId>tuprolog</artifactId>
+ <version>1</version> <scope>system</scope> <systemPath>${basedir}/lib/2p.jar</systemPath>
+ </dependency> -->
+ <!-- <dependency> <groupId>it.unibo.alice.tuprolog</groupId> <artifactId>tuprolog</artifactId>
+ <version>2.1.1</version> </dependency> -->
+ <dependency>
+ <groupId>eu.novi</groupId>
+ <artifactId>tuprolog-osgi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>eu.novi</groupId>
+ <artifactId>qdparser-osgi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.mirror</groupId>
+ <artifactId>apt</artifactId>
+ <version>1</version>
+ <scope>system</scope>
+ <systemPath>${basedir}/lib/tools.jar</systemPath>
+ </dependency>
+
+ <!-- <dependency> <groupId>net.ponder2.policy</groupId> <artifactId>PolicyP2Adaptor</artifactId>
+ <version>1</version> <scope>system</scope> <systemPath>${basedir}/lib/ponder2.jar</systemPath>
+ </dependency> -->
+ <!-- <dependency> <groupId>com.twicom</groupId> <artifactId>qdparser</artifactId>
+ <version>1.1.0</version> <scope>system</scope> <systemPath>${basedir}/lib/qdparser.jar</systemPath>
+ </dependency> -->
+
+ <!-- <dependency> <groupId>net.ponder2.apt</groupId> <artifactId>ponder2aptfactory</artifactId>
+ <version>1.0</version> <scope>system</scope> <systemPath>${basedir}/lib/ponder2aptfactory.jar</systemPath>
+ <exclusions> <exclusion> <groupId>com.sun</groupId> <artifactId>tools</artifactId>
+ </exclusion> </exclusions> </dependency> -->
+ <dependency>
+ <groupId>org.jmock</groupId>
+ <artifactId>jmock-junit4</artifactId>
+ <version>2.5.1</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jmock</groupId>
+ <artifactId>jmock</artifactId>
+ <version>2.5.1</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jmock</groupId>
+ <artifactId>jmock-legacy</artifactId>
+ <version>2.5.1</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+ <!-- <dependency> <groupId>org.eclipse.jdt.apt</groupId> <artifactId>core</artifactId>
+ <version>3.3.0-v20070607-1200</version> </dependency> -->
+ <!-- <dependency> <groupId>org.slf4j</groupId> <artifactId>integration</artifactId>
+ <version>1.6.4</version> </dependency> -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>${slf4j-log4j12.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicemix.bundles</groupId>
+ <artifactId>
+ org.apache.servicemix.bundles.antlr-runtime
+ </artifactId>
+ <version>3.4_2</version>
+ </dependency>
+ <dependency>
+ <groupId>eu.novi</groupId>
+ <artifactId>information-model</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>eu.novi</groupId>
+ <artifactId>ponder2aptfactory</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>eu.novi</groupId>
+ <artifactId>jackson-osgi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <!-- <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-core</artifactId>
+ <version>5.2.0</version>
+ </dependency> -->
+ <dependency>
+ <groupId>eu.novi</groupId>
+ <artifactId>communications</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>eu.novi</groupId>
+ <artifactId>policy-manager</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>eu.novi</groupId>
+ <artifactId>resource-information-service</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>eu.novi</groupId>
+ <artifactId>intelligent-resource-mapper</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-core</artifactId>
+ <version>5.7.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.xmlrpc</groupId>
+ <artifactId>xmlrpc-client</artifactId>
+ <version>3.1.3</version>
+ </dependency>
+
+ <dependency>
+ <groupId>oscar-osgi</groupId>
+ <artifactId>xmlrpc</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${pom.groupId}.${pom.artifactId};
+ blueprint.graceperiod:=true;
+ blueprint.timeout:= 480000
+ </Bundle-SymbolicName>
+ <Export-Package>
+ eu.novi.ponder2,
+ eu.novi.ponder2.policy,
+ eu.novi.ponder2.comms,
+ eu.novi.ponder2.comms.rmi,
+ eu.novi.ponder2.comms.rmistring,
+ eu.novi.ponder2.comms.rmixml,
+ eu.novi.ponder2.comms.socket,
+ eu.novi.ponder2.comms.http,
+ eu.novi.ponder2.comms.xmlblaster,
+ eu.novi.ponder2.exception,
+ eu.novi.ponder2.managedobject,
+ eu.novi.ponder2.parser,
+ eu.novi.ponder2.queue,
+ eu.novi.ponder2.objects,
+ eu.novi.ponder2.mission,
+ eu.novi.ponder2.inspector,
+ eu.novi.ponder2.interactions
+ </Export-Package>
+ <Private-Package></Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ <!-- I recommend to nod disable the unit tests since they work fine
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.4.2</version>
+ <configuration>
+ <skipTests>false</skipTests>
+ </configuration>
+ </plugin>-->
+ <!-- <plugin> -->
+ <!-- <groupId>org.apache.maven.plugins</groupId> -->
+ <!-- <artifactId>maven-jar-plugin</artifactId> -->
+ <!-- <version>2.3</version><configuration> -->
+ <!-- <excludes> -->
+ <!-- <exclude>**/doc/*</exclude> -->
+ <!-- </excludes> -->
+ <!-- </configuration> -->
+ <!-- </plugin> -->
+
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>apt-maven-plugin</artifactId>
+ <version>1.0-alpha-4</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>process</goal>
+ <goal>test-process</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/ponder2/src/.DS_Store b/ponder2/src/.DS_Store
new file mode 100644
index 0000000..86cb9d4
--- /dev/null
+++ b/ponder2/src/.DS_Store
Binary files differ
diff --git a/ponder2/src/main/.DS_Store b/ponder2/src/main/.DS_Store
new file mode 100644
index 0000000..8a0bc53
--- /dev/null
+++ b/ponder2/src/main/.DS_Store
Binary files differ
diff --git a/ponder2/src/main/java/.DS_Store b/ponder2/src/main/java/.DS_Store
new file mode 100644
index 0000000..3e1e329
--- /dev/null
+++ b/ponder2/src/main/java/.DS_Store
Binary files differ
diff --git a/ponder2/src/main/java/eu/novi/ponder2/.DS_Store b/ponder2/src/main/java/eu/novi/ponder2/.DS_Store
new file mode 100644
index 0000000..8a55a43
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/.DS_Store
Binary files differ
diff --git a/ponder2/src/main/java/eu/novi/ponder2/ArgumentList.java b/ponder2/src/main/java/eu/novi/ponder2/ArgumentList.java
new file mode 100644
index 0000000..837ae43
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/ArgumentList.java
@@ -0,0 +1,129 @@
+/**
+ * Created on Aug 18, 2005
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * $Log: ArgumentList.java,v $
+ * Revision 1.6 2005/10/22 08:53:33 kpt
+ * Changed TaggedElement getAtt to getAttribute
+ *
+ * Revision 1.5 2005/10/21 17:15:47 kpt
+ * Renamed XML Element types
+ *
+ * Revision 1.4 2005/10/21 17:12:55 kpt
+ * Tidied up and made sure demo still worked
+ *
+ * Revision 1.3 2005/10/21 14:31:39 kpt
+ * Changed to faster, meaner, external QDParser with LGPL licence.
+ *
+ * Revision 1.2 2005/09/22 08:38:01 kpt
+ * Fixes for demo
+ *
+ * Revision 1.1 2005/09/12 10:47:07 kpt
+ * Initial Checkin
+ *
+ */
+
+package eu.novi.ponder2;
+
+import java.util.Vector;
+
+//import eu.novi.ponder2.Entry;
+
+import eu.novi.ponder2.ArgumentList;
+
+/**
+ * Simple class to manage argument handling for Events and Policies
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class ArgumentList extends Vector<ArgumentList.Entry> {
+
+ /**
+ * adds a named argument to the list
+ *
+ * @param name
+ * name of string type argument
+ */
+ public void add(String name) {
+ add(new Entry(name, null));
+ }
+
+ /**
+ * get a named argument from the list
+ *
+ * @param name
+ * the name of the argument to retreive
+ * @return a name, type pair if found else null
+ */
+ public Entry getArg(String name) {
+ for (Entry entry : this) {
+ if (entry.name.equals(name))
+ return entry;
+ }
+ return null;
+ }
+
+ /**
+ * The entries for the argument list. Each entry comprises the name and the
+ * type
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+ public class Entry implements Comparable<Entry> {
+
+ /**
+ * The argument name
+ */
+ String name;
+ /**
+ * The arguement type
+ */
+ String type;
+
+ /**
+ * creats an entry for the argument list
+ *
+ * @param name
+ * the argument name
+ * @param type
+ * the argument type
+ */
+ public Entry(String name, String type) {
+ this.name = name;
+ if (type == null)
+ type = "string";
+ this.type = type;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ public int compareTo(Entry other) {
+ int value = name.compareTo(other.name);
+ if (value == 0)
+ value = type.compareTo(other.type);
+ return value;
+ }
+ }
+} \ No newline at end of file
diff --git a/ponder2/src/main/java/eu/novi/ponder2/Domain.java b/ponder2/src/main/java/eu/novi/ponder2/Domain.java
new file mode 100644
index 0000000..ca400b5
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/Domain.java
@@ -0,0 +1,453 @@
+/**
+ * Created on Jul 4, 2005
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * $Log: Domain.java,v $
+ * Revision 1.23 2006/03/15 13:36:42 kpt
+ * Lots of testing stuff and new XMLSaver managed object
+ *
+ * Revision 1.22 2005/11/19 17:26:17 kpt
+ * Error messages for add
+ *
+ * Revision 1.21 2005/11/17 11:36:28 kpt
+ * Added context to many ops for arg substitution
+ *
+ * Revision 1.20 2005/11/15 16:33:25 kpt
+ * Result added to create
+ *
+ * Revision 1.19 2005/11/14 21:02:21 kpt
+ * Made Result much more pervasive
+ *
+ * Revision 1.18 2005/11/14 13:59:00 kpt
+ * Improved results, fixed TickManager
+ *
+ * Revision 1.17 2005/11/07 12:05:42 kpt
+ * Added Result to the parsing
+ *
+ * Revision 1.16 2005/11/03 04:23:46 kpt
+ * More restore and tidying done
+ *
+ * Revision 1.15 2005/10/28 21:58:00 kpt
+ * Restore almost completed
+ *
+ * Revision 1.14 2005/10/27 16:57:38 kpt
+ * OID separated from P2ManagedObject
+ *
+ * Revision 1.13 2005/10/27 09:25:15 kpt
+ * Dump almost completed. Everything still works!
+ *
+ * Revision 1.12 2005/10/24 20:53:02 kpt
+ * Dump part of dump and restore working
+ *
+ * Revision 1.11 2005/10/22 16:49:46 kpt
+ * Returns results through Reply. Shell does rm properly
+ *
+ * Revision 1.10 2005/10/22 08:53:33 kpt
+ * Changed TaggedElement getAtt to getAttribute
+ *
+ * Revision 1.9 2005/10/21 17:15:47 kpt
+ * Renamed XML Element types
+ *
+ * Revision 1.8 2005/10/21 17:12:55 kpt
+ * Tidied up and made sure demo still worked
+ *
+ * Revision 1.7 2005/10/21 14:31:40 kpt
+ * Changed to faster, meaner, external QDParser with LGPL licence.
+ *
+ * Revision 1.6 2005/10/06 10:59:17 kpt
+ * Complete reorganisation of return values using Result.
+ Commands handed to MOs one at a time.
+ *
+ * Revision 1.5 2005/10/01 20:50:52 kpt
+ * Changed result type to new Result class
+ *
+ * Revision 1.4 2005/09/21 15:54:56 kpt
+ * USE now works through external domains
+ *
+ * Revision 1.3 2005/09/21 13:46:40 kpt
+ * Can now create and send events using XML and the event templates
+ *
+ * Revision 1.2 2005/09/14 08:45:38 kpt
+ * Down to import and use
+ *
+ * Revision 1.1 2005/09/12 10:47:08 kpt
+ * Initial Checkin
+ *
+ */
+
+package eu.novi.ponder2;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.objects.P2Array;
+import eu.novi.ponder2.objects.P2Block;
+import eu.novi.ponder2.objects.P2Hash;
+import eu.novi.ponder2.objects.P2Object;
+import eu.novi.ponder2.objects.P2String;
+
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.P2ManagedObject;
+import eu.novi.ponder2.Util;
+
+/**
+ * Domain is the basic managed object for Ponder2 that supports hierarchies.
+ * View it like a directory or a folder in a filesystem
+ *
+ * @author Kevin Twidle
+ * @version $Id: Domain.java,v 1.23 2006/03/15 13:36:42 kpt Exp $
+ */
+public class Domain implements ManagedObject {
+
+ /**
+ * the managed objects belonging to this domain
+ */
+ private final Map<String, P2ManagedObject> managedObjects;
+
+ private P2Object myP2Object;
+
+ /**
+ * creates a new Domain managed object
+ *
+ */
+ @Ponder2op("create")
+ protected Domain(P2Object myP2Object) {
+ this.myP2Object = myP2Object;
+ myP2Object.getOID().setDomain(true);
+ managedObjects = new HashMap<String, P2ManagedObject>();
+ }
+
+ /**
+ * adds a new managed object to this domain
+ *
+ * @param name
+ * the name of the new object to be added
+ * @param mo
+ * the OID of the object to be added
+ */
+ protected void add(String name, P2ManagedObject mo) {
+ mo.addParent(myP2Object.getManagedObject());
+ managedObjects.put(name, mo);
+ // sendEvent("/event/domain/add", this.myOID.toXML(), new
+ // TextElement(name), oid.toXML());
+ // try {
+ // Event event = new Event(P2Object.create(myOID), "/event/domain/add",
+ // P2Object.create(name),
+ // P2Object.create(oid));
+ // myOID.sendEvent(event);
+ // }
+ // catch (Ponder2ResolveException e) {
+ // }
+ // catch (Ponder2ArgumentException e) {
+ // }
+ // catch (Ponder2OperationException e) {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ }
+
+ /**
+ * removes a managed object from a domain
+ *
+ * @param name
+ * the name of the object to be removed
+ * @throws Ponder2Exception
+ */
+ protected P2ManagedObject remove(String name) throws Ponder2Exception {
+ P2ManagedObject mo = managedObjects.remove(name);
+ // The oid may be in this domain more than once under different names
+ if (mo != null && !managedObjects.containsValue(mo)) {
+ mo.removeParent(myP2Object.getManagedObject());
+ // // sendEvent("/event/domain/remove", this.myOID.toXML(), new
+ // // TextElement(name), oid.toXML());
+ // try {
+ // Event event = new Event(myP2Object, "/event/domain/remove",
+ // P2Object.create(name), P2Object
+ // .create(mo));
+ // myP2Object.getManagedObject().sendEvent(event);
+ // }
+ // catch (Ponder2ResolveException e) {
+ // }
+ // catch (Ponder2ArgumentException e) {
+ // }
+ // catch (Ponder2OperationException e) {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ }
+ return mo;
+ }
+
+ /**
+ * gets the P2ManagedObject of a named managed object
+ *
+ * @param name
+ * the name of the object to be located
+ * @return the P2ManagedObject of the named object or null if not found
+ */
+ public P2ManagedObject get(String name) {
+ return managedObjects.get(name);
+ }
+
+ /**
+ * returns true if the named object exists within the domain
+ *
+ * @param aName
+ * the name of the object to be located
+ * @return true if the object is found
+ */
+ @Ponder2op("has:")
+ public boolean contains(String aName) {
+ return managedObjects.containsKey(aName);
+ }
+
+ /**
+ * returns true if anObject exists within the domain
+ *
+ * @param anObject
+ * the object to be located
+ * @return true if the object is found
+ */
+ @Ponder2op("hasObject:")
+ public boolean contains(P2Object anObject) {
+ return managedObjects.containsValue(anObject.getManagedObject());
+ }
+
+ /**
+ * Answer the number of elements in the receiver.
+ *
+ * @return the number of elements held
+ */
+ @Ponder2op("size")
+ public int size() {
+ return managedObjects.size();
+ }
+
+ /**
+ * returns an array of the names of the objects in this domain
+ *
+ * @return a String array with the object names
+ */
+ protected String[] names() {
+ int size = managedObjects.size();
+ return managedObjects.keySet().toArray(new String[size]);
+ }
+
+ // Ponder2 operations
+
+ /**
+ * answers an array containing the names of all the domain's entries.
+ *
+ * @return a Ponder2 array with the object names
+ */
+ @Ponder2op("listNames")
+ protected P2Object operation_listNames() {
+ String[] names = names();
+ P2Object[] values = new P2Object[names.length];
+ for (int i = 0; i < names.length; i++) {
+ values[i] = new P2String(names[i]);
+ }
+ return new P2Array(values);
+ }
+
+ /**
+ * answers an array of Managed Object names containing all the entries in
+ * the domain.
+ *
+ * @return an array containing all the object in this domain
+ */
+ @Ponder2op("listObjects")
+ protected P2Object operation_listObjects() {
+ Collection<P2ManagedObject> mos = managedObjects.values();
+ P2Object[] values = new P2Object[mos.size()];
+ int i = 0;
+ for (Iterator<P2ManagedObject> iter = mos.iterator(); iter.hasNext();) {
+ P2ManagedObject mo = iter.next();
+ values[i++] = mo.getP2Object();
+ }
+ return new P2Array(values);
+ }
+
+ /**
+ * Returns a hash containing all the entries in the domain as name->object
+ * pairs
+ *
+ * @return a hash containing all the object in this domain as name,object
+ * pairs
+ */
+ @Ponder2op("asHash")
+ protected P2Hash operation_asHash() {
+ Map<String, P2Object> hash = new HashMap<String, P2Object>();
+ for (Map.Entry<String, P2ManagedObject> entry : managedObjects
+ .entrySet()) {
+ hash.put(entry.getKey(), entry.getValue().getP2Object());
+ }
+ return new P2Hash(hash);
+ }
+
+ /**
+ * answers the P2Object of the Managed Object at aName. Answers NIL if the
+ * object does not exist.
+ *
+ * @param aName
+ * the name of the object to be returned
+ * @return the object located by aName
+ */
+ @Ponder2op("at:")
+ protected P2Object operation_at(String aName) {
+ P2ManagedObject mo = get(aName);
+ return mo != null ? mo.getP2Object() : P2Object.create();
+ }
+
+ /**
+ * Answer the P2Object associated with aName. If not found evaluate aBlock
+ * (with no arguments) and return its result
+ *
+ * @param aName
+ * the name of the object to be returned
+ * @param aBlock
+ * a block to be executed if aName is not found
+ * @return the named object or the result of executing the block
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("at:ifAbsent:")
+ protected P2Object operation_at(P2Object source, String aName,
+ P2Block aBlock) throws Ponder2Exception {
+ return operation_asHash().operation_at_ifAbsent(source, aName, aBlock);
+ }
+
+ /**
+ * add anOid into the domain with aName. Answers anOid.
+ *
+ * @param aName
+ * the name to be used
+ * @param p2Object
+ * the object to be added
+ * @return the object added to the domain
+ */
+ @Ponder2op("at:put:")
+ protected P2Object operation_at_add(String aName, P2Object p2Object) {
+ add(aName, p2Object.getManagedObject());
+ return p2Object;
+ }
+
+ /**
+ * Calls aBlock with name/value pairs for each entry in the domain. Answers
+ * with the the receiver
+ *
+ * @param aBlock
+ * the block to be executed. It must take up to two arguments,
+ * the first being name and the second being value
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("do:")
+ protected void operation_do(P2Object source, P2Block aBlock)
+ throws Ponder2Exception {
+ operation_asHash().operation_do(source, aBlock);
+ }
+
+ /**
+ * Calls aBlock with name/value pairs for each entry in the domain. Answers
+ * with an array with all the answers from the executions
+ *
+ * @param aBlock
+ * the block to be executed
+ * @return an array with the results of the block executions
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("collect:")
+ protected P2Array operation_collect(P2Object source, P2Block aBlock)
+ throws Ponder2Exception {
+ return operation_asHash().operation_collect(source, aBlock);
+ }
+
+ /**
+ * Answers with the object from aPath relative to this domain
+ *
+ * @param aPath
+ * the relative path to be resolved
+ * @return the object found at the path location
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("resolve:")
+ protected P2Object operation_resolve(String aPath) throws Ponder2Exception {
+ return Util.resolve(myP2Object, aPath);
+ }
+
+ /**
+ * Removes aName and its ManagedObject from the domain. Answers the object
+ * removed. TODO Error checks?
+ *
+ * @param aName
+ * the name of the object to be removed
+ * @return the object removed or <code>nil</code>
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("remove:")
+ protected P2Object operation_remove(String aName) throws Ponder2Exception {
+ P2ManagedObject mo = remove(aName);
+ return mo != null ? mo.getP2Object() : P2Object.create();
+ }
+
+ /**
+ * Removes anObject from the receiver. All copies of anObject will be
+ * removed. Answers true if one or more were removed.
+ *
+ * @param anObject
+ * the object to be removed
+ * @return true if an object was removed
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("removeObject:")
+ protected boolean removeObject(P2Object anObject) throws Ponder2Exception {
+ boolean result = false;
+ // The object may be here more than once
+ Set<Entry<String, P2ManagedObject>> entrySet = new HashSet<Entry<String, P2ManagedObject>>(
+ managedObjects.entrySet());
+ for (Entry<String, P2ManagedObject> entry : entrySet) {
+ if (entry.getValue().getP2Object().equals(anObject)) {
+ remove(entry.getKey());
+ result = true;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Removes all objects from the domain. Answers the receiver.
+ *
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("removeAll")
+ protected void removeAll() throws Ponder2Exception {
+ Set<String> names = new HashSet<String>(managedObjects.keySet());
+ for (String name : names)
+ remove(name);
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/EventForwarder.java b/ponder2/src/main/java/eu/novi/ponder2/EventForwarder.java
new file mode 100644
index 0000000..433103c
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/EventForwarder.java
@@ -0,0 +1,177 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Feb 22, 2008
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.objects.P2Object;
+import eu.novi.ponder2.policy.Event;
+import eu.novi.ponder2.policy.EventListener;
+
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.P2ManagedObject;
+
+/**
+ * Forwards event from its attachment point to another part of the proximity
+ * event bus in this or another SMC. May also be used to forward events as
+ * ordinary messages to Managed Objects, useful for communicating with external
+ * event busses.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class EventForwarder implements ManagedObject, EventListener {
+
+ private P2Object myP2Object;
+ private Map<P2Object, String> forwardToSet = new HashMap<P2Object, String>();
+ private Set<P2Object> forwardEvents = null;
+ private boolean active = false;
+
+ public final static String eventCommand = "Ponder2.event:";
+
+ /**
+ * creates an EventForwarder
+ */
+ @Ponder2op("create")
+ EventForwarder(P2Object myP2Object) {
+ this.myP2Object = myP2Object;
+ }
+
+ /**
+ * attaches the EventForwarder to anObject. Any events generated at or below
+ * the managed object will be picked up by this event forwarder.
+ *
+ * @param anObject
+ * the object to attach this forwarder to
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("attachTo:")
+ void attachTo(P2Object source, P2Object anObject) throws Ponder2Exception {
+ anObject.operation(source, "Ponder2.attach:", myP2Object);
+ }
+
+ /**
+ * adds anObject to the list of managed objects to forward events to
+ *
+ * @param anObject
+ * the managed object to receive forwarded events
+ */
+ @Ponder2op("forwardTo:")
+ void forwardTo(P2Object anObject) {
+ forwardToSet.put(anObject, eventCommand);
+ }
+
+ /**
+ * adds anObject to the list of managed objects to forward events to. The
+ * events are forwarded to anObject using the message aMessage which is
+ * expected to take one parameter, the event. Hence aCommand should be a
+ * keyword parameter. e.g. "event:"
+ *
+ * @param anObject
+ * the managed object to receive forwarded events
+ * @param aMessage
+ * the message keyword to be used to pass the event on
+ */
+ @Ponder2op("forwardTo:as:")
+ void forwardTo(P2Object anObject, String aMessage) {
+ forwardToSet.put(anObject, aMessage);
+ }
+
+ /**
+ * removes anObject from the forward-to set
+ *
+ * @param anObject
+ * the managed object to be removed
+ */
+ @Ponder2op("remove:")
+ void remove(P2Object anObject) {
+ forwardToSet.remove(anObject);
+ }
+
+ /**
+ * Specifies that the forwarder is to forward events of anEventType
+ *
+ * @param eventType
+ */
+ @Ponder2op("forward:")
+ void forwardEvent(P2Object eventType) {
+ if (forwardEvents == null)
+ forwardEvents = new HashSet<P2Object>();
+ forwardEvents.add(eventType);
+ }
+
+ /**
+ * sets the forwarder to be active if aBoolean is true else inactive
+ *
+ * @param aBoolean
+ * true if the forwarder is to be activated
+ */
+ @Ponder2op("active:")
+ void setActive(boolean aBoolean) {
+ this.active = aBoolean;
+ }
+
+ /**
+ * answers the active state of the forwarder. true or false
+ *
+ * @return the active state
+ */
+ @Ponder2op("active")
+ boolean getActive() {
+ return active;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.novi.ponder2.policy.EventListener#event(eu.novi.ponder2.Event)
+ */
+ public void event(Event event) throws Ponder2Exception {
+ if (getActive())
+ if (forwardEvents == null
+ || forwardEvents.contains(event.getEventTemplate()))
+ for (Map.Entry<P2Object, String> entry : forwardToSet
+ .entrySet())
+ entry.getKey().operation(myP2Object, entry.getValue(),
+ event);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.novi.ponder2.policy.EventListener#getId()
+ */
+ public P2ManagedObject getId() {
+ return myP2Object.getManagedObject();
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/EventTemplate.java b/ponder2/src/main/java/eu/novi/ponder2/EventTemplate.java
new file mode 100644
index 0000000..c4ec2e3
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/EventTemplate.java
@@ -0,0 +1,254 @@
+/**
+ * Created on Aug 16, 2005
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * $Log: EventTemplate.java,v $
+ * Revision 1.16 2005/12/09 10:34:38 kpt
+ * Policy actions sorted out
+ *
+ * Revision 1.15 2005/11/23 14:47:08 kpt
+ * Removed Iterable from QDParser.
+ *
+ * Revision 1.14 2005/11/15 16:33:25 kpt
+ * Result added to create
+ *
+ * Revision 1.13 2005/11/14 21:02:21 kpt
+ * Made Result much more pervasive
+ *
+ * Revision 1.12 2005/10/28 21:58:00 kpt
+ * Restore almost completed
+ *
+ * Revision 1.11 2005/10/27 16:57:38 kpt
+ * OID separated from P2ManagedObject
+ *
+ * Revision 1.10 2005/10/24 20:53:02 kpt
+ * Dump part of dump and restore working
+ *
+ * Revision 1.9 2005/10/22 08:53:33 kpt
+ * Changed TaggedElement getAtt to getAttribute
+ *
+ * Revision 1.8 2005/10/21 17:15:47 kpt
+ * Renamed XML Element types
+ *
+ * Revision 1.7 2005/10/21 17:12:55 kpt
+ * Tidied up and made sure demo still worked
+ *
+ * Revision 1.6 2005/10/21 14:31:39 kpt
+ * Changed to faster, meaner, external QDParser with LGPL licence.
+ *
+ * Revision 1.5 2005/10/06 10:59:18 kpt
+ * Complete reorganisation of return values using Result.
+ Commands handed to MOs one at a time.
+ *
+ * Revision 1.4 2005/10/01 20:50:53 kpt
+ * Changed result type to new Result class
+ *
+ * Revision 1.3 2005/09/21 13:46:40 kpt
+ * Can now create and send events using XML and the event templates
+ *
+ * Revision 1.2 2005/09/14 08:45:38 kpt
+ * Down to import and use
+ *
+ * Revision 1.1 2005/09/12 10:47:07 kpt
+ * Initial Checkin
+ *
+ */
+
+package eu.novi.ponder2;
+
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.exception.Ponder2ArgumentException;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2OperationException;
+import eu.novi.ponder2.objects.P2Array;
+import eu.novi.ponder2.objects.P2Hash;
+import eu.novi.ponder2.objects.P2Object;
+import eu.novi.ponder2.policy.Event;
+import eu.novi.ponder2.ArgumentList;
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.SelfManagedCell;
+
+/**
+ * Managed object to act as a template for notifications (events). Each instance
+ * of the template contains a set of named arguments. These argument names can
+ * be retrieved for checking against Policies that expect to be activated by the
+ * events. When an event is created using this template the named arguments are
+ * packed into a map and sent around the system inside the event.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class EventTemplate implements ManagedObject {
+
+ protected ArgumentList argList;
+
+ public static String defaultDomain = SelfManagedCell.EventDomain;
+
+ private P2Object myP2Object;
+
+ /**
+ * creates an empty template. Further messages must be sent to give the
+ * named arguments.
+ *
+ * @param myP2Object
+ */
+ @Ponder2op("create")
+ protected EventTemplate(P2Object myP2Object) {
+ argList = new ArgumentList();
+ this.myP2Object = myP2Object;
+ }
+
+ /**
+ * creates an event template with anArray containing the argument names.
+ *
+ * @param myP2Object
+ * @param anArray
+ * @throws Ponder2ArgumentException
+ * @throws Ponder2OperationException
+ */
+ @Ponder2op("create:")
+ protected EventTemplate(P2Object myP2Object, P2Array anArray)
+ throws Ponder2ArgumentException, Ponder2OperationException {
+ this(myP2Object);
+ P2Object[] argNames = anArray.asArray();
+ for (int i = 0; i < argNames.length; i++) {
+ argList.add(argNames[i].asString());
+ }
+ }
+
+ /**
+ * INTERNAL OPERATION. Takes a list of objects and packages them into a hash
+ * indexed with the argument names. Answers the new hash.
+ *
+ * @param args
+ * the arguments to be taken as values
+ * @return a hash containing named values from args
+ * @throws Ponder2ArgumentException
+ */
+ public P2Hash packageArgs(P2Object... args) throws Ponder2ArgumentException {
+ P2Hash value = new P2Hash();
+ if (argList.size() > args.length)
+ throw new Ponder2ArgumentException(
+ "too few arguments for event, got " + args.length
+ + " wanted " + argList.size());
+ int count = 0;
+ for (ArgumentList.Entry entry : argList) {
+ value.operation_at_put(entry.name, args[count]);
+ count++;
+ }
+ return value;
+ }
+
+ @Ponder2op("packageArgs:")
+ public P2Hash packageArgs(P2Array anArray) throws Ponder2ArgumentException {
+ return packageArgs(anArray.asArray());
+ }
+
+ public P2Hash packageHash(P2Hash args) throws Ponder2ArgumentException {
+ P2Hash value = new P2Hash();
+ for (ArgumentList.Entry entry : argList) {
+ P2Object arg = args.get(entry.name);
+ if (arg == null)
+ throw new Ponder2ArgumentException(
+ "EventTemplate: missing argument " + entry.name);
+ value.operation_at_put(entry.name, arg);
+ }
+ return value;
+ }
+
+ /**
+ * adds an argument field to this event definition. Answers the receiver
+ *
+ * @param arg
+ * the name of the argument to add
+ * @throws Ponder2ArgumentException
+ */
+ @Ponder2op("arg:")
+ protected void operation_arg(String arg) throws Ponder2ArgumentException {
+ argList.add(arg);
+ }
+
+ /**
+ * adds anArray of argument fields to this event template. Answers the
+ * receiver.
+ *
+ * @param anArray
+ * the names of the arguments to become attributes of the event
+ * @throws Ponder2ArgumentException
+ * @throws Ponder2OperationException
+ */
+ @Ponder2op("args:")
+ protected void operation_args(P2Object anArray)
+ throws Ponder2ArgumentException, Ponder2OperationException {
+ P2Object[] strings = anArray.asArray();
+ for (int i = 0; i < strings.length; i++) {
+ argList.add(strings[i].asString());
+ }
+ }
+
+ /**
+ * creates and sends an event of this type with no values. Answers the
+ * receiver
+ *
+ * @param source
+ * the ID of the object initiating the event
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("create")
+ protected void operation_create(P2Object source) throws Ponder2Exception {
+ Event event = new Event(source, myP2Object, new P2Array());
+ source.getManagedObject().sendEvent(event);
+ }
+
+ /**
+ * creates and sends an event of this type with values from anArray. Answers
+ * the receiver
+ *
+ * @param source
+ * the ID of the object initiating the event
+ * @param anArray
+ * the values to be filled in as attributes of the event
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("create:")
+ protected void operation_create(P2Object source, P2Array anArray)
+ throws Ponder2Exception {
+ Event event = new Event(source, myP2Object, anArray);
+ source.getManagedObject().sendEvent(event);
+ }
+
+ /**
+ * creates and sends an event of this type with values from aHash. Answers
+ * the receiver
+ *
+ * @param source
+ * the ID of the object initiating the event
+ * @param aHash
+ * the named values to be filled in as attributes of the event
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("fromHash:")
+ protected void operation_create(P2Object source, P2Hash aHash)
+ throws Ponder2Exception {
+ Event event = new Event(source, myP2Object, packageHash(aHash));
+ source.getManagedObject().sendEvent(event);
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/ExternalManagedObject.java b/ponder2/src/main/java/eu/novi/ponder2/ExternalManagedObject.java
new file mode 100644
index 0000000..c3a9e57
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/ExternalManagedObject.java
@@ -0,0 +1,316 @@
+/**
+ * Created on Sep 20, 2005
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * $Log: ExternalManagedObject.java,v $
+ * Revision 1.18 2005/11/19 21:11:33 kpt
+ * Shows remote OID for e.g. ls -l
+ *
+ * Revision 1.17 2005/11/14 21:02:21 kpt
+ * Made Result much more pervasive
+ *
+ * Revision 1.16 2005/11/03 04:23:46 kpt
+ * More restore and tidying done
+ *
+ * Revision 1.15 2005/10/28 21:58:00 kpt
+ * Restore almost completed
+ *
+ * Revision 1.14 2005/10/27 16:57:38 kpt
+ * OID separated from P2ManagedObject
+ *
+ * Revision 1.13 2005/10/24 20:53:02 kpt
+ * Dump part of dump and restore working
+ *
+ * Revision 1.12 2005/10/22 08:53:33 kpt
+ * Changed TaggedElement getAtt to getAttribute
+ *
+ * Revision 1.11 2005/10/21 17:15:48 kpt
+ * Renamed XML Element types
+ *
+ * Revision 1.10 2005/10/21 14:31:40 kpt
+ * Changed to faster, meaner, external QDParser with LGPL licence.
+ *
+ * Revision 1.9 2005/10/11 10:11:40 kpt
+ * First full version of the demo
+ *
+ * Revision 1.8 2005/10/10 04:28:59 kpt
+ * Improved external use. Assume local unless remote specified
+ *
+ * Revision 1.7 2005/10/09 22:03:04 kpt
+ * First complete version of demo with a few fixes.
+ Local evaluation added on demand before shipping xml for export.
+ *
+ * Revision 1.6 2005/10/06 10:59:17 kpt
+ * Complete reorganisation of return values using Result.
+ Commands handed to MOs one at a time.
+ *
+ * Revision 1.5 2005/10/01 20:50:52 kpt
+ * Changed result type to new Result class
+ *
+ * Revision 1.4 2005/09/30 11:04:21 kpt
+ * Tidied up a little
+ *
+ * Revision 1.3 2005/09/21 15:54:56 kpt
+ * USE now works through external domains
+ *
+ * Revision 1.2 2005/09/21 13:46:40 kpt
+ * Can now create and send events using XML and the event templates
+ *
+ * Revision 1.1 2005/09/21 08:21:03 kpt
+ * First cut at external objects
+ *
+ */
+
+package eu.novi.ponder2;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.comms.Protocol;
+import eu.novi.ponder2.comms.Transmitter;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2RemoteException;
+import eu.novi.ponder2.objects.P2Object;
+
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.OID;
+
+/**
+ * A managed object that represents a remote managed object. It acts as a proxy,
+ * rerouting any requests that it receives to the remote object. An external
+ * managed object is not imported and used in the normal way, it is
+ * automatically instantiated and filled in by the <use> clause when it
+ * recognises a remote address.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class ExternalManagedObject implements ManagedObject {
+
+ /**
+ * Map of protocol names to that actual protocol code to perform I/O using
+ * that protocol
+ */
+ private static Map<String, Transmitter> protocolTable = new HashMap<String, Transmitter>();
+ /**
+ * Cache of locations to external protocol methods
+ */
+ private static Map<URI, Transmitter> locationTable = new HashMap<URI, Transmitter>();
+
+ /**
+ * Registers an external protocol so that it can be used as a transport
+ * mechanism. This is called from the install method of the protocol being
+ * installed
+ *
+ * @param name
+ * the name of the protocol
+ * @param protocol
+ * instance of the protocol interface allowing messages to be
+ * sent
+ * @param address
+ * the address of a remote SMC
+ */
+ public static void registerProtocol(String name, Transmitter protocol,
+ URI address) {
+ protocolTable.put(name, protocol);
+ if (address != null)
+ OID.addAddress(address);
+ }
+
+ /**
+ * sees if a protocol has already been loaded
+ *
+ * @param name
+ * the name of the protocol to be checked
+ * @return true if the protocol has been loaded
+ */
+ public static boolean hasProtocol(String name) {
+ return protocolTable.containsKey(name);
+ }
+
+ /**
+ * gets the protocol code for the given URI. if the protocol is not already
+ * loaded then it is located and loaded on the fly.
+ *
+ * @param location
+ * the remote address as a URI
+ * @return the comms class for the given protocol
+ * @throws Ponder2RemoteException
+ */
+ public static Transmitter getRemote(URI location)
+ throws Ponder2RemoteException {
+ if (location == null)
+ throw new Ponder2RemoteException(
+ "No known remote address for object");
+ String scheme = location.getScheme().toLowerCase();
+ // We had better make sure that we have the right protocol drivers
+ // loaded
+ if (!hasProtocol(scheme)) {
+ loadProtocol(scheme, null, location);
+ }
+ Transmitter protocol = protocolTable.get(scheme);
+ Transmitter remote = locationTable.get(location);
+ if (remote == null) {
+ // We have to find the remote for this location
+ remote = protocol.connect(location);
+ locationTable.put(location, remote);
+ }
+ return remote;
+ }
+
+ /**
+ * Loads a new communications protocol for interworking with other Ponder2
+ * SMCs
+ *
+ * @param protocol
+ * protocol name
+ * @param address
+ * address for others to reach us
+ * @param remote
+ * remote address that kicked off this request
+ * @throws Ponder2RemoteException
+ */
+ @SuppressWarnings("unchecked")
+ public static void loadProtocol(String protocol, String address, URI remote)
+ throws Ponder2RemoteException {
+ URI uri = null;
+ try {
+ if (address != null)
+ uri = new URI(address);
+ } catch (URISyntaxException e) {
+ throw new Ponder2RemoteException(e.getMessage());
+ }
+ if (protocol == null && uri != null)
+ protocol = uri.getScheme();
+ if (protocol == null)
+ throw new Ponder2RemoteException(
+ "Load protocol: protocol cannot be determined from "
+ + address);
+
+ // Make the protocol starts with uppercase, rest lower
+ // and construct the Class name
+ protocol = protocol.toLowerCase();
+ String start = protocol.substring(0, 1);
+ protocol = start.toUpperCase() + protocol.substring(1) + "Protocol";
+
+ // Now load and instantiate the class
+ Class<Protocol> cl = null;
+ try {
+ cl = (Class<Protocol>) Class.forName(protocol);
+ } catch (ClassNotFoundException e) {
+ // Ignore and try again
+ try {
+ cl = (Class<Protocol>) Class.forName("eu.novi.ponder2.comms."
+ + protocol);
+ } catch (ClassNotFoundException e1) {
+ throw new Ponder2RemoteException(
+ "Load protocol: protocol not found: " + protocol);
+ }
+ }
+ try {
+ // cl must have a value by this point
+ Protocol option = cl.newInstance();
+ option.install(uri, remote);
+ } catch (Exception e) {
+ throw new Ponder2RemoteException("Load protocol failure for: "
+ + protocol + " - " + e.getMessage());
+ }
+ }
+
+ /**
+ * The real external OID of the object
+ */
+ OID externalOID;
+
+ /**
+ * Valid addresses for the remote object
+ */
+ List<URI> addresses;
+
+ /**
+ * Preferred protocol
+ */
+ String protocol;
+
+ /**
+ * Preferred address
+ */
+ URI address;
+ private P2Object myP2Object;
+
+ /**
+ * Creates a new external Managed Object that acts as a proxy for the real
+ * remote object. The remote protocol is checked to see that it exists and
+ * the driver is kept handy for speedy communications. NB This message is
+ * used internally by Ponder2.
+ *
+ */
+ @Ponder2op("create")
+ public ExternalManagedObject(P2Object myP2Object) {
+ this.myP2Object = myP2Object;
+ }
+
+ public void setExternalOID(OID externalOID) {
+ this.externalOID = externalOID;
+ // TODO Is this ok? we still have the old uid in the global OID table.
+ myP2Object.getOID().setUid(externalOID.getUid());
+ myP2Object.getOID().setDomain(externalOID.isDomain());
+ // Get the valid addresses for the object
+ addresses = new Vector<URI>();
+ for (URI uri : externalOID.getRemoteAddresses()) {
+ addresses.add(uri);
+ String scheme = uri.getScheme();
+ if (protocolTable.containsKey(scheme)) {
+ protocol = scheme;
+ address = uri;
+ }
+ }
+
+ }
+
+ /**
+ * All operations are sent to the external Managed Object. Answers with the
+ * answer from the external Managed Object.
+ *
+ * @param op
+ * the operation to be performed
+ * @param args
+ * an array of the arguments for the operation
+ * @return the result of the operation
+ * @throws Ponder2Exception
+ */
+ @Ponder2op(Ponder2op.WILDCARD)
+ protected P2Object obj_operation(P2Object source, String op,
+ P2Object... args) throws Ponder2Exception {
+ // We have to send something to the remote object
+ Transmitter remote = getRemote(address);
+ P2Object value = remote.execute(address, externalOID, source, op, args);
+ // Patch up the result structure
+ // System.out.println("Remote execute returns: " + value);
+ return value;
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/FactoryObject.java b/ponder2/src/main/java/eu/novi/ponder2/FactoryObject.java
new file mode 100644
index 0000000..e9ae0da
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/FactoryObject.java
@@ -0,0 +1,138 @@
+/**
+ * Created on Sep 6, 2005
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * $Log: FactoryObject.java,v $
+ * Revision 1.14 2005/11/18 18:16:57 kpt
+ * Added better info for ls -l
+ *
+ * Revision 1.13 2005/11/15 16:33:25 kpt
+ * Result added to create
+ *
+ * Revision 1.12 2005/11/14 13:59:00 kpt
+ * Improved results, fixed TickManager
+ *
+ * Revision 1.11 2005/11/03 04:23:46 kpt
+ * More restore and tidying done
+ *
+ * Revision 1.10 2005/10/27 16:57:38 kpt
+ * OID separated from P2ManagedObject
+ *
+ * Revision 1.9 2005/10/27 09:25:15 kpt
+ * Dump almost completed. Everything still works!
+ *
+ * Revision 1.8 2005/10/24 20:53:02 kpt
+ * Dump part of dump and restore working
+ *
+ * Revision 1.7 2005/10/22 16:49:46 kpt
+ * Returns results through Reply. Shell does rm properly
+ *
+ * Revision 1.6 2005/10/21 17:15:48 kpt
+ * Renamed XML Element types
+ *
+ * Revision 1.5 2005/10/21 14:31:40 kpt
+ * Changed to faster, meaner, external QDParser with LGPL licence.
+ *
+ * Revision 1.4 2005/10/06 10:59:17 kpt
+ * Complete reorganisation of return values using Result.
+ Commands handed to MOs one at a time.
+ *
+ * Revision 1.3 2005/10/01 20:50:52 kpt
+ * Changed result type to new Result class
+ *
+ * Revision 1.2 2005/09/14 08:45:38 kpt
+ * Down to import and use
+ *
+ * Revision 1.1 2005/09/12 10:47:08 kpt
+ * Initial Checkin
+ *
+ */
+
+package eu.novi.ponder2;
+
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2OperationException;
+import eu.novi.ponder2.objects.P2Object;
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.P2ObjectAdaptor;
+import eu.novi.ponder2.SelfManagedCell;
+
+/**
+ * This managed object class is used to hold the factory classes for other
+ * managed objects and to instantiate new managed objects. This is the only way
+ * managed object types get into the system and the only way instances of those
+ * types are created (unless they are being restored).
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class FactoryObject implements ManagedObject {
+
+ /**
+ * the factory to create the specialised managed object
+ */
+ private Class<P2ObjectAdaptor> adaptorClass;
+
+ /**
+ * creates a managed object that acts as a factory for creating instances of
+ * the underlying managed object
+ *
+ * @param adaptorClass
+ * the P2Adaptor class that will be creating the correct object
+ * type later
+ */
+ @SuppressWarnings("unchecked")
+ @Ponder2op("create:")
+ public FactoryObject(Class<?> adaptorClass) {
+ super();
+ this.adaptorClass = (Class<P2ObjectAdaptor>) adaptorClass;
+ }
+
+ /**
+ * all messages are sent to the Managed Object being created. See the
+ * object's factory documentation for commands accepted.
+ *
+ * @param op
+ * the operation to be performed
+ * @param args
+ * an array of arguments for the operation
+ * @return the result of the operation
+ * @throws Ponder2Exception
+ */
+ @Ponder2op(Ponder2op.WILDCARD)
+ protected P2Object operation_create(P2Object source, String op,
+ P2Object... args) throws Ponder2Exception {
+ try {
+ P2ObjectAdaptor adaptor = adaptorClass.newInstance();
+ P2Object value = adaptor.create(source, op, args);
+ if (SelfManagedCell.SystemTrace)
+ System.out.println("Factory create returns " + value.getOID());
+ return value;
+ } catch (InstantiationException e) {
+ throw new Ponder2OperationException(
+ "Factory create: InstantiationException " + e.getMessage());
+ } catch (IllegalAccessException e) {
+ throw new Ponder2OperationException(
+ "Factory create: IllegalAccessException " + e.getMessage());
+ }
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/HashInspector.java b/ponder2/src/main/java/eu/novi/ponder2/HashInspector.java
new file mode 100644
index 0000000..2fe3a3c
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/HashInspector.java
@@ -0,0 +1,162 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Oct 16, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.swing.JFrame;
+import javax.swing.SwingUtilities;
+
+
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.exception.Ponder2ArgumentException;
+import eu.novi.ponder2.exception.Ponder2OperationException;
+import eu.novi.ponder2.inspector.InspectorWindow;
+import eu.novi.ponder2.objects.P2Hash;
+import eu.novi.ponder2.objects.P2Object;
+
+import eu.novi.ponder2.ManagedObject;
+
+/**
+ * Creates a window making available for editing the values of a Hash.
+ * Understands, strings, numbers and booleans. If objects are in the hash, they
+ * will be displayed but will not be editable.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class HashInspector implements ManagedObject {
+
+ private InspectorWindow inspector;
+
+ private Map<String, P2Hash> profile = new HashMap<String, P2Hash>();
+
+ private P2Hash currentHash = null;
+
+ private String currentName;
+
+ /**
+ * Creates a HashInspector window with the default title of "Hash Inspector"
+ *
+ */
+ @Ponder2op("create")
+ public HashInspector() {
+ initialise("Hash Inspector");
+ }
+
+ /**
+ * Creates a HashInspector window with the title aString
+ *
+ * @param aString
+ * the title of the window
+ */
+ @Ponder2op("create:")
+ public HashInspector(String aString) {
+ initialise(aString);
+ }
+
+ private void initialise(final String title) {
+ SwingUtilities.invokeLater(new Runnable() {
+
+ public void run() {
+ inspector = new InspectorWindow(title);
+ inspector.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ inspector.setVisible(true);
+ inspector.addPropertyChangeListener(
+ InspectorWindow.ProfileChange, profileChange);
+ inspector.addPropertyChangeListener(
+ InspectorWindow.AttributeChange, attributeChange);
+ inspector.addPropertyChangeListener(
+ InspectorWindow.NewValueChange, newValue);
+ }
+ });
+ }
+
+ /**
+ * manages aHash using the identifier aName for its display
+ *
+ * @param aHash
+ * the hash to be displayed
+ * @param aName
+ * the name to be given in the window for the hash
+ * @throws Ponder2ArgumentException
+ * @throws Ponder2OperationException
+ */
+ @Ponder2op("manage:as:")
+ public void manage(P2Object aHash, final String aName)
+ throws Ponder2ArgumentException, Ponder2OperationException {
+ profile.put(aName, aHash.asHash());
+ SwingUtilities.invokeLater(new Runnable() {
+
+ public void run() {
+ inspector.manage(aName);
+ }
+ });
+ }
+
+ private void showValues(String name) {
+ currentName = name;
+ currentHash = profile.get(name);
+ Map<String, P2Object> list = new HashMap<String, P2Object>();
+ for (String key : currentHash.keySet()) {
+ list.put(key, currentHash.get(key));
+ }
+ inspector.setList(list);
+ }
+
+ private PropertyChangeListener profileChange = new PropertyChangeListener() {
+
+ public void propertyChange(PropertyChangeEvent evt) {
+ String name = (String) evt.getNewValue();
+ showValues(name);
+ }
+
+ };
+
+ private PropertyChangeListener newValue = new PropertyChangeListener() {
+
+ public void propertyChange(PropertyChangeEvent evt) {
+ showValues(currentName);
+ }
+
+ };
+
+ private PropertyChangeListener attributeChange = new PropertyChangeListener() {
+
+ public void propertyChange(PropertyChangeEvent evt) {
+ System.out.println("Attribute " + evt.getOldValue()
+ + " changed to " + evt.getNewValue());
+ if (currentHash != null) {
+ P2Object value = (P2Object) evt.getNewValue();
+ currentHash.put((String) evt.getOldValue(), value);
+ }
+ }
+ };
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/ManagedObject.java b/ponder2/src/main/java/eu/novi/ponder2/ManagedObject.java
new file mode 100644
index 0000000..13069f6
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/ManagedObject.java
@@ -0,0 +1,37 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 8, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2;
+
+/**
+ * An empty interface to signal that a class should have an Ponder2 managed
+ * object adaptor created for it
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public interface ManagedObject {
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/OID.java b/ponder2/src/main/java/eu/novi/ponder2/OID.java
new file mode 100644
index 0000000..27b8aa0
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/OID.java
@@ -0,0 +1,483 @@
+/**
+ * Created on Jul 4, 2005
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * $Log: OID.java,v $
+ * Revision 1.12 2005/10/28 21:58:00 kpt
+ * Restore almost completed
+ *
+ * Revision 1.11 2005/10/27 16:57:38 kpt
+ * OID separated from P2ManagedObject
+ *
+ * Revision 1.10 2005/10/27 09:25:15 kpt
+ * Dump almost completed. Everything still works!
+ *
+ * Revision 1.9 2005/10/24 20:53:02 kpt
+ * Dump part of dump and restore working
+ *
+ * Revision 1.8 2005/10/22 08:53:33 kpt
+ * Changed TaggedElement getAtt to getAttribute
+ *
+ * Revision 1.7 2005/10/21 17:15:48 kpt
+ * Renamed XML Element types
+ *
+ * Revision 1.6 2005/10/21 17:12:55 kpt
+ * Tidied up and made sure demo still worked
+ *
+ * Revision 1.5 2005/10/21 14:31:40 kpt
+ * Changed to faster, meaner, external QDParser with LGPL licence.
+ *
+ * Revision 1.4 2005/10/06 10:59:17 kpt
+ * Complete reorganisation of return values using Result.
+ Commands handed to MOs one at a time.
+ *
+ * Revision 1.3 2005/09/21 15:54:56 kpt
+ * USE now works through external domains
+ *
+ * Revision 1.2 2005/09/21 08:21:03 kpt
+ * First cut at external objects
+ *
+ * Revision 1.1 2005/09/12 10:47:08 kpt
+ * Initial Checkin
+ *
+ */
+
+package eu.novi.ponder2;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.ObjectStreamException;
+import java.io.WriteAbortedException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+
+import eu.novi.ponder2.Domain;
+import eu.novi.ponder2.DomainP2Adaptor;
+import eu.novi.ponder2.ExternalManagedObject;
+import eu.novi.ponder2.ExternalManagedObjectP2Adaptor;
+import eu.novi.ponder2.OID;
+import eu.novi.ponder2.P2ManagedObject;
+import eu.novi.ponder2.SelfManagedCell;
+import eu.novi.ponder2.Util;
+
+import com.twicom.qdparser.Element;
+import com.twicom.qdparser.TaggedElement;
+
+import eu.novi.ponder2.comms.P2Serializable;
+import eu.novi.ponder2.exception.Ponder2ArgumentException;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2OperationException;
+import eu.novi.ponder2.exception.Ponder2RemoteException;
+import eu.novi.ponder2.objects.P2Object;
+
+/**
+ * This is the fundamental object identifier for all the managed objects in the
+ * system. Every managed object will have a single, unique OID associated with
+ * it on a one to one, reversible mapping. The OID also contains all the known
+ * ways of remotely contacting the SMC where the managed object resides.
+ *
+ * @author Kevin Twidle
+ * @version $Id: OID.java,v 1.12 2005/10/28 21:58:00 kpt Exp $
+ */
+public class OID implements P2Serializable, Externalizable {
+
+ /**
+ * Table of all OIDs at this location (SMC)
+ */
+ private static Map<String, OID> oidList = Collections
+ .synchronizedMap(new HashMap<String, OID>());
+
+ /**
+ * Set of our this SMC's addresses for different protocols
+ */
+ private static Set<URI> myAddresses = Collections
+ .synchronizedSet(new HashSet<URI>());
+
+ private static Domain remoteDomain = null;
+
+ private static int externalNumber = 0;
+
+ private static Random random = new Random(System.currentTimeMillis());
+
+ /**
+ * adds a new address to the set of addresses for this SMC
+ *
+ * @param address
+ * the address to be added
+ */
+ public static void addAddress(URI address) {
+ if (address != null)
+ myAddresses.add(address);
+ else
+ System.err.println("OID: Warning null address added - ignoring");
+ }
+
+ public static Set<URI> getAddresses() {
+ return myAddresses;
+ }
+
+ /**
+ * generates an OID from an XML structure. If the OID is already known to
+ * the SMC then the original OID is returned, otherwise a new OID is created
+ * and added to the SMC's set of OIDs.
+ *
+ * @param xml
+ * the XML structure containing the OID
+ * @return the OID generated from the XML structure
+ * @throws Ponder2ArgumentException
+ * @throws Ponder2OperationException
+ */
+ public static OID fromXML(TaggedElement xml)
+ throws Ponder2OperationException, Ponder2ArgumentException {
+ String uid = xml.getAttribute("uid");
+ OID oid = oidList.get(uid);
+ if (oid == null)
+ try {
+ // Get the OID info that we need
+ boolean isDomain = xml.getAttribute("isDomain", "false")
+ .equals("true");
+ Set<URI> remoteAddresses = new HashSet<URI>();
+ for (int i = 0; i < xml.elements(); i++) {
+ Element el = xml.getChild(i);
+ if (el instanceof TaggedElement) {
+ TaggedElement child = (TaggedElement) el;
+ if (child.getName().equals("address")) {
+ try {
+ URI uri = new URI(child.getAttribute("uri"));
+ remoteAddresses.add(uri);
+ } catch (URISyntaxException e) {
+ throw new Ponder2OperationException(
+ "OID: failed to parse URI ("
+ + child.getAttribute("uri")
+ + ")correctly" + e.getMessage());
+ }
+ }
+ }
+ }
+ OID externalOID = new OID(uid, isDomain, remoteAddresses);
+ oid = makeNewExternalObject(externalOID);
+ } catch (Exception e) {
+ throw new Ponder2OperationException("OID: failed to read OID"
+ + e.getMessage());
+ }
+ return oid;
+ }
+
+ //
+ // End of static declarations
+ //
+ /**
+ * the immutable unique ID for this OID
+ */
+ private String uid;
+
+ /**
+ * whether this OID is associated with a domain managed object
+ */
+ private boolean isDomain;
+
+ /**
+ * remote addresses held for external OIDs only. Used exclusively by
+ * ExternalManagedObject
+ */
+ private Set<URI> remoteAddresses = null;
+
+ /**
+ * the managed object associated with this OID
+ */
+ private P2ManagedObject managedObject;
+
+ /**
+ * Dummy required for serialisation
+ */
+ public OID() {
+ }
+
+ private OID(String uid, boolean isDomain, Set<URI> remoteAddresses) {
+ this.uid = uid;
+ this.isDomain = isDomain;
+ this.remoteAddresses = remoteAddresses;
+ }
+
+ /**
+ * creates a new OID, initialises its fields and adds it to the SMC's list
+ * of OIDs
+ *
+ */
+ public OID(P2ManagedObject managedObject) {
+ synchronized (random) {
+ uid = "" + random.nextLong();
+ }
+ // address = CommsManager.getAddress();
+ this.managedObject = managedObject;
+ isDomain = false;
+ oidList.put(uid, this);
+ }
+
+ /**
+ * checks whether this OID is associated with a domain managed object
+ *
+ * @return true if this OID is associated with a domain managed object
+ */
+ public boolean isDomain() {
+ return isDomain;
+ }
+
+ /**
+ * sets whether this OID is associated with a domain managed object
+ *
+ * @param isDomain
+ * true if this OID is to be associated with a domain managed
+ * object
+ */
+ protected void setDomain(boolean isDomain) {
+ this.isDomain = isDomain;
+ }
+
+ /**
+ * returns the actual managed object associated with this OID
+ *
+ * @return the OID's managed object
+ */
+ public P2ManagedObject getManagedObject() {
+ return managedObject;
+ }
+
+ /**
+ * returns the actual managed object associated with this OID
+ *
+ * @return the OID's managed object
+ */
+ public P2Object getP2Object() {
+ return managedObject.getP2Object();
+ }
+
+ protected Set<URI> getRemoteAddresses() {
+ return remoteAddresses;
+ }
+
+ protected Set<URI> getAddressSet() {
+ if (remoteAddresses != null)
+ return remoteAddresses;
+ return myAddresses;
+ }
+
+ /**
+ * returns the OID as an XML structure.
+ *
+ * @return a description of the OID as an XML structure
+ */
+ public TaggedElement toXML() {
+ TaggedElement oid = new TaggedElement("oid");
+ oid.setAttribute("uid", uid);
+ oid.setAttribute("isdomain", Boolean.toString(isDomain));
+ Set<URI> addresses = getAddressSet();
+ if (!addresses.isEmpty()) {
+ for (URI entry : addresses) {
+ TaggedElement addr = new TaggedElement("address");
+ addr.setAttribute("uri", entry.toString());
+ oid.add(addr);
+ }
+ }
+ return oid;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return toXML().toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.io.Externalizable#readExternal(java.io.ObjectInput)
+ */
+ @SuppressWarnings("unchecked")
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ uid = (String) in.readObject();
+ setDomain(in.readBoolean());
+ remoteAddresses = (Set<URI>) in.readObject();
+ }
+
+ /**
+ * Called by the serialization routines after readExternal as been called.
+ *
+ * @return the newly read in OID, actually probably an old one.
+ * @throws ObjectStreamException
+ */
+ protected Object readResolve() throws ObjectStreamException {
+ // Does this OID already exist?
+ OID oid = oidList.get(uid);
+ if (oid == null)
+ try {
+ oid = makeNewExternalObject(this);
+ } catch (Exception e) {
+ throw new WriteAbortedException("OID: failed to read OID", e);
+ }
+ return oid;
+ }
+
+ private static OID makeNewExternalObject(OID externalOID)
+ throws Ponder2RemoteException {
+ try {
+ // We need to create an External Managed Object for the OID
+ // First check that it is not really our object i.e. one we could
+ // not find e.g. an old object from a previous incarnation
+ for (URI uri : externalOID.getRemoteAddresses()) {
+ if (myAddresses.contains(uri))
+ throw new Ponder2RemoteException(
+ "this OID does not exist here: "
+ + externalOID.getUid());
+ }
+ ExternalManagedObjectP2Adaptor adaptor = new ExternalManagedObjectP2Adaptor(
+ SelfManagedCell.RootDomain, "create");
+ ((ExternalManagedObject) adaptor.getObj())
+ .setExternalOID(externalOID);
+ OID oid = adaptor.getOID();
+ oidList.put(externalOID.uid, oid);
+ // Make sure we have a domain to put it into
+ if (remoteDomain == null) {
+ try {
+ OID remote = Util.resolve("/", "/remote").getOID();
+ if (!remote.isDomain())
+ throw new Ponder2RemoteException(
+ "OID: Fatal error /remote is not a domain");
+ remoteDomain = (Domain) ((DomainP2Adaptor) remote
+ .getP2Object()).getObj();
+ } catch (Ponder2Exception e) {
+ // root/remote does not exist
+ DomainP2Adaptor domAdaptor = new DomainP2Adaptor(
+ SelfManagedCell.RootDomain, "create");
+ remoteDomain = (Domain) domAdaptor.getObj();
+ SelfManagedCell.RootDomain.operation(
+ SelfManagedCell.RootDomain, "at:put:",
+ P2Object.create("remote"), domAdaptor);
+ }
+ }
+ externalNumber++;
+ while (remoteDomain.get("external" + externalNumber) != null) {
+ externalNumber++;
+ }
+ remoteDomain.add("external" + externalNumber,
+ oid.getManagedObject());
+ return oid;
+
+ } catch (Ponder2Exception e) {
+ throw new Ponder2RemoteException("OID: failed to read OID"
+ + e.getMessage());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
+ */
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(uid);
+ out.writeBoolean(isDomain());
+ out.writeObject(getAddresses());
+ }
+
+ /**
+ * @return the uid
+ */
+ public String getUid() {
+ return uid;
+ }
+
+ /**
+ * @param uid
+ * the uid to set
+ */
+ protected void setUid(String uid) {
+ this.uid = uid;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.novi.ponder2.comms.P2Serializable#writeXml()
+ */
+ public TaggedElement writeXml(Set<P2Object> written)
+ throws Ponder2OperationException {
+ TaggedElement xml = new TaggedElement("P2Object");
+ xml.setAttribute("class", this.getClass().getCanonicalName());
+ xml.setAttribute("uid", getUid());
+ xml.setAttribute("isdomain", isDomain() ? "true" : "false");
+ Set<URI> addresses = getAddressSet();
+ for (URI uri : addresses) {
+ TaggedElement address = new TaggedElement("address");
+ address.setAttribute("uri", uri.toString());
+ xml.add(address);
+ }
+ return xml;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.novi.ponder2.comms.P2Serializable#readXml(com.twicom.qdparser.
+ * TaggedElement)
+ */
+ public P2Object readXml(TaggedElement xml, Map<Integer, P2Serializable> read)
+ throws Ponder2OperationException, Ponder2ArgumentException {
+ uid = xml.getAttribute("uid");
+ String isdomain = xml.getAttribute("isdomain");
+ setDomain(isdomain.equals("true"));
+ remoteAddresses = new HashSet<URI>();
+ for (Element element : xml.getElements()) {
+ TaggedElement address = (TaggedElement) element;
+ try {
+ URI uri = new URI(address.getAttribute("uri"));
+ remoteAddresses.add(uri);
+ } catch (URISyntaxException e) {
+ throw new Ponder2OperationException("Bad URI in OID address: "
+ + address.getAttribute("uri"));
+ }
+ }
+ // Does this OID exist?
+ OID oid = oidList.get(uid);
+ if (oid == null)
+ try {
+ oid = makeNewExternalObject(this);
+ } catch (Exception e) {
+ throw new Ponder2OperationException(
+ "OID: failed to make new external OID for " + uid
+ + ": " + e.getMessage());
+ }
+ return oid.getP2Object();
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/P2ManagedObject.java b/ponder2/src/main/java/eu/novi/ponder2/P2ManagedObject.java
new file mode 100644
index 0000000..f6f6f3b
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/P2ManagedObject.java
@@ -0,0 +1,422 @@
+/**
+ * Created on Jul 4, 2005
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * $Log: P2ManagedObject.java,v $
+ * Revision 1.22 2006/03/15 14:52:18 kpt
+ * Improved handling of visited interaction also now thread safe
+ *
+ * Revision 1.21 2006/03/15 14:37:38 kpt
+ * Fixed multiple and looping event paths
+ *
+ * Revision 1.20 2006/03/15 13:36:42 kpt
+ * Lots of testing stuff and new XMLSaver managed object
+ *
+ * Revision 1.19 2006/02/11 16:28:35 kpt
+ * Modified Event creation
+ *
+ * Revision 1.18 2005/11/23 14:47:07 kpt
+ * Removed Iterable from QDParser.
+ *
+ * Revision 1.17 2005/11/15 16:33:25 kpt
+ * Result added to create
+ *
+ * Revision 1.16 2005/11/15 15:00:51 kpt
+ * ExecuteSetup introduced, more result feedback
+ *
+ * Revision 1.15 2005/11/13 23:27:30 kpt
+ * Added time manager
+ *
+ * Revision 1.14 2005/11/03 04:23:46 kpt
+ * More restore and tidying done
+ *
+ * Revision 1.13 2005/10/29 20:22:56 kpt
+ * Tidied up managed object command execution a little
+ *
+ * Revision 1.12 2005/10/28 21:58:00 kpt
+ * Restore almost completed
+ *
+ * Revision 1.11 2005/10/27 16:57:38 kpt
+ * OID separated from P2ManagedObject
+ *
+ * Revision 1.10 2005/10/27 09:25:15 kpt
+ * Dump almost completed. Everything still works!
+ *
+ * Revision 1.9 2005/10/24 20:53:02 kpt
+ * Dump part of dump and restore working
+ *
+ * Revision 1.8 2005/10/21 17:15:48 kpt
+ * Renamed XML Element types
+ *
+ * Revision 1.7 2005/10/21 14:31:40 kpt
+ * Changed to faster, meaner, external QDParser with LGPL licence.
+ *
+ * Revision 1.6 2005/10/09 22:03:04 kpt
+ * First complete version of demo with a few fixes.
+ Local evaluation added on demand before shipping xml for export.
+ *
+ * Revision 1.5 2005/10/06 10:59:17 kpt
+ * Complete reorganisation of return values using Result.
+ Commands handed to MOs one at a time.
+ *
+ * Revision 1.4 2005/10/01 20:50:52 kpt
+ * Changed result type to new Result class
+ *
+ * Revision 1.3 2005/09/21 13:46:40 kpt
+ * Can now create and send events using XML and the event templates
+ *
+ * Revision 1.2 2005/09/14 08:45:38 kpt
+ * Down to import and use
+ *
+ * Revision 1.1 2005/09/12 10:47:08 kpt
+ * Initial Checkin
+ *
+ */
+
+package eu.novi.ponder2;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.ObjectStreamException;
+import java.util.HashSet;
+import java.util.Set;
+
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.objects.P2Object;
+import eu.novi.ponder2.policy.AuthorisationPolicy;
+import eu.novi.ponder2.policy.Event;
+import eu.novi.ponder2.policy.EventListener;
+
+import eu.novi.ponder2.OID;
+import eu.novi.ponder2.P2ManagedObject;
+import eu.novi.ponder2.Ponder2Message;
+import eu.novi.ponder2.SelfManagedCell;
+
+/**
+ * The base class for all Managed Objects within the system. The parent and
+ * policy sets are maintained here. All RPC calls come through this interface,
+ * the RPC is checked against the policies and then propagated to the actual
+ * object to perform the action.
+ *
+ * @author Kevin Twidle
+ * @version $Id: P2ManagedObject.java,v 1.22 2006/03/15 14:52:18 kpt Exp $
+ */
+public class P2ManagedObject implements Ponder2Message, Externalizable {
+
+ private Set<P2ManagedObject> parentSet;
+ private Set<EventListener> eventListenerSet = null;
+ private Set<AuthorisationPolicy> authorisationPolicySet = null;
+ private Set<P2Object> remoteEventSet = null;
+ private OID oid;
+ private P2Object p2Object;
+
+ /**
+ * The base class for all Managed Objects within the system. The parent and
+ * policy sets are maintained here. All RPC calls come through this
+ * interface, the RPC is checked against the policies and then propagated to
+ * the actual object to perform the action.
+ */
+ public P2ManagedObject(P2Object p2Object) {
+ parentSet = new HashSet<P2ManagedObject>();
+ oid = new OID(this);
+ this.p2Object = p2Object;
+ }
+
+ /**
+ * Constructor for serialisation
+ */
+ public P2ManagedObject() {
+ }
+
+ /**
+ * gets the object identifier for this object
+ *
+ * @return this object's identifier
+ */
+ public OID getOID() {
+ return oid;
+ }
+
+ public boolean isDomain() {
+ return getOID().isDomain();
+ }
+
+ /**
+ * gets the object identifier for this object
+ *
+ * @return this object's identifier
+ */
+ public P2Object getP2Object() {
+ return p2Object;
+ }
+
+ /**
+ * adds a parent managed object as a parent of this one
+ *
+ * @param mo
+ * the parent to be added
+ */
+ protected void addParent(P2ManagedObject mo) {
+ parentSet.add(mo);
+ }
+
+ /**
+ * removes a parent object from this object's parent set
+ *
+ * @param mo
+ * the parent to be removed
+ */
+ protected void removeParent(P2ManagedObject mo) {
+ parentSet.remove(mo);
+ }
+
+ public Set<P2ManagedObject> getParentSet() {
+ return parentSet;
+ }
+
+ /**
+ * returns the number of parents that this managed object has
+ *
+ * @return the number of parents
+ */
+ public int parentCount() {
+ return parentSet.size();
+ }
+
+ /**
+ * get all the obligation policies applying to this managed object
+ *
+ * @return a Set containing the policies
+ */
+ protected Set<EventListener> getEventListeners() {
+ if (eventListenerSet == null)
+ eventListenerSet = new HashSet<EventListener>();
+ return eventListenerSet;
+ }
+
+ /**
+ * get all the authorisation policies applying to this managed object
+ *
+ * @return a Set containing the policies
+ */
+ public Set<AuthorisationPolicy> getAuthorisationPolicies() {
+ if (authorisationPolicySet == null)
+ authorisationPolicySet = new HashSet<AuthorisationPolicy>();
+ return authorisationPolicySet;
+ }
+
+ /**
+ * @return the remoteEventSet
+ */
+ private Set<P2Object> getRemoteEventSet() {
+ if (remoteEventSet == null)
+ remoteEventSet = new HashSet<P2Object>();
+ return remoteEventSet;
+ }
+
+ /**
+ * applies a policy to this managed object
+ *
+ * @param policy
+ * the policy to be applied
+ */
+ public void applyPolicy(EventListener policy) {
+ getEventListeners().add(policy);
+ }
+
+ /**
+ * applies a policy to this managed object
+ *
+ * @param policy
+ * the policy to be applied
+ */
+ public void applyPolicy(AuthorisationPolicy policy) {
+ getAuthorisationPolicies().add(policy);
+ }
+
+ /**
+ * removes a policy from this managed object's policy set
+ *
+ * @param policy
+ * the policy to be removed
+ */
+ public void removePolicy(EventListener policy) {
+ getEventListeners().remove(policy);
+ }
+
+ /**
+ * removes a policy from this managed object's policy set
+ *
+ * @param policy
+ * the policy to be removed
+ */
+ public void removePolicy(AuthorisationPolicy policy) {
+ getAuthorisationPolicies().remove(policy);
+ }
+
+ public void attachRemotePolicy(P2Object remote) {
+ getRemoteEventSet().add(remote);
+ }
+
+ /**
+ * sends an event to policies attached to this managed object and above
+ *
+ * @param event
+ * the event to be sent to the policies
+ * @throws Ponder2Exception
+ */
+ public void sendEvent(Event event) {
+ // Have we already seen this event?
+ if (SelfManagedCell.SystemTrace) {
+ System.err.println();
+ System.err.print("Event " + event + " " + this + " ");
+ }
+ if (event.setVisited(this)) {
+ if (eventListenerSet != null) {
+ Set<EventListener> eventListeners = new HashSet<EventListener>(
+ getEventListeners());
+ for (EventListener listener : eventListeners) {
+ if (SelfManagedCell.SystemTrace)
+ System.err.print("listener " + listener + " ");
+ if (event.setVisited(listener.getId()))
+ try {
+ listener.event(event);
+ } catch (Ponder2Exception e) {
+ System.out.println("Event caused unhandled error: "
+ + e.getMessage());
+ }
+ }
+ }
+ if (remoteEventSet != null) {
+ Set<P2Object> remoteEvents = new HashSet<P2Object>(
+ getRemoteEventSet());
+ for (P2Object remote : remoteEvents) {
+ try {
+ remote.operation(event.getSource(), "Ponder2.event:",
+ event);
+ } catch (Ponder2Exception e) {
+ System.out
+ .println("Event (remote) caused unhandled error: "
+ + e.getMessage());
+ }
+ }
+ }
+ Set<P2ManagedObject> parents = new HashSet<P2ManagedObject>(
+ parentSet);
+ for (P2ManagedObject mo : parents) {
+ mo.sendEvent(event);
+ }
+ }
+ if (SelfManagedCell.SystemTrace)
+ System.err.println("Event end");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.novi.ponder2.Ponder2Message#create(eu.novi.ponder2.objects.P2OID,
+ * java.lang.String, eu.novi.ponder2.objects.P2Object[])
+ */
+ public P2Object create(P2Object source, String operation, P2Object... args)
+ throws Ponder2Exception {
+ return p2Object.create(source, operation, args);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * eu.novi.ponder2.Ponder2Message#operation(eu.novi.ponder2.objects.P2OID,
+ * java.lang.String, eu.novi.ponder2.objects.P2Object[])
+ */
+ public P2Object operation(P2Object source, String operation,
+ P2Object... args) throws Ponder2Exception {
+ return p2Object.operation(source, operation, args);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * eu.novi.ponder2.Ponder2Message#operation(eu.novi.ponder2.objects.P2Object
+ * , java.lang.String, java.lang.String, java.lang.String[])
+ */
+ public P2Object operation(P2Object source, String operation, String arg1,
+ String... args) throws Ponder2Exception {
+ return p2Object.operation(source, operation, arg1, args);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.io.Externalizable#readExternal(java.io.ObjectInput)
+ */
+ public void readExternal(ObjectInput arg0) throws IOException,
+ ClassNotFoundException {
+ // Nothing to read
+ }
+
+ /**
+ * Called by the serialization routines after readExternal as been called.
+ *
+ * @return the newly read in OID, actually probably an old one.
+ * @throws ObjectStreamException
+ */
+ protected Object readResolve() throws ObjectStreamException {
+ // Just return null, this object will be created elsewhere if necessary
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
+ */
+ public void writeExternal(ObjectOutput arg0) throws IOException {
+ // Nothing to write, we don't actually send this object
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null)
+ return false;
+ if (!(obj instanceof P2ManagedObject))
+ return false;
+ return getP2Object().equals(((P2ManagedObject) obj).getP2Object());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return getP2Object().hashCode();
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/P2ObjectAdaptor.java b/ponder2/src/main/java/eu/novi/ponder2/P2ObjectAdaptor.java
new file mode 100644
index 0000000..fefcf17
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/P2ObjectAdaptor.java
@@ -0,0 +1,496 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 8, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.ObjectStreamException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import eu.novi.ponder2.ExternalManagedObjectP2Adaptor;
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.OID;
+import eu.novi.ponder2.P2ObjectAdaptor;
+import eu.novi.ponder2.SelfManagedCell;
+
+import com.twicom.qdparser.TaggedElement;
+
+//import eu.novi.ponder2.CreateOperation;
+//import eu.novi.ponder2.CreateOrStaticOperation;
+//import eu.novi.ponder2.InstanceOperation;
+//import eu.novi.ponder2.StaticOperation;
+import eu.novi.ponder2.comms.P2Serializable;
+import eu.novi.ponder2.exception.Ponder2ArgumentException;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2OperationException;
+import eu.novi.ponder2.objects.P2Object;
+import eu.novi.ponder2.policy.AuthPolicyHolder;
+import eu.novi.ponder2.policy.AuthorisationModule;
+import eu.novi.ponder2.policy.Event;
+import eu.novi.ponder2.policy.EventListener;
+
+/**
+ * An object adaptor manages the interface between the ponder2 system and the
+ * actual managed object itself
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class P2ObjectAdaptor extends P2Object implements Externalizable {
+
+ /**
+ * The instance of the managed object to be called
+ */
+ protected ManagedObject objImpl = null;
+ private static AuthorisationModule authorisationModule = null;
+
+ /**
+ * Creates an empty object adaptor. Used only by factory object to create a
+ * new object. The create call must be made afterwards. See the other
+ * constructor.
+ */
+ public P2ObjectAdaptor() {
+ }
+
+ public P2ObjectAdaptor(P2Object source, String operation, P2Object... args)
+ throws Ponder2Exception {
+ create(source, operation, args);
+ }
+
+ public void setObj(ManagedObject obj) {
+ this.objImpl = obj;
+ }
+
+ public ManagedObject getObj() {
+ return objImpl;
+ }
+
+ /**
+ * Turns authorisation checking on by setting the authorisation module that
+ * will be checking commands. If an authorisation is blocked then an error
+ * will be thrown.
+ *
+ * @param auth
+ * the authorisation module that will perform the checks
+ */
+ public static void setAuthorisation(AuthorisationModule auth) {
+ authorisationModule = auth;
+ }
+
+ /**
+ * Returns the authorisation module in use, if any.
+ *
+ * @return the current authorisation module
+ */
+ public static AuthorisationModule getAuthorisation() {
+ return authorisationModule;
+ }
+
+ /**
+ * called as a result of an operation on the factory managed object for this
+ * managed object
+ *
+ * @param source
+ * the subject OID of the operation
+ * @param operation
+ * the name of the operation
+ * @param args
+ * arguments for the operation
+ * @return the result of the operation
+ * @throws Ponder2Exception
+ */
+ @Override
+ // public P2Object create(P2Object source, String operation, P2Object...
+ // args)
+ // throws Ponder2Exception {
+ // CreateOperation op = getCreateOperation(operation);
+ // if (SelfManagedCell.SystemTrace)
+ // trace("Create", this.getClass().getSimpleName(), operation, args);
+ // objImpl = op.call(this, source, operation, args);
+ // return this;
+ // }
+ public P2Object create(P2Object source, String operation, P2Object... args)
+ throws Ponder2Exception {
+ CreateOrStaticOperation opInfo = new CreateOrStaticOperation(operation);
+ getCreateOrStaticOperation(opInfo);
+ if (SelfManagedCell.SystemTrace)
+ trace("Create/Static call: ", this.getClass().getSimpleName(),
+ operation, args);
+ return opInfo.call(this, source, operation, args);
+ }
+
+ /**
+ * called as a result of an operation on the instantiated managed object
+ *
+ * @param source
+ * the subject OID of the operation
+ * @param operation
+ * the name of the operation
+ * @param args
+ * arguments for the operation
+ * @return the result of the operation
+ * @throws Ponder2Exception
+ */
+ @Override
+ public P2Object operation(P2Object source, String operation,
+ P2Object... args) throws Ponder2Exception {
+ InstanceOperation op = getInstanceOperation(operation);
+ if (SelfManagedCell.SystemTrace)
+ trace("Operation", this.getClass().getSimpleName(), operation, args);
+
+ AuthPolicyHolder holder = null;
+
+ boolean checkAuth = authorisationModule != null
+ && getManagedObject().getParentSet() != null
+ && !getManagedObject().getParentSet().isEmpty();
+
+ if (checkAuth) { // && (source != null)) {
+ holder = new AuthPolicyHolder();
+ authorisationModule.request(AuthorisationModule.PEP1, 's', holder,
+ source, this, operation, args);
+ if (!(objImpl instanceof ExternalManagedObjectP2Adaptor))
+ authorisationModule.request(AuthorisationModule.PEP2, 't',
+ holder, source, this, operation, args);
+ }
+ P2Object value = op.call(this, objImpl, source, operation, args);
+ if (SelfManagedCell.SystemTrace)
+ if (value != null)
+ System.err.println(" => " + value);
+ else
+ System.err.println(" => *** Error: return value is null ***");
+ if (checkAuth) {
+ if (!(objImpl instanceof ExternalManagedObjectP2Adaptor))
+ authorisationModule.reply(AuthorisationModule.PEP3, 't',
+ holder, source, this, operation, args, value);
+ authorisationModule.reply(AuthorisationModule.PEP4, 's', holder,
+ source, this, operation, args, value);
+ }
+ return value;
+ }
+
+ /**
+ * Prints a command trace line on stderr.
+ *
+ * @param opType
+ * the type of the operation, mainly "P2Op"
+ * @param className
+ * the class receiving the operation
+ * @param operation
+ * the name of the operation
+ * @param args
+ * the arguments for the operation
+ */
+ protected static void trace(String opType, String className,
+ String operation, P2Object... args) {
+ if (className.endsWith("P2Adaptor"))
+ className = className.substring(0, className.length() - 9);
+ System.err.print(opType + ": " + className + " " + operation + " ");
+ for (int i = 0; i < args.length; i++) {
+ P2Object value = args[i];
+ System.err.print(value + " ");
+ }
+ System.err.println();
+ }
+
+ public void getCreateOrStaticOperation(CreateOrStaticOperation opInfo)
+ throws Ponder2OperationException {
+ throw new Ponder2OperationException("Object "
+ + this.getClass().getSimpleName()
+ + " unknown constructor or static operation: '" + opInfo.opName
+ + "'");
+ }
+
+ public CreateOperation getCreateOperation(String opName)
+ throws Ponder2OperationException {
+ throw new Ponder2OperationException("Object "
+ + this.getClass().getSimpleName() + " unknown constructor '"
+ + opName + "'");
+ }
+
+ /**
+ * The map of instance operations to methods
+ */
+ private final static Map<String, InstanceOperation> operation;
+
+ // Create the default call tables when the class is loaded
+ static {
+ operation = new HashMap<String, InstanceOperation>();
+
+ // Ponder2 call to add a remote event listener
+ operation.put("Ponder2.attach:", new InstanceOperation() {
+
+ @Override
+ public P2Object call(P2Object thisObj, ManagedObject obj,
+ P2Object source, String operation, P2Object... args)
+ throws Ponder2Exception {
+ P2Object object = args[0];
+ if (object instanceof P2ObjectAdaptor) {
+ P2ObjectAdaptor listener = (P2ObjectAdaptor) object;
+ if (listener.getObj() instanceof EventListener) {
+ thisObj.getManagedObject().applyPolicy(
+ (EventListener) listener.getObj());
+ } else if (listener instanceof ExternalManagedObjectP2Adaptor) {
+ thisObj.getManagedObject().attachRemotePolicy(listener);
+ } else
+ throw new Ponder2ArgumentException(
+ "Ponder2.attach: Can only attach an Event Listener or External Managed Object");
+ }
+ return thisObj;
+ }
+ });
+
+ // Ponder2 call to inject an event
+ operation.put("Ponder2.event:", new InstanceOperation() {
+
+ @Override
+ public P2Object call(P2Object thisObj, ManagedObject obj,
+ P2Object source, String operation, P2Object... args)
+ throws Ponder2Exception {
+ P2Object event = args[0];
+ if (event instanceof Event) {
+ thisObj.getManagedObject().sendEvent((Event) event);
+ } else
+ throw new Ponder2ArgumentException(
+ "Ponder2.event: Object is not of type Event - "
+ + event.getClass());
+ return thisObj;
+ }
+ });
+
+ // Ponder2 call to return the class name
+ operation.put("class", new InstanceOperation() {
+
+ @Override
+ public P2Object call(P2Object thisObj, ManagedObject obj,
+ P2Object source, String operation, P2Object... args)
+ throws Ponder2Exception {
+ String name = ((P2ObjectAdaptor) thisObj).getObj().getClass()
+ .getSimpleName();
+ if (name.startsWith("P2")) {
+ name = name.substring(2);
+ }
+ return P2Object.create(name);
+ }
+ });
+ }
+
+ public InstanceOperation getInstanceOperation(String opName)
+ throws Ponder2OperationException {
+ InstanceOperation op = operation.get(opName);
+ if (op == null)
+ throw new Ponder2OperationException("Object " + this.getClass()
+ + " unknown operation '" + opName + "'");
+ return op;
+ }
+
+ public static class CreateOrStaticOperation {
+
+ private CreateOperation create = null;
+ private StaticOperation staticop = null;
+ private String opName;
+
+ CreateOrStaticOperation(String opName) {
+ this.opName = opName;
+ }
+
+ public boolean findOp(Map<String, CreateOperation> createMap,
+ Map<String, StaticOperation> staticMap) {
+ create = createMap.get(opName);
+ if (create == null) {
+ staticop = staticMap.get(opName);
+ if (staticop == null)
+ return false;
+ }
+ return true;
+ }
+
+ public P2Object call(P2ObjectAdaptor adaptor, P2Object source,
+ String operation, P2Object... args) throws Ponder2Exception {
+ if (create != null) {
+ adaptor.objImpl = create.call(adaptor, source, operation, args);
+ return adaptor;
+ }
+ if (staticop != null)
+ return staticop.call(source, operation, args);
+
+ throw new Ponder2OperationException("Object "
+ + this.getClass().getSimpleName()
+ + " unknown constructor or static operation: '" + operation
+ + "'");
+
+ }
+
+ }
+
+ /**
+ * Base class to map an operation with known arguments to a specific call
+ * within a managed object
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+ public static abstract class StaticOperation {
+
+ /**
+ * maps an operation to a static method
+ *
+ * @param source
+ * the subject OID of the operation
+ * @param args
+ * arguments for the operation
+ * @return the new managed object
+ * @throws Ponder2ArgumentException
+ */
+ public abstract P2Object call(P2Object source, String operation,
+ P2Object... args) throws Ponder2Exception;
+ }
+
+ /**
+ * Base class to map an operation with known arguments to a specific call
+ * within a managed object
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+ public static abstract class CreateOperation {
+
+ /**
+ * creates a managed object
+ *
+ * @param source
+ * the subject OID of the operation
+ * @param args
+ * arguments for the operation
+ * @return the new managed object
+ * @throws Ponder2ArgumentException
+ */
+ public abstract ManagedObject call(P2Object obj, P2Object source,
+ String operation, P2Object... args) throws Ponder2Exception;
+ }
+
+ /**
+ * Base class to map an operation with known arguments to a specific call
+ * within a managed object
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+ public static abstract class InstanceOperation {
+
+ /**
+ * calls an operation in a managed object
+ *
+ * @param obj
+ * the instance of the managed object to be called
+ * @param source
+ * the subject OID of the operation
+ * @param args
+ * arguments for the operation
+ * @return the result of the operation
+ * @throws Ponder2Exception
+ */
+ public abstract P2Object call(P2Object thisobj, ManagedObject obj,
+ P2Object source, String operation, P2Object... args)
+ throws Ponder2Exception;
+ }
+
+ // --------------------------------------------------------------
+
+ // This code is for serialising Java Managed Objects. All that we need do is
+ // serialise this object as an OID because the objects themselves do not
+ // travel around.
+ // When reading back in, we read in an OID and return the object associated
+ // with the OID. If the OID is external then we will be returning an
+ // ExternalManagedObject, if internal then we return the correct
+ // P2ObjectObjectAdaptor.
+
+ // Place holder for keeping our OID when reading this object from an
+ // external
+ // source
+ private OID myExternalOID = null;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.io.Externalizable#readExternal(java.io.ObjectInput)
+ */
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ // Just read an OID and save it
+ myExternalOID = (OID) in.readObject();
+ }
+
+ /**
+ * Resolves instances being deserialised to the preexisting objects.
+ *
+ * @return the intended object
+ * @throws ObjectStreamException
+ * if something happens
+ */
+ protected Object readResolve() throws ObjectStreamException {
+ // Return the object associated with the read OID.
+ return myExternalOID.getP2Object();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
+ */
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(getOID());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.novi.ponder2.objects.P2Object#writeXml()
+ */
+ @Override
+ public TaggedElement writeXml(Set<P2Object> written)
+ throws Ponder2OperationException {
+ return getOID().writeXml(written);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * eu.novi.ponder2.objects.P2Object#readXml(com.twicom.qdparser.TaggedElement
+ * )
+ */
+ @Override
+ public P2Object readXml(TaggedElement xml, Map<Integer, P2Serializable> read)
+ throws Ponder2OperationException, Ponder2ArgumentException {
+ throw new Ponder2OperationException(
+ "P2ObjectAdaptor cannot be read in as a serialised object");
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/Path.java b/ponder2/src/main/java/eu/novi/ponder2/Path.java
new file mode 100644
index 0000000..3054ea1
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/Path.java
@@ -0,0 +1,344 @@
+/**
+ * Created on Jul 7, 2005
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * $Log: Path.java,v $
+ * Revision 1.3 2005/10/01 14:35:03 kpt
+ * Improved toString
+ *
+ * Revision 1.2 2005/09/30 11:04:21 kpt
+ * Tidied up a little
+ *
+ * Revision 1.1 2005/09/12 10:47:08 kpt
+ * Initial Checkin
+ *
+ */
+
+package eu.novi.ponder2;
+
+import java.util.Iterator;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+import eu.novi.ponder2.Path;
+
+/**
+ * A path manipulation library. Handles Unix style path names and can index
+ * separate parts of the path, extract parts of the path and normalise
+ * pathnames.
+ *
+ * @author Kevin Twidle
+ * @version $Id: Path.java,v 1.3 2005/10/01 14:35:03 kpt Exp $
+ */
+public class Path implements Iterable<String>, Cloneable {
+
+ /**
+ * Default string for the current directory/domain
+ */
+ public static final String DOT = ".";
+
+ /**
+ * Default string for a path separator
+ */
+ public static final String SLASH = "/";
+
+ /**
+ * Default string for the root
+ */
+ public static final String ROOT = "/";
+
+ /**
+ * Default string for a parent directory/domain
+ */
+ public static final String DOTDOT = "..";
+
+ private Vector<String> paths;
+
+ /**
+ * creates a new Path based on a String value
+ *
+ * @param path
+ * the String pathname
+ */
+ public Path(String path) {
+ super();
+ paths = new Vector<String>();
+ set(path);
+ }
+
+ /**
+ * creates a new Path as a copy of another Path
+ *
+ * @param path
+ * the Path to be copied
+ */
+ public Path(Path path) {
+ super();
+ paths = new Vector<String>(path.paths);
+ }
+
+ /**
+ * creates a new Path as a concatenation of a Path and a String joined with
+ * a SLASH
+ *
+ * @param path
+ * the first component of the pathname
+ * @param extra
+ * the last component of the pathname
+ */
+ public Path(Path path, String extra) {
+ this(path);
+ add(extra);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#clone()
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ Path clone = (Path) super.clone();
+ clone.paths = (Vector<String>) paths.clone();
+ return clone;
+ }
+
+ /**
+ * clears the content of the Path
+ *
+ */
+ public void clear() {
+ paths.clear();
+ }
+
+ /**
+ * Checks whether the path is complete or goes up from the current element
+ *
+ * @return true if the path is complete
+ */
+ public boolean isComplete() {
+ return (paths.size() > 0 && !paths.get(0).equals(DOTDOT));
+ }
+
+ /**
+ * Checks whether the path starts from the current domain
+ *
+ * @return true if the path is relative
+ */
+ public boolean isRelative() {
+ return (paths.size() > 0 && !paths.get(0).equals(SLASH));
+ }
+
+ /**
+ * Checks whether the path starts from the root
+ *
+ * @return true if the path starts from the root
+ */
+ public boolean isAbsolute() {
+ return (paths.size() > 0 && paths.get(0).equals(SLASH));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Iterable#iterator()
+ */
+ public Iterator<String> iterator() {
+ return paths.iterator();
+ }
+
+ /**
+ * Returns a new Path being the parent of the current one
+ *
+ * @return the Path of the parent
+ */
+ public Path parent() {
+ Path path = null;
+ try {
+ path = (Path) clone();
+ path.add(DOTDOT);
+ } catch (CloneNotSupportedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return path;
+ }
+
+ /**
+ * Returns the child part of the Path as a String
+ *
+ * @return the child of the Path
+ */
+ public String child() {
+ return paths.lastElement();
+ }
+
+ /**
+ * sets the Path to be the same as a String
+ *
+ * @param path
+ * the new full pathname
+ */
+ public void set(String path) {
+ clear();
+ add(path);
+ }
+
+ /**
+ * adds a component to the end of the Path. A SLASH is also added as a
+ * Separator if necessary.
+ *
+ * @param path
+ */
+ public void add(String path) {
+ StringTokenizer st = new StringTokenizer(path, SLASH);
+ if (path.startsWith(SLASH)) {
+ paths.clear();
+ paths.add(SLASH);
+ }
+ while (st.hasMoreTokens()) {
+ String bit = st.nextToken();
+ if (bit != null && !bit.equals(DOT)) {
+ // Check for climbing up the path
+ if (!bit.equals(DOTDOT)) {
+ paths.add(bit);
+ } else {
+ // We have DOTODT
+ // Special case if PATH is DOT
+ if (paths.size() == 1 && paths.get(0).equals(DOT)) {
+ paths.set(0, DOTDOT);
+ } else
+ // Ignore if we have we hit root
+ if (!(paths.size() == 1 && paths.get(0).equals(SLASH))) {
+ // Do we remove or add to the elements?
+ if (paths.size() > 0
+ && !paths.lastElement().equals(DOTDOT)) {
+ paths.remove(paths.size() - 1);
+ } else {
+ paths.add(bit);
+ }
+ }
+ }
+ }
+ }
+ if (paths.isEmpty()) {
+ paths.add(DOT);
+ }
+ }
+
+ /**
+ * returns the number of elements in the path
+ *
+ * @return the number of elements in the path
+ */
+ public int size() {
+ return paths.size();
+ }
+
+ /**
+ * returns beginning n elements of the path. If the index is negative,
+ * returns all but the first n elements.
+ *
+ * @param index
+ * the number of elements to return
+ * @return the required part of the path as a string
+ */
+ public String head(int index) {
+ if (index < 0)
+ return tail(paths.size() + index);
+ return subpath(0, index - 1);
+ }
+
+ /**
+ * returns the last n elements of the Path. If the index is negative,
+ * returns all but the last n elements.
+ *
+ * @param index
+ * the number of elements to return
+ * @return the beginning of the Path as a String
+ */
+ public String tail(int index) {
+ if (index < 0)
+ return head(paths.size() + index);
+ return subpath(paths.size() - index, paths.size() - 1);
+ }
+
+ /**
+ * returns a subset of the path from the n'th element to the end.
+ *
+ * @param start
+ * the first element to copy
+ * @return a string containing the subset of the Path
+ */
+ public String subpath(int start) {
+ return subpath(start, paths.size() - 1);
+ }
+
+ /**
+ * returns a subset of the path indexed by the start element and the end
+ * element
+ *
+ * @param start
+ * the index of the first element of the substring
+ * @param end
+ * the index of the last element of the substring
+ * @return the substring
+ */
+ public String subpath(int start, int end) {
+ StringBuffer result = new StringBuffer();
+ if (start < 0)
+ start = 0;
+ if (end >= paths.size())
+ end = paths.size() - 1;
+ if (end < start)
+ return "";
+ boolean addSlash = false;
+ while (start <= end) {
+ if (addSlash)
+ result.append('/');
+ String s = paths.elementAt(start++);
+ result.append(s);
+ addSlash = !s.equals(SLASH);
+ }
+ return result.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+ boolean addSlash = isRelative();
+ for (String part : paths) {
+ buf.append(part);
+ if (addSlash)
+ buf.append(SLASH);
+ addSlash = true;
+ }
+ if (buf.length() > 1 && buf.charAt(buf.length() - 1) == '/')
+ buf.deleteCharAt(buf.length() - 1);
+ return buf.toString();
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/Ponder2Message.java b/ponder2/src/main/java/eu/novi/ponder2/Ponder2Message.java
new file mode 100644
index 0000000..e339c8b
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/Ponder2Message.java
@@ -0,0 +1,56 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Feb 1, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2;
+
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.objects.P2Object;
+
+/**
+ * Interface defining the methods that anything able to receive a Ponder2
+ * message must implement. This allows the object to recognise the command and
+ * execute the command.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public interface Ponder2Message {
+
+ // public P2Object getP2Object();
+ //
+ // public P2ManagedObject getDomainObject();
+ //
+ // public OID getOID();
+
+ public P2Object create(P2Object source, String operation, P2Object... args)
+ throws Ponder2Exception;
+
+ public P2Object operation(P2Object source, String operation,
+ P2Object... args) throws Ponder2Exception;
+
+ public P2Object operation(P2Object source, String operation, String arg1,
+ String... args) throws Ponder2Exception;
+
+} \ No newline at end of file
diff --git a/ponder2/src/main/java/eu/novi/ponder2/PonderTalk.java b/ponder2/src/main/java/eu/novi/ponder2/PonderTalk.java
new file mode 100644
index 0000000..315cf39
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/PonderTalk.java
@@ -0,0 +1,267 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Jun 18, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2;
+
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
+
+
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.exception.Ponder2ArgumentException;
+import eu.novi.ponder2.exception.Ponder2OperationException;
+import eu.novi.ponder2.objects.P2Object;
+import eu.novi.ponder2.parser.P2Compiler;
+import eu.novi.ponder2.parser.XMLParser;
+
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.PonderTalkInterface;
+
+/**
+ * A Managed Object that parses and executes PonderTalk. PonderTalk can be
+ * supplied as strings from other PonderTalk statements or as strings received
+ * over RMI. The PonderTalk string is executed and the result is returned as a
+ * string. If an error occurs then a Ponder2Exception or a RemoteException is
+ * thrown.
+ *
+ * This managed object can also be used as a stand-alone program to send
+ * PonderTalk to a remote SMC using RMI.<br>
+ * 1. Create this managed object in an SMC giving it a RMI name to use. e.g.
+ * MyPonder2<br>
+ * 2. Send PonderTalk to the SMC using the Ponder2 JAR file e.g.<br>
+ * java -cp ponder2.jar eu.novi.ponder2.PonderTalk MyPonder2 any PonderTalk
+ * statement
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class PonderTalk implements ManagedObject {
+
+ private boolean trace = false;
+ private final P2Object myP2Object;
+ private String rmiName;
+
+ /**
+ * Creates a PonderTalk managed object
+ *
+ * @param myP2Object
+ * @throws Ponder2ArgumentException
+ */
+ @Ponder2op("create")
+ public PonderTalk(P2Object myP2Object) {
+ this.myP2Object = myP2Object;
+ this.rmiName = null;
+ }
+
+ /**
+ * Creates a PonderTalk managed object with rmiName as the RMI name that
+ * will be listened to
+ *
+ * @param myP2Object
+ * @param rmiName
+ * @throws Ponder2ArgumentException
+ */
+ @Ponder2op("create:")
+ PonderTalk(P2Object myP2Object, String rmiName)
+ throws Ponder2ArgumentException {
+ this.myP2Object = myP2Object;
+ this.rmiName = rmiName;
+ try {
+ System.out.println("Trying");
+ Naming.rebind(rmiName, new PonderTalkReceiver());
+ System.out.println("NO man");
+ } catch (Exception e) {
+ throw new Ponder2ArgumentException(e.getMessage());
+ }
+ }
+
+ /**
+ * Binds this managed object to a new RMI name. Any previous bindings are
+ * maintained.
+ *
+ * @param rmiName
+ * @throws Ponder2ArgumentException
+ */
+ @Ponder2op("rmi:")
+ void bind(String rmiName) throws Ponder2ArgumentException {
+ this.rmiName = rmiName;
+ try {
+ Naming.rebind(rmiName, new PonderTalkReceiver());
+ } catch (Exception e) {
+ throw new Ponder2ArgumentException(e.getMessage());
+ }
+ }
+
+ /**
+ * turns tracing on if aBoolean is true else turns it off.
+ *
+ * @param aBoolean
+ */
+ @Ponder2op("trace:")
+ public void trace(boolean aBoolean) {
+ trace = aBoolean;
+ }
+
+ /**
+ * tests the RMI interface without having to run a separate SMC
+ *
+ * @param aString
+ * the PonderTalk to be executed
+ * @return the result of the execution as a String
+ * @throws Ponder2OperationException
+ */
+ @Ponder2op("test:")
+ public String test(String aString) throws Ponder2OperationException {
+ String result;
+
+ if (rmiName == null)
+ throw new Ponder2OperationException(
+ "PonderTalk has not been given an RMI name");
+ try {
+ PonderTalkInterface pt = (PonderTalkInterface) Naming
+ .lookup(rmiName);
+ result = pt.execute(aString);
+ } catch (Exception e) {
+ throw new Ponder2OperationException("remote failure: "
+ + e.getMessage());
+ }
+
+ return result;
+ }
+
+ private class PonderTalkReceiver extends UnicastRemoteObject implements
+ PonderTalkInterface {
+
+ /**
+ * @throws RemoteException
+ */
+ protected PonderTalkReceiver()throws RemoteException {
+ System.out.println("created the pondertalkreceiver");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.novi.ponder2.PonderTalkInterface#execute(java.lang.String)
+ */
+ public String execute(String ponderTalk) throws RemoteException {
+ try {
+
+ P2Object value = executePonderTalk(ponderTalk);
+ return value.toString();
+ } catch (Exception e) {
+ throw new RemoteException(e.getMessage());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.novi.ponder2.PonderTalkInterface#compile(java.lang.String)
+ */
+ public String compile(String ponderTalk) throws RemoteException {
+ try {
+ return P2Compiler.parse(ponderTalk);
+ } catch (Exception e) {
+ throw new RemoteException(e.getMessage());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.novi.ponder2.PonderTalkInterface#executeXML(java.lang.String)
+ */
+ public String executeXML(String p2xml) throws RemoteException {
+ try {
+ P2Object value = new XMLParser().execute(myP2Object, p2xml);
+ return value.toString();
+ } catch (Exception e) {
+ throw new RemoteException(e.getMessage());
+ }
+ }
+ }
+
+ /**
+ * Compiles and executes aPonderTalkString and returns the result.
+ *
+ * @param aPonderTalkString
+ * the PonderTalk to be executed
+ * @return the object that results from the PonderTalk being executed
+ * @throws Ponder2OperationException
+ */
+ @Ponder2op("execute:")
+ public P2Object executePonderTalk(String aPonderTalkString)
+ throws Ponder2OperationException {
+ try {
+ if (trace) {
+ System.out.println("PonderTalk executing: ");
+ System.out.println("-------------------");
+ System.out.println(aPonderTalkString);
+ System.out.println("-------------------");
+ }
+ String p2xml = P2Compiler.parse(aPonderTalkString);
+ return new XMLParser().execute(myP2Object, p2xml);
+ } catch (Exception e) {
+ throw new Ponder2OperationException("Caught P2 Exception: "
+ + e.getMessage());
+ }
+ }
+
+ public static void main(String args[]) {
+ Response response = send(args);
+ System.out.println(response.message);
+ System.exit(response.ok ? 0 : 1);
+ }
+
+ public static Response send(String args[]) {
+ Response response = new Response();
+ if (args.length < 2) {
+ response.message = "Too few arguments. Need: RMIname pondertalk statement.";
+ response.ok = false;
+ return response;
+ }
+ String rmiName = args[0];
+ String ponderTalk = "";
+ for (int i = 1; i < args.length; i++) {
+ ponderTalk += " " + args[i];
+ }
+ try {
+ PonderTalkInterface pt = (PonderTalkInterface) Naming
+ .lookup(rmiName);
+ response.message = pt.execute(ponderTalk);
+ } catch (Exception e) {
+ response.message = "Remote PonderTalk failure: " + e.getMessage();
+ response.ok = false;
+ }
+ return response;
+ }
+
+ public static class Response {
+ public boolean ok = true;
+ public String message = "";
+ }
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/PonderTalkInterface.java b/ponder2/src/main/java/eu/novi/ponder2/PonderTalkInterface.java
new file mode 100644
index 0000000..54cc20f
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/PonderTalkInterface.java
@@ -0,0 +1,78 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Jun 18, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+/**
+ * Interface for sending PonderTalk to the SMC. Retruns the result as a string
+ * if it is sucessful otherwise it throws a RemoteException
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public interface PonderTalkInterface extends Remote {
+
+ /**
+ * Takes a PonderTalk string, compiles and executes it. Returns the result
+ * at a string.
+ *
+ * @param ponderTalk
+ * a string containing one or more PonderTalk statements
+ * separated by full-stops (periods).
+ * @return the result of the operation as a string
+ * @throws RemoteException
+ * if something goes wrong
+ */
+ public String execute(String ponderTalk) throws RemoteException;
+
+ /**
+ * Takes a PonderTalk string and compiles it to internal XML. The XML is
+ * returned as a string.
+ *
+ * @param ponderTalk
+ * a string containing one or more PonderTalk statements
+ * separated by full-stops (periods).
+ * @return the XML result of the compilation as a string
+ * @throws RemoteException
+ * if something goes wrong
+ */
+ public String compile(String ponderTalk) throws RemoteException;
+
+ /**
+ * Takes a Ponder2 internal XML execution structure as a string, executes it
+ * and returns the result as a string.
+ *
+ * @param xml
+ * a string containing a single XML structure to be executed
+ * @return the result of the operation as a string
+ * @throws RemoteException
+ * if something goes wrong
+ */
+ public String executeXML(String xml) throws RemoteException;
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/SMCStartInterface.java b/ponder2/src/main/java/eu/novi/ponder2/SMCStartInterface.java
new file mode 100644
index 0000000..72119ba
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/SMCStartInterface.java
@@ -0,0 +1,26 @@
+package eu.novi.ponder2;
+
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.objects.P2Object;
+import eu.novi.ponder2.policy.AuthPolicyHolder;
+
+public interface SMCStartInterface {
+
+ /**
+ * Create new Node(Managed Object) in the SMC
+ * @param PlNode
+ * @return id of the Node
+ */
+ public void start();
+ //public PlNode createNode(String newNode, String slice);
+ //public P2Object createEvent(P2Object thisObj, ManagedObject obj,
+ // P2Object source, String operation, P2Object... args) throws Ponder2Exception;
+ public void stop();
+
+ public Boolean searchauth(AuthPolicyHolder holder, short pepType,
+ P2Object subject, P2Object target, String action, char focus,
+ P2Object[] args, P2Object result);
+
+ public Boolean searchauth(P2Object myP2Object, P2Object resource);
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/SelfManagedCell.java b/ponder2/src/main/java/eu/novi/ponder2/SelfManagedCell.java
new file mode 100644
index 0000000..ab1a21d
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/SelfManagedCell.java
@@ -0,0 +1,769 @@
+/**
+ * Created on Jul 4, 2005
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * $Log: SelfManagedCell.java,v $
+ * Revision 1.20 2006/03/15 13:36:42 kpt
+ * Lots of testing stuff and new XMLSaver managed object
+ *
+ * Revision 1.19 2006/02/22 18:15:57 kpt
+ * Tidied up
+ *
+ * Revision 1.18 2006/02/22 16:35:58 kpt
+ * First version of Proxy integration
+ *
+ * Revision 1.17 2005/11/28 16:02:02 kpt
+ * Added Event to external invocation
+ *
+ * Revision 1.16 2005/11/20 13:47:50 kpt
+ * prints return values for boot files
+ *
+ * Revision 1.15 2005/11/20 13:06:17 kpt
+ * Import returns error if not found
+ *
+ * Revision 1.14 2005/11/19 17:00:07 kpt
+ * Fixed bootfile param and prints shell port when ready
+ *
+ * Revision 1.13 2005/11/19 12:12:34 kpt
+ * use -rmi - to turn RMI off
+ *
+ * Revision 1.12 2005/11/18 15:17:29 kpt
+ * Added - boot option and . to terminate XML input
+ *
+ * Revision 1.11 2005/11/17 11:36:28 kpt
+ * Added context to many ops for arg substitution
+ *
+ * Revision 1.10 2005/11/15 16:33:25 kpt
+ * Result added to create
+ *
+ * Revision 1.9 2005/11/14 21:02:21 kpt
+ * Made Result much more pervasive
+ *
+ * Revision 1.8 2005/10/28 21:58:00 kpt
+ * Restore almost completed
+ *
+ * Revision 1.7 2005/10/21 17:15:48 kpt
+ * Renamed XML Element types
+ *
+ * Revision 1.6 2005/10/21 14:31:40 kpt
+ * Changed to faster, meaner, external QDParser with LGPL licence.
+ *
+ * Revision 1.5 2005/10/11 10:11:40 kpt
+ * First full version of the demo
+ *
+ * Revision 1.4 2005/09/22 08:38:01 kpt
+ * Fixes for demo
+ *
+ * Revision 1.3 2005/09/21 15:54:56 kpt
+ * USE now works through external domains
+ *
+ * Revision 1.2 2005/09/21 08:21:03 kpt
+ * First cut at external objects
+ *
+ * Revision 1.1 2005/09/12 10:47:08 kpt
+ * Initial Checkin
+ *
+ */
+
+package eu.novi.ponder2;
+
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.comms.Transmitter;
+import eu.novi.ponder2.exception.Ponder2ArgumentException;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2OperationException;
+import eu.novi.ponder2.exception.Ponder2RemoteException;
+import eu.novi.ponder2.objects.P2Array;
+import eu.novi.ponder2.objects.P2Block;
+import eu.novi.ponder2.objects.P2Hash;
+import eu.novi.ponder2.objects.P2Object;
+import eu.novi.ponder2.parser.P2Compiler;
+import eu.novi.ponder2.parser.XMLParser;
+import eu.novi.ponder2.policy.BasicAuthModule;
+
+import eu.novi.ponder2.Domain;
+import eu.novi.ponder2.ExternalManagedObject;
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.P2ObjectAdaptor;
+import eu.novi.ponder2.SelfManagedCell;
+import eu.novi.ponder2.SelfManagedCellP2Adaptor;
+import eu.novi.ponder2.Shell;
+import eu.novi.ponder2.Util;
+
+/**
+ * The top level root domain of the whole system. Contains main() to start the
+ * whole thing off
+ *
+ * @author Kevin Twidle
+ * @version $Id: SelfManagedCell.java,v 1.20 2006/03/15 13:36:42 kpt Exp $
+ */
+public class SelfManagedCell extends Domain implements ManagedObject {
+
+ public static final String SVNDate = "$Date: 2010-03-23 14:45:20 +0100 (Tue, 23 Mar 2010) $";
+
+ public static final String SVNRevision = "$Rev: 3570 $";
+
+ public static boolean SystemTrace = false;
+
+ public static final String EventDomain = "/event";
+
+ public static final String PolicyDomain = "/policy";
+
+ public static P2Object RootDomain = null;
+
+ public static int port = 13570;
+
+ public static Map<String, P2Object> startupArgs;
+
+ public static String[] startupArgsArray;
+
+ /**
+ * The default value for authorization. Setting its value to true means that
+ * all actions are allowed by default, otherwise as default no actions are
+ * authorised. If no value is set by the user then the default value will be
+ * set to false.
+ */
+ static boolean defaulAuthPolicy = false;
+
+ /**
+ * This flag if set to true means that an authorisation module has been
+ * loaded. false otherwise.
+ */
+ static boolean isAuthModSet = false;
+
+ /**
+ * creates a new SelfManagedCell domain. This is normally the root domain of
+ * an SMC. It contains code for loading other objects, printing etc.
+ */
+ @Ponder2op("create")
+ public SelfManagedCell(P2Object myP2Object) {
+ super(myP2Object);
+ P2Object.setSMC(this);
+
+ if (RootDomain == null)
+ RootDomain = myP2Object;
+
+ if (SystemTrace) {
+ System.out.println("SelfManagedCell.SelfManagedCell(): my OID is "
+ + myP2Object.getOID());
+ System.out
+ .println("SelfManagedCell.SelfManagedCell(): my myP2Object is "
+ + myP2Object);
+ }
+ }
+
+ /**
+ * answers with a hash containing the user supplied arguments to the SMC.
+ * User supplied arguments are those after an argument of '-' by itself.
+ * <p>
+ * The arguments are interpreted as key=>value pairs where the key is an
+ * argument starting with a '-'. A value cannot start with a '-', it is
+ * taken to be the next key instead. The hash is indexed with the names of
+ * the keys without the '-'. If a value follows a key then it is included as
+ * the value in the hash. If a value is found without a preceding key, it is
+ * ignored. In the following example "copper" will be lost.
+ * <p>
+ * -a -b gold -c silver copper -d
+ * <p>
+ * becomes
+ *
+ * <pre>
+ * a =&gt; &quot;&quot;
+ * b =&gt; gold
+ * c =&gt; silver
+ * d =&gt; &quot;&quot;
+ * </pre>
+ *
+ * @return a hash containing the user, run-time arguments
+ */
+ @Ponder2op("argsAsHash")
+ protected P2Object argsAsHash() {
+ return P2Object.create(startupArgs);
+ }
+
+ /**
+ * answers with an array containing all the user supplied arguments to the
+ * SMC. User supplied arguments are those after an argument of '-' by
+ * itself. All arguments are added to the array as-is, any '-' characters
+ * are left intact.
+ *
+ * @return an array containing all the user, run-time arguments
+ */
+ @Ponder2op("argsAsArray")
+ protected P2Object argsAsArray() {
+ return P2Object.create(startupArgsArray);
+ }
+
+ /**
+ * Sleeps for secs seconds
+ *
+ * @param secs
+ */
+ @Ponder2op("sleep:")
+ protected void sleep(int secs) {
+ try {
+ Thread.sleep(secs * 1000);
+ } catch (InterruptedException e) {
+ System.err.println("Sleep interrupted " + e.getMessage());
+ }
+ }
+
+ /**
+ * Terminates the Ponder2 SMC with a zero status
+ */
+ @Ponder2op("exit")
+ protected void exit() {
+ System.exit(0);
+ }
+
+ /**
+ * Terminates the Ponder2 SMC with exitStatus
+ *
+ * @param exitStatus
+ */
+ @Ponder2op("exit:")
+ protected void exit(int exitStatus) {
+ System.exit(exitStatus);
+ }
+
+ /**
+ * Loads a communications protocol and sets the SMC's local address to
+ * anAddress. This is functionally the same as using the -address argument
+ * when running Ponder2, however, it means that communications can be
+ * delayed until the domain structure is setup correctly
+ *
+ * @param anAddress
+ * the new address as a string in the correct format for the
+ * protocol chosen
+ * @throws Ponder2RemoteException
+ * if the protocol cannot be loaded properly
+ */
+ @Ponder2op("address:")
+ protected void address(String anAddress) throws Ponder2RemoteException {
+ if (anAddress.contains(":"))
+ ExternalManagedObject.loadProtocol(null, anAddress, null);
+ else
+ ExternalManagedObject.loadProtocol(anAddress, null, null);
+ }
+
+ /**
+ * Loads the code necessary for creating an instance of anObject. Answers
+ * the factory for creating instances of anObject.
+ *
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("load:")
+ protected P2Object operation_load(String anObject) throws Ponder2Exception {
+ return Util.loadFactory(anObject);
+ }
+
+ /**
+ * Pings remote SMC to see if it is alive. Answers true if it is.
+ *
+ * @param location
+ * address of remote site
+ * @return true if the remote is alive
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("ping:")
+ public static boolean ping(String location) throws Ponder2Exception {
+ try {
+ if (location == null)
+ throw new Ponder2ArgumentException(
+ "Ping error: location cannot be null");
+
+ URI uri = new URI(location);
+ String scheme = uri.getScheme();
+ if (scheme == null)
+ throw new Ponder2ArgumentException(
+ "Ping: missing scheme/protocol in " + location);
+
+ // Ok, let's get for the remote proxy
+ Transmitter remote = ExternalManagedObject.getRemote(uri);
+ // Finally ask for the remote object
+ return remote != null && remote.ping(uri);
+ } catch (URISyntaxException e) {
+ throw new Ponder2RemoteException("getRemote: " + e.getMessage());
+ }
+ }
+
+ /**
+ * Answers the remote managed object which has aName belonging to an SMC at
+ * aLocation.
+ *
+ * @throws Ponder2Exception
+ *
+ */
+ @Ponder2op("import:from:")
+ protected P2Object operation_import_from(String aName, String aLocation)
+ throws Ponder2Exception {
+ return Util.getRemoteObject(aName, aLocation);
+ }
+
+ /**
+ * answers with the amount of free memory in the Java VM
+ *
+ * @return the amount of free memory
+ */
+ @Ponder2op("memory")
+ protected long memory() {
+ Runtime runtime = Runtime.getRuntime();
+ long max = runtime.maxMemory();
+ long free = runtime.freeMemory();
+ System.out.println("Max : " + max + ". Free: " + free);
+ runtime.gc();
+ free = runtime.freeMemory();
+ System.out.println("Max : " + max + ". Free: " + free);
+ return free;
+ }
+
+ /**
+ * Reads and executes PonderTalk from aUrl.
+ *
+ * @param source
+ * @param aUrl
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("read:")
+ public void read(P2Object source, String aUrl) throws Ponder2Exception {
+ Util.parseFile(source, aUrl);
+ }
+
+ /**
+ * Reads and executes PonderTalk from aUrl. The parser is initialized with
+ * the variables in the P2Hash varHash
+ *
+ * @param source
+ * @param aUrl
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("read:withVars:")
+ public void read(P2Object source, String aUrl, P2Hash varHash)
+ throws Ponder2Exception {
+ Util.parseFile(source, aUrl, varHash);
+ }
+
+ /**
+ * Reads and executes PonderTalk from aPonderTalkString.
+ *
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("readString:")
+ public P2Object readString(P2Object source, String aPonderTalkString)
+ throws Ponder2Exception {
+ String p2xml = P2Compiler.parse(aPonderTalkString);
+ return new XMLParser().execute(source, p2xml);
+ }
+
+ /**
+ * Reads and executes PonderTalk from aPonderTalkString. The parser is
+ * initialised with the variables in the P2Hash varHash
+ *
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("readString:withVars:")
+ public P2Object readString(P2Object source, String aPonderTalkString,
+ P2Hash varHash) throws Ponder2Exception {
+ String p2xml = P2Compiler.parse(aPonderTalkString);
+ return new XMLParser(varHash).execute(source, p2xml);
+ }
+
+ /**
+ * Reads a text file called aFileName into a string and returns it.
+ *
+ * @param aFileName
+ * @return the contents of the file
+ * @throws Ponder2OperationException
+ */
+ @Ponder2op("getFile:")
+ public String getFile(String aFileName) throws Ponder2OperationException {
+ String content;
+ try {
+ InputStream is = Util.getInputStream(new URI(aFileName));
+ int x = is.available();
+ byte b[] = new byte[x];
+ is.read(b);
+ content = new String(b);
+ } catch (Exception e) {
+ throw new Ponder2OperationException(e.getMessage());
+ }
+ return content;
+ }
+
+ /**
+ * Answers aBoolean. Set system tracing on or off.
+ *
+ */
+ @Ponder2op("trace:")
+ protected boolean trace(boolean aBoolean) {
+ SystemTrace = aBoolean;
+ return aBoolean;
+ }
+
+ /**
+ * Answers aString. Displays aString on the console.
+ *
+ */
+ @Ponder2op("print:")
+ protected String print(String aString) {
+ if (SystemTrace)
+ System.out.print("Print: ");
+ System.out.println(aString);
+ return aString;
+ }
+
+ /**
+ * Executes aBlock with no arguments. Answers with the answer from aBlock.
+ * Used to force execution of a block within a particular SMC.
+ *
+ * @throws Ponder2Exception
+ *
+ */
+ @Ponder2op("execute:")
+ protected P2Object execute(P2Object source, P2Block aBlock)
+ throws Ponder2Exception {
+ return aBlock.operation_value0(source);
+ }
+
+ /**
+ * Executes aBlock with the values of its arguments being taken by name from
+ * aHash. Answers the value of the last statement executed by the block.
+ * Throws an error if aHash does not satisfy the block's arguments. Used to
+ * force execution of a block within a particular SMC.
+ *
+ * @throws Ponder2Exception
+ *
+ */
+ @Ponder2op("execute:withHash:")
+ protected P2Object executeHash(P2Object source, P2Block aBlock, P2Hash aHash)
+ throws Ponder2Exception {
+ return aBlock.operation_valueHash(source, aHash);
+ }
+
+ /**
+ * Executes aBlock with anArray of arguments. Answers with the result of the
+ * last statement executed by the block. Used to force execution of a block
+ * within a particular SMC.
+ *
+ * @throws Ponder2Exception
+ *
+ */
+ @Ponder2op("execute:args:")
+ protected P2Object executeArgs(P2Object source, P2Block aBlock,
+ P2Array anArray) throws Ponder2Exception {
+ return aBlock.operation_array(source, anArray);
+ }
+
+ static public boolean getDefaulAuthPolicy() {
+ return defaulAuthPolicy;
+ }
+
+ /**
+ * starts the whole system running and returns the root OID. The root OID
+ * can be useful for starting the SMC from within a Java VM.
+ *
+ * @param args
+ * see doc for argument values and meanings
+ */
+ public static void start(String[] args) {
+
+ // Set the default policy to off unless changed with -auth option
+ String defaultPolicyValue = null;
+ // the name of prolog file that implements the strategy for conflict
+ // resolution.
+ String confStrgFile = null;
+
+ List<String> bootFiles = new Vector<String>();
+ int portBase = port = 13570;
+ boolean multipleSMCs = false;
+ bootFiles.add("boot.p2");
+ SelfManagedCellP2Adaptor smc;
+ try {
+ smc = new SelfManagedCellP2Adaptor(null, "create");
+ } catch (Exception e) {
+ System.out.println("Failed to start SMC: ");
+ e.printStackTrace();
+ return;
+ }
+ int i;
+ for (i = 0; i < args.length; i++) {
+ String arg = args[i];
+ if (arg.startsWith("-")) {
+ // Have we reached the end of the system arguments? i.e. a "-"
+ // by itself
+ if (arg.length() == 1) {
+ // Consume this arg and drop out
+ i++;
+ break;
+ }
+ if (arg.equals("-port"))
+ port = portBase = Integer.parseInt(args[++i]);
+ else if (arg.equals("-boot")) {
+ String bootFile = args[++i];
+ if (bootFile.equals("-"))
+ bootFiles.clear();
+ else {
+ String[] file = bootFile.split(",");
+ for (int j = 0; j < file.length; j++) {
+ bootFiles.add(file[j]);
+ }
+ }
+ } else if (arg.equals("-multiple")) {
+ multipleSMCs = true;
+ } else if (arg.equals("-trace")) {
+ SystemTrace = true;
+ } else if (arg.equals("-loadpath")) {
+ String paths = args[++i];
+ if (paths.equals("-"))
+ Util.setLoadPath(new String[0]);
+ else {
+ String[] path = paths.split(",");
+ for (int j = 0; j < path.length; j++) {
+ Util.addLoadPath(path[j]);
+ }
+ }
+ } else if (arg.equals("-address")) {
+ // This is an address where we can be contacted
+ // Load the protocol and start a receiver
+ String address = args[++i];
+ try {
+ if (address.contains(":"))
+ ExternalManagedObject.loadProtocol(null, address,
+ null);
+ else
+ ExternalManagedObject.loadProtocol(address, null,
+ null);
+ } catch (Ponder2RemoteException e) {
+ System.err.println("Failed to allocate address "
+ + address + ": " + e.getMessage());
+ }
+ } else if (arg.equals("-auth")) {
+ defaultPolicyValue = args[++i];
+ }
+
+ else if (arg.equals("-strategy")) {
+ confStrgFile = args[++i];
+ } else if (arg.equals("-version") || arg.equals("--version")) {
+ System.out.print("Ponder2 Core ");
+ System.out.print(SVNRevision.substring(1,
+ SVNRevision.length() - 2));
+ System.out.print(" ");
+ System.out
+ .print(SVNDate.substring(1, SVNDate.length() - 2));
+ System.out.println();
+ System.exit(0);
+ }
+ // else if (flag.equals("-path")) {
+ // Path path = new Path(args[++i]);
+ // DomainP2Adaptor parent = RootDomain;
+ // for (int p = 1; p < path.size(); p++) {
+ // String pname = path.head(p);
+ // OID newDom = null;
+ // try {
+ // newDom = Util.resolve("/", pname).asOID();
+ // }
+ // catch (Ponder2ArgumentException e) {
+ // }
+ // catch (Ponder2ResolveException e) {
+ // }
+ // if (newDom == null) {
+ // DomainP2Adaptor dom = new DomainP2Adaptor();
+ // parent.add(path.subpath(p - 1, p - 1), dom.getOID());
+ // newDom = dom.getOID();
+ // }
+ // parent = (DomainP2Adaptor)newDom.getManagedObject();
+ // }
+ // parent.add(path.tail(1), smc.getOID());
+ // }
+ }
+ }
+
+ // Move to next argument
+ int argsleft = args.length - i;
+ startupArgsArray = new String[argsleft];
+ startupArgs = new HashMap<String, P2Object>();
+ // Now deal with user arguments, if any.
+ int j = 0;
+ while (i < args.length) {
+ String arg = args[i];
+ startupArgsArray[j] = arg;
+ i++;
+ j++;
+ // We only deal with flagged arguments
+ if (arg.startsWith("-")) {
+ String name = arg.substring(1);
+ String value = "";
+ // Does this arg have a value with it?
+ if (i < args.length && !args[i].startsWith("-")) {
+ value = args[i];
+ startupArgsArray[j] = value;
+ i++;
+ j++;
+ }
+ // Store the arg name and value, if any
+ startupArgs.put(name, P2Object.create(value));
+ }
+
+ }
+
+ if (portBase != 0) {
+ port = Shell.initialise(smc, portBase, multipleSMCs);
+ if (port == 0) {
+ System.err.println("Failed to open port " + portBase + ".");
+ System.err.println("Use -multiple for multiple SMCs");
+ System.err.println("Use -port 0 for no shell access");
+ System.exit(1);
+ }
+ }
+
+ if (defaultPolicyValue != null) {
+
+ isAuthModSet = true; // the authorisation module is going to be
+ // loaded!
+
+ // Set the default policy true otherwise the ponder interpreter
+ // structure cannot be loaded.
+ SelfManagedCell.defaulAuthPolicy = true;
+ BasicAuthModule bAuthMod = new BasicAuthModule(confStrgFile);
+ bAuthMod.setRootDomain(RootDomain);
+ P2ObjectAdaptor.setAuthorisation(bAuthMod);
+ }
+
+ for (String bootfile : bootFiles) {
+ try {
+ Util.parseFile(RootDomain, bootfile);
+ } catch (Ponder2OperationException e) {
+ System.out.println("Ponder2 operation exception: "
+ + e.getMessage());
+ if (SelfManagedCell.SystemTrace)
+ e.printStackTrace();
+ } catch (Ponder2ArgumentException e) {
+ System.out.println("Ponder2 argument exception: "
+ + e.getMessage());
+ if (SelfManagedCell.SystemTrace)
+ e.printStackTrace();
+ } catch (Ponder2Exception e) {
+ System.out.println("Ponder2 exception: " + e.getMessage());
+ if (SelfManagedCell.SystemTrace)
+ e.printStackTrace();
+ }
+ }
+
+ if (defaultPolicyValue != null) {
+ // After building of domain structure we can re-set the default
+ // policy
+ SelfManagedCell.defaulAuthPolicy = defaultPolicyValue
+ .equals("allow");
+ System.out.println("SMC, the default authorization policy is "
+ + (defaulAuthPolicy ? "positive" : "negative"));
+ }
+
+ if (port != 0)
+ System.out.println("Shell port " + port + " ready");
+ }
+
+ /**
+ * starts the whole system running
+ *
+ * @param args
+ * see doc for argument values and meanings
+ */
+ public static void main(String[] args) {
+ SelfManagedCell.start(args);
+ }
+
+ public static Map<String, P2Object> getStartupArgs() {
+ return startupArgs;
+ }
+
+ public static void setStartupArgs(Map<String, P2Object> startupArgs) {
+ SelfManagedCell.startupArgs = startupArgs;
+ }
+
+ public static String[] getStartupArgsArray() {
+ return startupArgsArray;
+ }
+
+ public static void setStartupArgsArray(String[] startupArgsArray) {
+ SelfManagedCell.startupArgsArray = startupArgsArray;
+ }
+
+ public static boolean isSystemTrace() {
+ return SystemTrace;
+ }
+
+ public static void setSystemTrace(boolean systemTrace) {
+ SystemTrace = systemTrace;
+ }
+
+ public static P2Object getRootDomain() {
+ return RootDomain;
+ }
+
+ public static void setRootDomain(P2Object rootDomain) {
+ RootDomain = rootDomain;
+ }
+
+ public static int getPort() {
+ return port;
+ }
+
+ public static void setPort(int port) {
+ SelfManagedCell.port = port;
+ }
+
+ public static boolean isAuthModSet() {
+ return isAuthModSet;
+ }
+
+ public static void setAuthModSet(boolean isAuthModSet) {
+ SelfManagedCell.isAuthModSet = isAuthModSet;
+ }
+
+ public static String getSvndate() {
+ return SVNDate;
+ }
+
+ public static String getSvnrevision() {
+ return SVNRevision;
+ }
+
+ public static String getEventdomain() {
+ return EventDomain;
+ }
+
+ public static String getPolicydomain() {
+ return PolicyDomain;
+ }
+
+ public static void setDefaulAuthPolicy(boolean defaulAuthPolicy) {
+ SelfManagedCell.defaulAuthPolicy = defaulAuthPolicy;
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/Semaphore.java b/ponder2/src/main/java/eu/novi/ponder2/Semaphore.java
new file mode 100644
index 0000000..1d5d5ed
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/Semaphore.java
@@ -0,0 +1,80 @@
+/**
+ * Copyright 2008 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Feb 18, 2010
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2;
+
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.apt.Ponder2op;
+
+/**
+ * A semaphore object to enable synchronisation between managed objects.
+ * Typically used when interacting with GUIs
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class Semaphore implements ManagedObject {
+
+ private java.util.concurrent.Semaphore semaphore;
+
+ /**
+ * Creates a new semaphore with zero permits available. The first acquire
+ * will block the task.
+ */
+ @Ponder2op("create")
+ Semaphore() {
+ this.semaphore = new java.util.concurrent.Semaphore(0);
+ }
+
+ /**
+ * Creates a new semaphore with anInteger permits available.
+ *
+ * @param initial
+ */
+ @Ponder2op("create:")
+ Semaphore(int initial) {
+ this.semaphore = new java.util.concurrent.Semaphore(initial);
+ }
+
+ /**
+ * Tries to acquire a permit. If none are available then the task will hang
+ * until one becomes available
+ */
+ @Ponder2op("wait")
+ protected void acquire() {
+ semaphore.acquireUninterruptibly();
+ }
+
+ /**
+ * Releases the semaphore ay incrementing the number of permits available.
+ * If a task is blocked on this semaphore then that task is released instead
+ * of increasing the number of permits.
+ */
+ @Ponder2op("release")
+ protected void release() {
+ semaphore.release();
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/Shell.java b/ponder2/src/main/java/eu/novi/ponder2/Shell.java
new file mode 100644
index 0000000..6c07b9d
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/Shell.java
@@ -0,0 +1,300 @@
+/**
+ * Created on Jul 9, 2005
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * $Log: Shell.java,v $
+ * Revision 1.38 2006/03/01 22:50:58 kpt
+ * New Version
+ *
+ * Revision 1.37 2006/02/11 16:28:35 kpt
+ * Modified Event creation
+ *
+ * Revision 1.36 2006/01/19 22:28:44 kpt
+ * Allowed parameter substitution with any element
+ *
+ * Revision 1.35 2006/01/15 14:24:03 kpt
+ * New Version Number
+ *
+ * Revision 1.34 2005/12/16 18:01:32 kpt
+ * Fixed new method of send and receive
+ *
+ * Revision 1.33 2005/12/14 12:41:35 kpt
+ * New version number
+ *
+ * Revision 1.32 2005/12/09 10:46:46 kpt
+ * Fixed unknown command bug
+ *
+ * Revision 1.31 2005/11/23 14:47:08 kpt
+ * Removed Iterable from QDParser.
+ *
+ * Revision 1.30 2005/11/20 23:20:54 kpt
+ * Improved startup message
+ *
+ * Revision 1.29 2005/11/20 23:19:06 kpt
+ * Added Id to version string
+ *
+ * Revision 1.28 2005/11/20 13:39:39 kpt
+ * improved the reply mechanism for the shell
+ *
+ * Revision 1.27 2005/11/20 10:58:59 kpt
+ * Upped version number
+ *
+ * Revision 1.26 2005/11/20 10:57:20 kpt
+ * Added managed object commands
+ *
+ * Revision 1.25 2005/11/18 15:17:29 kpt
+ * Added - boot option and . to terminate XML input
+ *
+ * Revision 1.24 2005/11/17 11:36:28 kpt
+ * Added context to many ops for arg substitution
+ *
+ * Revision 1.23 2005/11/14 21:02:22 kpt
+ * Made Result much more pervasive
+ *
+ * Revision 1.22 2005/11/14 13:59:00 kpt
+ * Improved results, fixed TickManager
+ *
+ * Revision 1.21 2005/11/07 12:05:42 kpt
+ * Added Result to the parsing
+ *
+ * Revision 1.20 2005/11/03 04:23:46 kpt
+ * More restore and tidying done
+ *
+ * Revision 1.19 2005/10/29 15:52:19 kpt
+ * Restore almost done
+ *
+ * Revision 1.18 2005/10/28 21:58:00 kpt
+ * Restore almost completed
+ *
+ * Revision 1.17 2005/10/27 16:57:38 kpt
+ * OID separated from P2ManagedObject
+ *
+ * Revision 1.16 2005/10/27 09:25:15 kpt
+ * Dump almost completed. Everything still works!
+ *
+ * Revision 1.15 2005/10/24 20:53:02 kpt
+ * Dump part of dump and restore working
+ *
+ * Revision 1.14 2005/10/22 16:49:46 kpt
+ * Returns results through Reply. Shell does rm properly
+ *
+ * Revision 1.13 2005/10/22 08:53:33 kpt
+ * Changed TaggedElement getAtt to getAttribute
+ *
+ * Revision 1.12 2005/10/21 17:15:48 kpt
+ * Renamed XML Element types
+ *
+ * Revision 1.11 2005/10/21 17:12:55 kpt
+ * Tidied up and made sure demo still worked
+ *
+ * Revision 1.10 2005/10/21 14:31:41 kpt
+ * Changed to faster, meaner, external QDParser with LGPL licence.
+ *
+ * Revision 1.9 2005/10/12 13:45:13 kpt
+ * Changed mkdom to use XML rather than talk straight to a domain
+ *
+ * Revision 1.8 2005/10/11 10:11:40 kpt
+ * First full version of the demo
+ *
+ * Revision 1.7 2005/10/08 23:05:44 kpt
+ * Airline Demonstration almost complete
+ *
+ * Revision 1.6 2005/10/06 10:59:18 kpt
+ * Complete reorganisation of return values using Result.
+ Commands handed to MOs one at a time.
+ *
+ * Revision 1.5 2005/09/22 15:07:25 kpt
+ * Trimed lines on input from telnet session
+ *
+ * Revision 1.4 2005/09/21 08:21:03 kpt
+ * First cut at external objects
+ *
+ * Revision 1.3 2005/09/15 21:02:48 kpt
+ * Improved JAR receipe
+ *
+ * Revision 1.2 2005/09/14 21:22:36 kpt
+ * Added flat bedstation XML
+ *
+ * Revision 1.1 2005/09/12 10:47:08 kpt
+ * Initial Checkin
+ *
+ */
+
+package eu.novi.ponder2;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2ResolveException;
+import eu.novi.ponder2.objects.P2Object;
+
+import eu.novi.ponder2.DomainP2Adaptor;
+import eu.novi.ponder2.SelfManagedCell;
+import eu.novi.ponder2.Shell;
+import eu.novi.ponder2.ShellInstance;
+import eu.novi.ponder2.Util;
+
+/**
+ * The shell is responsible for all the interactions with an interactive user.
+ * The shell parses commands, converts them into XML structures and sends them
+ * to managed objects to be executed.
+ *
+ * @author Kevin Twidle
+ * @version $Id: Shell.java 762 2008-05-22 22:17:15Z Kevin Twidle $
+ */
+public class Shell implements Runnable {
+
+ /**
+ * the socket that the shell communicates through
+ */
+ private ServerSocket ssc;
+ /**
+ * the root domain act as a default for many commands
+ */
+ private static P2Object root;
+
+ /**
+ * the IP port number of this SMC
+ */
+ private int port;
+
+ /**
+ * The location of the /shell domain for shell instances
+ */
+ private P2Object shellDomain = null;
+
+ /**
+ * The count of shells that have connected
+ */
+ private int shellNumber = 0;
+ private static final transient Logger log = LoggerFactory.getLogger(Shell.class);
+ /**
+ * instantiates and sets the shell up to receive connections on the given
+ * port. The shell is run as a separate thread.
+ *
+ * @param root
+ * the root domain for this SMC
+ * @param port
+ * the preferred IP port number to listen on for connections
+ * @return the actual IP port number that was opened for connections
+ */
+ public static int initialise(P2Object root, int port, boolean multipleSMCs) {
+ Shell.root = root;
+ Shell shell = new Shell(port, multipleSMCs);
+ if (shell.port == 0)
+ return 0;
+ Thread tshell = new Thread(shell);
+ tshell.start();
+ return shell.port;
+ }
+
+ /**
+ * creates an instance of the main shell listener. An attempt is made to
+ * open the given IP port but if it is not available then the next port up
+ * is tried. this continues until an available port is opened successfully.
+ *
+ * @param port
+ * the preferred IP port number to listen on
+ */
+ private Shell(int port, boolean multipleSMCs) {
+ super();
+ boolean gotPort = false;
+ while (!gotPort) {
+ try {
+ System.out.println("Shell: trying port " + port);
+ log.info("Shell: trying port " + port);
+ ssc = setup(port);
+ gotPort = true;
+ } catch (IOException e) {
+ if (!multipleSMCs) {
+ port = 0;
+ break;
+ }
+ port++;
+ }
+ }
+ this.port = port;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Runnable#run()
+ */
+ public void run() {
+ if (ssc == null) {
+ System.out.println("No socket for shell");
+ return;
+ }
+ while (true) {
+ Socket sc;
+ try {
+ sc = ssc.accept();
+ // Check /shell exists else create it
+ if (shellDomain == null) {
+ try {
+ shellDomain = Util.resolve("/", "/shell");
+ } catch (Ponder2ResolveException e) {
+ shellDomain = new DomainP2Adaptor(root, "create");
+ SelfManagedCell.RootDomain.operation(root, "at:put:",
+ P2Object.create("shell"), shellDomain);
+ // if an authorisation module is loaded
+ // then we need to read the file that specifies the
+ // authorisation policies for the shell instances
+ if (SelfManagedCell.isAuthModSet)
+ Util.parseFile(SelfManagedCell.RootDomain,
+ "shell-auth.p2");
+ }
+ }
+ Thread thread = new Thread(new ShellInstance(sc, root,
+ shellDomain, ++shellNumber));
+ thread.start();
+ } catch (Ponder2Exception e) {
+ System.err.println("Shell: " + e.getMessage());
+ break;
+ } catch (IOException e) {
+ System.err.println("Shell: socket accept error: "
+ + e.getMessage());
+ break;
+ }
+ }
+
+ }
+
+ /**
+ * opens and binds the server-socket channel
+ *
+ * @param port
+ * the IP port number to be opened
+ * @return the new socket channel
+ * @throws IOException
+ * if the port is not available
+ */
+ public static ServerSocket setup(int port) throws IOException {
+ ServerSocket ssc = new ServerSocket(port);
+ return ssc;
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/ShellInstance.java b/ponder2/src/main/java/eu/novi/ponder2/ShellInstance.java
new file mode 100644
index 0000000..49e9292
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/ShellInstance.java
@@ -0,0 +1,753 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Jul 20, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.net.Socket;
+import java.util.StringTokenizer;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+//import eu.novi.ponder2.Commands;
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.exception.Ponder2ArgumentException;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2OperationException;
+import eu.novi.ponder2.exception.Ponder2ResolveException;
+import eu.novi.ponder2.objects.P2Hash;
+import eu.novi.ponder2.objects.P2Object;
+import eu.novi.ponder2.parser.P2Compiler;
+import eu.novi.ponder2.parser.XMLParser;
+import eu.novi.ponder2.policy.EventListener;
+
+import eu.novi.ponder2.DomainP2Adaptor;
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.P2ObjectAdaptor;
+import eu.novi.ponder2.Path;
+import eu.novi.ponder2.SelfManagedCell;
+import eu.novi.ponder2.ShellInstanceP2Adaptor;
+import eu.novi.ponder2.Util;
+import eu.novi.ponder2.policy.PolicyP2Adaptor;
+
+/**
+ * The actual class that an interactive user interacts with. One ShellInstance
+ * is spawned off in a new thread for each new connection received.
+ *
+ * @author Kevin Twidle
+ * @version $Id: Shell.java 468 2007-07-11 09:51:47Z kpt $
+ */
+public class ShellInstance implements Runnable, ManagedObject {
+ private static final transient Logger log = LoggerFactory.getLogger(ShellInstance.class);
+ /**
+ * the internal commands recognised by the shell
+ */
+ protected static enum Commands {
+ help, read, ls, cd, mkdom, mkdir, md, rm, rmdom, rmdir, rd, mkpolicy, mv, ln, lp, apply, ap, policy, event;
+ }
+
+ /**
+ * the current domain cf current directory in Unix
+ */
+ private P2Object currentDomain;
+ /**
+ * the full path name used to get to the current domain
+ */
+ private Path currentPath;
+ /**
+ * the current command being executed
+ */
+ private String currentCommand;
+ /**
+ * The managed object that represents this shell in the domain structure
+ */
+ private P2Object shellmo;
+ private PrintWriter out;
+ private BufferedReader in;
+ private P2Hash variables;
+ private P2Object root;
+
+ /**
+ * creates a new shell instance with a particular socket to be used for
+ * communication
+ *
+ * @param sc
+ * the socket to be used by this shell instance
+ * @param shellDomain
+ * the default domains for shells
+ * @param shellNumber
+ * the number of this shell connection
+ * @throws Ponder2OperationException
+ * @throws Ponder2ArgumentException
+ */
+ ShellInstance(Socket socket, P2Object root, P2Object shellDomain,
+ int shellNumber) {
+
+ this.root = root;
+
+ // Sort out the I/O streams
+ try {
+ out = new PrintWriter(socket.getOutputStream(), true);
+ in = new BufferedReader(new InputStreamReader(
+ socket.getInputStream()));
+ } catch (IOException e) {
+ System.err.println("Couldn't get I/O for the Shell connection");
+ }
+
+ // Add this new shell to the domain hierarchy
+ ShellInstanceP2Adaptor shellAdaptor = new ShellInstanceP2Adaptor();
+ shellAdaptor.setObj(this);
+ shellmo = shellAdaptor;
+
+ try {
+ shellDomain.operation(SelfManagedCell.RootDomain, "at:put:",
+ P2Object.create("shell" + shellNumber), shellmo);
+ } catch (Ponder2Exception e) {
+ System.err.println("Shell setup error - Should never happen!");
+ e.printStackTrace();
+ }
+
+ // Set up our initial values
+ currentDomain = root;
+ currentPath = new Path("/");
+
+ // Persistent variables for this instance of the shell
+ variables = new P2Hash();
+ variables.put("Variables", variables);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Runnable#run()
+ */
+ public void run() {
+ try {
+
+ out.print("Ponder2 Shell "
+ + SelfManagedCell.SVNRevision.substring(1,
+ SelfManagedCell.SVNRevision.length() - 2)
+ + " "
+ + SelfManagedCell.SVNDate.substring(1,
+ SelfManagedCell.SVNDate.length() - 2)
+ + "\r\nNo wild chars yet\r\n");
+ log.info("Ponder2 Shell "
+ + SelfManagedCell.SVNRevision.substring(1,
+ SelfManagedCell.SVNRevision.length() - 2)
+ + " "
+ + SelfManagedCell.SVNDate.substring(1,
+ SelfManagedCell.SVNDate.length() - 2)
+ + "\r\nNo wild chars yet\r\n");
+
+ StringBuffer buffer = new StringBuffer();
+ while (true) {
+ buffer.setLength(0);
+ out.print(currentPath + " $ ");
+ out.flush();
+ String line = in.readLine();
+ if (line == null)
+ break;
+ line = trim(line);
+
+ String result;
+ try {
+ try {
+ result = doCommand(line);
+ } catch (IllegalArgumentException e) {
+ result = doPonderTalk(line);
+ }
+ } catch (Ponder2Exception e) {
+ System.out.println("Ponder2 Exception: " + e.getMessage());
+ log.info("Ponder2 Exception: " + e.getMessage());
+ if (SelfManagedCell.SystemTrace)
+ e.printStackTrace();
+
+ Writer writer = new StringWriter();
+ PrintWriter printWriter = new PrintWriter(writer);
+ e.printStackTrace(printWriter);
+ log.info("Command failed:" + e);
+ log.info("Failure is:"+ writer.toString());
+ result = "Command failed:" + e;
+ } catch (Exception e) {
+ //e.printStackTrace();
+ Writer writer = new StringWriter();
+ PrintWriter printWriter = new PrintWriter(writer);
+ e.printStackTrace(printWriter);
+ log.info("Command failed:" + e);
+ log.info("Failure is:"+writer.toString());
+ result = "Command failed:" + e;
+ }
+
+ if (result != null && result.length() > 0
+ && result.charAt(result.length() - 1) != '\n')
+ result = result + "\r\n";
+ out.print(result);
+ log.info(result);
+ out.flush();
+ }
+ } catch (Exception e) {
+ System.out.println("Shell exception - " + e.getMessage());
+ log.info("Shell exception - " + e.getMessage());
+ }
+ System.out.println("Lost connection");
+ log.info("Lost connection");
+ try {
+ in.close();
+ } catch (IOException e1) {
+ }
+ out.close();
+ }
+
+ private String doPonderTalk(String line) throws Ponder2Exception {
+ StringBuffer buffer = new StringBuffer(line);
+ while (buffer.charAt(buffer.length() - 1) != '.') {
+ try {
+ out.print(currentPath + " [PonderTalk or . ] $ ");
+ log.info(currentPath + " [PonderTalk or . ] $ ");
+ out.flush();
+ line = in.readLine();
+ System.out.println(line);
+ log.info(line + "\n");
+ buffer.append('\n');
+ buffer.append(trim(line));
+ } catch (IOException e) {
+ log.info(e.getMessage());
+ throw new Ponder2ArgumentException("Caught IO Exception: "
+ + e.getMessage());
+ }
+ }
+ // We have reached the end the PonderTalk
+ String p2xml = P2Compiler.parse(buffer.toString());
+ P2Object value = new XMLParser(variables).execute(shellmo, p2xml);
+ return value != null ? value.toString() : "";
+ }
+
+ private String trim(String line) throws IOException {
+ StringBuffer buf = new StringBuffer();
+ int lindex = 0;
+ while (lindex < line.length()) {
+ char ch = line.charAt(lindex);
+ // System.out.print((0 + ch) + " ");
+ if (ch > 512) {
+ throw new IOException("bad character");
+ } else if (ch == 0x03 || ch == 0x04 || ch == 0x1a)
+ throw new IOException("EOF Character");
+ else if (ch == 0x08) {
+ // Backspace
+ if (buf.length() > 0)
+ buf.setLength(buf.length() - 1);
+ } else {
+ buf.append(ch);
+ }
+ lindex++;
+ }
+ return buf.toString().trim();
+ }
+
+ /**
+ * executes a command once it has been read in
+ *
+ * @param line
+ * @return
+ * @throws Ponder2Exception
+ */
+ private String doCommand(String line) throws IllegalArgumentException,
+ Ponder2Exception {
+ String output = "";
+ StringTokenizer st = new StringTokenizer(line);
+ if (st.countTokens() <= 0)
+ return output;
+ currentCommand = st.nextToken();
+ if (currentCommand.startsWith("#"))
+ return output;
+ System.out.println("Command is " + currentCommand);
+ log.info("Command is " + currentCommand);
+ switch (Commands.valueOf(currentCommand)) {
+ // List
+ case ls:
+ output = doCommandLS(st);
+ break;
+ // Change Directory
+ case cd:
+ output = doCommandCD(st);
+ break;
+ // Make domain
+ case mkdom:
+ case mkdir:
+ case md:
+ output = doCommandMKDOM(st);
+ break;
+ // Remove domain or object
+ case rmdom:
+ case rmdir:
+ case rd:
+ case rm:
+ output = doCommandRM(st);
+ break;
+ // Move
+ // case mv:
+ // result = doCommandMV(st);
+ // break;
+ // Apply policy
+ case ap:
+ case apply:
+ output = doCommandAP(st);
+ break;
+ // List Policies
+ case lp:
+ output = doCommandLP(st);
+ break;
+ case event:
+ output = doCommandEvent(st);
+ break;
+ case read:
+ output = doCommandRead(st);
+ break;
+ // Help
+ case help:
+ output = doCommandHelp(st);
+ break;
+ default:
+ output = currentCommand + ": Unimplemented command";
+ }
+ return output;
+ }
+
+ /**
+ * applies a named policy to a named managed object
+ *
+ * @param st
+ * the string tokenizer to enable the arguments to be read and
+ * consumed
+ * @param result
+ * the standard result structure for OIDs and errors
+ * @return any errors generated as a string
+ * @throws Ponder2Exception
+ */
+ private String doCommandAP(StringTokenizer st) throws Ponder2Exception {
+ // TODO should use result
+ StringBuffer output = new StringBuffer();
+ if (st.countTokens() < 2) {
+ return currentCommand + ": not enough arguments";
+ }
+
+ // Find the policy
+ String policyName = st.nextToken();
+ P2Object pvalue;
+ try {
+ pvalue = Util.resolve(currentDomain, policyName);
+ } catch (Ponder2ResolveException e) {
+ // It may be in the Policy domain
+ try {
+ pvalue = Util.resolve(currentDomain, "/policy/" + policyName);
+ } catch (Ponder2ResolveException e1) {
+ return policyName + ": policy not found";
+ }
+ }
+
+ // We do actually have a policy, don't we?
+ if (!(pvalue instanceof PolicyP2Adaptor)) {
+ return policyName + ": not a policy";
+ }
+
+ PolicyP2Adaptor policy = (PolicyP2Adaptor) pvalue;
+
+ // Ok, now deal with the objects that this policy is to be applied to
+ while (st.hasMoreTokens()) {
+ String arg = st.nextToken();
+ P2Object mo = Util.resolve(currentDomain, arg);
+ if (mo != null)
+ mo.getManagedObject().applyPolicy(
+ (EventListener) policy.getObj());
+ else {
+ output.append(arg + ": not found\r\n");
+ }
+ }
+ return output.toString();
+ }
+
+ /**
+ * changes the curent domain. The current domain is used as a starting point
+ * for many other commands involving names of managed objects.
+ *
+ * @param st
+ * the string tokenizer to enable the arguments to be read and
+ * consumed
+ * @param result
+ * the standard result structure for OIDs and errors
+ * @return any errors that might be flagged
+ * @throws Ponder2Exception
+ */
+ private String doCommandCD(StringTokenizer st) throws Ponder2Exception {
+ // TODO should use result
+ String output = "";
+ switch (st.countTokens()) {
+ case 0:
+ currentDomain = root;
+ break;
+ case 1:
+ String arg = st.nextToken();
+ P2Object p2Object = Util.resolve(currentPath.toString(), arg);
+ if (p2Object == null) {
+ output = currentCommand + ": " + arg + " does not exist";
+ } else if (p2Object.getOID().isDomain()) {
+ currentDomain = p2Object;
+ currentPath.add(arg);
+ } else {
+ output = currentCommand + ": " + arg + " is not a domain";
+ }
+ break;
+ default:
+ output = currentCommand + ": too many parameters";
+ }
+ return output;
+ }
+
+ /**
+ * creates an event with arguments
+ *
+ * @param st
+ * the string tokenizer to enable the arguments to be read and
+ * consumed
+ * @return any errors that may have occured
+ * @throws Ponder2Exception
+ */
+ private String doCommandEvent(StringTokenizer st) throws Ponder2Exception {
+ StringBuffer pondertalk = new StringBuffer();
+ if (!st.hasMoreTokens()) {
+ throw new Ponder2ArgumentException(
+ "usage: event <event name> args ...");
+ }
+ String eventTemplate = st.nextToken();
+ while (st.hasMoreTokens()) {
+ pondertalk.append(' ');
+ pondertalk.append(st.nextToken());
+ }
+ return doPonderTalk("root/event/" + eventTemplate + " create: #( "
+ + pondertalk + " ).");
+ }
+
+ /**
+ * lists the command help information for interactive use with the shell
+ *
+ * @param st
+ * the string tokenizer to enable the arguments to be read and
+ * consumed
+ * @return the help information as a printable string
+ */
+ private String doCommandHelp(StringTokenizer st) {
+ String result = "";
+ result += "cd [dom]\r\n";
+ result += " Change Directory\r\n";
+ result += "help\r\n";
+ result += " Help\r\n";
+ result += "ln obj ... dom or ln obj obj\r\n";
+ result += " Link\r\n";
+ result += "ls [-l] [obj ...]\r\n";
+ result += " List\r\n";
+ result += "mkdom dom ...\r\n";
+ result += " Make Domain\r\n";
+ result += "rm [-f] obj ...\r\n";
+ result += " Remove\r\n";
+ result += "ap policy obj ...\r\n";
+ result += " Apply Policy\r\n";
+ result += "lp [obj ...]\r\n";
+ result += " List Policy\r\n";
+ result += "event <template name> [arg ...]\r\n";
+ result += " Create event\r\n";
+ result += "policy +|-[event] [policy ...]\r\n";
+ result += " Manipulate policy\r\n";
+ result += "<objPathName> [att=val ...] [sub command [att=val ...]]\r\n";
+ result += " Send command to object\r\n";
+ return result;
+ }
+
+ /**
+ * executes the list managed object command
+ *
+ * @param st
+ * the string tokenizer to enable the arguments to be read and
+ * consumed
+ * @param result
+ * the standard result structure for OIDs and errors
+ * @return the output string ready for display
+ * @throws Ponder2Exception
+ */
+ private String doCommandLS(StringTokenizer st) throws Ponder2Exception {
+ StringBuffer output = new StringBuffer();
+ boolean longForm = false;
+ boolean doneOne = false;
+ while (st.hasMoreTokens()) {
+ String arg = st.nextToken();
+ if (arg.equals("-l")) {
+ longForm = true;
+ continue;
+ }
+ try {
+ P2Object oid = Util.resolve(currentDomain, arg);
+ doCommandLS(output, arg, oid, longForm);
+ } catch (Ponder2ResolveException e) {
+ output.append(arg + ": not found");
+ output.append("\r\n");
+ }
+ doneOne = true;
+ }
+ if (!doneOne) {
+ doCommandLS(output, currentPath.toString(), currentDomain, longForm);
+ }
+ return output.toString();
+ }
+
+ /**
+ * list information about a managed object. If the managed object is a
+ * domain the all the domain's managed objects are listed instead.
+ *
+ * @param output
+ * the buffer for adding printable output to
+ * @param name
+ * the name of the managed object being listed
+ * @param oid
+ * the OID of the managed object being listed
+ * @param longForm
+ * true if longform (-l) output is required
+ * @param result
+ * the standard result structure for OIDs and errors
+ * @throws Ponder2Exception
+ */
+ private void doCommandLS(StringBuffer output, String name, P2Object oid,
+ boolean longForm) throws Ponder2Exception {
+ if (!oid.getOID().isDomain()) {
+ doCommandLSwrite(output, name, oid, longForm);
+ } else {
+ // Run through the domain, it may be remote
+ P2ObjectAdaptor domain = (P2ObjectAdaptor) oid;
+ P2Object[] names = domain.operation(shellmo, "listNames").asArray();
+ for (int i = 0; i < names.length; i++) {
+ P2Object child = names[i];
+ P2Object object = domain.operation(shellmo, "at:", child);
+ doCommandLSwrite(output, child.asString(), object, longForm);
+ }
+ }
+ }
+
+ /**
+ * writes information about a managed object as a string
+ *
+ * @param output
+ * the buffer for adding printable output to
+ * @param name
+ * the name of the managed object being listed
+ * @param oid
+ * the OID of the managed object being listed
+ * @param longForm
+ * true if longform (-l) output is required
+ */
+ private void doCommandLSwrite(StringBuffer output, String name,
+ P2Object oid, boolean longForm) {
+ if (!longForm) {
+ output.append(name);
+ if (oid.getOID().isDomain())
+ output.append("/");
+ } else {
+ output.append(name);
+ output.append(": ");
+ output.append(oid.getManagedObject().getP2Object().getClass()
+ .toString());
+ output.append("\r\n");
+ output.append(oid.getOID().toXML());
+ }
+ output.append("\r\n");
+ }
+
+ /**
+ * lists the policies applying to events generated by a managed object
+ *
+ * @param st
+ * the string tokenizer to enable the arguments to be read and
+ * consumed
+ * @param result
+ * the standard result structure for OIDs and errors
+ * @return a list of policies in printable form
+ * @throws Ponder2Exception
+ */
+ private String doCommandLP(StringTokenizer st) throws Ponder2Exception {
+ StringBuffer output = new StringBuffer();
+ boolean doneOne = false;
+ while (st.hasMoreTokens()) {
+ String name = st.nextToken();
+ try {
+ P2Object oid = Util.resolve(currentDomain, name);
+ doCommandLP(output, name, oid);
+ } catch (Ponder2ResolveException e) {
+ output.append(name + ": not found");
+ output.append("\r\n");
+ }
+ doneOne = true;
+ }
+
+ if (!doneOne) {
+ doCommandLP(output, currentPath.toString(), currentDomain);
+ }
+ return output.toString();
+ }
+
+ /**
+ * lists a single policy and its contents
+ *
+ * @param output
+ * the buffer for adding printable output to
+ * @param name
+ * the name of the policy being listed
+ * @param oid
+ * the OID of the policy being listed
+ */
+ private void doCommandLP(StringBuffer output, String name, P2Object oid) {
+ output.append(name);
+ output.append(": ");
+ output.append(oid.getClass().toString());
+ for (EventListener policy : oid.getManagedObject().getEventListeners()) {
+ output.append("\r\n" + " -> ");
+ output.append(policy.toString());
+ }
+ output.append("\r\n");
+ }
+
+ /**
+ * creates a new domain and places it into the domain structure
+ *
+ * @param st
+ * the string tokenizer to enable the arguments to be read and
+ * consumed
+ * @param result
+ * the standard result structure for OIDs and errors
+ * @return
+ * @throws Ponder2Exception
+ */
+ private String doCommandMKDOM(StringTokenizer st) throws Ponder2Exception {
+ String output = "";
+ while (st.hasMoreTokens()) {
+ String arg = st.nextToken();
+ Path path = new Path(arg);
+ P2Object p2Object;
+ try {
+ p2Object = Util.resolve(currentDomain, path);
+ output = output + arg + " already exists\r\n";
+ continue;
+ } catch (Ponder2ResolveException e) {
+ }
+ Path parent = path.parent();
+ try {
+ p2Object = Util.resolve(currentDomain, parent);
+ } catch (Ponder2ResolveException e) {
+ output = output + arg + ": cannot access parent domain\r\n";
+ continue;
+ }
+ if (!p2Object.getOID().isDomain()) {
+ output += path.toString() + "is not a domain\r\n";
+ continue;
+ }
+
+ DomainP2Adaptor adaptor = new DomainP2Adaptor(shellmo, "create");
+ p2Object.operation(shellmo, "at:put:",
+ P2Object.create(path.child()), adaptor);
+ }
+ return output;
+ }
+
+ /**
+ * reads XML structure commands from a file or resource
+ *
+ * @param st
+ * the string tokenizer to enable the arguments to be read and
+ * consumed
+ * @return any errors returned in the result structure or and empty string
+ * @throws Ponder2Exception
+ */
+ private String doCommandRead(StringTokenizer st) throws Ponder2Exception {
+ while (st.hasMoreTokens()) {
+ String file = st.nextToken();
+ Util.parseFile(shellmo, file);
+ }
+ return "";
+ }
+
+ /**
+ * removes an object from a domain. Domains are only removed if the -f flag
+ * is given.
+ *
+ * @param st
+ * the string tokenizer to enable the arguments to be read and
+ * consumed
+ * @param result
+ * the standard result structure for OIDs and errors
+ * @return any errors that might be flagged
+ * @throws Ponder2Exception
+ */
+ private String doCommandRM(StringTokenizer st) throws Ponder2Exception {
+ String output = "";
+ while (st.hasMoreTokens()) {
+ String arg = st.nextToken();
+ Path path = new Path(arg);
+ P2Object mo;
+ try {
+ mo = Util.resolve(currentDomain, path);
+ } catch (Ponder2ResolveException e) {
+ output = output + arg + " not found\r\n";
+ continue;
+ }
+ // Check we can access the parent
+ Path parent = path.parent();
+ try {
+ mo = Util.resolve(currentDomain, parent);
+ } catch (Ponder2ResolveException e) {
+ output = output + arg + ": cannot access parent domain\r\n";
+ continue;
+ }
+ // Check that the parent is a domain
+ if (!mo.getOID().isDomain()) {
+ output += path.toString() + "is not a domain\r\n";
+ continue;
+ }
+ // Ok, send the unlink command
+ mo.operation(shellmo, "remove:", P2Object.create(path.child()));
+ }
+ return output;
+ }
+
+ /**
+ * Dummy operation to make sure Eclipse gives this file to the APT compiler
+ */
+ @Ponder2op("no op")
+ public void dummyop() {
+ };
+
+} \ No newline at end of file
diff --git a/ponder2/src/main/java/eu/novi/ponder2/StartStopPonder2SMC.java b/ponder2/src/main/java/eu/novi/ponder2/StartStopPonder2SMC.java
new file mode 100644
index 0000000..64b855c
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/StartStopPonder2SMC.java
@@ -0,0 +1,181 @@
+package eu.novi.ponder2;
+import java.rmi.RMISecurityManager;
+import java.util.Collection;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import eu.novi.ponder2.P2ObjectAdaptor.InstanceOperation;
+import eu.novi.ponder2.exception.Ponder2ArgumentException;
+import eu.novi.ponder2.exception.Ponder2AuthorizationException;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.interactions.CallstoIRM;
+import eu.novi.ponder2.objects.P2Object;
+import eu.novi.ponder2.policy.AuthPolicyHolder;
+import eu.novi.ponder2.policy.AuthPolicySearch;
+import eu.novi.ponder2.policy.AuthorisationModule;
+import eu.novi.ponder2.policy.Event;
+import eu.novi.ponder2.policy.StaticAuthPolicySearch;
+//import eu.novi.resources.discovery.remote.discovery.Testbeds;
+//import eu.novi.resources.discovery.util.Testbeds;
+
+public class StartStopPonder2SMC implements SMCStartInterface{
+ private static String testbed;
+ private static final transient Logger log = LoggerFactory.getLogger(StartStopPonder2SMC.class);
+ /**
+ * Initialize SMC
+ */
+ public void start(){
+ // System.setProperty("java." );
+ //System.setProperty("java.rmi.server.codebase", "..\\lib\\ponder2.jar c:\\Users\\Administrator\\Documents\\gitPSNC\\novi\\Software\\ponder2\\lib\\ponder2comms.jar");
+ //System.setProperty("address", "rmi://localhost/MyPonderPL");
+ /* if (System.getSecurityManager()!=null){
+ log.info("O Security Manager einai: "+System.getSecurityManager().toString());
+ }
+ else
+ {
+ log.info("O Security Manager einai: NULLLLLLL");
+ RMISecurityManager SecMan= new RMISecurityManager();
+ System.setSecurityManager(SecMan);
+ log.info("O Security Manager einai: "+System.getSecurityManager().toString());
+ }
+ log.info(System.getProperties().toString());*/
+ //System.ge
+ if (testbed == null)
+ {
+ log.warn("The testbed values is null.");
+ }
+ else if (testbed.contains("PlanetLab"))
+ {
+ String[] argsPL={"-multiple","-port","13570","-auth","allow","-boot","boot.p2,nodemo.p2,linkmo.p2,topologymo.p2,virtualnodemo.p2,users.p2,roles.p2,authpolicy.p2,talkPL.p2,platformmoPL.p2,bootmissionNOVI.p2,planetlabmission2.p2","-address","rmi://150.254.160.28:1113/Ponder2PL"};
+ //,"-address","rmi://localhost/Ponder2PL"
+ log.info("StartStopPonder2SMC.start(): Starting SelfManagedCell on PlanetLab side");
+ SelfManagedCell.start(argsPL);
+ try {
+ log.info("Sleeping for 100 seconds to give time for the init Policy Manager");
+ Thread.sleep(100000);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ log.info("Calling Policy Manager for the init");
+ CallstoIRM.initThePonder();
+ }
+ else if (testbed.contains("FEDERICA"))
+ {
+ String[] argsFED={"-multiple","-port","13570","-auth","allow","-boot","boot.p2,nodemo.p2,linkmo.p2,topologymo.p2,virtualnodemo.p2,roles.p2,users.p2,authpolicy.p2,talkFED.p2,platformmoFED.p2,bootmissionNOVI.p2,federicamission2.p2","-address","rmi://194.132.52.214:1113/Ponder2FED"};
+ //,"-address","rmi://localhost/Ponder2FED"
+ log.info("StartStopPonder2SMC.start(): Starting SelfManagedCell on FEDERICA side");
+ SelfManagedCell.start(argsFED);
+ }
+ else
+ {
+ log.warn("The testbed values is {}. It is not accepted by Ponder2", testbed);
+ }
+ }
+
+ public void stop(){
+ log.info("StartStopPonder2SMC.stop(): Stop SelfManagedCell");
+ //SelfManagedCell.exit();
+ }
+
+
+ /*public Node createNode(String aName, String aSlice)
+ {
+ String aPlatform="PlanetLab";
+ Node newNode = new Node(aName,aPlatform,aSlice);
+ return newNode;
+
+ }*/
+
+ /* // Ponder2 call to inject an event
+ operation.put("Ponder2.event:", new InstanceOperation() {
+
+ @Override
+ public P2Object call(P2Object thisObj, ManagedObject obj,
+ P2Object source, String operation, P2Object... args)
+ throws Ponder2Exception {
+ P2Object event = args[0];
+ if (event instanceof Event) {
+ thisObj.getManagedObject().sendEvent((Event) event);
+ } else
+ throw new Ponder2ArgumentException(
+ "Ponder2.event: Object is not of type Event - "
+ + event.getClass());
+ return thisObj;
+ }
+ });*/
+
+ public P2Object createEvent(P2Object thisObj, ManagedObject obj,
+ P2Object source, String operation, P2Object... args)
+ throws Ponder2Exception {
+ P2Object event = args[0];
+ if (event instanceof Event) {
+ thisObj.getManagedObject().sendEvent((Event) event);
+ } else
+ throw new Ponder2ArgumentException(
+ "Ponder2.event: Object is not of type Event - "
+ + event.getClass());
+ return thisObj;
+
+ }
+ /**
+ *Stop the SMC service.
+ */
+ /*public void destroyDatabase()
+ {
+ SelfManagedCell.stop());
+ }*/
+
+ public Boolean searchauth(P2Object myP2Object, P2Object resource)
+ {
+
+ try {
+ resource.operation(myP2Object, "access");
+ return true;
+
+ } catch (Ponder2AuthorizationException e) {
+ return false;
+ } catch (Ponder2Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ System.out.println("We shouldn't be here");
+ return false;
+
+
+
+ }
+
+ public Boolean searchauth(AuthPolicyHolder holder, short pepType,
+ P2Object subject, P2Object target, String action, char focus,
+ P2Object[] args, P2Object result) {
+ AuthPolicySearch aps = new StaticAuthPolicySearch();
+ short auth = aps.search(holder, pepType, subject, target, action, focus, args, result);
+ if (auth == AuthPolicySearch.AUTH)
+ {
+ return true;
+ }
+ if (auth ==AuthPolicySearch.NOTAUTH)
+ {
+ return false;
+ }
+ if (auth ==AuthPolicySearch.POL_NOT_DEFINED)
+ {
+ System.out.println("The policy is not defined so we supposed it is true");
+ return true;
+ }
+ return null;
+
+ }
+ public String getTestbed() {
+ return testbed;
+ }
+
+ public void setTestbed(String testbed) {
+ this.testbed = testbed;
+ }
+
+
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/Timer.java b/ponder2/src/main/java/eu/novi/ponder2/Timer.java
new file mode 100644
index 0000000..3006f9d
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/Timer.java
@@ -0,0 +1,234 @@
+/**
+ * Copyright � 2008 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ */
+package eu.novi.ponder2;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+
+//import eu.novi.ponder2.Ticker;
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.exception.Ponder2ArgumentException;
+import eu.novi.ponder2.objects.P2Hash;
+import eu.novi.ponder2.objects.P2Object;
+
+import eu.novi.ponder2.ManagedObject;
+
+/**
+ * Implements a multiple timer. Events may be fired off at regular intervals or
+ * after a single interval. <br>
+ * Time can be given in milliseconds as a simple number or as hh:mm:ss. e.g.
+ * 0:22 would be 22 seconds.<br>
+ * If the event is declared with a count attribute then the attribute will be
+ * set to the event number before each event is sent.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class Timer implements ManagedObject {
+
+ Map<Integer, Ticker> tickers;
+ int index;
+
+ /**
+ * Creates a new timer managed object
+ */
+ @Ponder2op("create")
+ Timer() {
+ tickers = new HashMap<Integer, Ticker>();
+ index = 0;
+ }
+
+ /**
+ * sets up and starts a one off timer. Sends the event after the specified
+ * time.
+ *
+ * @param time
+ * the time before the event is sent
+ * @param event
+ * the event to send
+ * @return the timer's index for later stopping or restarting
+ * @throws Ponder2ArgumentException
+ */
+ @Ponder2op("tick:event:")
+ protected int tick(P2Object source, String time, P2Object event)
+ throws Ponder2ArgumentException {
+ Ticker ticker = new Ticker(source, false, time, event);
+ return add(ticker);
+ }
+
+ /**
+ * sets up and starts a repetitive timer that send the event periodically.
+ *
+ * @param time
+ * the time before the event is sent
+ * @param event
+ * the event to send
+ * @return the timer's index for later stopping or restarting
+ * @throws Ponder2ArgumentException
+ */
+ @Ponder2op("repeat:event:")
+ protected int repeat(P2Object source, String time, P2Object event)
+ throws Ponder2ArgumentException {
+ Ticker ticker = new Ticker(source, true, time, event);
+ return add(ticker);
+ }
+
+ private synchronized int add(Ticker ticker) {
+ index++;
+ tickers.put(index, ticker);
+ return index;
+ }
+
+ /**
+ * starts the timer at anIndex
+ *
+ * @param anIndex
+ * the index of the timer to be started
+ */
+ @Ponder2op("start:")
+ protected void start(int anIndex) {
+ Ticker ticker = tickers.get(anIndex);
+ if (ticker != null)
+ ticker.start();
+ }
+
+ /**
+ * stops the timer at anIndex
+ *
+ * @param anIndex
+ * the index of the timer to be stopped
+ */
+ @Ponder2op("stop:")
+ protected void stop(int anIndex) {
+ Ticker ticker = tickers.get(anIndex);
+ if (ticker != null)
+ ticker.stop();
+ }
+
+ /**
+ * stops and cancels all the timers. The indexes are invalid after this
+ * operation.
+ */
+ @Ponder2op("cancel")
+ protected void cancel() {
+ for (Iterator<Map.Entry<Integer, Ticker>> iterator = tickers.entrySet()
+ .iterator(); iterator.hasNext();) {
+ Map.Entry<Integer, Ticker> entry = iterator.next();
+ entry.getValue().stop();
+ iterator.remove();
+ }
+ }
+
+ /**
+ * stops and cancels the timer at anIndex. anIndex cannot be used again.
+ *
+ * @param anIndex
+ */
+ @Ponder2op("cancel:")
+ protected void cancel(int anIndex) {
+ Ticker ticker = tickers.remove(anIndex);
+ if (ticker != null)
+ ticker.stop();
+ }
+
+ private static long decode(String time) throws Ponder2ArgumentException {
+ try {
+ String[] times = time.split(":");
+ if (times.length == 0)
+ throw new Ponder2ArgumentException("Bad time string: " + time);
+ if (times.length == 1)
+ return Long.parseLong(time);
+
+ // Ok we must have hh:mm:ss or something like it.
+ long msecs = 0;
+ for (String number : times) {
+ msecs = msecs * 60 + Long.parseLong(number);
+ }
+ return msecs * 1000;
+ } catch (NumberFormatException e) {
+ throw new Ponder2ArgumentException("Bad time string: " + time);
+ }
+ }
+
+ public class Ticker implements Runnable {
+ boolean repeat;
+ boolean running;
+ long count = 1;
+ private final P2Object event;
+ private final P2Object source;
+ private final long msecs;
+ private Thread thread;
+
+ Ticker(P2Object source, boolean repeat, String time, P2Object event)
+ throws Ponder2ArgumentException {
+ this.repeat = repeat;
+ running = false;
+ this.source = source;
+ this.msecs = decode(time);
+ this.event = event;
+ start();
+ }
+
+ public void start() {
+ if (!running) {
+ thread = new Thread(this);
+ thread.start();
+ }
+ }
+
+ public void stop() {
+ running = false;
+ if (thread != null)
+ thread.interrupt();
+ }
+
+ public boolean isRunning() {
+ return running;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Runnable#run()
+ */
+ public void run() {
+ P2Hash hash = new P2Hash();
+ running = repeat;
+ while (true) {
+ try {
+ Thread.sleep(msecs);
+ hash.put("count", P2Object.create(count++));
+ event.operation(source, "fromHash:", hash);
+ } catch (Exception e) {
+ // System.err
+ // .println("Timer thread caught error, terminating: "
+ // + e.getMessage());
+ running = false;
+ }
+ if (!running)
+ break;
+ }
+ }
+ }
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/Util.java b/ponder2/src/main/java/eu/novi/ponder2/Util.java
new file mode 100644
index 0000000..16f3218
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/Util.java
@@ -0,0 +1,572 @@
+/**
+ * Created on Jul 27, 2005
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * $Log: Util.java,v $
+ * Revision 1.19 2006/03/15 13:36:42 kpt
+ * Lots of testing stuff and new XMLSaver managed object
+ *
+ * Revision 1.18 2006/03/01 22:57:32 kpt
+ * Added remote execution of external xml via RMI
+ *
+ * Revision 1.17 2006/01/19 22:28:44 kpt
+ * Allowed parameter substitution with any element
+ *
+ * Revision 1.16 2005/12/09 10:34:38 kpt
+ * Policy actions sorted out
+ *
+ * Revision 1.15 2005/11/23 14:47:07 kpt
+ * Removed Iterable from QDParser.
+ *
+ * Revision 1.14 2005/11/20 13:06:17 kpt
+ * Import returns error if not found
+ *
+ * Revision 1.13 2005/11/19 18:05:10 kpt
+ * eval tries resource then file
+ *
+ * Revision 1.12 2005/11/19 16:58:52 kpt
+ * Only call execute if the use has attributes or child elements for the MO
+ *
+ * Revision 1.11 2005/11/19 12:12:54 kpt
+ * Added error returns for <use>
+ *
+ * Revision 1.10 2005/11/18 10:44:55 kpt
+ * Added trace. Tweaked boot.xml
+ *
+ * Revision 1.9 2005/11/17 11:36:28 kpt
+ * Added context to many ops for arg substitution
+ *
+ * Revision 1.8 2005/11/15 16:33:25 kpt
+ * Result added to create
+ *
+ * Revision 1.7 2005/11/15 15:00:51 kpt
+ * ExecuteSetup introduced, more result feedback
+ *
+ * Revision 1.6 2005/11/14 21:02:21 kpt
+ * Made Result much more pervasive
+ *
+ * Revision 1.5 2005/11/13 23:27:30 kpt
+ * Added time manager
+ *
+ * Revision 1.4 2005/11/12 18:02:23 kpt
+ * Sorted out return values from managed objects. MO conditions now work
+ *
+ * Revision 1.3 2005/11/07 12:05:42 kpt
+ * Added Result to the parsing
+ *
+ * Revision 1.2 2005/10/29 15:52:19 kpt
+ * Restore almost done
+ *
+ * Revision 1.1 2005/10/28 21:58:00 kpt
+ * Restore almost completed
+ *
+ * Revision 1.21 2005/10/27 16:57:38 kpt
+ * OID separated from P2ManagedObject
+ *
+ * Revision 1.20 2005/10/27 09:25:15 kpt
+ * Dump almost completed. Everything still works!
+ *
+ * Revision 1.19 2005/10/24 20:53:02 kpt
+ * Dump part of dump and restore working
+ *
+ * Revision 1.18 2005/10/22 08:53:33 kpt
+ * Changed TaggedElement getAtt to getAttribute
+ *
+ * Revision 1.17 2005/10/21 17:15:48 kpt
+ * Renamed XML Element types
+ *
+ * Revision 1.16 2005/10/21 17:12:55 kpt
+ * Tidied up and made sure demo still worked
+ *
+ * Revision 1.15 2005/10/21 14:31:41 kpt
+ * Changed to faster, meaner, external QDParser with LGPL licence.
+ *
+ * Revision 1.14 2005/10/19 21:58:19 kpt
+ * Removed NormalEOFException
+ *
+ * Revision 1.13 2005/10/17 14:55:35 kpt
+ * Fixed problem where eval did not return an OID
+ *
+ * Revision 1.12 2005/10/12 15:20:00 kpt
+ * Logs sensible error to console if file to be read is missing
+ *
+ * Revision 1.11 2005/10/11 10:10:00 kpt
+ * Fixed null return from parsing.
+ Added -name argument substitution
+ *
+ * Revision 1.10 2005/10/10 04:28:59 kpt
+ * Improved external use. Assume local unless remote specified
+ *
+ * Revision 1.9 2005/10/09 22:03:04 kpt
+ * First complete version of demo with a few fixes.
+ Local evaluation added on demand before shipping xml for export.
+ *
+ * Revision 1.8 2005/10/06 10:59:18 kpt
+ * Complete reorganisation of return values using Result.
+ Commands handed to MOs one at a time.
+ *
+ * Revision 1.7 2005/09/22 08:38:01 kpt
+ * Fixes for demo
+ *
+ * Revision 1.6 2005/09/21 15:54:56 kpt
+ * USE now works through external domains
+ *
+ * Revision 1.5 2005/09/21 13:46:40 kpt
+ * Can now create and send events using XML and the event templates
+ *
+ * Revision 1.4 2005/09/21 10:13:15 kpt
+ * Implemented <local> and context for policies
+ *
+ * Revision 1.3 2005/09/21 08:21:03 kpt
+ * First cut at external objects
+ *
+ * Revision 1.2 2005/09/14 08:45:38 kpt
+ * Down to import and use
+ *
+ * Revision 1.1 2005/09/12 10:47:07 kpt
+ * Initial Checkin
+ *
+ */
+
+package eu.novi.ponder2;
+
+import java.io.ByteArrayInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
+import java.util.Vector;
+
+import eu.novi.ponder2.comms.Transmitter;
+import eu.novi.ponder2.exception.Ponder2ArgumentException;
+import eu.novi.ponder2.exception.Ponder2AuthorizationException;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2OperationException;
+import eu.novi.ponder2.exception.Ponder2RemoteException;
+import eu.novi.ponder2.exception.Ponder2ResolveException;
+import eu.novi.ponder2.objects.P2Hash;
+import eu.novi.ponder2.objects.P2Null;
+import eu.novi.ponder2.objects.P2Object;
+import eu.novi.ponder2.parser.P2Compiler;
+import eu.novi.ponder2.parser.XMLParser;
+import eu.novi.ponder2.policy.AuthPolicyHolder;
+import eu.novi.ponder2.policy.AuthorisationModule;
+
+import eu.novi.ponder2.ExternalManagedObject;
+import eu.novi.ponder2.ExternalManagedObjectP2Adaptor;
+import eu.novi.ponder2.FactoryObjectP2Adaptor;
+import eu.novi.ponder2.P2ManagedObject;
+import eu.novi.ponder2.P2ObjectAdaptor;
+import eu.novi.ponder2.Path;
+import eu.novi.ponder2.SelfManagedCell;
+import eu.novi.ponder2.Util;
+
+/**
+ * Utility routines to support the Ponder2 framework
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class Util {
+ // Used to allow libraries e.g. Android to override resource location
+ protected static Util util = new Util();
+
+ public static P2Object resolve(String name) throws Ponder2Exception {
+ return resolve("/", name);
+ }
+
+ public static P2Object resolve(String defaultDomain, String name)
+ throws Ponder2Exception {
+ Path path;
+ if (name == null)
+ return null;
+ if (name.startsWith("/"))
+ path = new Path(name);
+ else
+ path = new Path(defaultDomain + "/" + name);
+ return resolve(path);
+ }
+
+ /**
+ * resolves a pathname of a managed object into an OID
+ *
+ * @param defaultDomain
+ * the starting point if path is relative
+ * @param path
+ * the name of the managed object
+ * @return the P2ManagedObject of the managed object or null if not found
+ * @throws Ponder2Exception
+ */
+ public static P2Object resolve(String defaultDomain, Path path)
+ throws Ponder2Exception {
+ if (!path.isAbsolute())
+ path = new Path(defaultDomain + "/" + path.toString());
+ return resolve(path);
+ }
+
+ /**
+ * resolves a pathname of a managed object into an OID
+ *
+ * @param path
+ * the name of the managed object
+ * @return the P2ManagedObject of the managed object or null if not found
+ * @throws Ponder2Exception
+ */
+ public static P2Object resolve(Path path) throws Ponder2Exception {
+ if (!path.isAbsolute()) {
+ throw new Ponder2ResolveException("Resolve: relative path'" + path
+ + "' not found");
+ }
+ return resolve(SelfManagedCell.RootDomain.getManagedObject(), path);
+ }
+
+ public static P2Object resolve(P2Object dom, String name)
+ throws Ponder2Exception {
+ return resolve(dom.getManagedObject(), new Path(name));
+ }
+
+ public static P2Object resolve(P2Object dom, Path path)
+ throws Ponder2Exception {
+ return resolve(dom.getManagedObject(), path);
+ }
+
+ /**
+ * resolves a pathname of a managed object into an OID
+ *
+ * @param dom
+ * the starting point if name is relative
+ * @param path
+ * the name of the managed object
+ * @return the P2ManagedObject of the managed object or null if not found
+ * @throws Ponder2Exception
+ */
+ public static P2Object resolve(P2ManagedObject dom, Path path)
+ throws Ponder2Exception {
+ if (SelfManagedCell.SystemTrace)
+ System.out.print("Util: resolve path " + path + " => ");
+
+ P2ManagedObject mo = dom;
+ if (!(path.isRelative() || path.isAbsolute())) {
+ return mo.getP2Object();
+ }
+ int count = 0;
+ // Work our way down the path
+ for (String bit : path) {
+ count++;
+ // If dot then we have finished
+ if (bit.equals(".")) {
+ mo = dom;
+ break;
+ }
+ // TODO Sort out mo and dom, probably do not need both
+ // KPT to allow root at the start
+ if (bit.equals(Path.ROOT) || (count == 2 && bit.equals("root"))) {
+ mo = dom = SelfManagedCell.RootDomain.getManagedObject();
+ } else {
+ // If we have a remote domain we can ask it to resolve the path
+ if (dom.isDomain()
+ && dom.getP2Object() instanceof ExternalManagedObjectP2Adaptor) {
+ // This is external, it will be completely resolved remotely
+ String rest = rest(path, count - 1);
+ if (!rest.equals("")) {
+ P2Object result = dom.operation(
+ SelfManagedCell.RootDomain, "resolve:",
+ P2Object.create(rest));
+ mo = result.getManagedObject();
+ }
+ break;
+ }
+ P2Object obj = dom.operation(SelfManagedCell.RootDomain, "at:",
+ P2Object.create(bit));
+ if (obj == P2Null.Null)
+ throw new Ponder2ResolveException("Resolve: path'" + path
+ + "' not found");
+ dom = mo = obj.getManagedObject();
+ }
+ }
+ if (SelfManagedCell.SystemTrace)
+ System.out.println(mo);
+ return mo.getP2Object();
+ }
+
+ // Return path - count bits from the front
+ private static String rest(Path path, int count) {
+ String result = "";
+ boolean slash = false;
+ for (String bit : path) {
+ if (count-- <= 0) {
+ result += (slash ? "/" : "") + bit;
+ slash = true;
+ }
+ }
+ return result;
+ }
+
+ public static void parseFile(P2Object source, String name)
+ throws Ponder2Exception {
+ System.out.println("Reading " + name);
+ parseFile(source, name, new XMLParser());
+ }
+
+ public static void parseFile(P2Object source, String name, P2Hash variables)
+ throws Ponder2Exception {
+ System.out.println("Reading (with variables) " + name);
+ parseFile(source, name, new XMLParser(variables));
+ }
+
+ public static void parseFile(P2Object source, String name, XMLParser parser)
+ throws Ponder2Exception {
+ try {
+ InputStream is = getInputStream(new URI(name));
+ String xml = P2Compiler.parse(name, is);
+ parser.execute(source, xml);
+ } catch (MalformedURLException e) {
+ throw new Ponder2OperationException(e.getMessage());
+ } catch (IOException e) {
+ throw new Ponder2OperationException(e.getMessage());
+ } catch (URISyntaxException e) {
+ throw new Ponder2OperationException(e.getMessage());
+ }
+ }
+
+ /**
+ * loads Managed Object code into this VM and returns a Ponder2 factory
+ * object
+ *
+ * @param name
+ * the URL of the object to be loaded. Currently the scheme can
+ * only be blank or 'resource'. e.g.
+ *
+ * <pre>
+ * MyObjectName
+ * resource:MyObjectName
+ * </pre>
+ *
+ * @return the factory object of the new managed object type
+ * @throws Ponder2Exception
+ * it it can't be found or there is a syntax error
+ */
+ public static P2Object loadFactory(String name) throws Ponder2Exception {
+ P2Object p2Object = null;
+ URI uri;
+ try {
+ uri = new URI(name);
+ String scheme = uri.getScheme();
+ if (scheme == null)
+ scheme = "resource";
+ if (!scheme.equals("resource")) {
+ throw new Ponder2ArgumentException(
+ "Load Managed Object - Scheme '" + scheme
+ + "' not understood");
+ }
+
+ Class<P2ObjectAdaptor> adaptorClass = Util
+ .getManagedObjectAdaptor(uri.getSchemeSpecificPart());
+ if (adaptorClass == null) {
+ throw new Ponder2ArgumentException(
+ "Load Managed Object - Adaptor for '"
+ + uri.getSchemeSpecificPart() + "' not found");
+ }
+
+ p2Object = new FactoryObjectP2Adaptor(null, "create:",
+ P2Object.create(adaptorClass));
+ } catch (URISyntaxException e) {
+ throw new Ponder2ArgumentException(
+ "Load Managed Object - Bad URI syntax " + e.getReason());
+ }
+ return p2Object;
+ }
+
+ private static List<String> loadPath;
+ private static final String[] initialLoadPath = new String[] { "resource",
+ "eu.novi.ponder2", "eu.novi.ponder2.policy",
+ "eu.novi.ponder2.managedobject" };
+ static {
+ setLoadPath(initialLoadPath);
+ }
+
+ public static void setLoadPath(String[] paths) {
+ List<String> newPath = new Vector<String>();
+ for (String path : paths) {
+ newPath.add(path);
+ }
+ loadPath = newPath;
+ }
+
+ public static void addLoadPath(String path) {
+ loadPath.add(0, path);
+ }
+
+ protected static Class<P2ObjectAdaptor> getManagedObjectAdaptor(String name) {
+ Class<P2ObjectAdaptor> cl = null;
+ String adaptorName = '.' + name + "P2Adaptor";
+ for (String path : loadPath) {
+ cl = getFactory(path + adaptorName);
+ if (cl != null)
+ break;
+ }
+ return cl;
+ }
+
+ @SuppressWarnings("unchecked")
+ private static Class<P2ObjectAdaptor> getFactory(String name) {
+ Class<P2ObjectAdaptor> cl = null;
+ try {
+ cl = (Class<P2ObjectAdaptor>) Class.forName(name);
+ } catch (ClassNotFoundException e) {
+ // ignore any errors here, we simple return null
+ }
+ return cl;
+ }
+
+ /**
+ * Imports a remote Managed Object from another SMC using the protocol
+ * defined in the URI
+ *
+ * @param name
+ * the pathname of the remote object
+ * @param location
+ * the URI of the remote SMC
+ * @return the imported object. This is actually an External Managed Object
+ * @throws Ponder2Exception
+ * if the object cannot be found or imported
+ */
+ public static P2Object getRemoteObject(String name, String location)
+ throws Ponder2Exception {
+ try {
+ if (name == null || location == null)
+ throw new Ponder2ArgumentException(
+ "Get remote object error: name " + name + " from "
+ + location);
+
+ URI uri = new URI(location);
+ String scheme = uri.getScheme();
+ if (scheme == null)
+ throw new Ponder2ArgumentException(
+ "Get remote object: missing scheme/protocol in "
+ + location);
+
+ // Ok, let's get for the remote proxy
+ Transmitter remote = ExternalManagedObject.getRemote(uri);
+ // Finally ask for the remote object
+ return remote.getObject(uri, name);
+ } catch (URISyntaxException e) {
+ throw new Ponder2RemoteException("getRemote: " + e.getMessage());
+ }
+ }
+
+ private static final String STRING_SCHEME = "string";
+ private static final String RESOURCE_SCHEME = "resource";
+
+ // private static final String FILE_SCHEME = "file";
+
+ public static InputStream getInputStream(URI uri)
+ throws MalformedURLException, IOException, URISyntaxException {
+ String scheme = uri.getScheme();
+ boolean emptyScheme = false;
+ if (scheme == null) {
+ emptyScheme = true;
+ scheme = RESOURCE_SCHEME;
+ }
+
+ if (scheme.equals(STRING_SCHEME)) {
+ byte[] bytes = uri.getSchemeSpecificPart().getBytes();
+ return new ByteArrayInputStream(bytes);
+ }
+
+ InputStream istream;
+
+ String resource = uri.getSchemeSpecificPart();
+ if (scheme.equals(RESOURCE_SCHEME)) {
+ String fullResourceName = resource;
+ istream = util.openResource(fullResourceName);
+ if (istream == null && emptyScheme) {
+ URI fileUri = new URI("file", resource, uri.getFragment());
+ try {
+ istream = fileUri.toURL().openStream();
+ } catch (FileNotFoundException e) {
+ }
+ }
+ if (istream == null && !resource.startsWith("/")) {
+ fullResourceName = "resource/" + resource;
+ istream = util.openResource(fullResourceName);
+ }
+ if (istream == null && !resource.startsWith("/")) {
+ fullResourceName = "/" + resource;
+ istream = util.openResource(fullResourceName);
+ }
+ if (istream == null && !resource.startsWith("/")) {
+ fullResourceName = "/resource/" + resource;
+ istream = util.openResource(fullResourceName);
+ }
+ if (istream == null)
+ throw new IOException("resource " + resource + " not found");
+ return istream;
+ }
+
+ // Nothing found above, just try to open the URI
+ // it might be file:// jar:// etc
+ return uri.toURL().openStream();
+
+ }
+
+ protected InputStream openResource(String resource) {
+ return this.getClass().getResourceAsStream(resource);
+ }
+
+ /**
+ * Check if an object has permission to perform an operation on another
+ * object. Returns true or false.
+ *
+ * @param source
+ * the source object
+ * @param target
+ * the target object
+ * @param operation
+ * the operation to be performed
+ * @param args
+ * the arguments for the operation
+ * @return true if the operation would be allowed
+ */
+ public static boolean canPerform(P2Object source, P2Object target,
+ String operation, P2Object... args) {
+ AuthorisationModule authorisationModule = P2ObjectAdaptor
+ .getAuthorisation();
+
+ if (authorisationModule != null) {
+ AuthPolicyHolder holder = new AuthPolicyHolder();
+ try {
+ authorisationModule.request(AuthorisationModule.PEP1, 's',
+ holder, source, target, operation, args);
+ // authorisationModule.request(AuthorisationModule.PEP2, 't',
+ // holder,
+ // source, target,
+ // operation, args);
+ } catch (Ponder2AuthorizationException e) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/apt/DocWriter.java b/ponder2/src/main/java/eu/novi/ponder2/apt/DocWriter.java
new file mode 100644
index 0000000..9842817
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/apt/DocWriter.java
@@ -0,0 +1,119 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 29, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.apt;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+import com.sun.mirror.apt.Filer;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public abstract class DocWriter {
+
+ public final static int CONSTRUCTOR = 0;
+ public final static int OPERATION = 1;
+
+ DocWriter(Filer filer, String className) throws IOException {
+ }
+
+ public abstract void writeClass(String className, String superClass,
+ String comment);
+
+ protected abstract void writeOperation(List<String> operations,
+ String comment, List<String> parameterList, String returnType);
+
+ public abstract void close();
+
+ public void writeOperation(String operation, String comment,
+ List<String> parameterList, String returnType) {
+ writeOperation(splitOperation(operation), strip(comment),
+ parameterList, returnType);
+ }
+
+ public static List<String> splitOperation(String operation) {
+ List<String> result = new Vector<String>();
+ if (operation.indexOf(':') < 0) {
+ result.add(operation);
+ } else {
+ StringTokenizer st = new StringTokenizer(operation, ":");
+ while (st.hasMoreTokens()) {
+ result.add(st.nextToken() + ":");
+ }
+ }
+ return result;
+ }
+
+ /**
+ * strips comment chars from comments
+ *
+ * @param comment
+ * @return the stripped comment
+ */
+ protected String strip(String comment) {
+ String result = "";
+ if (comment == null)
+ return result;
+ StringReader sr = new StringReader(comment);
+ BufferedReader in = new BufferedReader(sr);
+ try {
+ while (true) {
+ String line = in.readLine();
+ if (line == null)
+ break;
+ line = line.trim();
+ while (line.length() > 0
+ && (line.charAt(0) == '/' || line.charAt(0) == '*'))
+ line = line.substring(1);
+ line = line.trim();
+ if (line.length() > 0 && line.charAt(0) == '@')
+ break;
+ result += " " + line;
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return result;
+ }
+
+ /**
+ * Tells the writer which section we are in
+ *
+ * @param section
+ */
+ public abstract void section(int section);
+
+ public abstract void endSection(int section);
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/apt/DocWriterHtml.java b/ponder2/src/main/java/eu/novi/ponder2/apt/DocWriterHtml.java
new file mode 100644
index 0000000..687d5d7
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/apt/DocWriterHtml.java
@@ -0,0 +1,222 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 29, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.apt;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.List;
+
+import eu.novi.ponder2.apt.DocWriter;
+
+import com.sun.mirror.apt.Filer;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class DocWriterHtml extends DocWriter {
+
+ private PrintWriter out;
+ private Filer filer;
+ private static PrintWriter index = null;
+
+ /**
+ * @param filer
+ * @param className
+ * @throws IOException
+ */
+ DocWriterHtml(Filer filer, String className) throws IOException {
+ super(filer, className);
+ this.filer = filer;
+ out = filer.createTextFile(Filer.Location.SOURCE_TREE, "doc", new File(
+ className + ".html"), null);
+
+ try {
+ // Copy the css file over
+ PrintWriter pdocOut = filer.createTextFile(
+ Filer.Location.SOURCE_TREE, "doc",
+ new File("PonderDoc.css"), null);
+ BufferedInputStream pdocIn = new BufferedInputStream(this
+ .getClass().getResourceAsStream("PonderDoc.css"));
+ while (true) {
+ int ch = pdocIn.read();
+ if (ch == -1)
+ break;
+ pdocOut.write(ch);
+ }
+ pdocOut.close();
+ pdocIn.close();
+ } catch (IOException e) {
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.novi.ponder2.adaptor.DocWriter#writeClass(java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ @Override
+ public void writeClass(String className, String superClass, String comment) {
+ comment = strip(comment);
+ writeIndexFile(filer, className, comment);
+ writeHeader(out, className);
+ if (!superClass.equals("eu.novi.ponder2.P2ObjectAdaptor"))
+ out.println("<h2>Based on " + superClass + "</h2>");
+ out.println("<p class='object_description'>");
+ out.println(comment);
+ out.println("</p>");
+ }
+
+ private void writeHeader(PrintWriter pw, String title) {
+ pw.println("<html>");
+ pw.println("<head>");
+ pw.println("<meta http-equiv=Content-Type content=\"text/html; charset=windows-1252\">");
+ pw.println("<title>" + title + "</title>");
+ pw.println("<link rel='stylesheet' type='text/css' href='PonderDoc.css' />");
+ pw.println("</head>");
+ pw.println("<body>");
+ pw.println("<h1 class='object-title'>" + title + "</h1>");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.novi.ponder2.adaptor.DocWriter#section(int)
+ */
+ @Override
+ public void section(int section) {
+ String text;
+ String header = null;
+ switch (section) {
+ case DocWriter.CONSTRUCTOR:
+ text = "Factory Messages";
+ header = "<tr><th>Operation</th><th>Description</th>";
+ break;
+ case DocWriter.OPERATION:
+ text = "Operational Messages";
+ header = "<tr><th>Operation</th><th>Return</th><th>Description</th>";
+ break;
+ default:
+ text = "Danger Will Robinson, error in Doc Writer!";
+ }
+ out.println("<table class='message-table'><tr><th colspan='3' class='message-header'>"
+ + text + "</th></tr>");
+ out.println(header);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.novi.ponder2.apt.DocWriter#endSection(int)
+ */
+ @Override
+ public void endSection(int section) {
+ out.println("</table><p/>");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.novi.ponder2.adaptor.DocWriter#writeOperation(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public void writeOperation(List<String> operation, String comment,
+ List<String> parameters, String returnType) {
+ int opSize = operation.size();
+ int paramSize = parameters.size();
+ String line = "";
+ for (int i = 0; i < opSize; i++) {
+ String op = operation.get(i);
+ line += "<span class='keyword'>" + op + "</span>";
+ // Is this a unary operation?
+ char ch = op.charAt(0);
+ if (((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
+ && !op.endsWith(":"))
+ break;
+ line += " ";
+ if (i < paramSize)
+ line += "<span class='argument'>" + parameters.get(i)
+ + "</span>";
+ else
+ line += "<b>ERROR PARAM MISSING</b>";
+ line += " ";
+ }
+ out.println("</tr>");
+ out.println("<td class='message-prototype'>" + line + "</td>");
+ if (returnType != null) {
+ int index = returnType.lastIndexOf('.');
+ if (index > 0)
+ returnType = returnType.substring(index + 1);
+ out.println("<td class='message-return'>"
+ + (returnType.equals("void") ? "self" : returnType)
+ + "</td>");
+ }
+ out.println("<td class='message-description'>" + comment + "</td>");
+ out.println("</tr>");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.novi.ponder2.adaptor.DocWriter#close()
+ */
+ @Override
+ public void close() {
+ out.close();
+ }
+
+ /**
+ * @param objects
+ * @throws IOException
+ */
+ private void writeIndexFile(Filer filer, String className, String comment) {
+ try {
+ index = filer.createTextFile(Filer.Location.SOURCE_TREE, "doc",
+ new File("index.html"), null);
+ writeHeader(index, "PonderTalk Object Reference");
+ index.println("");
+ index.println("<table class='object-table'><tr><th colspan='2' class='object-header'>"
+ + "Managed Object" + "</th></tr>");
+
+ } catch (IOException e) {
+ }
+ index.println("<tr>");
+ index.println("<td><a href=\"" + className + ".html" + "\">"
+ + className + "</a></td>");
+ index.println("<td>" + comment + "</td>");
+ index.println("</tr>");
+ index.flush();
+ // index.println("</body>");
+ // index.println("</html>");
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/apt/Ponder2Factory.java b/ponder2/src/main/java/eu/novi/ponder2/apt/Ponder2Factory.java
new file mode 100644
index 0000000..0fa3c57
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/apt/Ponder2Factory.java
@@ -0,0 +1,76 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 11, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.apt;
+
+import static java.util.Collections.emptySet;
+import static java.util.Collections.unmodifiableCollection;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Set;
+
+import eu.novi.ponder2.apt.Ponder2Processor;
+import eu.novi.ponder2.apt.Ponder2notify;
+import eu.novi.ponder2.apt.Ponder2op;
+
+import com.sun.mirror.apt.AnnotationProcessor;
+import com.sun.mirror.apt.AnnotationProcessorEnvironment;
+import com.sun.mirror.apt.AnnotationProcessorFactory;
+import com.sun.mirror.declaration.AnnotationTypeDeclaration;
+
+/**
+ * This class is used to run an annotation processor that lists class names. The
+ * functionality of the processor is analogous to the ListClass doclet in the
+ * Doclet Overview.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class Ponder2Factory implements AnnotationProcessorFactory {
+
+ // Process set of annotations
+ private static final Collection<String> supportedAnnotations = unmodifiableCollection(Arrays
+ .asList(Ponder2op.class.getName(), Ponder2notify.class.getName()));
+
+ // No supported options
+ private static final Collection<String> supportedOptions = emptySet();
+
+ public Collection<String> supportedAnnotationTypes() {
+ return supportedAnnotations;
+ }
+
+ public Collection<String> supportedOptions() {
+ return supportedOptions;
+ }
+
+ public AnnotationProcessor getProcessorFor(
+ Set<AnnotationTypeDeclaration> atds,
+ AnnotationProcessorEnvironment env) {
+
+ return new Ponder2Processor(env);
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/apt/Ponder2Processor.java b/ponder2/src/main/java/eu/novi/ponder2/apt/Ponder2Processor.java
new file mode 100644
index 0000000..add7853
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/apt/Ponder2Processor.java
@@ -0,0 +1,545 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 11, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.apt;
+
+import static com.sun.mirror.util.DeclarationVisitors.NO_OP;
+import static com.sun.mirror.util.DeclarationVisitors.getDeclarationScanner;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.math.BigDecimal;
+import java.util.Collection;
+import java.util.List;
+import java.util.Vector;
+
+import eu.novi.ponder2.apt.DocWriter;
+import eu.novi.ponder2.apt.DocWriterHtml;
+//import eu.novi.ponder2.apt.ManagedObjectVisitor;
+import eu.novi.ponder2.apt.Ponder2notify;
+import eu.novi.ponder2.apt.Ponder2op;
+
+import com.sun.mirror.apt.AnnotationProcessor;
+import com.sun.mirror.apt.AnnotationProcessorEnvironment;
+import com.sun.mirror.apt.Filer;
+import com.sun.mirror.declaration.ClassDeclaration;
+import com.sun.mirror.declaration.ConstructorDeclaration;
+import com.sun.mirror.declaration.MethodDeclaration;
+import com.sun.mirror.declaration.Modifier;
+import com.sun.mirror.declaration.ParameterDeclaration;
+import com.sun.mirror.declaration.TypeDeclaration;
+import com.sun.mirror.type.ClassType;
+import com.sun.mirror.type.InterfaceType;
+import com.sun.mirror.util.SimpleDeclarationVisitor;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+@SuppressWarnings("restriction")
+public class Ponder2Processor implements AnnotationProcessor {
+
+ private static final String typeBigDecimal = BigDecimal.class
+ .getCanonicalName();
+ private static final String typeBlock = "eu.novi.ponder2.objects.P2Block";
+ private static final String typeBoolean = "boolean";
+ private static final String typeClass = Class.class.getCanonicalName();
+ private static final String typeDouble = "double";
+ private static final String typeFloat = "float";
+ private static final String typeInt = "int";
+ private static final String typeLong = "long";
+ private static final String typeManagedObject = "eu.novi.ponder2.ManagedObject";
+ private static final String typeP2Array = "eu.novi.ponder2.objects.P2Array";
+ private static final String typeP2Hash = "eu.novi.ponder2.objects.P2Hash";
+ private static final String typeP2ObjectAdaptor = "eu.novi.ponder2.P2ObjectAdaptor";
+ private static final String typeP2Value = "eu.novi.ponder2.objects.P2Object";
+ private static final String typePonder2Exception = "eu.novi.ponder2.exception.Ponder2Exception";
+ private static final String typePonder2OperationException = "eu.novi.ponder2.exception.Ponder2OperationException";
+ private static final String typeString = String.class.getCanonicalName();
+ private static final String typeXML = "com.twicom.qdparser.TaggedElement";
+
+ private final AnnotationProcessorEnvironment env;
+ private final Filer filer;
+
+ Ponder2Processor(AnnotationProcessorEnvironment env) {
+ this.env = env;
+ filer = env.getFiler();
+ }
+
+ public void process() {
+ for (TypeDeclaration typeDecl : env.getSpecifiedTypeDeclarations()) {
+ typeDecl.accept(getDeclarationScanner(new ManagedObjectVisitor(
+ filer), NO_OP));
+ }
+ }
+
+ private static class ManagedObjectVisitor extends SimpleDeclarationVisitor {
+
+ Filer filer;
+
+ public ManagedObjectVisitor(Filer filer) {
+ this.filer = filer;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.sun.mirror.util.SimpleDeclarationVisitor#visitClassDeclaration
+ * (com.sun.mirror.declaration.ClassDeclaration)
+ */
+ @Override
+ public void visitClassDeclaration(ClassDeclaration classDecl) {
+ for (InterfaceType iface : classDecl.getSuperinterfaces()) {
+ if (!typeManagedObject.equals(iface.toString()))
+ continue;
+ // We have to create an adaptor for this Class
+ // System.out.println("Class: " + classDecl + ". Iface: " +
+ // iface);
+ try {
+ String packageName = classDecl.getPackage()
+ .getQualifiedName();
+ String className = classDecl.getSimpleName();
+ String adaptorName = className + "P2Adaptor";
+ String superClass = getSuperClass(classDecl);
+ // System.out.println("Super class is " + superClass);
+ PrintWriter source = filer.createSourceFile(packageName
+ + "." + adaptorName);
+ writeHeader(source, packageName, adaptorName, superClass);
+ DocWriter doc = new DocWriterHtml(filer, className);
+ doc.writeClass(className, superClass,
+ classDecl.getDocComment());
+ doc.section(DocWriter.CONSTRUCTOR);
+ // Deal with Ponder2 statics
+ for (MethodDeclaration decl : classDecl.getMethods()) {
+ Ponder2op p2op = decl.getAnnotation(Ponder2op.class);
+ if (p2op != null && isStatic(decl)) {
+ writeStatic(source, doc, className, p2op.value(),
+ decl);
+ }
+ }
+ // Deal with Ponder2 constructors
+ for (ConstructorDeclaration decl : classDecl
+ .getConstructors()) {
+ Ponder2op p2op = decl.getAnnotation(Ponder2op.class);
+ if (p2op != null)
+ writeConstructor(source, doc, className,
+ p2op.value(), decl);
+ }
+ doc.endSection(DocWriter.CONSTRUCTOR);
+ // Deal with Ponder2 operations
+ doc.section(DocWriter.OPERATION);
+ boolean wildcard = false;
+ for (MethodDeclaration decl : classDecl.getMethods()) {
+ Ponder2op p2op = decl.getAnnotation(Ponder2op.class);
+ if (p2op != null) {
+ writeOperation(source, doc, className,
+ p2op.value(), decl);
+ if (p2op.value().equals(Ponder2op.WILDCARD))
+ wildcard = true;
+ }
+ }
+ doc.endSection(DocWriter.OPERATION);
+ writeStaticEnd(source, adaptorName);
+ // Deal with Ponder2 notifications
+ for (MethodDeclaration decl : classDecl.getMethods()) {
+ Ponder2notify notify = decl
+ .getAnnotation(Ponder2notify.class);
+ if (notify != null)
+ writeNotification(source, notify.value(),
+ className, decl);
+ }
+ writeFooter(source, wildcard);
+ doc.close();
+ source.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ // Nothing else to do for this class
+ break;
+ }
+ }
+
+ /**
+ * returns true if the method has a static flag
+ *
+ * @param decl
+ * @return
+ */
+ boolean isStatic(MethodDeclaration decl) {
+ Collection<Modifier> modifiers = decl.getModifiers();
+ return modifiers.contains(Modifier.STATIC);
+ }
+
+ /**
+ * @param classDecl
+ * @return
+ */
+ private String getSuperClass(ClassDeclaration classDecl) {
+ // System.out.println("Looking for super class for " + classDecl);
+ ClassType superClass = classDecl.getSuperclass();
+ if (superClass == null)
+ return typeP2ObjectAdaptor;
+ classDecl = superClass.getDeclaration();
+ for (InterfaceType iface : classDecl.getSuperinterfaces()) {
+ // System.out.println("Interface is " + iface);
+ if (typeManagedObject.equals(iface.toString()))
+ return classDecl + "P2Adaptor";
+ }
+ return getSuperClass(classDecl);
+ }
+
+ private void writeConstructor(PrintWriter source, DocWriter doc,
+ String className, String operation, ConstructorDeclaration decl) {
+ String params = processParameters(doc, operation,
+ decl.getDocComment(), decl.getParameters(), null);
+ source.println();
+ source.println(" // Create operation '" + operation
+ + "' calls constructor for " + className);
+ source.println(" create.put(\"" + operation
+ + "\", new CreateOperation() {");
+ source.println(" @Override");
+ source.println(" public "
+ + typeManagedObject
+ + " call(P2Object obj, P2Object source, String operation, P2Object... args)");
+ source.println(" throws " + typePonder2Exception + " {");
+ source.println(" return new " + className + "(" + params
+ + ");");
+ source.println(" }");
+ source.println(" });");
+ }
+
+ private void writeStatic(PrintWriter source, DocWriter doc,
+ String className, String operation, MethodDeclaration decl) {
+ String methodName = decl.getSimpleName();
+ String returnType = decl.getReturnType().toString();
+ String params = processParameters(doc, operation,
+ decl.getDocComment(), decl.getParameters(), decl
+ .getReturnType().toString());
+ source.println();
+ source.println(" // Static operation '" + operation
+ + "' calls static method " + methodName);
+ source.println(" staticop.put(\"" + operation
+ + "\", new StaticOperation() {");
+ source.println(" @Override");
+ source.println(" public P2Object call(P2Object source, String operation, P2Object... args)");
+ source.println(" throws " + typePonder2Exception + " {");
+ boolean voidReturn = returnType.equals("void");
+ if (!voidReturn)
+ source.println(" " + returnType + " value = ");
+ source.println(" " + className + "." + methodName + "("
+ + params + ");");
+ if (voidReturn)
+ source.println(" return P2Null.NULL;");
+ else if (returnType.startsWith("eu.novi.ponder2.objects."))
+ source.println(" return value;");
+ else {
+ // Do we need to convert the return value to a P2Object?
+ String returnStatement = " return P2Object.create(value);";
+ try {
+ if (instanceOf("class " + typeP2Value,
+ Class.forName(returnType)))
+ returnStatement = " return value;";
+ } catch (ClassNotFoundException e) {
+ } catch (NoClassDefFoundError e) {
+ }
+ source.println(returnStatement);
+ }
+
+ source.println(" }");
+ source.println(" });");
+ }
+
+ private void writeOperation(PrintWriter source, DocWriter doc,
+ String className, String operation, MethodDeclaration decl) {
+ String methodName = decl.getSimpleName();
+ String returnType = decl.getReturnType().toString();
+ boolean isStatic = isStatic(decl);
+ String params = processParameters(doc, operation,
+ decl.getDocComment(), decl.getParameters(), decl
+ .getReturnType().toString());
+ source.println();
+ source.print(" // Operation '" + operation + "' calls ");
+ if (isStatic)
+ source.print("static method ");
+ source.println(methodName);
+ source.println(" operation.put(\"" + operation
+ + "\", new InstanceOperation() {");
+ source.println(" @Override");
+ source.println(" public P2Object call(P2Object thisObj, "
+ + typeManagedObject
+ + " obj, P2Object source, String operation, P2Object... args)");
+ source.println(" throws " + typePonder2Exception + " {");
+ if (operation.equals(Ponder2op.WILDCARD)) {
+ source.print(" return ");
+ // TODO The following line does not seem to detect static
+ // methods
+ if (isStatic(decl))
+ source.print(className);
+ else
+ source.print("((" + className + ")obj)");
+ source.println("." + methodName + "(source, operation, args);");
+ } else {
+ boolean voidReturn = returnType.equals("void");
+ if (!voidReturn)
+ source.println(" " + returnType + " value = ");
+ source.print(" ");
+ if (isStatic)
+ source.print(className);
+ else
+ source.print("((" + className + ")obj)");
+ source.println("." + methodName + "(" + params + ");");
+ if (voidReturn)
+ source.println(" return thisObj;");
+ else if (returnType.startsWith("eu.novi.ponder2.objects."))
+ source.println(" return value;");
+ else {
+ // Do we need to convert the return value to a P2Object?
+ String returnStatement = " return P2Object.create(value);";
+ try {
+ if (instanceOf("class " + typeP2Value,
+ Class.forName(returnType)))
+ returnStatement = " return value;";
+ } catch (ClassNotFoundException e) {
+ } catch (NoClassDefFoundError e) {
+ }
+ source.println(returnStatement);
+ }
+ }
+ source.println(" }");
+ source.println(" });");
+ }
+
+ /**
+ * @param typeP2Value
+ * @param name
+ * @return
+ */
+ private boolean instanceOf(String typeP2Value, Class<?> name) {
+ if (name == null)
+ return false;
+ if (typeP2Value.equals(name.toString()))
+ return true;
+ return instanceOf(typeP2Value, name.getSuperclass());
+ }
+
+ private String processParameters(DocWriter doc, String operation,
+ String comment, Collection<ParameterDeclaration> parameters,
+ String returnType) {
+ StringBuffer paramString = new StringBuffer();
+ int argIndex = 0;
+ List<String> parameterList = new Vector<String>();
+ boolean first = true;
+ for (ParameterDeclaration parameter : parameters) {
+ String type = parameter.getType().toString();
+ String name = parameter.getSimpleName();
+ if (first) {
+ first = false;
+ if (type.equals(typeP2Value) && name.equals("source")) {
+ paramString.append("source");
+ continue;
+ }
+ if (type.equals(typeP2Value) && name.equals("myP2Object")) {
+ paramString.append("obj");
+ continue;
+ }
+ } else {
+ paramString.append(", ");
+ }
+ // System.out.println("Parameter is " + type + " " + name);
+ parameterList.add(name);
+ if (type.equals(typeString)) {
+ paramString.append("args[" + argIndex + "].asString()");
+ } else if (type.equals(typeBigDecimal)) {
+ paramString.append("args[" + argIndex + "].asNumber()");
+ } else if (type.equals(typeInt)) {
+ paramString.append("args[" + argIndex + "].asInteger()");
+ } else if (type.equals(typeLong)) {
+ paramString.append("args[" + argIndex + "].asLong()");
+ } else if (type.equals(typeFloat)) {
+ paramString.append("args[" + argIndex + "].asFloat()");
+ } else if (type.equals(typeDouble)) {
+ paramString.append("args[" + argIndex + "].asDouble()");
+ } else if (type.equals(typeBoolean)) {
+ paramString.append("args[" + argIndex + "].asBoolean()");
+ } else if (type.equals(typeBlock)) {
+ paramString.append("args[" + argIndex + "].asBlock()");
+ } else if (type.equals(typeP2Array)) {
+ paramString.append("args[" + argIndex + "].asP2Array()");
+ } else if (type.startsWith(typeClass)) {
+ paramString.append("args[" + argIndex + "].asClass()");
+ } else if (type.equals(typeP2Hash)) {
+ paramString.append("args[" + argIndex + "].asHash()");
+ } else if (type.equals(typeXML)) {
+ paramString.append("args[" + argIndex + "].asXML()");
+ } else if (type.equals(typeP2Value)) {
+ paramString.append("args[" + argIndex + "]");
+ } else if (type.equals(typeP2Value + "[]")) {
+ paramString.append("args");
+ } else {
+ System.err
+ .println("Ponder2Processor: Unknown type " + type);
+ paramString
+ .append("Compilation Error: Cannot convert type "
+ + type);
+ }
+ argIndex++;
+ }
+
+ int expected = argsIn(operation);
+ if (expected >= 0 && expected != argIndex) {
+ System.err.println("Wrong number of args '" + operation
+ + "' expected " + expected + " but found " + argIndex);
+ paramString
+ .append(" --- Compilation Error: Argument mismatch: '"
+ + operation + "' expected " + expected
+ + " but found " + argIndex);
+ }
+
+ doc.writeOperation(operation, comment, parameterList, returnType);
+
+ return paramString.toString();
+ }
+
+ private int argsIn(String operation) {
+ if (!Character.isLetter(operation.charAt(0)))
+ return 1;
+ if (operation.equals(Ponder2op.WILDCARD))
+ return -1;
+ int count = 0;
+ byte[] bytes = operation.getBytes();
+ for (byte b : bytes) {
+ if (b == ':')
+ count++;
+ }
+ return count;
+ }
+
+ private void writeHeader(PrintWriter source, String packageName,
+ String className, String superClassName) {
+ // System.out.println("Class name is " + className);
+ if (packageName != null && packageName.length() > 0)
+ source.println("package " + packageName + ";");
+ source.println();
+ source.println("import java.util.HashMap;");
+ source.println("import java.util.Map;");
+ source.println();
+ source.println("import " + typeP2Value + ";");
+ source.println("import " + typePonder2Exception + ";");
+ source.println();
+ source.println("/**");
+ source.println(" * Adaptor object for managed object");
+ source.println(" * ");
+ source.println(" * @author Auto generated by annotation processor tool");
+ source.println(" */");
+ source.println("public class " + className + " extends "
+ + superClassName + " {");
+ source.println();
+ source.println(" /**");
+ source.println(" * The map of static operations");
+ source.println(" */");
+ source.println(" private final static Map<String, StaticOperation> staticop;");
+ source.println(" /**");
+ source.println(" * The map of create operations to constructors");
+ source.println(" */");
+ source.println(" private final static Map<String, CreateOperation> create;");
+ source.println(" /**");
+ source.println(" * The map of instance operations to methods");
+ source.println(" */");
+ source.println(" private final static Map<String, InstanceOperation> operation;");
+ source.println();
+ source.println(" // Create the call tables when the class is loaded");
+ source.println(" static {");
+ source.println(" staticop = new HashMap<String, StaticOperation>();");
+ source.println(" create = new HashMap<String, CreateOperation>();");
+ source.println(" operation = new HashMap<String, InstanceOperation>();");
+ }
+
+ private void writeStaticEnd(PrintWriter source, String adaptorName) {
+ source.println(" }");
+ source.println();
+ source.println(" public " + adaptorName + "() {");
+ source.println(" }");
+ source.println();
+ source.println(" public " + adaptorName
+ + "(P2Object source, String operation, P2Object... args)");
+ source.println(" throws Ponder2Exception {");
+ source.println(" super(source, operation, args);");
+ source.println(" }");
+ source.println();
+ }
+
+ private void writeNotification(PrintWriter source, String notify,
+ String className, MethodDeclaration decl) {
+ String methodName = decl.getSimpleName();
+ // TypeMirror returnType = decl.getReturnType();
+ // String params = getParameters(decl.getParameters());
+ if (notify.equals("oid")) {
+ source.println(" @Override");
+ source.println(" protected void notifyOID(OID oid) {");
+ source.println(" ((" + className + ")objImpl)." + methodName
+ + "(oid);");
+ source.println(" super.notifyOID(oid);");
+ source.println(" }");
+ }
+ }
+
+ private void writeFooter(PrintWriter source, boolean wildcard) {
+ source.println();
+ source.println(" @Override");
+ source.println(" public void getCreateOrStaticOperation(CreateOrStaticOperation opInfo) throws "
+ + typePonder2OperationException + " {");
+ source.println(" boolean found = opInfo.findOp(create,staticop);");
+ source.println(" if (!found) super.getCreateOrStaticOperation(opInfo);");
+ source.println(" }");
+ source.println();
+ source.println();
+ source.println(" @Override");
+ source.println(" public CreateOperation getCreateOperation(String opName) throws "
+ + typePonder2OperationException + " {");
+ source.println(" CreateOperation op = create.get(opName);");
+ source.println(" return op != null ? op : super.getCreateOperation(opName);");
+ source.println(" }");
+ source.println();
+ source.println(" @Override");
+ source.println(" public InstanceOperation getInstanceOperation(String opName) throws "
+ + typePonder2OperationException + " {");
+ source.println(" InstanceOperation op = operation.get(opName);");
+ source.print(" return op != null ? op : ");
+ if (wildcard)
+ source.println("operation.get(\"" + Ponder2op.WILDCARD + "\");");
+ else
+ source.println("super.getInstanceOperation(opName);");
+ source.println(" }");
+ source.println();
+ source.println("}");
+ source.println();
+ }
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/apt/Ponder2notify.java b/ponder2/src/main/java/eu/novi/ponder2/apt/Ponder2notify.java
new file mode 100644
index 0000000..60e3b18
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/apt/Ponder2notify.java
@@ -0,0 +1,37 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 9, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.apt;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public @interface Ponder2notify {
+
+ String value();
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/apt/Ponder2op.java b/ponder2/src/main/java/eu/novi/ponder2/apt/Ponder2op.java
new file mode 100644
index 0000000..8a3da26
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/apt/Ponder2op.java
@@ -0,0 +1,39 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 9, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.apt;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public @interface Ponder2op {
+
+ public static final String WILDCARD = "Wild Card";
+
+ String value();
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/HttpProtocol.java b/ponder2/src/main/java/eu/novi/ponder2/comms/HttpProtocol.java
new file mode 100644
index 0000000..8ff6909
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/HttpProtocol.java
@@ -0,0 +1,52 @@
+/**
+ * Copyright 2006 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 20, 2006
+ *
+ * $Log:$
+ *//*
+
+package eu.novi.ponder2.comms;
+
+import java.net.URI;
+
+import eu.novi.ponder2.ExternalManagedObject;
+import eu.novi.ponder2.comms.http.HTTPTransmitter;
+import eu.novi.ponder2.exception.Ponder2RemoteException;
+
+*//**
+ * Web Service protocol implementation for inter-SMC chit chat
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ *//*
+public class HttpProtocol implements Protocol {
+
+ (non-Javadoc)
+ * @see net.ponder2.comms.Protocol#install(java.net.URI)
+
+ public void install(URI address, URI remote) throws Ponder2RemoteException {
+ // If we don't have a local address we have no idea what we should be, just
+ // let it go through blank. It simply means that the other end can't
+ // initiate messages to send to us
+ ExternalManagedObject.registerProtocol("http", new HTTPTransmitter(), address);
+ }
+}
+*/ \ No newline at end of file
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/P2Serializable.java b/ponder2/src/main/java/eu/novi/ponder2/comms/P2Serializable.java
new file mode 100644
index 0000000..9323df3
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/P2Serializable.java
@@ -0,0 +1,53 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Aug 7, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.comms;
+
+import java.util.Map;
+import java.util.Set;
+
+import eu.novi.ponder2.comms.P2Serializable;
+
+import com.twicom.qdparser.TaggedElement;
+
+import eu.novi.ponder2.exception.Ponder2ArgumentException;
+import eu.novi.ponder2.exception.Ponder2OperationException;
+import eu.novi.ponder2.objects.P2Object;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public interface P2Serializable {
+
+ public TaggedElement writeXml(Set<P2Object> written)
+ throws Ponder2OperationException;
+
+ public P2Object readXml(TaggedElement xml, Map<Integer, P2Serializable> read)
+ throws Ponder2OperationException, Ponder2ArgumentException;
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/Protocol.java b/ponder2/src/main/java/eu/novi/ponder2/comms/Protocol.java
new file mode 100644
index 0000000..fecc026
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/Protocol.java
@@ -0,0 +1,53 @@
+/**
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 24, 2006
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.comms;
+
+import java.net.URI;
+
+import eu.novi.ponder2.exception.Ponder2RemoteException;
+
+/**
+ * defines the methods that all protocols must implement to be able to
+ * automatically install themselves into an SMC
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public interface Protocol {
+
+ /**
+ * Installs a new communications address as an address that this SMC can be
+ * referred to
+ *
+ * @param address
+ * the local address as a URI comprising
+ * <code>protocol://host/protocol-dependent<code>
+ * @param remote
+ * the remote address that initiated this call to install
+ * @throws Ponder2RemoteException
+ */
+ public void install(URI address, URI remote) throws Ponder2RemoteException;
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/Receiver.java b/ponder2/src/main/java/eu/novi/ponder2/comms/Receiver.java
new file mode 100644
index 0000000..5a9f4bb
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/Receiver.java
@@ -0,0 +1,198 @@
+/**
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 24, 2006
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.comms;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+
+import eu.novi.ponder2.comms.P2Serializable;
+
+import com.twicom.qdparser.TaggedElement;
+import com.twicom.qdparser.XMLReader;
+
+import eu.novi.ponder2.OID;
+import eu.novi.ponder2.SelfManagedCell;
+import eu.novi.ponder2.Util;
+import eu.novi.ponder2.exception.Ponder2ArgumentException;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.objects.P2Object;
+
+/**
+ * receive methods to match the transmit methods. This is a helper class common
+ * to all protocols. If the protocol is capable of handing the transmit
+ * arguments straight across then these methods simply have to be called without
+ * any further work
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class Receiver {
+
+ /**
+ * Returns a managed object to a remote SMC. The object is located by using
+ * the given pathname. The address used to access this SMC is also given.
+ * This address is added to the list of the SMC's addresses in case the
+ * local SMC did not know that it could be addressed this way. Future OIDs
+ * when serialised will include the new address.
+ *
+ * @param address
+ * the URI used to talk to this SMC
+ * @param path
+ * the local pathname for the object to be looked up
+ * @return the object located at the pathname
+ * @throws Ponder2Exception
+ */
+ public static P2Object getObject(URI address, String path)
+ throws Ponder2Exception {
+ System.out.println("Remote getObject called for path " + path);
+ // This may be a new address for us, we had better save it to tell
+ // people
+ // about it
+ OID.addAddress(address);
+ return Util.resolve("/", path);
+ }
+
+ /**
+ * Executes a remotely received command. All the arguments are the basic
+ * types required by the operation method
+ *
+ * @param address
+ * the URI that this SMC was addressed with
+ * @param oid
+ * the OID of the object (target) to receive the command
+ * @param source
+ * the source object of the command
+ * @param op
+ * the operation itself
+ * @param args
+ * an array of operation arguments
+ * @return the result of the operation as an internal SMC object
+ * @throws Ponder2Exception
+ * if an error is found
+ */
+ public static P2Object execute(URI address, OID oid, P2Object source,
+ String op, P2Object[] args) throws Ponder2Exception {
+ if (SelfManagedCell.SystemTrace)
+ System.out.println("Receiver: execute called for oid/op " + oid
+ + " " + op);
+ P2Object result = oid.getP2Object().operation(source, op, args);
+ return result;
+ }
+
+ /**
+ * Executes a remotely received command. All Ponder2 types are expressed as
+ * Ponder2 XML.
+ *
+ * @param address
+ * the URI that this SMC was addressed with
+ * @param xoid
+ * the OID of the object (target) to receive the command in XML
+ * format
+ * @param xsource
+ * the source object of the command in XML format
+ * @param op
+ * the operation itself
+ * @param xargs
+ * an array of operation arguments in XML format
+ * @return the result of the operation as a Ponder2 object in XML format
+ * @throws Ponder2Exception
+ */
+ public static TaggedElement execute(URI address, TaggedElement xoid,
+ TaggedElement xsource, String op, TaggedElement[] xargs)
+ throws Ponder2Exception {
+ if (SelfManagedCell.SystemTrace)
+ System.out.println("Receiver: execute called for oid/op " + xoid
+ + " " + op);
+
+ Map<Integer, P2Serializable> read = new HashMap<Integer, P2Serializable>();
+ OID oid = P2Object.fromXml(xoid, read).getOID();
+ P2Object source = P2Object.fromXml(xsource, read);
+ P2Object[] args = new P2Object[xargs.length];
+ for (int i = 0; i < args.length; i++) {
+ args[i] = P2Object.fromXml(xargs[i], read);
+ }
+ P2Object result = oid.getP2Object().operation(source, op, args);
+ return result.writeXml(new HashSet<P2Object>());
+ }
+
+ /**
+ * Executes a remotely received command. All the arguments are rolled into a
+ * single XML structure. This method has to be matched by the method in
+ * TransmitterImpl that rolls the arguments up into the XML structure.
+ *
+ * @param xml
+ * a single XML structure containing all the information for the
+ * execute command as sub-elements
+ * @return the result of the operation as a Ponder2 object in XML format
+ * @throws Ponder2Exception
+ */
+ public static TaggedElement execute(TaggedElement xml)
+ throws Ponder2Exception {
+ try {
+ TaggedElement result;
+ String action = xml.getAttribute("action", "execute");
+ URI address = new URI(xml.getAttribute("address"));
+ // The xml could actually be a getObject call
+ if (action.equals("getobject")) {
+ String path = xml.getAttribute("path");
+ result = getObject(address, path).writeXml(
+ new HashSet<P2Object>());
+ } else {
+ TaggedElement target = (TaggedElement) xml.getChild(0);
+ TaggedElement source = (TaggedElement) xml.getChild(1);
+ String op = xml.getAttribute("op");
+ int elements = xml.elements();
+ TaggedElement[] args = new TaggedElement[elements - 2];
+ for (int i = 2; i < elements; i++) {
+ args[i - 2] = (TaggedElement) xml.getChild(i);
+ }
+ result = execute(address, target, source, op, args);
+ }
+ return result;
+ } catch (URISyntaxException e) {
+ throw new Ponder2ArgumentException("Receive: bad URI address - "
+ + e.getMessage());
+ }
+ }
+
+ /**
+ * Executes a remotely received command. All the arguments are rolled into a
+ * single XML string
+ *
+ * @param sxml
+ * a single XML structure, in string form, containing all the
+ * information for the execute command as sub-elements
+ * @return the result of the operation as a Ponder2 object in XML format
+ * @throws Ponder2Exception
+ */
+ public static String execute(String sxml) throws Ponder2Exception {
+ TaggedElement xml = XMLReader.parse(sxml);
+ return execute(xml).toString();
+ }
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/RmiProtocol.java b/ponder2/src/main/java/eu/novi/ponder2/comms/RmiProtocol.java
new file mode 100644
index 0000000..906038e
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/RmiProtocol.java
@@ -0,0 +1,113 @@
+/**
+ * Copyright 2006 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 20, 2006
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.comms;
+
+import java.net.InetAddress;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.UnknownHostException;
+import java.rmi.RMISecurityManager;
+import java.rmi.RemoteException;
+import java.util.Random;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import eu.novi.ponder2.comms.rmi.RMIReceiver;
+import eu.novi.ponder2.comms.rmi.RMITransmitter;
+
+import eu.novi.ponder2.ExternalManagedObject;
+import eu.novi.ponder2.Path;
+import eu.novi.ponder2.SelfManagedCell;
+import eu.novi.ponder2.StartStopPonder2SMC;
+import eu.novi.ponder2.exception.Ponder2RemoteException;
+
+/**
+ * RMI protocol implementation for inter-SMC chit-chat
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class RmiProtocol implements Protocol {
+ private static final transient Logger log = LoggerFactory.getLogger(RmiProtocol.class);
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Protocol#install(java.net.URI,
+ * uk.ac.ic.doc.dse.ponder2.Result)
+ */
+ public void install(URI address, URI remote) throws Ponder2RemoteException {
+ // Assign a security manager
+ // Is this necessary here?
+ if (System.getSecurityManager() == null){
+ log.info("Assign a security manager if it does not exist(DISABLED)");
+ // System.setSecurityManager(new RMISecurityManager());
+ // log.info("System.setSecurityManager(new RMISecurityManager())");
+
+ }
+
+ // If we don't have a local address, we had better make one up
+ if (address == null) {
+ try {
+ String host = InetAddress.getLocalHost().getHostAddress();
+ int rand = new Random().nextInt();
+ address = new URI("rmi://" + host + "/Ponder2-" + rand);
+ System.out.println("Remote RMI address is " + address);
+ log.info("Remote RMI address is " + address);
+ }
+ catch (UnknownHostException e) {
+ // This should not happen! That's what they all say.
+ throw new Ponder2RemoteException("RmiProtocol: unknown host " + address + ": "
+ + e.getMessage());
+ }
+ catch (URISyntaxException e) {
+ // Nor this!
+ throw new Ponder2RemoteException("RmiProtocol URI syntax error " + address + ": "
+ + e.getMessage());
+ }
+ }
+ Path path = new Path(address.getSchemeSpecificPart());
+ String RMIName = path.tail(1);
+ try {
+ // Register a new name for this SMC with the rmiregistry
+ new RMIReceiver(address.getSchemeSpecificPart());
+ System.out.println("Remote RMI address is " + address);
+ log.info("Remote RMI address is " + address);
+ }
+ catch (RemoteException e) {
+ throw new Ponder2RemoteException("RmiProtocol cannot contact RMI registry for " + RMIName
+ + ". Is it running? " + (SelfManagedCell.SystemTrace ? e.getMessage() : ""));
+ }
+ catch (MalformedURLException e) {
+ throw new Ponder2RemoteException("RmiProtocol: bad RMI name " + RMIName + ": "
+ + e.getMessage());
+ }
+ String protocol = address.getScheme().toLowerCase();
+ // Now register the protocol and let the external managed object use it
+ ExternalManagedObject.registerProtocol(protocol, new RMITransmitter(), address);
+ }
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/RmistringProtocol.java b/ponder2/src/main/java/eu/novi/ponder2/comms/RmistringProtocol.java
new file mode 100644
index 0000000..69fd456
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/RmistringProtocol.java
@@ -0,0 +1,100 @@
+/**
+ * Copyright 2006 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 20, 2006
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.comms;
+
+import java.net.InetAddress;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.UnknownHostException;
+import java.rmi.RemoteException;
+import java.util.Random;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import eu.novi.ponder2.comms.rmistring.RmiStringReceiver;
+import eu.novi.ponder2.comms.rmistring.RmiStringTransmitter;
+
+import eu.novi.ponder2.ExternalManagedObject;
+import eu.novi.ponder2.Path;
+import eu.novi.ponder2.SelfManagedCell;
+import eu.novi.ponder2.exception.Ponder2RemoteException;
+
+/**
+ * RMI protocol implementation for inter-SMC chit-chat
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class RmistringProtocol implements Protocol {
+ private static final transient Logger log = LoggerFactory.getLogger(RmistringProtocol.class);
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Protocol#install(java.net.URI,
+ * uk.ac.ic.doc.dse.ponder2.Result)
+ */
+ public void install(URI address, URI remote) throws Ponder2RemoteException {
+ // If we don't have a local address, we had better make one up
+ if (address == null) {
+ try {
+ String host = InetAddress.getLocalHost().getHostAddress();
+ int rand = new Random().nextInt();
+ address = new URI("rmistring://" + host + "/Ponder2-" + rand);
+ }
+ catch (UnknownHostException e) {
+ // This should not happen! That's what they all say.
+ throw new Ponder2RemoteException("RmiStringProtocol: unknown host " + address + ": "
+ + e.getMessage());
+ }
+ catch (URISyntaxException e) {
+ // Nor this!
+ throw new Ponder2RemoteException("RmiStringProtocol URI syntax error " + address + ": "
+ + e.getMessage());
+ }
+ }
+ Path path = new Path(address.getSchemeSpecificPart());
+ String RMIName = path.tail(1);
+ try {
+ // Register a new name for this SMC with the rmiregistry
+ new RmiStringReceiver(RMIName);
+ System.out.println("Remote RMI address is " + address);
+ log.info("Remote RMI address is " + address);
+ }
+ catch (RemoteException e) {
+ throw new Ponder2RemoteException("RmiStringProtocol cannot contact RMI registry for " + RMIName
+ + ". Is it running? " + (SelfManagedCell.SystemTrace ? e.getMessage() : ""));
+ }
+ catch (MalformedURLException e) {
+ throw new Ponder2RemoteException("RmiProtocol: bad RMI name " + RMIName + ": "
+ + e.getMessage());
+ }
+ String protocol = address.getScheme().toLowerCase();
+ // Now register the protocol and let the external managed object use it
+ ExternalManagedObject.registerProtocol(protocol, new RmiStringTransmitter(), address);
+ }
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/RmixmlProtocol.java b/ponder2/src/main/java/eu/novi/ponder2/comms/RmixmlProtocol.java
new file mode 100644
index 0000000..433ab1a
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/RmixmlProtocol.java
@@ -0,0 +1,101 @@
+/**
+ * Copyright 2006 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 20, 2006
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.comms;
+
+import java.net.InetAddress;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.UnknownHostException;
+import java.rmi.RemoteException;
+import java.util.Random;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import eu.novi.ponder2.comms.rmixml.RmiXmlReceiver;
+import eu.novi.ponder2.comms.rmixml.RmiXmlTransmitter;
+
+import eu.novi.ponder2.ExternalManagedObject;
+import eu.novi.ponder2.Path;
+import eu.novi.ponder2.SelfManagedCell;
+import eu.novi.ponder2.exception.Ponder2RemoteException;
+
+/**
+ * RMI protocol implementation for inter-SMC chit-chat
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class RmixmlProtocol implements Protocol {
+ private static final transient Logger log = LoggerFactory.getLogger(RmixmlProtocol.class);
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Protocol#install(java.net.URI,
+ * uk.ac.ic.doc.dse.ponder2.Result)
+ */
+ public void install(URI address, URI remote) throws Ponder2RemoteException {
+
+ // If we don't have a local address, we had better make one up
+ if (address == null) {
+ try {
+ String host = InetAddress.getLocalHost().getHostAddress();
+ int rand = new Random().nextInt();
+ address = new URI("rmixml://" + host + "/Ponder2-" + rand);
+ }
+ catch (UnknownHostException e) {
+ // This should not happen! That's what they all say.
+ throw new Ponder2RemoteException("RmiXmlProtocol: unknown host " + address + ": "
+ + e.getMessage());
+ }
+ catch (URISyntaxException e) {
+ // Nor this!
+ throw new Ponder2RemoteException("RmiXmlProtocol URI syntax error " + address + ": "
+ + e.getMessage());
+ }
+ }
+ Path path = new Path(address.getSchemeSpecificPart());
+ String RMIName = path.tail(1);
+ try {
+ // Register a new name for this SMC with the rmiregistry
+ new RmiXmlReceiver(RMIName);
+ System.out.println("Remote RMI address is " + address);
+ log.info("Remote RMI address is " + address);
+ }
+ catch (RemoteException e) {
+ throw new Ponder2RemoteException("RmiXmlProtocol cannot contact RMI registry for " + RMIName
+ + ". Is it running? " + (SelfManagedCell.SystemTrace ? e.getMessage() : ""));
+ }
+ catch (MalformedURLException e) {
+ throw new Ponder2RemoteException("RmiXmlProtocol: bad RMI name " + RMIName + ": "
+ + e.getMessage());
+ }
+ String protocol = address.getScheme().toLowerCase();
+ // Now register the protocol and let the external managed object use it
+ ExternalManagedObject.registerProtocol(protocol, new RmiXmlTransmitter(), address);
+ }
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/SocketProtocol.java b/ponder2/src/main/java/eu/novi/ponder2/comms/SocketProtocol.java
new file mode 100644
index 0000000..cb233a8
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/SocketProtocol.java
@@ -0,0 +1,172 @@
+/**
+ * Copyright 2006 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 20, 2006
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.comms;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import eu.novi.ponder2.comms.socket.SocketReceiver;
+import eu.novi.ponder2.comms.socket.SocketTransmitter;
+
+import eu.novi.ponder2.ExternalManagedObject;
+import eu.novi.ponder2.Shell;
+import eu.novi.ponder2.exception.Ponder2RemoteException;
+
+/**
+ * RMI protocol implementation for inter-SMC chit-chat
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class SocketProtocol implements Protocol, Runnable {
+
+ public static final int portbase = 23570;
+ public static int port = portbase;
+ public static final int maxport = 24000;
+ protected ServerSocket serverSocket;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Protocol#install(java.net.URI,
+ * uk.ac.ic.doc.dse.ponder2.Result)
+ */
+ public void install(URI address, URI remote) throws Ponder2RemoteException {
+ serverSocket = null;
+ // If we don't have a local address, we had better make one up
+ if (address == null) {
+ String host = null;
+ boolean gotPort = false;
+ while (!gotPort) {
+ try {
+ System.out.println("SocketProtocol: trying port " + port);
+ serverSocket = Shell.setup(port);
+ gotPort = true;
+ host = Utilities.getLocalIpAddress();
+ String newaddress = "socket://" + host + ":" + port;
+ address = new URI(newaddress);
+ System.out.println("SocketProtocol: opened port: " + newaddress);
+ }
+ catch (IOException e) {
+ port++;
+ if (port > maxport)
+ throw new Ponder2RemoteException("SocketProtocol: Cannot assign any ports: "
+ + e.getMessage());
+ }
+ catch (URISyntaxException e) {
+ throw new Ponder2RemoteException("SocketProtocol URI syntax error " + "socket://" + host
+ + ":" + port + " - " + e.getMessage());
+ }
+ }
+ }
+ else {
+ HostPort hostport = new HostPort(address);
+ String host = hostport.host;
+
+ // Try a few times to get this port, may be in time-wait state
+ int tries = 33;
+ IOException error = null;
+ while (tries-- > 0) {
+ try {
+ serverSocket = Shell.setup(hostport.port);
+ break;
+ }
+ catch (IOException e) {
+ error = e;
+ if (!e.getMessage().contains("Address already in use"))
+ break;
+ System.out.println("SocketProtocol: waiting for port " + port + " - " + tries
+ + " tries left: " + e.getMessage());
+ try {
+ Thread.sleep(2000);
+ }
+ catch (InterruptedException e1) {
+ }
+ }
+ }
+ if (serverSocket == null) {
+ throw new Ponder2RemoteException("SocketProtocol: Cannot assign port " + host + ":"
+ + hostport.port + " (" + address + "): " + error.getMessage());
+ }
+ System.out.println("Remote Socket address is " + address);
+ // OK we have the port set up
+ try {
+ if (host.equalsIgnoreCase("localhost") || host.equals("127.0.0.1")) {
+ host = Utilities.getLocalIpAddress();
+ address = new URI("socket://" + host + ":" + port);
+ }
+ }
+ catch (URISyntaxException e) {
+ throw new Ponder2RemoteException("SocketProtocol URI syntax error " + "socket://" + host
+ + ":" + port + " - " + e.getMessage());
+ }
+ }
+ new Thread(this).start();
+ String protocol = address.getScheme().toLowerCase();
+ // Now register the protocol and let the external managed object use it
+ ExternalManagedObject.registerProtocol(protocol, new SocketTransmitter(), address);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Runnable#run()
+ */
+ public void run() {
+ while (true) {
+ try {
+ Socket clientSocket = serverSocket.accept();
+ new SocketReceiver(clientSocket);
+ }
+ catch (IOException e) {
+ System.out.print("SocketProtocol: lost connection");
+ }
+ }
+ }
+
+ public static class HostPort {
+
+ public String host;
+ @SuppressWarnings("hiding")
+ public int port;
+
+ public HostPort(URI address) {
+ String hostport = address.getSchemeSpecificPart();
+ // remove leading '/'s
+ while (hostport.length() > 0 && hostport.charAt(0) == '/')
+ hostport = hostport.substring(1);
+ // New style with a ':' or old with a '/'?
+ int index = hostport.indexOf(':');
+ if (index < 0)
+ index = hostport.indexOf('/');
+ host = hostport.substring(0, index);
+ port = Integer.parseInt(hostport.substring(index + 1));
+ }
+ }
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/SscProtocol.java b/ponder2/src/main/java/eu/novi/ponder2/comms/SscProtocol.java
new file mode 100644
index 0000000..4db57e7
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/SscProtocol.java
@@ -0,0 +1,125 @@
+/**
+ * Copyright 2006 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 20, 2006
+ *
+ * $Log:$
+ *//*
+
+package eu.novi.ponder2.comms;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import eu.novi.ponder2.ExternalManagedObject;
+import eu.novi.ponder2.SelfManagedCell;
+import eu.novi.ponder2.exception.Ponder2RemoteException;
+
+import com.twicom.comms.singlesocket.client.Client;
+
+import eu.novi.ponder2.comms.ssc.SscReceiver;
+import eu.novi.ponder2.comms.ssc.SscTransmitter;
+
+*//**
+ * Single Socket Protocol implementation for inter-SMC chit-chat
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ *//*
+public class SscProtocol implements Protocol {
+
+
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Protocol#install(java.net.URI,
+ * uk.ac.ic.doc.dse.ponder2.Result)
+
+ public void install(URI address, URI remote) throws Ponder2RemoteException {
+ try {
+ String host;
+ int port;
+ String name;
+ String protocol;
+
+ if (address != null) {
+ protocol = address.getScheme().toLowerCase();
+ host = address.getHost();
+ port = address.getPort();
+ name = address.getPath();
+ }
+ else {
+ if (remote == null)
+ throw new Ponder2RemoteException("Invalid empty address");
+
+ protocol = remote.getScheme().toLowerCase();
+ // We need the host:port because that is the address of the server
+ host = remote.getHost();
+ port = remote.getPort();
+ // We need to make up a unique name, don't use the remote's
+ name = null;
+ }
+
+ // get a unique string ready
+ String unique = SelfManagedCell.RootDomain.getOID().getUid();
+ if (unique.charAt(0)=='-')
+ unique = unique.substring(1);
+
+ // Verify name
+ if (name == null || name.length() == 0) {
+ // We need to make up a unique name
+ name = unique;
+ }
+
+ // Check we don't have a / at the beginning
+ if (name.charAt(0) == '/')
+ name = name.substring(1);
+
+ // Check we still have a name
+ if (name.length() == 0) {
+ // We need to make up a unique name
+ name = unique;
+ }
+
+ // See if we need to add a unique identifier
+ if (name.endsWith("-")) {
+ name = name + unique;
+ }
+
+ Client client = new Client(name, host, port);
+
+ new SscReceiver(client);
+
+ // Now register the protocol and let the external managed object use it
+ try {
+ address = new URI(protocol, null, host, port, "/" + name, null, null);
+ ExternalManagedObject.registerProtocol(protocol, new SscTransmitter(client), address);
+ }
+ catch (URISyntaxException e) {
+ throw new Ponder2RemoteException("SscProtocol: failed to create new URI: " + e.getMessage());
+ }
+
+ }
+ catch (IOException e) {
+ throw new Ponder2RemoteException(e.getMessage());
+ }
+ }
+}
+*/ \ No newline at end of file
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/Transmitter.java b/ponder2/src/main/java/eu/novi/ponder2/comms/Transmitter.java
new file mode 100644
index 0000000..db11946
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/Transmitter.java
@@ -0,0 +1,106 @@
+/**
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 23, 2006
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.comms;
+
+import java.net.URI;
+
+import eu.novi.ponder2.OID;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2RemoteException;
+import eu.novi.ponder2.objects.P2Object;
+
+import eu.novi.ponder2.comms.Transmitter;
+
+/**
+ * Describes the methods that all Ponder2 comms protocols for inter-SMC
+ * communication must supply
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public interface Transmitter {
+
+ /**
+ * creates and connects a Transmitter to a remote location. This is called
+ * once every time a new remote address is brought into play. If the
+ * location is important to the Transmitter i.e. a permanent channel is
+ * opened then a new instance of transmitter should be created. If the
+ * remote location does not matter then only one instance of the Transmitter
+ * need be created and this method can return itself.
+ *
+ * @param address
+ * the location that this protocol is to be connected to
+ * @return a new communications protocol connected to the appropriate place
+ * or throw an error if it fails
+ * @throws Ponder2RemoteException
+ */
+ public Transmitter connect(URI address) throws Ponder2RemoteException;
+
+ /**
+ * Checks to see if the remote service is up and running. Returns true or
+ * false.
+ *
+ * @param address
+ * the address of the remote service
+ * @return true if the service is running
+ */
+ public boolean ping(URI address);
+
+ /**
+ * gets a managed object from a remote SMC
+ *
+ * @param address
+ * the address of the remote SMC
+ * @param path
+ * the full path name of the remote managed object
+ * @return the result of the operation.
+ * @throws Ponder2Exception
+ * if an exception occurs in the remote system
+ */
+ public P2Object getObject(URI address, String path) throws Ponder2Exception;
+
+ /**
+ * executes commands at a remote managed object. The command will either be
+ * a create or use clause.
+ *
+ * @param address
+ * the address of the remote SMC
+ * @param target
+ * the remote object's OID
+ * @param source
+ * the originator of the operation
+ * @param op
+ * the operation to be performed
+ * @param args
+ * the arguments for the operation
+ * @return the result of the operation as a Ponder2 object
+ * @throws Ponder2Exception
+ * if an exception occurs in the remote system
+ */
+ public P2Object execute(URI address, OID target, P2Object source,
+ String op, P2Object[] args) throws Ponder2Exception;
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/TransmitterImpl.java b/ponder2/src/main/java/eu/novi/ponder2/comms/TransmitterImpl.java
new file mode 100644
index 0000000..db48e45
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/TransmitterImpl.java
@@ -0,0 +1,309 @@
+/**
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 23, 2006
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.comms;
+
+import java.net.URI;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+
+import eu.novi.ponder2.comms.P2Serializable;
+import eu.novi.ponder2.comms.Transmitter;
+
+import com.twicom.qdparser.TaggedElement;
+import com.twicom.qdparser.XMLReader;
+
+import eu.novi.ponder2.OID;
+import eu.novi.ponder2.SelfManagedCell;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2OperationException;
+import eu.novi.ponder2.exception.Ponder2RemoteException;
+import eu.novi.ponder2.objects.P2Object;
+
+/**
+ * Describes the methods that all Ponder2 comms protocols for inter-SMC
+ * communication must supply
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public abstract class TransmitterImpl implements Transmitter {
+
+ /**
+ * creates and connects a Transmitter to a remote location. This is called
+ * once every time a new remote address is brought into play. If the
+ * location is important to the Transmitter i.e. a permanent channel is
+ * opened then a new instance of transmitter should be created. If the
+ * remote location does not matter then only one instance of the Transmitter
+ * need be created and this method can return itself.
+ *
+ * @param address
+ * the location that this protocol is to be connected to
+ * @return a new communications protocol connected to the appropriate place
+ * or null if it fails
+ * @throws Ponder2RemoteException
+ */
+ public Transmitter connect(URI address) throws Ponder2RemoteException {
+ return this;
+ }
+
+ /**
+ * Checks to see if the remote service is up and running. Returns true or
+ * false.
+ *
+ * @param address
+ * the address of the remote service
+ * @return true if the service is running
+ */
+ public boolean ping(URI address) {
+ try {
+ getObject(address, "root");
+ return true;
+ } catch (Exception e) {
+ if (SelfManagedCell.SystemTrace)
+ System.err.println("Ping failed for " + address);
+ return false;
+ }
+ }
+
+ /**
+ * gets a managed object from a remote SMC
+ *
+ * @param address
+ * the address of the remote SMC
+ * @param path
+ * the full path name of the remote managed object
+ * @return the requested Ponder2 object
+ * @throws Ponder2Exception
+ */
+ public abstract P2Object getObject(URI address, String path)
+ throws Ponder2Exception;
+
+ /**
+ * gets a managed object from a remote SMC using XML for the communications
+ *
+ * @param address
+ * the address of the remote SMC
+ * @param path
+ * the full path name of the remote managed object
+ * @return the requested Ponder2 object
+ * @throws Ponder2Exception
+ */
+ protected final P2Object getObjectXml(URI address, String path)
+ throws Ponder2Exception {
+ TaggedElement xml = makeXmlGetObject(address, path);
+ TaggedElement reply = execute(address, xml);
+ return P2Object.fromXml(reply, new HashMap<Integer, P2Serializable>());
+ }
+
+ /**
+ * gets a managed object from a remote SMC using XML as a string for the
+ * communications
+ *
+ * @param address
+ * the address of the remote SMC
+ * @param path
+ * the full path name of the remote managed object
+ * @return the requested Ponder2 object
+ * @throws Ponder2Exception
+ */
+ protected final P2Object getObjectString(URI address, String path)
+ throws Ponder2Exception {
+ TaggedElement xml = makeXmlGetObject(address, path);
+ String sxml = xml.toString(false);
+ String reply = execute(address, sxml);
+ return P2Object.fromXml(XMLReader.parse(reply),
+ new HashMap<Integer, P2Serializable>());
+ }
+
+ /**
+ * Rolls the getObject parameters into an XML structure. This method has to
+ * be match by its counterpart in Receiver.
+ *
+ * @param address
+ * the address of the remote SMC
+ * @param path
+ * the full path name of the remote managed object
+ * @return the newly created XML structure
+ * @throws Ponder2Exception
+ */
+ private final TaggedElement makeXmlGetObject(URI address, String path)
+ throws Ponder2Exception {
+ TaggedElement xml = new TaggedElement("P2Remote");
+ xml.setAttribute("action", "getobject");
+ xml.setAttribute("address", address.toString());
+ xml.setAttribute("path", path);
+ return xml;
+ }
+
+ /**
+ * executes commands at a remote managed object
+ *
+ * @param address
+ * the address of the remote SMC
+ * @param target
+ * the remote object's OID
+ * @param source
+ * the originator of the operation
+ * @param op
+ * the operation to be performed
+ * @param args
+ * the arguments for the operation
+ * @return the result of the operation
+ * @throws Ponder2Exception
+ */
+ public abstract P2Object execute(URI address, OID target, P2Object source,
+ String op, P2Object[] args) throws Ponder2Exception;
+
+ /**
+ * executes commands at a remote managed object. All the information is
+ * rolled into an XML structure which is passed to the remote site
+ *
+ * @param address
+ * the address of the remote SMC
+ * @param target
+ * the remote object's OID
+ * @param source
+ * the originator of the operation
+ * @param op
+ * the operation to be performed
+ * @param args
+ * the arguments for the operation
+ * @return the result of the operation
+ * @throws Ponder2Exception
+ */
+ protected final P2Object executeXml(URI address, OID target,
+ P2Object source, String op, P2Object[] args)
+ throws Ponder2Exception {
+ TaggedElement xml = makeXmlExecute(address, target, source, op, args);
+ TaggedElement reply = execute(address, xml);
+ return P2Object.fromXml(reply, new HashMap<Integer, P2Serializable>());
+ }
+
+ /**
+ * executes commands at a remote managed object. All the information is
+ * rolled into an XML structure which is passed to the remote site as a
+ * string
+ *
+ * @param address
+ * the address of the remote SMC
+ * @param target
+ * the remote object's OID
+ * @param source
+ * the originator of the operation
+ * @param op
+ * the operation to be performed
+ * @param args
+ * the arguments for the operation
+ * @return the result of the operation
+ * @throws Ponder2Exception
+ */
+ protected final P2Object executeString(URI address, OID target,
+ P2Object source, String op, P2Object[] args)
+ throws Ponder2Exception {
+ TaggedElement xml = makeXmlExecute(address, target, source, op, args);
+ String sxml = xml.toString(false);
+ String reply = execute(address, sxml);
+ return P2Object.fromXml(XMLReader.parse(reply),
+ new HashMap<Integer, P2Serializable>());
+ }
+
+ /**
+ * Rolls the execute arguments into a single XML structure. This method must
+ * be matched by the method in Receiver which unravels the arguments before
+ * executing them.
+ *
+ * @param address
+ * the address of the remote SMC
+ * @param target
+ * the remote object's OID
+ * @param source
+ * the originator of the operation
+ * @param op
+ * the operation to be performed
+ * @param args
+ * the arguments for the operation
+ * @return the newly created XML structure
+ * @throws Ponder2Exception
+ */
+ private final TaggedElement makeXmlExecute(URI address, OID target,
+ P2Object source, String op, P2Object[] args)
+ throws Ponder2Exception {
+ TaggedElement xml = new TaggedElement("P2Remote");
+ xml.setAttribute("action", "execute");
+ xml.setAttribute("address", address.toString());
+ xml.setAttribute("op", op);
+ Set<P2Object> written = new HashSet<P2Object>();
+ TaggedElement xtarget = target.writeXml(written);
+ xml.add(xtarget);
+ TaggedElement xsource = source.writeXml(written);
+ xml.add(xsource);
+ for (int i = 0; i < args.length; i++) {
+ xml.add(args[i].writeXml(written));
+ }
+ return xml;
+ }
+
+ // The following classes must be overridden when using one or more of the
+ // above,
+ // matching execute methods
+
+ /**
+ * Executes a command remotely
+ *
+ * @param address
+ * the address of the remote SMC
+ * @param xml
+ * all the required arguments rolled into an XML structure
+ * @return the object returned after executing the xmlString
+ * @throws Ponder2Exception
+ */
+ protected TaggedElement execute(URI address, TaggedElement xml)
+ throws Ponder2Exception {
+ throw new Ponder2OperationException(
+ "Transmitter execute xml is not valid for class "
+ + this.getClass().getCanonicalName());
+ }
+
+ /**
+ * Executes a command remotely
+ *
+ * @param address
+ * the address of the remote SMC
+ * @param xmlString
+ * all the required arguments rolled into an XML structure
+ * expressed as a string
+ * @return the object returned after executing the xmlString
+ * @throws Ponder2Exception
+ */
+ protected String execute(URI address, String xmlString)
+ throws Ponder2Exception {
+ throw new Ponder2OperationException(
+ "Transmitter execute string is not valid for class "
+ + this.getClass().getCanonicalName());
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/Utilities.java b/ponder2/src/main/java/eu/novi/ponder2/comms/Utilities.java
new file mode 100644
index 0000000..379189e
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/Utilities.java
@@ -0,0 +1,81 @@
+/**
+ * Copyright 2008 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Feb 9, 2010
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.comms;
+
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.util.Enumeration;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class Utilities {
+
+ /**
+ * Finds the local IP address. In the normal Java call returns the localhost
+ * number then the interfaces are checked to see if a nonlocal IP number can
+ * be obtained. If not the localhost number is ised.
+ *
+ * @return the local IP address
+ */
+ public static String getLocalIpAddress() {
+ try {
+ String host = InetAddress.getLocalHost().getHostAddress();
+ if (!host.startsWith("127.")) {
+ System.out.println("Ponder2Comms: local host is: " + host);
+ return host;
+ }
+ for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en
+ .hasMoreElements();) {
+ NetworkInterface intf = en.nextElement();
+ for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr
+ .hasMoreElements();) {
+ InetAddress inetAddress = enumIpAddr.nextElement();
+ System.out.println("Ponder2Comms: Looking at " + inetAddress.getHostAddress());
+ if (!inetAddress.isLoopbackAddress()) {
+ host = inetAddress.getHostAddress().toString();
+ System.out.println("Ponder2Comms: local host is: " + host);
+ return host;
+ }
+ }
+ }
+ }
+ catch (SocketException e) {
+ System.err.println("Ponder2Comms: Trying to find local IP address " + e.getMessage());
+ }
+ catch (UnknownHostException e) {
+ System.err.println("Ponder2Comms: Trying to find local IP address " + e.getMessage());
+ }
+ System.out.println("Ponder2Comms: no external IP number found - using localhost");
+ return "127.0.0.1";
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/XmlblasterProtocol.java b/ponder2/src/main/java/eu/novi/ponder2/comms/XmlblasterProtocol.java
new file mode 100644
index 0000000..a468158
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/XmlblasterProtocol.java
@@ -0,0 +1,169 @@
+/**
+ * Copyright 2008 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Feb 6, 2010
+ *
+ * $Log:$
+ *//*
+
+package eu.novi.ponder2.comms;
+
+import java.net.URI;
+
+import eu.novi.ponder2.ExternalManagedObject;
+import eu.novi.ponder2.SelfManagedCell;
+import eu.novi.ponder2.exception.Ponder2RemoteException;
+
+import org.xmlBlaster.client.I_XmlBlasterAccess;
+import org.xmlBlaster.client.key.PublishKey;
+import org.xmlBlaster.client.key.SubscribeKey;
+import org.xmlBlaster.client.qos.ConnectQos;
+import org.xmlBlaster.client.qos.ConnectReturnQos;
+import org.xmlBlaster.client.qos.PublishQos;
+import org.xmlBlaster.client.qos.SubscribeQos;
+import org.xmlBlaster.util.Global;
+import org.xmlBlaster.util.MsgUnit;
+import org.xmlBlaster.util.SessionName;
+import org.xmlBlaster.util.XmlBlasterException;
+import org.xmlBlaster.util.property.Property;
+import org.xmlBlaster.util.qos.address.Address;
+import org.xmlBlaster.util.qos.address.Destination;
+import org.xmlBlaster.util.qos.storage.ClientQueueProperty;
+
+import eu.novi.ponder2.comms.xmlblaster.XmlBlasterReceiver;
+import eu.novi.ponder2.comms.xmlblaster.XmlBlasterSync;
+import eu.novi.ponder2.comms.xmlblaster.XmlBlasterTransmitter;
+
+*//**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ *//*
+public class XmlblasterProtocol implements Protocol {
+
+ private I_XmlBlasterAccess con;
+ public static final String P2TOPIC = "Ponder2Message";
+
+
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Protocol#install(java.net.URI)
+
+ public void install(URI address, URI remote) throws Ponder2RemoteException {
+
+ try {
+ // Set up semaphore block for this connection
+ // we need to sync the requests and replies
+ XmlBlasterSync sync = new XmlBlasterSync();
+
+ // Sort out our name
+ String host = null;
+ int port = -1;
+ String clientName;
+ if (address == null) {
+ clientName = SelfManagedCell.RootDomain.getOID().getUid();
+ }
+ else {
+ host = address.getHost();
+ port = address.getPort();
+ // Get name and knock off leading '/'
+ clientName = address.getPath();
+ clientName = clientName.substring(1);
+ }
+ clientName = "Ponder2_" + clientName;
+
+ final Global glob = new Global();
+ con = glob.getXmlBlasterAccess();
+
+ Property property = glob.getProperty();
+ property.set("protocol", "SOCKET");
+ property.set("persistence/defaultPlugin", "RAM");
+ property.set("queue/defaultPlugin", "RAM");
+ if (host != null)
+ property.set("dispatch/connection/plugin/socket/hostname", host);
+ if (port > 0)
+ property.set("dispatch/connection/plugin/socket/port", "" + port);
+
+ ClientQueueProperty prop = new ClientQueueProperty(glob, null);
+ // Client side queue up to 100 entries if not connected
+ prop.setMaxEntries(100);
+
+ Address channel = new Address(glob);
+ channel.setType("SOCKET"); // force SOCKET protocol
+ channel.setDelay(4000L); // retry connecting every 4 sec
+ channel.setRetries(-1); // -1 == forever
+ // channel.setPingInterval(2000L); // ping every 2 sec
+ prop.setAddress(channel);
+
+ // Give name and password
+ ConnectQos qos = new ConnectQos(glob);
+ qos.setSessionName(new SessionName(glob, clientName));
+ qos.setPersistent(true);
+ qos.setPtpAllowed(true);
+ qos.addClientQueueProperty(prop);
+
+ // Login to xmlBlaster, register for updates
+ ConnectReturnQos conRetQos = con.connect(qos, new XmlBlasterReceiver(con, sync));
+
+ System.out.println("connection name is :" + con.getSessionName().getRelativeName());
+ System.out.println(("Sender connected to xmlBlaster " + conRetQos.getSessionName()
+ .getRelativeName()));
+
+ // // Erase our topic
+ // EraseKey ek = new EraseKey(glob, P2TOPIC);
+ // EraseQos eq = new EraseQos(glob);
+ // con.erase(ek, eq);
+
+ // Subscribe to our topic
+ SubscribeKey sk = new SubscribeKey(glob, P2TOPIC);
+ SubscribeQos sq = new SubscribeQos(glob);
+ // Suppress duplicate updates
+ //sq.setMultiSubscribe(false);
+ sq.setPersistent(true);
+
+ con.subscribe(sk, sq);
+
+ ExternalManagedObject.registerProtocol("xmlblaster", new XmlBlasterTransmitter(con, sync),
+ address);
+ }
+ catch (XmlBlasterException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ public static void publish(I_XmlBlasterAccess connection, Destination destination,
+ String message, String type, String ponder2id) throws XmlBlasterException {
+ Global glob = connection.getGlobal();
+ // PublishKey pk = new PublishKey(glob, XmlblasterProtocol.P2TOPIC);
+ // No need to use a topic if using PtP
+ PublishKey pk = new PublishKey(glob);
+ PublishQos pq = new PublishQos(glob);
+ destination.forceQueuing(true);
+ pq.addDestination(destination);
+ pq.addClientProperty("Ponder2msgtype", type);
+ pq.addClientProperty("Ponder2id", ponder2id);
+ MsgUnit msgUnit = new MsgUnit(pk, message, pq);
+ connection.publish(msgUnit);
+ }
+
+}
+*/ \ No newline at end of file
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/http/HTTPTransmitter.java b/ponder2/src/main/java/eu/novi/ponder2/comms/http/HTTPTransmitter.java
new file mode 100644
index 0000000..38301df
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/http/HTTPTransmitter.java
@@ -0,0 +1,133 @@
+///**
+// * Copyright 2005 Imperial College, London, England.
+// *
+// * This library is free software; you can redistribute it and/or
+// * modify it under the terms of the GNU Lesser General Public
+// * License as published by the Free Software Foundation; either
+// * version 2.1 of the License, or (at your option) any later version.
+// *
+// * This library is distributed in the hope that it will be useful,
+// * but WITHOUT ANY WARRANTY; without even the implied warranty of
+// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// * Lesser General Public License for more details.
+// *
+// * You should have received a copy of the GNU Lesser General
+// * Public License along with this library; if not, write to the
+// * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+// * Boston, MA 02110-1301 USA
+// *
+// * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+// *
+// * Created on Mar 24, 2006
+// *
+// * $Log:$
+// */
+//
+//package eu.novi.ponder2.comms.http;
+//
+//import java.net.URI;
+//import java.rmi.RemoteException;
+//
+//import javax.xml.namespace.QName;
+//import javax.xml.rpc.Call;
+//
+//import eu.novi.ponder2.OID;
+//import eu.novi.ponder2.exception.Ponder2Exception;
+//import eu.novi.ponder2.exception.Ponder2RemoteException;
+//import eu.novi.ponder2.objects.P2Object;
+//
+//import org.apache.axis.client.Service;
+//
+//import eu.novi.ponder2.comms.Transmitter;
+//import eu.novi.ponder2.comms.TransmitterImpl;
+//
+//
+//
+///**
+// * Class for sending commands to remote managed objects using Web Services via
+// * HTTP
+// *
+// * @author Kevin Twidle
+// * @version $Id:$
+// */
+//public class HTTPTransmitter extends TransmitterImpl implements Transmitter {
+//
+// @Override
+// public Transmitter connect(URI location) {
+// // We use the location in every call, we can just return ourself
+// return this;
+// }
+//
+//// /*
+//// * (non-Javadoc)
+//// *
+//// * @see net.ponder2.comms.Transmitter#getObject(java.net.URI,
+//// * java.lang.String, net.ponder2.Result)
+//// */
+//// public P2OID getObject(URI location, String path) {
+//// return call(location, "getObject", location.toString(), path);
+//// }
+//
+// /* (non-Javadoc)
+// * @see net.ponder2.comms.Transmitter#getObject(java.net.URI, java.lang.String)
+// */
+// @Override
+// public P2Object getObject(URI address, String path) throws Ponder2Exception {
+// return getObjectString(address, path);
+// }
+//
+// /* (non-Javadoc)
+// * @see net.ponder2.comms.Transmitter#execute(java.net.URI, net.ponder2.OID, net.ponder2.objects.P2Object, java.lang.String, net.ponder2.objects.P2Object[])
+// */
+// @Override
+// public P2Object execute(URI address, OID target, P2Object source, String op, P2Object[] args) throws Ponder2Exception {
+// return executeString(address, target, source, op, args);
+// }
+//
+//
+// /* (non-Javadoc)
+// * @see net.ponder2.comms.TransmitterImpl#execute(java.net.URI, java.lang.String)
+// */
+// @Override
+// protected String execute(URI address, String xmlString) throws Ponder2Exception {
+// try {
+// Service service = new Service();
+// Call call = service.createCall();
+//
+// call.setOperationName(new QName(address.toString(), "execute"));
+// call.setTargetEndpointAddress(address.toString());
+// return (String)call.invoke(new Object[] {xmlString});
+// }
+// catch (Exception e) {
+// throw new Ponder2RemoteException(e.getMessage());
+// }
+// }
+//
+// /**
+// * sets up and performs the actual call to the remote Web Service
+// *
+// * @param endpoint
+// * the address of the remote web service
+// * @param operation
+// * the operaton to be performed at the remote site
+// * @param args
+// * an array of string arguments for the operation
+// * @return the standard result structure from the remote site containing OIDs
+// * or errors
+// * @throws RemoteException
+// * @throws Exception
+// */
+// public static P2Object call(URI endpoint, String operation, String... args) throws Exception {
+// Service service = new Service();
+// Call call = service.createCall();
+//
+// call.setOperationName(new QName(endpoint.toString(), operation));
+// call.setTargetEndpointAddress(endpoint.toString());
+// call.invoke(args);
+// System.out.println("HTTPTransmitter: Invoke returns ");
+// return null;
+// }
+//
+//
+//
+//}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/http/Ponder2.jws b/ponder2/src/main/java/eu/novi/ponder2/comms/http/Ponder2.jws
new file mode 100644
index 0000000..221aa29
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/http/Ponder2.jws
@@ -0,0 +1,63 @@
+package net.ponder2.comms.http;
+
+// This file should be places in the appropriate place in the Axis 1 installation. It communicates with a local
+// Ponder2 application using the RMI name Ponder2
+// Remove the package line above.
+
+/*
+ * Copyright 2002,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.rmi.Naming;
+
+import net.ponder2.PonderTalkInterface;
+import net.ponder2.comms.rmistring.RmiStringReceiveInterface;
+
+/**
+ * class to list headers sent in request as a string array
+ */
+public class Ponder2 {
+
+ public static String PONDER2 = "rmi://localhost/Ponder2";
+
+ public static String PONDERTALK = "rmi://localhost/PonderTalk";
+
+ public String execute(String xmlString) {
+ String reply = "Operation failed - lookup failed: " + PONDER2;
+ try {
+ RmiStringReceiveInterface ponder2 = (RmiStringReceiveInterface)Naming.lookup(PONDER2);
+ if (ponder2 != null)
+ reply = ponder2.execute(xmlString);
+ }
+ catch (Exception e) {
+ reply = "Operation failed " + e.getMessage();
+ }
+ return reply;
+ }
+
+ public String executePonderTalk(String ponderTalkString) {
+ String reply = "Operation failed - lookup failed: " + PONDERTALK;
+ try {
+ PonderTalkInterface ponderTalk = (PonderTalkInterface)Naming.lookup(PONDERTALK);
+ if (ponderTalk != null)
+ reply = ponderTalk.execute(ponderTalkString);
+ }
+ catch (Exception e) {
+ reply = "Operation failed " + e.getMessage();
+ }
+ return reply;
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/java.policy b/ponder2/src/main/java/eu/novi/ponder2/comms/java.policy
new file mode 100644
index 0000000..48184f1
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/java.policy
@@ -0,0 +1,3 @@
+ grant {
+ permission java.security.AllPermission;
+ }; \ No newline at end of file
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/rmi/CheckRMI.java b/ponder2/src/main/java/eu/novi/ponder2/comms/rmi/CheckRMI.java
new file mode 100644
index 0000000..f528d59
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/rmi/CheckRMI.java
@@ -0,0 +1,134 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Jun 4, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.comms.rmi;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+
+/**
+ * Check that rmiregistry is running, keep asking until it is running. This
+ * program does a system.exit from wherever it likes. Once it spots the
+ * rmiregistry working, it's bye bye
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class CheckRMI {
+
+ String locations[] = { "rmiregistry", "/bin/rmiregistry", "\\bin\\rmiregistry.exe"};
+
+ private Runtime runtime;
+
+ CheckRMI() {
+ runtime = Runtime.getRuntime();
+ checkRmi();
+
+ System.out.println("The RMI registry is not running, it will be started now.");
+ System.out.println("If running under Windows you may have to hit ctrl-C after");
+ System.out.println("it has been started and re-run the ant command.");
+ startRegistry();
+ for (int i = 0; i < 5; i++) {
+ sleep(1);
+ checkRmi();
+ }
+ while (true) {
+ doDialog();
+ checkRmi();
+ }
+ }
+
+ void doDialog() {
+ JFrame frame = null;
+ Object[] options = { "Cancel", "Check Again"};
+ int n = JOptionPane.showOptionDialog(frame,
+ "Failed to start rmiregistry\nPlease start it and click Check Again\nIf you are running Safari on Windows\nplease stop it and run this program again!", "RMI Registry",
+ JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
+ if (n != 1)
+ System.exit(1);
+ }
+
+ void startRegistry() {
+ String home = System.getenv("JAVA_HOME");
+ for (int i = 0; i < locations.length; i++) {
+ startRegistryAt(locations[i]);
+ startRegistryAt(home + locations[i]);
+ }
+ }
+
+ void startRegistryAt(String name) {
+ try {
+ System.out.println("Trying to start rmi registry: " + name);
+ runtime.exec(name);
+ sleep(1);
+ checkRmi();
+ }
+ catch (IOException e) {
+ }
+ }
+
+ private void checkRmi() {
+ boolean answer = false;
+ try {
+ Naming.list("");;
+ answer = true;
+ }
+ catch (MalformedURLException e) {
+ e.printStackTrace();
+ System.err.println("Something wrong in CheckRMI, please report it");
+ System.exit(1);
+ }
+ catch (RemoteException e) {
+ answer = false;
+ }
+ System.out.println("rmiregistry" + (answer ? "" : " not") + " running");
+ if (answer)
+ System.exit(0);
+ }
+
+ private void sleep(int secs) {
+ try {
+ Thread.sleep(secs * 1000);
+ }
+ catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ new CheckRMI();
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/rmi/RMIReceiveInterface.java b/ponder2/src/main/java/eu/novi/ponder2/comms/rmi/RMIReceiveInterface.java
new file mode 100644
index 0000000..efbd8ba
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/rmi/RMIReceiveInterface.java
@@ -0,0 +1,88 @@
+/**
+ * Created on Sep 19, 2005
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * $Log: RMIReceiveInterface.java,v $
+ * Revision 1.2 2006/03/01 22:57:33 kpt
+ * Added remote execution of external xml via RMI
+ *
+ * Revision 1.1 2005/09/21 08:21:03 kpt
+ * First cut at external objects
+ *
+ */
+
+package eu.novi.ponder2.comms.rmi;
+
+import java.net.URI;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+import eu.novi.ponder2.OID;
+import eu.novi.ponder2.exception.Ponder2ArgumentException;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2OperationException;
+import eu.novi.ponder2.objects.P2Object;
+
+/**
+ * Interface description of the class handed over to the RMI registry. The RMI
+ * registry hand this description off to SMCs that look up the address. The
+ * methods below are operations that can be made through RMI with all
+ * serialisation and rebuilding done by the RMI system.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public interface RMIReceiveInterface extends Remote {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Transmitter#getObject(java.net.URI,
+ * java.lang.String, net.ponder2.Result)
+ */
+ public OID getObject(URI location, String path) throws RemoteException, Ponder2Exception;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Transmitter#execute(java.net.URI,
+ * com.twicom.qdparser.TaggedElement, com.twicom.qdparser.TaggedElement,
+ * net.ponder2.Result)
+ */
+ public P2Object execute(URI address, OID target, P2Object source, String op, P2Object[] args)
+ throws RemoteException, Ponder2Exception;
+
+ /**
+ * executes the given XML string. Used for external, non-SMC applications to
+ * inject XML into the system
+ *
+ * @param xmlString
+ * the XML commands to be executed
+ * @return the standard result structure as an XML string
+ * @throws RemoteException
+ * because it has to be a possibility
+ * @throws Ponder2OperationException
+ * @throws Ponder2ArgumentException
+ */
+ public P2Object executeXml(String xmlString) throws RemoteException, Ponder2Exception;
+
+ public P2Object executePonderTalk(String ponderTalk) throws RemoteException, Ponder2Exception;
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/rmi/RMIReceiver.java b/ponder2/src/main/java/eu/novi/ponder2/comms/rmi/RMIReceiver.java
new file mode 100644
index 0000000..9b0aa67
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/rmi/RMIReceiver.java
@@ -0,0 +1,146 @@
+/**
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 24, 2006
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.comms.rmi;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.rmi.AlreadyBoundException;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import eu.novi.ponder2.comms.Receiver;
+
+import eu.novi.ponder2.OID;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.objects.P2Object;
+import eu.novi.ponder2.parser.P2Compiler;
+import eu.novi.ponder2.parser.XMLParser;
+
+/**
+ * The receiving class that is registered with the rmiregistry. Any messages for
+ * this RMI name come through this receiver in its own thread.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class RMIReceiver extends UnicastRemoteObject implements RMIReceiveInterface {
+ private static final transient Logger log = LoggerFactory.getLogger(RMIReceiver.class);
+
+ /**
+ * creates an RMI receiver. This simply registers the RMI name and the new
+ * receiver with the rmi registry
+ *
+ * @param RMIName
+ * @throws RemoteException
+ * @throws MalformedURLException
+ */
+ public RMIReceiver(String RMIName) throws RemoteException, MalformedURLException {
+ register(RMIName);
+ }
+
+ /**
+ * registers the RMI name and this instance with the RMI registry
+ *
+ * @param RMIName
+ * the RMI name as a string
+ * @throws RemoteException
+ * if the RMI registry is not running or can't be contacted
+ * @throws MalformedURLException
+ * if the RMI name does not conform to the specification
+ */
+ public void register(String RMIName) {
+ try {
+ try {
+ System.out.println("Reading rmiregistry - " + RMIName);
+ log.info("Reading rmiregistry - " + RMIName);
+ String names[] = Naming.list(RMIName);
+ for (String name : names) {
+ System.out.println("Found in rmiregistry - " + name);
+ log.info("Found in rmiregistry - " + name);
+ }
+ Naming.bind(RMIName, this);
+ }
+ catch (AlreadyBoundException e) {
+ System.out.println("Rebinding " + RMIName);
+ log.info("Rebinding " + RMIName);
+ Naming.rebind(RMIName, this);
+ }
+ }
+ catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch (MalformedURLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ System.out.println("Local RMI address is " + RMIName);
+ log.info("Local RMI address is " + RMIName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.rmi.RMIReceiveInterface#getObject(java.net.URI,
+ * java.lang.String, net.ponder2.Result)
+ */
+ public OID getObject(URI location, String path) throws RemoteException, Ponder2Exception {
+ return Receiver.getObject(location, path).getOID();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.rmi.RMIReceiveInterface#execute(com.twicom.qdparser.TaggedElement,
+ * com.twicom.qdparser.TaggedElement, net.ponder2.Result)
+ */
+ public P2Object execute(URI address, OID target, P2Object source, String op, P2Object[] args)
+ throws RemoteException, Ponder2Exception {
+ return Receiver.execute(address, target, source, op, args);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.rmi.RMIReceiveInterface#execute(java.lang.String)
+ */
+ public P2Object executeXml(String xmlString) throws RemoteException, Ponder2Exception {
+ System.out.println("Remote RMI execute called for xml " + xmlString);
+ log.info("Remote RMI execute called for xml " + xmlString);
+ return new XMLParser().execute(null, xmlString);
+ }
+
+ public P2Object executePonderTalk(String ponderTalk) throws RemoteException, Ponder2Exception {
+ System.out.println("Remote RMI execute called for PonderTalk " + ponderTalk);
+ log.info("Remote RMI execute called for PonderTalk " + ponderTalk);
+ String xml = P2Compiler.parse(ponderTalk);
+ return new XMLParser().execute(null, xml);
+ }
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/rmi/RMITransmitter.java b/ponder2/src/main/java/eu/novi/ponder2/comms/rmi/RMITransmitter.java
new file mode 100644
index 0000000..07ce984
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/rmi/RMITransmitter.java
@@ -0,0 +1,165 @@
+/**
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 24, 2006
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.comms.rmi;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.rmi.ConnectException;
+import java.rmi.Naming;
+import java.rmi.NotBoundException;
+import java.rmi.RemoteException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import eu.novi.ponder2.comms.Transmitter;
+import eu.novi.ponder2.comms.TransmitterImpl;
+
+import eu.novi.ponder2.OID;
+import eu.novi.ponder2.StartStopPonder2SMC;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2OperationException;
+import eu.novi.ponder2.objects.P2Object;
+
+/**
+ * This class embodies the sending mechanism for inter-SMC communications using
+ * the RMI protocol. When instantiated it locks itself to one particular
+ * destination. One RMITransmitter is created for each RMI destination that is
+ * used.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class RMITransmitter extends TransmitterImpl implements Transmitter {
+ private static final transient Logger log = LoggerFactory.getLogger(RMITransmitter.class);
+ /**
+ * the receiving interface of the remote SMC
+ */
+ private RMIReceiveInterface remote = null;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Transmitter#connect(java.net.URI)
+ */
+ @Override
+ public Transmitter connect(URI address) {
+ RMITransmitter tx = new RMITransmitter();
+ if (tx.lookup(address))
+ return tx;
+ return null;
+ }
+
+ /**
+ * looks up the interface for the remote SMC
+ *
+ * @param location
+ * the remote RMI name
+ * @return true if the lookup succeeded
+ */
+ private boolean lookup(URI location) {
+ try {
+ Object obj = Naming.lookup(location.getSchemeSpecificPart());
+ remote = (RMIReceiveInterface)obj;
+ }
+ catch (MalformedURLException e) {
+ System.out.println("RMIReceiveInterface: bad form of address - " + location);
+ log.info("RMIReceiveInterface: bad form of address - " + location);
+ }
+ catch (RemoteException e) {
+ System.out.println("RMIReceiveInterface: remote exception - " + location + " - "
+ + e.getMessage());
+ log.info("RMIReceiveInterface: remote exception - " + location + " - "
+ + e.getMessage());
+ }
+ catch (NotBoundException e) {
+ System.out.println("RMIReceiveInterface: remote RMI name not bound - " + location);
+ log.info("RMIReceiveInterface: remote RMI name not bound - " + location);
+ }
+ return (remote != null);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Transmitter#getObject(java.net.URI,
+ * java.lang.String)
+ */
+ @Override
+ public P2Object getObject(URI location, String path) throws Ponder2Exception {
+ RemoteException error = null;
+ int tries = 0;
+ while (tries++ < 2) {
+ try {
+ OID oid = remote.getObject(location, path);
+ return oid.getP2Object();
+ }
+ catch (ConnectException e) {
+ error = e;
+ System.out.println("RMI Transmitter: lost remote. Reconnecting to " + location);
+ log.info("RMI Transmitter: lost remote. Reconnecting to " + location);
+
+ lookup(location);
+ }
+ catch (RemoteException e) {
+ error = e;
+ break;
+ }
+ }
+ throw new Ponder2OperationException(error.getMessage());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Transmitter#execute(java.net.URI, net.ponder2.OID,
+ * net.ponder2.objects.P2Object, java.lang.String,
+ * net.ponder2.objects.P2Object[])
+ */
+ @Override
+ public P2Object execute(URI address, OID target, P2Object source, String op, P2Object[] args)
+ throws Ponder2Exception {
+ RemoteException error = null;
+ int tries = 0;
+ while (tries++ < 2) {
+ try {
+ return remote.execute(address, target, source, op, args);
+ }
+ catch (ConnectException e) {
+ error = e;
+ System.out.println("RMI Transmitter: lost remote. Reconnecting to " + address);
+ log.info("RMI Transmitter: lost remote. Reconnecting to " + address);
+ lookup(address);
+ }
+ catch (RemoteException e) {
+ error = e;
+ break;
+ }
+ }
+ throw new Ponder2OperationException(error.getMessage());
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/rmistring/RmiStringReceiveInterface.java b/ponder2/src/main/java/eu/novi/ponder2/comms/rmistring/RmiStringReceiveInterface.java
new file mode 100644
index 0000000..db42ee6
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/rmistring/RmiStringReceiveInterface.java
@@ -0,0 +1,69 @@
+/**
+ * Created on Sep 19, 2005
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * $Log: RMIReceiveInterface.java,v $
+ * Revision 1.2 2006/03/01 22:57:33 kpt
+ * Added remote execution of external xml via RMI
+ *
+ * Revision 1.1 2005/09/21 08:21:03 kpt
+ * First cut at external objects
+ *
+ */
+
+package eu.novi.ponder2.comms.rmistring;
+
+import java.net.URI;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+import eu.novi.ponder2.exception.Ponder2Exception;
+
+import com.twicom.qdparser.TaggedElement;
+
+/**
+ * Interface description of the class handed over to the RMI registry. The RMI
+ * registry hand this description off to SMCs that look up the address. The
+ * methods below are operations that can be made through RMI with all
+ * serialisation and rebuilding done by the RMI system.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public interface RmiStringReceiveInterface extends Remote {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Transmitter#getObject(java.net.URI,
+ * java.lang.String, net.ponder2.Result)
+ */
+ public TaggedElement getObject(URI location, String path) throws RemoteException, Ponder2Exception;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Transmitter#execute(java.net.URI,
+ * com.twicom.qdparser.TaggedElement, com.twicom.qdparser.TaggedElement,
+ * net.ponder2.Result)
+ */
+ public String execute(String xml) throws RemoteException, Ponder2Exception;
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/rmistring/RmiStringReceiver.java b/ponder2/src/main/java/eu/novi/ponder2/comms/rmistring/RmiStringReceiver.java
new file mode 100644
index 0000000..1e07594
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/rmistring/RmiStringReceiver.java
@@ -0,0 +1,92 @@
+/**
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 24, 2006
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.comms.rmistring;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
+import java.util.HashSet;
+
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.objects.P2Object;
+
+import com.twicom.qdparser.TaggedElement;
+
+import eu.novi.ponder2.comms.Receiver;
+
+/**
+ * The receiving class that is registered with the rmiregistry. Any messages for
+ * this RMI name come through this receiver in its own thread.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class RmiStringReceiver extends UnicastRemoteObject implements RmiStringReceiveInterface {
+
+ /**
+ * creates an RMI receiver. This simply registers the RMI name and the new
+ * receiver with the rmi registry
+ *
+ * @param RMIName
+ * @throws RemoteException
+ * @throws MalformedURLException
+ */
+ public RmiStringReceiver(String RMIName) throws RemoteException, MalformedURLException {
+ register(RMIName);
+ }
+
+ /**
+ * registers the RMI name and this instance with the RMI registry
+ *
+ * @param RMIName
+ * the RMI name as a string
+ * @throws RemoteException
+ * if the RMI registry is not running or can't be contacted
+ * @throws MalformedURLException
+ * if the RMI name does not conform to the specification
+ */
+ public void register(String RMIName) throws RemoteException, MalformedURLException {
+ Naming.rebind(RMIName, this);
+ System.out.println("Local RMI String address is " + RMIName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.rmi.RMIReceiveInterface#getObject(java.net.URI,
+ * java.lang.String, net.ponder2.Result)
+ */
+ public TaggedElement getObject(URI location, String path) throws Ponder2Exception {
+ return Receiver.getObject(location, path).writeXml(new HashSet<P2Object>());
+ }
+
+ public String execute(String sxml) throws Ponder2Exception {
+ return Receiver.execute(sxml);
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/rmistring/RmiStringTransmitter.java b/ponder2/src/main/java/eu/novi/ponder2/comms/rmistring/RmiStringTransmitter.java
new file mode 100644
index 0000000..1922b21
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/rmistring/RmiStringTransmitter.java
@@ -0,0 +1,146 @@
+/**
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 24, 2006
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.comms.rmistring;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.rmi.Naming;
+import java.rmi.NotBoundException;
+import java.rmi.RemoteException;
+import java.util.HashMap;
+
+import eu.novi.ponder2.OID;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2OperationException;
+import eu.novi.ponder2.objects.P2Object;
+
+import com.twicom.qdparser.TaggedElement;
+
+import eu.novi.ponder2.comms.P2Serializable;
+import eu.novi.ponder2.comms.Transmitter;
+import eu.novi.ponder2.comms.TransmitterImpl;
+
+/**
+ * This class embodies the sending mechanism for inter-SMC communications using
+ * the RMI protocol. When instantiated it locks itself to one particular
+ * destination. One RMITransmitter is created for each RMI destination that is
+ * used.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class RmiStringTransmitter extends TransmitterImpl implements Transmitter {
+
+ /**
+ * the receiving interface of the remote SMC
+ */
+ private RmiStringReceiveInterface remote = null;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Transmitter#connect(java.net.URI)
+ */
+ @Override
+ public Transmitter connect(URI address) {
+ RmiStringTransmitter tx = new RmiStringTransmitter();
+ if (tx.lookup(address))
+ return tx;
+ return null;
+ }
+
+ /**
+ * looks up the interface for the remote SMC
+ *
+ * @param location
+ * the remote RMI name
+ * @return true if the lookup succeeded
+ */
+ private boolean lookup(URI location) {
+ try {
+ Object obj = Naming.lookup("rmi:" + location.getSchemeSpecificPart());
+ remote = (RmiStringReceiveInterface)obj;
+ }
+ catch (MalformedURLException e) {
+ System.out.println("RmiReceiveInterface: bad form of address - " + location);
+ }
+ catch (RemoteException e) {
+ System.out.println("RmiReceiveInterface: remote exception - " + location + " - "
+ + e.getMessage());
+ }
+ catch (NotBoundException e) {
+ System.out.println("RmiReceiveInterface: remote RMI name not bound - " + location);
+ }
+ return (remote != null);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.TransmitterImpl#getObject(java.net.URI,
+ * java.lang.String)
+ */
+ @Override
+ public P2Object getObject(URI location, String path) throws Ponder2Exception {
+ TaggedElement reply;
+ try {
+ reply = remote.getObject(location, path);
+ return P2Object.fromXml(reply, new HashMap<Integer,P2Serializable>());
+ }
+ catch (RemoteException e) {
+ throw new Ponder2OperationException(e.getMessage());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Transmitter#execute(java.net.URI, net.ponder2.OID,
+ * net.ponder2.objects.P2Object, java.lang.String,
+ * net.ponder2.objects.P2Object[])
+ */
+ @Override
+ public P2Object execute(URI address, OID target, P2Object source, String op, P2Object[] args)
+ throws Ponder2Exception {
+ return executeString(address, target, source, op, args);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.TransmitterImpl#execute(java.lang.String)
+ */
+ @Override
+ protected String execute(URI address, String xmlString) throws Ponder2Exception {
+ try {
+ return remote.execute(xmlString);
+ }
+ catch (RemoteException e) {
+ throw new Ponder2OperationException(e.getMessage());
+ }
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/rmixml/RmiXmlReceiveInterface.java b/ponder2/src/main/java/eu/novi/ponder2/comms/rmixml/RmiXmlReceiveInterface.java
new file mode 100644
index 0000000..29fc853
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/rmixml/RmiXmlReceiveInterface.java
@@ -0,0 +1,70 @@
+/**
+ * Created on Sep 19, 2005
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * $Log: RMIReceiveInterface.java,v $
+ * Revision 1.2 2006/03/01 22:57:33 kpt
+ * Added remote execution of external xml via RMI
+ *
+ * Revision 1.1 2005/09/21 08:21:03 kpt
+ * First cut at external objects
+ *
+ */
+
+package eu.novi.ponder2.comms.rmixml;
+
+import java.net.URI;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+import eu.novi.ponder2.exception.Ponder2Exception;
+
+import com.twicom.qdparser.TaggedElement;
+
+/**
+ * Interface description of the class handed over to the RMI registry. The RMI
+ * registry hand this description off to SMCs that look up the address. The
+ * methods below are operations that can be made through RMI with all
+ * serialisation and rebuilding done by the RMI system.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public interface RmiXmlReceiveInterface extends Remote {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Transmitter#getObject(java.net.URI,
+ * java.lang.String, net.ponder2.Result)
+ */
+ public TaggedElement getObject(URI location, String path) throws RemoteException,
+ Ponder2Exception;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Transmitter#execute(java.net.URI,
+ * com.twicom.qdparser.TaggedElement, com.twicom.qdparser.TaggedElement,
+ * net.ponder2.Result)
+ */
+ public TaggedElement execute(TaggedElement xml) throws RemoteException, Ponder2Exception;
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/rmixml/RmiXmlReceiver.java b/ponder2/src/main/java/eu/novi/ponder2/comms/rmixml/RmiXmlReceiver.java
new file mode 100644
index 0000000..a1a979b
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/rmixml/RmiXmlReceiver.java
@@ -0,0 +1,96 @@
+/**
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 24, 2006
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.comms.rmixml;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
+import java.util.HashSet;
+
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.objects.P2Object;
+
+import com.twicom.qdparser.TaggedElement;
+
+import eu.novi.ponder2.comms.Receiver;
+
+/**
+ * The receiving class that is registered with the rmiregistry. Any messages for
+ * this RMI name come through this receiver in its own thread.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class RmiXmlReceiver extends UnicastRemoteObject implements RmiXmlReceiveInterface {
+
+ /**
+ * creates an RMI receiver. This simply registers the RMI name and the new
+ * receiver with the rmi registry
+ *
+ * @param RMIName
+ * @throws RemoteException
+ * @throws MalformedURLException
+ */
+ public RmiXmlReceiver(String RMIName) throws RemoteException, MalformedURLException {
+ register(RMIName);
+ }
+
+ /**
+ * registers the RMI name and this instance with the RMI registry
+ *
+ * @param RMIName
+ * the RMI name as a string
+ * @throws RemoteException
+ * if the RMI registry is not running or can't be contacted
+ * @throws MalformedURLException
+ * if the RMI name does not conform to the specification
+ */
+ public void register(String RMIName) throws RemoteException, MalformedURLException {
+ Naming.rebind(RMIName, this);
+ System.out.println("Local RMI XML address is " + RMIName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.rmi.RMIReceiveInterface#getObject(java.net.URI,
+ * java.lang.String, net.ponder2.Result)
+ */
+ public TaggedElement getObject(URI location, String path) throws RemoteException,
+ Ponder2Exception {
+ return Receiver.getObject(location, path).writeXml(new HashSet<P2Object>());
+ }
+
+ /* (non-Javadoc)
+ * @see net.ponder2.comms.rmixml.RmiXmlReceiveInterface#execute(com.twicom.qdparser.TaggedElement)
+ */
+ public TaggedElement execute(TaggedElement xml) throws RemoteException, Ponder2Exception {
+ return Receiver.execute(xml);
+ }
+
+ }
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/rmixml/RmiXmlTransmitter.java b/ponder2/src/main/java/eu/novi/ponder2/comms/rmixml/RmiXmlTransmitter.java
new file mode 100644
index 0000000..3ee1c10
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/rmixml/RmiXmlTransmitter.java
@@ -0,0 +1,140 @@
+/**
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 24, 2006
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.comms.rmixml;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.rmi.Naming;
+import java.rmi.NotBoundException;
+import java.rmi.RemoteException;
+import java.util.HashMap;
+
+import eu.novi.ponder2.OID;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2OperationException;
+import eu.novi.ponder2.objects.P2Object;
+
+import com.twicom.qdparser.TaggedElement;
+
+import eu.novi.ponder2.comms.P2Serializable;
+import eu.novi.ponder2.comms.Transmitter;
+import eu.novi.ponder2.comms.TransmitterImpl;
+
+/**
+ * This class embodies the sending mechanism for inter-SMC communications using
+ * the RMI protocol. When instantiated it locks itself to one particular
+ * destination. One RMITransmitter is created for each RMI destination that is
+ * used.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class RmiXmlTransmitter extends TransmitterImpl implements Transmitter {
+
+ /**
+ * the receiving interface of the remote SMC
+ */
+ private RmiXmlReceiveInterface remote = null;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Transmitter#connect(java.net.URI)
+ */
+ @Override
+ public Transmitter connect(URI address) {
+ RmiXmlTransmitter tx = new RmiXmlTransmitter();
+ if (tx.lookup(address))
+ return tx;
+ return null;
+ }
+
+ /**
+ * looks up the interface for the remote SMC
+ *
+ * @param location
+ * the remote RMI name
+ * @return true if the lookup succeeded
+ */
+ private boolean lookup(URI location) {
+ try {
+ Object obj = Naming.lookup("rmi:"+location.getSchemeSpecificPart());
+ remote = (RmiXmlReceiveInterface)obj;
+ }
+ catch (MalformedURLException e) {
+ System.out.println("RmiReceiveInterface: bad form of address - " + location);
+ }
+ catch (RemoteException e) {
+ System.out.println("RmiReceiveInterface: remote exception - " + location + " - "
+ + e.getMessage());
+ }
+ catch (NotBoundException e) {
+ System.out.println("RmiReceiveInterface: remote RMI name not bound - " + location);
+ }
+ return (remote != null);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Transmitter#getObject(java.net.URI,
+ * java.lang.String)
+ */
+ @Override
+ public P2Object getObject(URI location, String path) throws Ponder2Exception {
+ try {
+ TaggedElement reply = remote.getObject(location, path);
+ return P2Object.fromXml(reply, new HashMap<Integer,P2Serializable>());
+ }
+ catch (RemoteException e) {
+ throw new Ponder2OperationException(e.getMessage());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Transmitter#execute(java.net.URI, net.ponder2.OID,
+ * net.ponder2.objects.P2Object, java.lang.String,
+ * net.ponder2.objects.P2Object[])
+ */
+ @Override
+ public P2Object execute(URI address, OID target, P2Object source, String op, P2Object[] args)
+ throws Ponder2Exception {
+ return executeXml(address, target, source, op, args);
+ }
+
+ @Override
+ protected TaggedElement execute(URI address, TaggedElement xml) throws Ponder2Exception {
+ try {
+ return remote.execute(xml);
+ }
+ catch (RemoteException e) {
+ throw new Ponder2OperationException(e.getMessage());
+ }
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/socket/SocketReceiver.java b/ponder2/src/main/java/eu/novi/ponder2/comms/socket/SocketReceiver.java
new file mode 100644
index 0000000..dc4198f
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/socket/SocketReceiver.java
@@ -0,0 +1,91 @@
+/**
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 24, 2006
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.comms.socket;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.net.Socket;
+
+import eu.novi.ponder2.comms.Receiver;
+
+import eu.novi.ponder2.exception.Ponder2Exception;
+
+/**
+ * The receiving class that is registered with the rmiregistry. Any messages for
+ * this RMI name come through this receiver in its own thread.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class SocketReceiver implements Runnable {
+
+ Socket socket;
+ private DataOutputStream os;
+ private DataInputStream is;
+
+ /**
+ * creates a socket receiver.
+ *
+ * @param socket
+ * @throws IOException
+ */
+ public SocketReceiver(Socket socket) throws IOException {
+ this.socket = socket;
+ os = new DataOutputStream(socket.getOutputStream());
+ is = new DataInputStream(socket.getInputStream());
+ new Thread(this).start();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Runnable#run()
+ */
+ public void run() {
+ try {
+ String xml = is.readUTF();
+ System.out.println("Socketreceiver: Received an XML request");
+ os.writeUTF(Receiver.execute(xml));
+ }
+ catch (IOException e) {
+ if (e.getMessage() != null)
+ System.out.println("SocketReceiver: Closing because of IOException:" + e.getMessage());
+ try {
+ os.close();
+ is.close();
+ socket.close();
+ }
+ catch (IOException e1) {
+ System.out.println("SocketReceiver: failed to close down:" + e1.getMessage());
+ }
+ }
+ catch (Ponder2Exception e) {
+ System.out.println("SocketReceiver: Ponder2Exception:" + e.getMessage());
+ }
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/socket/SocketTransmitter.java b/ponder2/src/main/java/eu/novi/ponder2/comms/socket/SocketTransmitter.java
new file mode 100644
index 0000000..8e64d04
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/socket/SocketTransmitter.java
@@ -0,0 +1,146 @@
+/**
+ * Copyright 2005 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 24, 2006
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.comms.socket;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.net.Socket;
+import java.net.URI;
+
+import eu.novi.ponder2.comms.Transmitter;
+import eu.novi.ponder2.comms.TransmitterImpl;
+import eu.novi.ponder2.comms.SocketProtocol.HostPort;
+
+import eu.novi.ponder2.OID;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2RemoteException;
+import eu.novi.ponder2.objects.P2Object;
+
+/**
+ * This class embodies the sending mechanism for inter-SMC communications using
+ * the Socket protocol. When instantiated it locks itself to one particular
+ * destination. One SocketTransmitter is created for each Socket destination
+ * that is used.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class SocketTransmitter extends TransmitterImpl implements Transmitter {
+
+ Socket socket = null;
+ DataOutputStream os;
+ DataInputStream is;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Transmitter#connect(java.net.URI)
+ */
+ @Override
+ public Transmitter connect(URI address) throws Ponder2RemoteException {
+ // We always open a new socket to cope with parallel threads
+ return this;
+ }
+
+ /**
+ * looks up the interface for the remote SMC
+ *
+ * @param address
+ * the remote IP address
+ * @return true if the lookup succeeded
+ * @throws Ponder2RemoteException
+ */
+ private boolean open(URI address) throws Ponder2RemoteException {
+ HostPort hostport = new HostPort(address);
+ try {
+ socket = new Socket(hostport.host, hostport.port);
+ os = new DataOutputStream(socket.getOutputStream());
+ is = new DataInputStream(socket.getInputStream());
+ }
+ catch (IOException e) {
+ System.out.println("SocketTransmitter: failed to open " + address + " (" + hostport.host + ","
+ + hostport.port + ") - " + e.getMessage());
+ }
+ return (socket != null);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.TransmitterImpl#getObject(java.net.URI,
+ * java.lang.String)
+ */
+ @Override
+ public P2Object getObject(URI location, String path) throws Ponder2Exception {
+ return getObjectString(location, path);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Transmitter#execute(java.net.URI, net.ponder2.OID,
+ * net.ponder2.objects.P2Object, java.lang.String,
+ * net.ponder2.objects.P2Object[])
+ */
+ @Override
+ public P2Object execute(URI address, OID target, P2Object source, String op, P2Object[] args)
+ throws Ponder2Exception {
+ return executeString(address, target, source, op, args);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.TransmitterImpl#execute(java.lang.String)
+ */
+ @Override
+ protected String execute(URI address, String xmlString) throws Ponder2RemoteException {
+ IOException error = null;
+ int tries = 0;
+ open(address);
+ while (tries++ < 3) {
+ try {
+ if (os==null) throw new IOException("Socket transmitter not open");
+ os.writeUTF(xmlString);
+ return is.readUTF();
+ }
+ catch (IOException e) {
+ error = e;
+ System.out.println("Socket Transmitter: Lost remote. Reconnecting to " + address);
+ if (tries > 0)
+ try {
+ Thread.sleep(2000);
+ }
+ catch (InterruptedException e1) {
+ }
+ open(address);
+ }
+ }
+ throw new Ponder2RemoteException(error.getMessage());
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/ssc/SscReceiver.java b/ponder2/src/main/java/eu/novi/ponder2/comms/ssc/SscReceiver.java
new file mode 100644
index 0000000..a73de6d
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/ssc/SscReceiver.java
@@ -0,0 +1,91 @@
+/**
+ * Copyright 2008 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Feb 13, 2010
+ *
+ * $Log:$
+ *//*
+
+package eu.novi.ponder2.comms.ssc;
+
+import java.io.IOException;
+
+import eu.novi.ponder2.exception.Ponder2Exception;
+
+import com.twicom.comms.singlesocket.Message;
+import com.twicom.comms.singlesocket.MessageInterface;
+import com.twicom.comms.singlesocket.client.Client;
+import com.twicom.comms.singlesocket.client.ClientCallback;
+
+import eu.novi.ponder2.comms.Receiver;
+
+*//**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ *//*
+public class SscReceiver implements ClientCallback {
+
+ public SscReceiver(Client client) {
+ client.register(this);
+ }
+
+
+ * (non-Javadoc)
+ *
+ * @see
+ * com.twicom.comms.singlesocket.ClientCallback#broadcast(com.twicom.comms
+ * .singlesocket.MessageInterface)
+
+ public void broadcast(MessageInterface message) {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ * (non-Javadoc)
+ *
+ * @seecom.twicom.comms.singlesocket.ClientCallback#notify(com.twicom.comms.
+ * singlesocket.MessageInterface)
+
+ public void notify(MessageInterface message) {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ * (non-Javadoc)
+ *
+ * @seecom.twicom.comms.singlesocket.ClientCallback#request(com.twicom.comms.
+ * singlesocket.MessageInterface)
+
+ public Message request(MessageInterface message) throws IOException {
+ try {
+ String reply = Receiver.execute(message.asString());
+ return new Message(reply);
+ }
+ catch (Ponder2Exception e) {
+ throw new IOException(e.getMessage());
+ }
+ }
+
+}
+*/ \ No newline at end of file
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/ssc/SscTransmitter.java b/ponder2/src/main/java/eu/novi/ponder2/comms/ssc/SscTransmitter.java
new file mode 100644
index 0000000..7548db6
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/ssc/SscTransmitter.java
@@ -0,0 +1,98 @@
+/**
+ * Copyright 2008 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Feb 13, 2010
+ *
+ * $Log:$
+ *//*
+
+package eu.novi.ponder2.comms.ssc;
+
+import java.io.IOException;
+import java.net.URI;
+
+import eu.novi.ponder2.OID;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2RemoteException;
+import eu.novi.ponder2.objects.P2Object;
+
+import com.twicom.comms.singlesocket.client.Client;
+
+import eu.novi.ponder2.comms.Transmitter;
+import eu.novi.ponder2.comms.TransmitterImpl;
+
+*//**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ *//*
+public class SscTransmitter extends TransmitterImpl implements Transmitter {
+
+ private Client client;
+
+ public SscTransmitter(Client client) {
+ this.client = client;
+ }
+
+
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.TransmitterImpl#execute(java.net.URI,
+ * net.ponder2.OID, net.ponder2.objects.P2Object, java.lang.String,
+ * net.ponder2.objects.P2Object[])
+
+ @Override
+ public P2Object execute(URI address, OID target, P2Object source, String op, P2Object[] args)
+ throws Ponder2Exception {
+ return executeString(address, target, source, op, args);
+ }
+
+
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.TransmitterImpl#getObject(java.net.URI,
+ * java.lang.String)
+
+ @Override
+ public P2Object getObject(URI address, String path) throws Ponder2Exception {
+ return getObjectString(address, path);
+ }
+
+
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.TransmitterImpl#execute(java.net.URI,
+ * java.lang.String)
+
+ @Override
+ protected String execute(URI address, String xmlString) throws Ponder2Exception {
+ try {
+ String destination = address.getPath();
+ destination = destination.substring(1);
+ return client.request(destination, xmlString);
+ }
+ catch (IOException e) {
+ throw new Ponder2RemoteException(e.getMessage());
+ }
+ }
+
+}
+*/ \ No newline at end of file
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/xmlblaster/XmlBlasterReceiver.java b/ponder2/src/main/java/eu/novi/ponder2/comms/xmlblaster/XmlBlasterReceiver.java
new file mode 100644
index 0000000..00eae47
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/xmlblaster/XmlBlasterReceiver.java
@@ -0,0 +1,116 @@
+/**
+ * Copyright 2008 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Feb 6, 2010
+ *
+ * $Log:$
+ *//*
+
+package eu.novi.ponder2.comms.xmlblaster;
+
+import net.ponder2.exception.Ponder2Exception;
+
+import org.xmlBlaster.client.I_Callback;
+import org.xmlBlaster.client.I_XmlBlasterAccess;
+import org.xmlBlaster.client.key.UpdateKey;
+import org.xmlBlaster.client.qos.UpdateQos;
+import org.xmlBlaster.client.qos.UpdateReturnQos;
+import org.xmlBlaster.util.Global;
+import org.xmlBlaster.util.SessionName;
+import org.xmlBlaster.util.XmlBlasterException;
+import org.xmlBlaster.util.qos.address.Destination;
+
+import eu.novi.ponder2.comms.Receiver;
+import eu.novi.ponder2.comms.XmlblasterProtocol;
+
+*//**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ *//*
+public class XmlBlasterReceiver implements I_Callback {
+
+ private Global glob;
+ private I_XmlBlasterAccess receiver;
+ private XmlBlasterSync sync;
+
+ public XmlBlasterReceiver(I_XmlBlasterAccess receiver, XmlBlasterSync sync) {
+ this.receiver = receiver;
+ this.glob = receiver.getGlobal();
+ this.sync = sync;
+ }
+
+
+ * (non-Javadoc)
+ *
+ * @see org.xmlBlaster.client.I_Callback#update(java.lang.String,
+ * org.xmlBlaster.client.key.UpdateKey, byte[],
+ * org.xmlBlaster.client.qos.UpdateQos)
+
+ public String update(String cbSessionId, UpdateKey updateKey, byte[] content, UpdateQos updateQos)
+ throws XmlBlasterException {
+ if (updateKey.isInternal())
+ return "";
+ if (updateQos.isErased())
+ return "";
+ // Ignore messages that we have sent
+ SessionName sender = updateQos.getSender();
+ if (receiver.getSessionName().equalsRelative(sender))
+ return "";
+
+ String message = new String(content);
+ String msgtype = updateQos.getClientProperty("Ponder2msgtype", "");
+ String ponder2id = updateQos.getClientProperty("Ponder2id", "");
+
+ // Is this a reply or a new message?
+ if (msgtype.equals("request")) {
+ // Execute the request and get the reply
+ System.out.println("XmlBlasterReceiver: Got request from '" + sender + "'");
+
+ Destination destination = new Destination(sender);
+
+ String reply;
+ String type;
+ try {
+ reply = Receiver.execute(message);
+ type = "reply";
+ }
+ catch (Ponder2Exception e) {
+ reply = e.toString();
+ type = "exception";
+ }
+ XmlblasterProtocol.publish(receiver, destination, reply, type, ponder2id);
+ }
+ else if (msgtype.equals("reply")) {
+ // We have a reply. We must match it to the waiting task
+ sync.reply(ponder2id, message);
+ }
+ else if (msgtype.equals("exception")) {
+ // We have a remote exception. We must let the matching task know
+ sync.exception(ponder2id, message);
+ }
+ else
+ System.out.println("XmlBlasterReceiver: received bad message type: " + updateKey);
+ UpdateReturnQos uq = new UpdateReturnQos(glob);
+ return uq.toXml();
+ }
+}
+*/ \ No newline at end of file
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/xmlblaster/XmlBlasterSync.java b/ponder2/src/main/java/eu/novi/ponder2/comms/xmlblaster/XmlBlasterSync.java
new file mode 100644
index 0000000..fd52b4e
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/xmlblaster/XmlBlasterSync.java
@@ -0,0 +1,110 @@
+/**
+ * Copyright 2008 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Feb 8, 2010
+ *
+ * $Log:$
+ *//*
+
+package eu.novi.ponder2.comms.xmlblaster;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.Semaphore;
+
+import net.ponder2.exception.Ponder2RemoteException;
+
+*//**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ *//*
+public class XmlBlasterSync {
+
+ Map<String, SyncEntry> entries;
+ private static int count = 0;
+
+ public XmlBlasterSync() {
+ entries = new HashMap<String, SyncEntry>();
+ }
+
+ synchronized String create() {
+ String id = String.valueOf(++count);
+ SyncEntry se = new SyncEntry(id);
+ entries.put(id, se);
+ return id;
+ }
+
+ private synchronized void remove(String id) {
+ entries.remove(id);
+ }
+
+ private synchronized SyncEntry get(String id) {
+ return entries.get(id);
+ }
+
+ String awaitReply(String id) throws Ponder2RemoteException {
+ SyncEntry se = get(id);
+ se.sem.acquireUninterruptibly();
+ remove(id);
+ if (se.exception)
+ throw new Ponder2RemoteException(se.reply);
+ return se.reply;
+ }
+
+ void reply(String id, String message) {
+ SyncEntry se = get(id);
+ if (se == null) {
+ System.err.println("XmlBlasterProtocol: Sync, unknown reply id: " + id + " - " + message);
+ return;
+ }
+ se.reply = message;
+ se.sem.release();
+ }
+
+ void exception(String id, String message) {
+ SyncEntry se = get(id);
+ if (se == null) {
+ System.err.println("XmlBlasterProtocol: Sync, unknown reply id: " + id + " - " + message);
+ return;
+ }
+ se.reply = message;
+ se.exception = true;
+ se.sem.release();
+ }
+
+ static public class SyncEntry {
+
+ Semaphore sem;
+ String id;
+ String reply;
+ boolean exception;
+
+ SyncEntry(String id) {
+ this.id = id;
+ sem = new Semaphore(0);
+ reply = null;
+ exception = false;
+ }
+ }
+
+}
+*/ \ No newline at end of file
diff --git a/ponder2/src/main/java/eu/novi/ponder2/comms/xmlblaster/XmlBlasterTransmitter.java b/ponder2/src/main/java/eu/novi/ponder2/comms/xmlblaster/XmlBlasterTransmitter.java
new file mode 100644
index 0000000..b7d78ab
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/comms/xmlblaster/XmlBlasterTransmitter.java
@@ -0,0 +1,124 @@
+/**
+ * Copyright 2008 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Feb 6, 2010
+ *
+ * $Log:$
+ *//*
+
+package eu.novi.ponder2.comms.xmlblaster;
+
+import java.net.URI;
+
+import eu.novi.ponder2.OID;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2OperationException;
+import eu.novi.ponder2.exception.Ponder2RemoteException;
+import eu.novi.ponder2.objects.P2Object;
+
+import org.xmlBlaster.client.I_XmlBlasterAccess;
+import org.xmlBlaster.util.Global;
+import org.xmlBlaster.util.SessionName;
+import org.xmlBlaster.util.XmlBlasterException;
+import org.xmlBlaster.util.qos.address.Destination;
+
+import eu.novi.ponder2.comms.Transmitter;
+import eu.novi.ponder2.comms.TransmitterImpl;
+import eu.novi.ponder2.comms.XmlblasterProtocol;
+
+*//**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ *//*
+public class XmlBlasterTransmitter extends TransmitterImpl implements Transmitter {
+
+ private I_XmlBlasterAccess transmitter;
+ private Global glob;
+ private XmlBlasterSync sync;
+
+ public XmlBlasterTransmitter(I_XmlBlasterAccess transmitter, XmlBlasterSync sync) {
+ this.glob = transmitter.getGlobal();
+ this.transmitter = transmitter;
+ this.sync = sync;
+ }
+
+
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Transmitter#connect(java.net.URI)
+
+ @Override
+ public Transmitter connect(URI address) throws Ponder2RemoteException {
+ return this;
+ }
+
+
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Transmitter#getObject(java.net.URI,
+ * java.lang.String)
+
+ @Override
+ public P2Object getObject(URI address, String path) throws Ponder2Exception {
+ return getObjectString(address, path);
+ }
+
+
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.Transmitter#execute(java.net.URI, net.ponder2.OID,
+ * net.ponder2.objects.P2Object, java.lang.String,
+ * net.ponder2.objects.P2Object[])
+
+ @Override
+ public P2Object execute(URI address, OID target, P2Object source, String op, P2Object[] args)
+ throws Ponder2Exception {
+ return executeString(address, target, source, op, args);
+ }
+
+
+ * (non-Javadoc)
+ *
+ * @see net.ponder2.comms.TransmitterImpl#execute(java.net.URI,
+ * java.lang.String)
+
+ @Override
+ protected String execute(URI address, String xmlString) throws Ponder2Exception {
+ try {
+ // Get name and knock off leading '/'
+ String remote = address.getPath();
+ remote = remote.substring(1);
+ remote = "Ponder2_" + remote;
+
+ Destination destination = new Destination(new SessionName(glob, remote));
+ String ponder2id = sync.create();
+ XmlblasterProtocol.publish(transmitter, destination, xmlString, "request", ponder2id);
+ return sync.awaitReply(ponder2id);
+ }
+ catch (XmlBlasterException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ throw new Ponder2OperationException("XmlBlasterTransmitter: " + e);
+ }
+ }
+}
+*/ \ No newline at end of file
diff --git a/ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2ArgumentException.java b/ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2ArgumentException.java
new file mode 100644
index 0000000..615b1b2
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2ArgumentException.java
@@ -0,0 +1,42 @@
+/**
+ * Copyright 2006 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Jan 6, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.exception;
+
+import eu.novi.ponder2.exception.Ponder2Exception;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class Ponder2ArgumentException extends Ponder2Exception {
+
+ public Ponder2ArgumentException(String message) {
+ super(message);
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2AuthorizationException.java b/ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2AuthorizationException.java
new file mode 100644
index 0000000..a457772
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2AuthorizationException.java
@@ -0,0 +1,45 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 8, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.exception;
+
+import eu.novi.ponder2.exception.Ponder2Exception;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class Ponder2AuthorizationException extends Ponder2Exception {
+
+ /**
+ * @param arg0
+ */
+ public Ponder2AuthorizationException(String arg0) {
+ super(arg0);
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2Exception.java b/ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2Exception.java
new file mode 100644
index 0000000..583506d
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2Exception.java
@@ -0,0 +1,106 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 8, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.exception;
+
+import com.twicom.qdparser.TaggedElement;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public abstract class Ponder2Exception extends Exception {
+
+ private TaggedElement xml;
+ private String source;
+
+ /**
+ * @param message
+ */
+ public Ponder2Exception(String message) {
+ super(message);
+ this.xml = null;
+ this.source = null;
+ }
+
+ public void addXML(TaggedElement xml) {
+ if (this.xml == null)
+ this.xml = xml;
+ }
+
+ public void addSource(String source) {
+ if (this.source == null && source != null
+ && !source.equals("UnknownFile"))
+ this.source = source;
+ }
+
+ public String getSource() {
+ return source == null ? "unknown file" : source;
+ }
+
+ public String getLine() {
+ String result = null;
+ if (xml != null)
+ result = xml.getAttribute("line");
+ if (result == null)
+ result = "unknown line";
+ return result;
+ }
+
+ public String getLineInfo() {
+ StringBuffer info = new StringBuffer();
+ // TODO stack backtrace
+ if (xml != null) {
+ info.append(getSource());
+ info.append(":");
+ info.append(getLine());
+ info.append(" - ");
+ }
+ return info.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Throwable#getMessage()
+ */
+ @Override
+ public String getMessage() {
+ return getLineInfo() + super.getMessage();// +" - "+xml;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Throwable#toString()
+ */
+ @Override
+ public String toString() {
+ return getLineInfo() + super.toString();// +" - "+xml;
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2OperationException.java b/ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2OperationException.java
new file mode 100644
index 0000000..19dfe7d
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2OperationException.java
@@ -0,0 +1,50 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 8, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.exception;
+
+import org.mortbay.log.Log;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import eu.novi.ponder2.StartStopPonder2SMC;
+import eu.novi.ponder2.exception.Ponder2Exception;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class Ponder2OperationException extends Ponder2Exception {
+
+ private static final transient Logger log = LoggerFactory.getLogger(Ponder2OperationException.class);
+ public Ponder2OperationException(String message) {
+ super(message);
+ log.info(message);
+
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2RemoteException.java b/ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2RemoteException.java
new file mode 100644
index 0000000..4478c27
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2RemoteException.java
@@ -0,0 +1,45 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 8, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.exception;
+
+import eu.novi.ponder2.exception.Ponder2OperationException;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class Ponder2RemoteException extends Ponder2OperationException {
+
+ /**
+ * @param arg0
+ */
+ public Ponder2RemoteException(String arg0) {
+ super(arg0);
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2ResolveException.java b/ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2ResolveException.java
new file mode 100644
index 0000000..e220333
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/exception/Ponder2ResolveException.java
@@ -0,0 +1,45 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 5, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.exception;
+
+import eu.novi.ponder2.exception.Ponder2OperationException;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class Ponder2ResolveException extends Ponder2OperationException {
+
+ /**
+ * @param arg0
+ */
+ public Ponder2ResolveException(String arg0) {
+ super(arg0);
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/inspector/BooleanPanel.java b/ponder2/src/main/java/eu/novi/ponder2/inspector/BooleanPanel.java
new file mode 100644
index 0000000..f4e0b2f
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/inspector/BooleanPanel.java
@@ -0,0 +1,107 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Feb 19, 2008
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.inspector;
+
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+
+import javax.swing.ButtonGroup;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JRadioButton;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+class BooleanPanel extends JPanel {
+
+ private JRadioButton trueButton = null;
+ private JRadioButton falseButton = null;
+ private ButtonGroup buttonGroup = null;
+
+ public BooleanPanel() {
+ GridBagConstraints gridBagConstraints = new GridBagConstraints();
+ gridBagConstraints.gridx = 2;
+ gridBagConstraints.gridy = 0;
+ JLabel jLabel1 = new JLabel("False");
+ JLabel jLabel = new JLabel("True");
+ this.setLayout(new GridBagLayout());
+ this.add(jLabel, new GridBagConstraints());
+ this.add(getTrueButton(), new GridBagConstraints());
+ this.add(getFalseButton(), gridBagConstraints);
+ this.add(jLabel1, new GridBagConstraints());
+ getButtonGroup().add(getFalseButton());
+ getButtonGroup().add(getTrueButton());
+ }
+
+ void setValue(Boolean value) {
+ JRadioButton button = value ? getTrueButton() : getFalseButton();
+ button.setSelected(true);
+ }
+
+ Boolean getValue() {
+ return getTrueButton().isSelected();
+ }
+
+ /**
+ * This method initializes trueButton
+ *
+ * @return javax.swing.JRadioButton
+ */
+ private JRadioButton getTrueButton() {
+ if (trueButton == null) {
+ trueButton = new JRadioButton();
+ }
+ return trueButton;
+ }
+
+ /**
+ * This method initializes falseButton
+ *
+ * @return javax.swing.JRadioButton
+ */
+ private JRadioButton getFalseButton() {
+ if (falseButton == null) {
+ falseButton = new JRadioButton();
+ }
+ return falseButton;
+ }
+
+ /**
+ * This method initializes buttonGroup
+ *
+ * @return javax.swing.ButtonGroup
+ */
+ private ButtonGroup getButtonGroup() {
+ if (buttonGroup == null) {
+ buttonGroup = new ButtonGroup();
+ }
+ return buttonGroup;
+ }
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/inspector/InspectorWindow.java b/ponder2/src/main/java/eu/novi/ponder2/inspector/InspectorWindow.java
new file mode 100644
index 0000000..361a518
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/inspector/InspectorWindow.java
@@ -0,0 +1,256 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Oct 17, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.inspector;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.GridLayout;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.SwingUtilities;
+
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.objects.P2Boolean;
+import eu.novi.ponder2.objects.P2Number;
+import eu.novi.ponder2.objects.P2Object;
+import eu.novi.ponder2.objects.P2String;
+
+import eu.novi.ponder2.inspector.InspectorWindow;
+import eu.novi.ponder2.inspector.Value;
+import eu.novi.ponder2.inspector.ValueBoolean;
+import eu.novi.ponder2.inspector.ValueNew;
+import eu.novi.ponder2.inspector.ValueNumber;
+import eu.novi.ponder2.inspector.ValueP2Object;
+import eu.novi.ponder2.inspector.ValueString;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class InspectorWindow extends JFrame {
+
+ private static final long serialVersionUID = 1L;
+
+ private JPanel jContentPane = null;
+
+ private JComboBox profile = null;
+
+ private JPanel list = null;
+
+ public static final String ProfileChange = "InspectorProfile";
+ public static final String AttributeChange = "InspectorAttribute";
+ public static final String NewValueChange = "InspectorNewValue";
+
+ /**
+ * This method initializes profile
+ *
+ * @return javax.swing.JComboBox
+ */
+ private JComboBox getProfile() {
+ if (profile == null) {
+ profile = new JComboBox();
+ profile.addActionListener(new java.awt.event.ActionListener() {
+
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+ System.out.println("actionPerformed()"); // TODO
+ // Auto-generated
+ // Event
+ // stub actionPerformed()
+ firePropertyChange(ProfileChange, "",
+ profile.getSelectedItem());
+ }
+ });
+ }
+ return profile;
+ }
+
+ /**
+ * This method initializes list
+ *
+ * @return javax.swing.JPanel
+ */
+ private JPanel getList() {
+ if (list == null) {
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.setRows(25);
+ gridLayout.setHgap(2);
+ gridLayout.setVgap(2);
+ gridLayout.setColumns(1);
+ list = new JPanel();
+ list.setLayout(gridLayout);
+ }
+ return list;
+ }
+
+ /**
+ * This method initializes jPanel
+ *
+ * @return javax.swing.JPanel
+ */
+ private JPanel getJPanel() {
+ if (jPanel == null) {
+ jPanel = new JPanel();
+ jPanel.setLayout(new GridBagLayout());
+ jPanel.add(getOk(), new GridBagConstraints());
+ }
+ return jPanel;
+ }
+
+ /**
+ * This method initializes ok
+ *
+ * @return javax.swing.JButton
+ */
+ private JButton getOk() {
+ if (ok == null) {
+ ok = new JButton();
+ ok.setText("Set");
+ ok.addActionListener(new java.awt.event.ActionListener() {
+
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+ System.out.println("Set button actionPerformed()"); // TODO
+ // Auto-generated
+ // Event stub
+ // actionPerformed()
+ for (Component component : getList().getComponents()) {
+ Value attr = (Value) component;
+ if (attr.changed()) {
+ firePropertyChange(AttributeChange,
+ attr.getAttributeName(), attr.getNewValue());
+ }
+ }
+ firePropertyChange(NewValueChange, null, null);
+ }
+ });
+ }
+ return ok;
+ }
+
+ /**
+ * This method initializes jScrollPane
+ *
+ * @return javax.swing.JScrollPane
+ */
+ private JScrollPane getJScrollPane() {
+ if (jScrollPane == null) {
+ jScrollPane = new JScrollPane();
+ jScrollPane.setViewportView(getList());
+ }
+ return jScrollPane;
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+
+ SwingUtilities.invokeLater(new Runnable() {
+
+ public void run() {
+ InspectorWindow thisClass = new InspectorWindow(
+ "Test Inspector");
+ thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ thisClass.setVisible(true);
+ }
+ });
+ }
+
+ /**
+ * This is the default constructor
+ */
+ public InspectorWindow(String title) {
+ this.setSize(300, 200);
+ this.setContentPane(getJContentPane());
+ this.setTitle(title);
+ }
+
+ /**
+ * This method initializes jContentPane
+ *
+ * @return javax.swing.JPanel
+ */
+ private JPanel getJContentPane() {
+ if (jContentPane == null) {
+ jContentPane = new JPanel();
+ jContentPane.setLayout(new BorderLayout());
+ jContentPane.add(getProfile(), BorderLayout.NORTH);
+ jContentPane.add(getJPanel(), BorderLayout.SOUTH);
+ jContentPane.add(getJScrollPane(), BorderLayout.CENTER);
+ }
+ return jContentPane;
+ }
+
+ public void manage(String name) {
+ getProfile().addItem(name);
+ }
+
+ public void setList(Map<String, P2Object> list2) {
+ List<String> names = new Vector<String>(list2.keySet());
+ Collections.sort(names);
+ getList().removeAll();
+ GridLayout gridLayout = (GridLayout) getList().getLayout();
+ gridLayout.setRows(names.size() + 1);
+ getList().setLayout(gridLayout);
+ for (String name : names) {
+ JPanel att;
+ P2Object obj = list2.get(name);
+ try {
+ if (obj instanceof P2Boolean)
+ att = new ValueBoolean(name, obj.asBoolean());
+ else if (obj instanceof P2Number)
+ att = new ValueNumber(name, obj.asNumber().longValue());
+ else if (obj instanceof P2String)
+ att = new ValueString(name, obj.asString());
+ else
+ att = new ValueP2Object(name, obj);
+ getList().add(att);
+ } catch (Ponder2Exception e) {
+ }
+ }
+ getList().add(new ValueNew());
+ getList().revalidate();
+ }
+
+ private JPanel jPanel = null;
+
+ private JButton ok = null;
+
+ private JScrollPane jScrollPane = null;
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/inspector/Value.java b/ponder2/src/main/java/eu/novi/ponder2/inspector/Value.java
new file mode 100644
index 0000000..b7da836
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/inspector/Value.java
@@ -0,0 +1,44 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Oct 18, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.inspector;
+
+import eu.novi.ponder2.objects.P2Object;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public interface Value {
+
+ public boolean changed();
+
+ public String getAttributeName();
+
+ public P2Object getNewValue();
+
+} \ No newline at end of file
diff --git a/ponder2/src/main/java/eu/novi/ponder2/inspector/ValueBoolean.java b/ponder2/src/main/java/eu/novi/ponder2/inspector/ValueBoolean.java
new file mode 100644
index 0000000..274a1a7
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/inspector/ValueBoolean.java
@@ -0,0 +1,66 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Oct 16, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.inspector;
+
+import eu.novi.ponder2.objects.P2Object;
+import eu.novi.ponder2.inspector.BooleanPanel;
+import eu.novi.ponder2.inspector.ValuePanel;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class ValueBoolean extends ValuePanel {
+
+ private BooleanPanel field;
+
+ private Boolean oldValue;
+
+ /**
+ * Creates a new string attribute
+ */
+ public ValueBoolean(String name, Boolean value) {
+ super(name, new BooleanPanel());
+ field = (BooleanPanel) getValue();
+ field.setValue(value);
+ oldValue = value;
+ }
+
+ @Override
+ public boolean changed() {
+ return oldValue != field.getValue();
+ }
+
+ @Override
+ public P2Object getNewValue() {
+ boolean value = field.getValue();
+ oldValue = value;
+ return P2Object.create(value);
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/inspector/ValueNew.java b/ponder2/src/main/java/eu/novi/ponder2/inspector/ValueNew.java
new file mode 100644
index 0000000..d624ebf
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/inspector/ValueNew.java
@@ -0,0 +1,79 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Oct 16, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.inspector;
+
+import java.math.BigDecimal;
+
+import javax.swing.JTextField;
+
+import eu.novi.ponder2.objects.P2Object;
+
+import eu.novi.ponder2.inspector.ValuePanel;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class ValueNew extends ValuePanel {
+
+ private JTextField field;
+
+ /**
+ * Creates a new string attribute
+ */
+ public ValueNew() {
+ super(new JTextField());
+ field = (JTextField) getValue();
+ field.setText("");
+ }
+
+ @Override
+ public boolean changed() {
+ return getAttributeName().length() != 0
+ && field.getText().length() != 0;
+ }
+
+ @Override
+ public P2Object getNewValue() {
+ String value = field.getText();
+ P2Object result;
+ if (value.equalsIgnoreCase("true"))
+ result = P2Object.create(true);
+ else if (value.equalsIgnoreCase("false"))
+ result = P2Object.create(false);
+ else {
+ try {
+ result = P2Object.create(new BigDecimal(value));
+ } catch (NumberFormatException e) {
+ result = P2Object.create(value);
+ }
+ }
+ return result;
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/inspector/ValueNumber.java b/ponder2/src/main/java/eu/novi/ponder2/inspector/ValueNumber.java
new file mode 100644
index 0000000..b1f9f58
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/inspector/ValueNumber.java
@@ -0,0 +1,71 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Oct 16, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.inspector;
+
+import java.math.BigDecimal;
+import java.text.NumberFormat;
+
+import javax.swing.JFormattedTextField;
+
+import eu.novi.ponder2.objects.P2Object;
+
+import eu.novi.ponder2.inspector.ValuePanel;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class ValueNumber extends ValuePanel {
+
+ private JFormattedTextField field;
+
+ private long oldValue;
+
+ /**
+ * Creates a new string attribute
+ */
+ public ValueNumber(String name, long value) {
+ super(name, new JFormattedTextField(NumberFormat.getIntegerInstance()));
+ field = (JFormattedTextField) getValue();
+ field.setValue(value);
+ oldValue = value;
+ }
+
+ @Override
+ public boolean changed() {
+ return oldValue != (Long) field.getValue();
+ }
+
+ @Override
+ public P2Object getNewValue() {
+ long value = (Long) field.getValue();
+ oldValue = value;
+ return P2Object.create(new BigDecimal(value));
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/inspector/ValueP2Object.java b/ponder2/src/main/java/eu/novi/ponder2/inspector/ValueP2Object.java
new file mode 100644
index 0000000..fdd8b8d
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/inspector/ValueP2Object.java
@@ -0,0 +1,66 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Oct 16, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.inspector;
+
+import javax.swing.JTextField;
+
+import eu.novi.ponder2.objects.P2Object;
+
+import eu.novi.ponder2.inspector.ValuePanel;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class ValueP2Object extends ValuePanel {
+
+ private JTextField field;
+
+ private P2Object oldValue;
+
+ /**
+ * Creates a new string attribute
+ */
+ public ValueP2Object(String name, P2Object value) {
+ super(name, new JTextField());
+ field = (JTextField) getValue();
+ field.setText(value.toString());
+ oldValue = value;
+ }
+
+ @Override
+ public boolean changed() {
+ return false;
+ }
+
+ @Override
+ public P2Object getNewValue() {
+ return oldValue;
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/inspector/ValuePanel.java b/ponder2/src/main/java/eu/novi/ponder2/inspector/ValuePanel.java
new file mode 100644
index 0000000..eefc2a0
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/inspector/ValuePanel.java
@@ -0,0 +1,85 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Oct 16, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.inspector;
+
+import java.awt.GridLayout;
+
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+
+import eu.novi.ponder2.objects.P2Object;
+
+import eu.novi.ponder2.inspector.Value;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public abstract class ValuePanel extends JPanel implements Value {
+
+ private JLabel attName = null;
+ private JTextField noAttName = null;
+ private JComponent value;
+
+ public ValuePanel(JComponent value) {
+ noAttName = new JTextField();
+ initialize(noAttName, value);
+ }
+
+ public ValuePanel(String name, JComponent value) {
+ attName = new JLabel();
+ attName.setText(name);
+ initialize(attName, value);
+ }
+
+ private void initialize(JComponent attField, JComponent value) {
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.setRows(1);
+ gridLayout.setHgap(10);
+ this.setLayout(gridLayout);
+ this.setSize(360, 25);
+ this.add(attField, null);
+ this.value = value;
+ this.add(value, null);
+ }
+
+ public abstract boolean changed();
+
+ public String getAttributeName() {
+ return attName != null ? attName.getText() : noAttName.getText();
+ }
+
+ public abstract P2Object getNewValue();
+
+ protected JComponent getValue() {
+ return value;
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/inspector/ValueString.java b/ponder2/src/main/java/eu/novi/ponder2/inspector/ValueString.java
new file mode 100644
index 0000000..388b1a2
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/inspector/ValueString.java
@@ -0,0 +1,68 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Oct 16, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.inspector;
+
+import javax.swing.JTextField;
+
+import eu.novi.ponder2.objects.P2Object;
+
+import eu.novi.ponder2.inspector.ValuePanel;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class ValueString extends ValuePanel {
+
+ private JTextField field;
+
+ private String oldValue;
+
+ /**
+ * Creates a new string attribute
+ */
+ public ValueString(String name, String value) {
+ super(name, new JTextField());
+ field = (JTextField) getValue();
+ field.setText(value);
+ oldValue = value;
+ }
+
+ @Override
+ public boolean changed() {
+ return !oldValue.equals(field.getText());
+ }
+
+ @Override
+ public P2Object getNewValue() {
+ String value = field.getText();
+ oldValue = value;
+ return P2Object.create(value);
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/interactions/CallstoIRM.java b/ponder2/src/main/java/eu/novi/ponder2/interactions/CallstoIRM.java
new file mode 100644
index 0000000..cc5eef3
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/interactions/CallstoIRM.java
@@ -0,0 +1,58 @@
+package eu.novi.ponder2.interactions;
+
+import java.util.Collection;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import eu.novi.policy.interfaces.interfaceforponder2;
+
+
+public class CallstoIRM {
+ private static final transient Logger log =
+ LoggerFactory.getLogger(CallstoIRM.class);
+ private static interfaceforponder2 policyServiceCalls;
+
+
+
+
+ public Collection<String> updateSliceinIRM(String currentTopology,Collection<String> failingResources) {
+
+ if (policyServiceCalls == null)
+ {
+ log.warn("The object from policy service is null");
+ return null;
+ }
+ else
+ {
+ //failingResources.add("sliver1");
+ //RequestToIRM req= new RequestToIRM();
+ log.info("Calling policy manager to initiate the updateSlice");
+ Collection<String> failed=policyServiceCalls.callUpdateSliceFP(currentTopology, failingResources);
+ log.info("DONE the update: CallstoIRM");
+ //log.info(failed.toString());
+ //log.info("DONE the update: CallstoIRM");
+ return failed;
+ }
+ }
+
+ public static void initThePonder()
+ {
+ if (policyServiceCalls == null)
+ {
+ log.warn("The object from policy service is null");
+ }
+ else
+ {
+ log.info("Calling policy manager to initiate the init of Ponder2");
+ policyServiceCalls.initPonder();
+ log.info("DONE the init");
+ }
+ }
+
+ public interfaceforponder2 getPolicyServiceCalls() {
+ return policyServiceCalls;
+ }
+ public void setPolicyServiceCalls(interfaceforponder2 policyServiceCalls) {
+ this.policyServiceCalls = policyServiceCalls;
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/interactions/CallstoPonder2.java b/ponder2/src/main/java/eu/novi/ponder2/interactions/CallstoPonder2.java
new file mode 100644
index 0000000..b6d368d
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/interactions/CallstoPonder2.java
@@ -0,0 +1,22 @@
+package eu.novi.ponder2.interactions;
+
+import java.util.Collection;
+
+import eu.novi.policy.interfaces.interfaceforponder2;
+
+public class CallstoPonder2{
+
+/* private interfaceforponder2 policyServiceCalls;
+
+
+ public static interfaceforponder2 getPolicyServiceCalls() {
+ return policyServiceCalls;
+ }
+
+ public static void setPolicyServiceCalls(interfaceforponder2 policyServiceCalls) {
+ this.policyServiceCalls = policyServiceCalls;
+ }
+
+ */
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/managedobject/CsvHash.java b/ponder2/src/main/java/eu/novi/ponder2/managedobject/CsvHash.java
new file mode 100644
index 0000000..173f49f
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/managedobject/CsvHash.java
@@ -0,0 +1,137 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Sep 4, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.managedobject;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Iterator;
+import java.util.Vector;
+
+
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.Util;
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.objects.P2Array;
+import eu.novi.ponder2.objects.P2Block;
+import eu.novi.ponder2.objects.P2Hash;
+import eu.novi.ponder2.objects.P2Object;
+import eu.novi.ponder2.objects.P2String;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class CsvHash extends P2Array implements ManagedObject {
+
+ private char comma = ',';
+ P2String[] headers;
+
+ @Ponder2op("create:")
+ CsvHash(String url) {
+ try {
+ URI uri = new URI(url);
+ InputStream is = Util.getInputStream(uri);
+ BufferedReader in = new BufferedReader(new InputStreamReader(is));
+ String header = in.readLine();
+ if (header == null)
+ return;
+ headers = split(0, header);
+ String line;
+ while ((line = in.readLine()) != null) {
+ P2String[] data = split(headers.length, line);
+ this.add(P2Object.create(data));
+ }
+ } catch (MalformedURLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (URISyntaxException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * answers an array containing the titles of the columns
+ *
+ * @return an array with the titles
+ */
+ @Ponder2op("titles")
+ P2Object getTitles() {
+ return P2Object.create(headers);
+ }
+
+ @Ponder2op("do:")
+ void op_do(P2Object source, P2Block aBlock) throws Ponder2Exception {
+ P2Object oldValue[] = new P2Object[headers.length];
+ for (Iterator<P2Object> iter = getValues().iterator(); iter.hasNext();) {
+ P2Array line = iter.next().asP2Array();
+ P2Hash hash = new P2Hash();
+ for (int i = 0; i < headers.length; i++) {
+ P2Object value = line.at(i);
+ if (oldValue[i] == null)
+ oldValue[i] = value;
+ if (value.asString().length() == 0)
+ value = oldValue[i];
+ else
+ oldValue[i] = value;
+ hash.put(headers[i].asString(), value);
+ }
+ aBlock.operation(source, "value:", hash);
+ }
+ }
+
+ /**
+ * @param line
+ * @return
+ */
+ private P2String[] split(int size, String line) {
+ Vector<P2Object> vec = new Vector<P2Object>();
+ int findex = 0;
+ int tindex = 0;
+ while ((tindex = line.indexOf(comma, findex)) >= 0l) {
+ vec.add(P2Object.create(line.substring(findex, tindex)));
+ findex = tindex + 1;
+ }
+ vec.add(P2Object.create(line.substring(findex)));
+ // If necessary bring the array up to size,
+ // trailing delimiters may have been lost
+ if (size > 0)
+ while (vec.size() < headers.length)
+ vec.add(P2Object.create(""));
+ return vec.toArray(new P2String[vec.size()]);
+ }
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/managedobject/DateTime.java b/ponder2/src/main/java/eu/novi/ponder2/managedobject/DateTime.java
new file mode 100644
index 0000000..2faef78
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/managedobject/DateTime.java
@@ -0,0 +1,106 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Aug 10, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.managedobject;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.util.Date;
+import java.util.Map;
+
+
+import eu.novi.ponder2.managedobject.DateTime;
+
+import com.twicom.qdparser.TaggedElement;
+
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.comms.P2Serializable;
+import eu.novi.ponder2.exception.Ponder2ArgumentException;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2OperationException;
+import eu.novi.ponder2.objects.P2Object;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class DateTime extends P2Object implements ManagedObject {
+
+ Date date;
+
+ @Ponder2op("create")
+ DateTime() {
+ date = new Date();
+ }
+
+ @Ponder2op("create:")
+ DateTime(String aString) throws Ponder2ArgumentException {
+ try {
+ date = DateFormat.getDateInstance().parse(aString);
+ } catch (ParseException e) {
+ throw new Ponder2ArgumentException("Bad date format "
+ + e.getMessage());
+ }
+ }
+
+ DateTime(long secs) {
+ date = new Date(secs);
+ }
+
+ @Ponder2op("secs")
+ public String operation_secs() {
+ return "" + date.getTime();
+ }
+
+ @Ponder2op("-")
+ public P2Object operation_minus(P2Object source, P2Object aDateTime)
+ throws Ponder2Exception {
+ long secs = Long.parseLong(aDateTime.operation(source, "secs")
+ .asString());
+ return new DateTime(date.getTime() - secs);
+ }
+
+ @Ponder2op("print")
+ public String operation_print() {
+ return date.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * eu.novi.ponder2.objects.P2Object#readXml(com.twicom.qdparser.TaggedElement
+ * )
+ */
+ @Override
+ public P2Object readXml(TaggedElement xml, Map<Integer, P2Serializable> read)
+ throws Ponder2OperationException, Ponder2ArgumentException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/managedobject/DynamicString.java b/ponder2/src/main/java/eu/novi/ponder2/managedobject/DynamicString.java
new file mode 100644
index 0000000..c04ee8d
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/managedobject/DynamicString.java
@@ -0,0 +1,98 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Oct 9, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.managedobject;
+
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.apt.Ponder2op;
+
+/**
+ * Implements a dynamic string. This string can be appended to and otherwise
+ * used as a String.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class DynamicString implements ManagedObject {
+
+ private StringBuffer buffer;
+
+ /**
+ * Creates a new Dynamic String
+ */
+ @Ponder2op("create")
+ public DynamicString() {
+ buffer = new StringBuffer();
+ }
+
+ /**
+ * Creates a new Dynamic String initialised with aString
+ *
+ * @param aString
+ * the string to initialise the DynamicString
+ */
+ @Ponder2op("create:")
+ public DynamicString(String aString) {
+ buffer = new StringBuffer(aString);
+ }
+
+ /**
+ * Appends anObject to the receiver. Answers anObject.
+ *
+ * @param aString
+ * the string to be appended
+ */
+ @Ponder2op("add:")
+ public void add(String aString) {
+ buffer.append(aString);
+ }
+
+ /**
+ * Appends a newline sequence to the receiver.
+ */
+ @Ponder2op("cr")
+ public void add_cr() {
+ buffer.append("\r\n");
+ }
+
+ /**
+ * Appends a tab character to the receiver.
+ */
+ @Ponder2op("tab")
+ public void add_tab() {
+ buffer.append('\t');
+ }
+
+ /**
+ * Returns the receiver as a String
+ *
+ * @return the value of this object as a string
+ */
+ @Override
+ @Ponder2op("asString")
+ public String toString() {
+ return buffer.toString();
+ }
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/managedobject/LinkMO.java b/ponder2/src/main/java/eu/novi/ponder2/managedobject/LinkMO.java
new file mode 100644
index 0000000..6228a93
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/managedobject/LinkMO.java
@@ -0,0 +1,24 @@
+package eu.novi.ponder2.managedobject;
+
+import eu.novi.im.core.impl.LinkImpl;
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.apt.Ponder2op;
+
+public class LinkMO extends LinkImpl implements ManagedObject{
+ private String Uri;
+ private String Topologyuri;
+
+ @Ponder2op("create:topology:")
+ public LinkMO(String link,String topology) {
+ super(link);
+ System.out.println("Creating a Link");
+ Uri=link;
+ Topologyuri=topology;
+
+ }
+
+ @Ponder2op("linkfailure:")
+ void linkfailure(String urifailure) {
+ System.out.println("We have a link failure");
+ }
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/managedobject/MemoryMO.java b/ponder2/src/main/java/eu/novi/ponder2/managedobject/MemoryMO.java
new file mode 100644
index 0000000..4c943fd
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/managedobject/MemoryMO.java
@@ -0,0 +1,7 @@
+package eu.novi.ponder2.managedobject;
+
+import eu.novi.ponder2.ManagedObject;
+
+public class MemoryMO implements ManagedObject {
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/managedobject/NodeMO.java b/ponder2/src/main/java/eu/novi/ponder2/managedobject/NodeMO.java
new file mode 100644
index 0000000..dbb6252
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/managedobject/NodeMO.java
@@ -0,0 +1,20 @@
+package eu.novi.ponder2.managedobject;
+
+import eu.novi.im.core.impl.NodeImpl;
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.apt.*;
+
+public class NodeMO extends NodeImpl implements ManagedObject{
+ private String URI;
+ @Ponder2op("create:")
+ public NodeMO(String uri) {
+ super(uri);
+ System.out.println("Creating a Node with uri "+ uri);
+ URI=uri;
+ }
+ @Ponder2op("access:")
+ void access(int value) {
+
+ //return "AUTH_for_Node";
+ }
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/managedobject/PlatformMO.java b/ponder2/src/main/java/eu/novi/ponder2/managedobject/PlatformMO.java
new file mode 100644
index 0000000..be54554
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/managedobject/PlatformMO.java
@@ -0,0 +1,117 @@
+package eu.novi.ponder2.managedobject;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+
+import javax.jms.JMSException;
+
+import org.mortbay.log.Log;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import eu.novi.im.core.impl.PlatformImpl;
+import eu.novi.im.core.impl.TopologyImpl;
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.StartStopPonder2SMC;
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.interactions.CallstoIRM;
+import eu.novi.ponder2.objects.P2Object;
+import eu.novi.ponder2.policy.AuthPolicyHolder;
+import eu.novi.ponder2.policy.AuthorisationModule;
+import eu.novi.ponder2.queue.PolicyQueueProducer;
+
+public class PlatformMO extends PlatformImpl implements ManagedObject {
+ private static final transient Logger log = LoggerFactory.getLogger(PlatformMO.class);
+ private int NumberOfRemoteVNodesProvidedToRemote=0;
+ private int NumberOfRemoteVNodesIgotFromRemote=0;
+ @Ponder2op("create:")
+ public PlatformMO(String PlatformName) {
+ super(PlatformName);
+ // TODO Auto-generated constructor stub
+ }
+
+ @Ponder2op("remove:")
+ public void TopologyMO(String uri) {
+ try {
+ this.finalize();
+ } catch (Throwable e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ // TODO Auto-generated constructor stub
+ }
+
+
+ @Ponder2op("findpartitioningcost:")
+ public void findpartitioningcost(String topo) {
+
+ //Should communicate with policy-Manager to execute the IRM-call
+
+ //Collection<String> failingResources= new HashSet<String>();
+ //String currentTopology=uri;
+ //failingResources.add(resourceuri);
+ System.out.println("I am trying to find the partitioning cost");
+ log.info("I am trying to find the partitioning cost");
+ log.info("At this point we must call RIS");
+ // CallstoIRM.findpartitioningcost(topo);
+
+ /*System.out.println("I sending a message with activemq to Policy-Manager to update the Slice");
+
+
+ try {
+ String queueProcessingID = policyProducer.pushRequest("fdskl");
+ } catch (JMSException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }*/
+
+ }
+
+ @Ponder2op("addToNumberOfRemoteVNodesIprovide")
+ public void addToNumberOfRemoteVNodesIprovide() {
+
+ System.out.println("I am providing a VNode to the remote Platform");
+ log.info("I am providing a VNode to the remote Platform");
+ log.info("Number of VNodes I provide: "+NumberOfRemoteVNodesProvidedToRemote);
+ NumberOfRemoteVNodesProvidedToRemote++;
+ log.info("Number of VNodes I provide: "+NumberOfRemoteVNodesProvidedToRemote);
+ }
+
+ @Ponder2op("addToNumberOfRemoteVNodesIgot")
+ public void addToNumberOfRemoteVNodesIgot()
+ {
+ System.out.println("I am adding one to the number of RemoteVnodes I got from Remote Platform");
+ log.info("I am adding one to the number of RemoteVnodes I got from Remote Platform");
+ this.NumberOfRemoteVNodesIgotFromRemote++;
+ }
+
+ @Ponder2op("getquota")
+ public int getquota()
+ {
+ log.info("We want to see the quota of the VNodes we can deliver to the other Platform");
+ log.info("We have: "+ this.NumberOfRemoteVNodesProvidedToRemote +" of VNodes that we provided and: " + this.NumberOfRemoteVNodesIgotFromRemote + " of VNodes that we got.");
+ int quota= this.NumberOfRemoteVNodesProvidedToRemote-this.NumberOfRemoteVNodesIgotFromRemote+100;
+ log.info("So we have quota" + quota);
+ return quota;
+ }
+
+ @Ponder2op("initMissions")
+ public void initMissions()
+ {
+ log.info("Ponder2:Manually init Missions");
+ CallstoIRM.initThePonder();
+ log.info("Ponder2: Called init");
+ }
+ /*@Ponder2op("returnNumberOfRemoteVNodes")
+ public int returnNumberOfRemoteVNodes() {
+
+ System.out.println("I am returning the Number of Remote VNodes I am providing");
+ log.info("I am returning the Number of Remote VNodes.");
+ log.info("Number of VNodes: "+this.NumberOfRemoteVNodesProvidedToFED);
+ return this.NumberOfRemoteVNodesProvidedToFED;
+ }*/
+
+
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/managedobject/ResourceMO.java b/ponder2/src/main/java/eu/novi/ponder2/managedobject/ResourceMO.java
new file mode 100644
index 0000000..3c49f1e
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/managedobject/ResourceMO.java
@@ -0,0 +1,8 @@
+package eu.novi.ponder2.managedobject;
+
+import eu.novi.ponder2.ManagedObject;
+
+
+public class ResourceMO implements ManagedObject{
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/managedobject/RoleMO.java b/ponder2/src/main/java/eu/novi/ponder2/managedobject/RoleMO.java
new file mode 100644
index 0000000..f47b7f2
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/managedobject/RoleMO.java
@@ -0,0 +1,39 @@
+package eu.novi.ponder2.managedobject;
+
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.exception.Ponder2AuthorizationException;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.objects.P2Object;
+import eu.novi.ponder2.StartStopPonder2SMC;
+public class RoleMO implements ManagedObject{
+
+ //Should extend the Role from the IM
+ private P2Object myP2Object;
+ private String Name;
+ @Ponder2op("create:")
+ public RoleMO(P2Object myP2Object, String uri) {
+ Name =uri;
+ this.myP2Object = myP2Object;
+ }
+
+ @Ponder2op("search:")
+ public Boolean search(P2Object resource) {
+ System.out.println("Searching");
+ int value = 1;
+ try {
+ resource.operation(myP2Object, "access:", P2Object.create(value));
+ return true;
+
+ } catch (Ponder2AuthorizationException e) {
+ return false;
+ } catch (Ponder2Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ System.out.println("No such object");
+ return false;
+
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/managedobject/SampleObject.java b/ponder2/src/main/java/eu/novi/ponder2/managedobject/SampleObject.java
new file mode 100644
index 0000000..43c4f4d
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/managedobject/SampleObject.java
@@ -0,0 +1,115 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 8, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.managedobject;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.objects.P2Object;
+
+/**
+ * Implements a hash or dictionary. This object holds name/object pairs. Objects
+ * may be added and removed.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class SampleObject implements ManagedObject {
+
+ private Map<String, P2Object> data;
+
+ /**
+ * Creates an empty hash
+ */
+ @Ponder2op("create")
+ SampleObject() {
+ data = new HashMap<String, P2Object>();
+ }
+
+ /**
+ * Creates a hash with a particular minimum size
+ *
+ * @param size
+ * the size with which to create the hash
+ */
+ @Ponder2op("size:")
+ SampleObject(int size) {
+ data = new HashMap<String, P2Object>(size);
+ }
+
+ /**
+ * add an object to the hash
+ *
+ * @param name
+ * the name of the object to be added
+ * @param oid
+ * the object to be added
+ * @return the object added
+ */
+ @Ponder2op("at:put:")
+ P2Object p2_operation_at_put(String name, P2Object oid) {
+ data.put(name, oid);
+ return oid;
+ }
+
+ /**
+ * retrieves an object by name
+ *
+ * @param name
+ * the name of the object to be found
+ * @return the named object
+ */
+ @Ponder2op("at:")
+ P2Object p2_operation_at(String name) {
+ return data.get(name);
+ }
+
+ /**
+ * removes the named object from the hash
+ *
+ * @param name
+ * the name of the object to be removed
+ * @return the object removed
+ */
+ @Ponder2op("remove:")
+ P2Object p2_operation_remove(String name) {
+ return data.remove(name);
+ }
+
+ /**
+ * get the number of objects in the hash
+ *
+ * @return the number of objects in the hash
+ */
+ @Ponder2op("size")
+ int p2_operation_size() {
+ return data.size();
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/managedobject/SearhingMO.java b/ponder2/src/main/java/eu/novi/ponder2/managedobject/SearhingMO.java
new file mode 100644
index 0000000..01f6524
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/managedobject/SearhingMO.java
@@ -0,0 +1,21 @@
+package eu.novi.ponder2.managedobject;
+
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.apt.Ponder2op;
+
+public class SearhingMO implements ManagedObject{
+
+ @Ponder2op("create:")
+ public void SearchingMO(String name) {
+ System.out.println("Creating a ManObj to search for AUTH Policies");
+
+ }
+
+ @Ponder2op("search:")
+ public void search(String name) {
+ System.out.println("Creating a ManObj to search for AUTH Policies");
+
+ }
+
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/managedobject/TopologyMO.java b/ponder2/src/main/java/eu/novi/ponder2/managedobject/TopologyMO.java
new file mode 100644
index 0000000..8460bd6
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/managedobject/TopologyMO.java
@@ -0,0 +1,129 @@
+package eu.novi.ponder2.managedobject;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+
+import javax.jms.JMSException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import eu.novi.im.core.impl.TopologyImpl;
+import eu.novi.policy.RequestToIRM.RequestToIRM2;
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.StartStopPonder2SMC;
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.interactions.CallstoIRM;
+import eu.novi.ponder2.objects.P2Object;
+import eu.novi.ponder2.policy.AuthPolicyHolder;
+import eu.novi.ponder2.policy.AuthorisationModule;
+import eu.novi.ponder2.queue.PolicyQueueProducer;
+
+public class TopologyMO extends TopologyImpl implements ManagedObject {
+ private static final transient Logger log =
+ LoggerFactory.getLogger(TopologyMO.class);
+/* PolicyQueueProducer policyProducer;
+
+ public PolicyQueueProducer getPolicyProducer()
+ {
+ return policyProducer;
+ }
+
+ public void setPolicyProducer ( PolicyQueueProducer policyProducer)
+ {
+ this.policyProducer=policyProducer;
+ }*/
+
+ private boolean updatePermission=true;
+ @Ponder2op("create:")
+ public TopologyMO(String uri) {
+ super(uri);
+ // TODO Auto-generated constructor stub
+ }
+
+ @Ponder2op("remove:")
+ public void TopologyMO(String uri) {
+ try {
+ this.finalize();
+ } catch (Throwable e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ // TODO Auto-generated constructor stub
+ }
+
+ /*@Ponder2op("search")
+ public void search() {
+ System.out.println("Searching");
+ AuthPolicyHolder holder = new AuthPolicyHolder();
+ short pepType = AuthorisationModule.PEP1;
+ P2Object subject = P2Object.create();
+ P2Object target = P2Object.create();
+ String action = "*";
+ P2Object[] args = new P2Object[] {};
+ P2Object result =P2Object.create("Foo");
+ char focus ='t';
+ StartStopPonder2SMC smc= new StartStopPonder2SMC();
+ Boolean authornot =smc.searchauth(holder, pepType, subject, target, action, focus, args, result);
+ if (authornot == true)
+ {
+ System.out.println("OK it is auth as it should");
+ }
+ else {
+ System.out.println("failure or the auth result is : " + authornot);
+ }
+
+
+ }*/
+
+ @Ponder2op("getUpdatePermission:")
+ boolean getUpdatePermission(String vnode) {
+ return this.updatePermission;
+ }
+
+ @Ponder2op("setUpdatePermission:status:")
+ void setUpdatePermission(String vnode,boolean status) {
+ this.updatePermission=status;
+ }
+
+ @Ponder2op("topologyfailure:resource:")
+ public int topologyfailure(String uri, String resourceuri) {
+
+ //Should communicate with policy-Manager to execute the IRM-call
+
+ Collection<String> failingResources= new HashSet<String>();
+ String currentTopology=uri;
+ String resourceuriV2=resourceuri.replace(uri,"");
+ failingResources.add(resourceuriV2);
+ System.out.println("In the topologyMO I am handling the failure");
+ log.info("In the topologyMO I am handling the failure");
+ log.info("The failure was in slice "+ uri +" for resource "+ resourceuriV2);
+ log.info("The updatePermission value is:"+this.updatePermission);
+ CallstoIRM callIRM=new CallstoIRM();
+ Collection<String> failed=callIRM.updateSliceinIRM(currentTopology , failingResources);
+ return 1;
+ /*if (failed!=null)
+ {
+ log.info("DONE the update");
+ return failed.size();
+ }
+ else
+ {
+ log.info("DONE the update (No-success)");
+ return 0;
+ }
+ */
+ /*System.out.println("I sending a message with activemq to Policy-Manager to update the Slice");
+
+
+ try {
+ String queueProcessingID = policyProducer.pushRequest("fdskl");
+ } catch (JMSException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }*/
+
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/managedobject/UserMO.java b/ponder2/src/main/java/eu/novi/ponder2/managedobject/UserMO.java
new file mode 100644
index 0000000..c74e823
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/managedobject/UserMO.java
@@ -0,0 +1,39 @@
+package eu.novi.ponder2.managedobject;
+
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.exception.Ponder2AuthorizationException;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.objects.P2Object;
+import eu.novi.ponder2.StartStopPonder2SMC;
+public class UserMO implements ManagedObject{
+
+ //Should extend the User from the IM
+ private P2Object myP2Object;
+ private String Name;
+ @Ponder2op("create:")
+ public UserMO(P2Object myP2Object, String uri) {
+ Name =uri;
+ this.myP2Object = myP2Object;
+ }
+
+ @Ponder2op("search:")
+ public Boolean search(P2Object resource) {
+ System.out.println("Searching");
+ int value = 1;
+ try {
+ resource.operation(myP2Object, "access:", P2Object.create(value));
+ return true;
+
+ } catch (Ponder2AuthorizationException e) {
+ return false;
+ } catch (Ponder2Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ System.out.println("No such object");
+ return false;
+
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/managedobject/VirtualNodeMO.java b/ponder2/src/main/java/eu/novi/ponder2/managedobject/VirtualNodeMO.java
new file mode 100644
index 0000000..75c01a7
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/managedobject/VirtualNodeMO.java
@@ -0,0 +1,51 @@
+package eu.novi.ponder2.managedobject;
+
+import eu.novi.im.core.impl.VirtualNodeImpl;
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.apt.Ponder2op;
+
+public class VirtualNodeMO extends VirtualNodeImpl implements ManagedObject{
+
+ private String Uri;
+ private String Topologyuri;
+
+
+ @Ponder2op("create:topology:")
+ public VirtualNodeMO(String vnode,String topology) {
+ super(vnode);
+ System.out.println("Creating a VirtualNode with uri "+ vnode + " for Slice " + topology);
+ Uri=vnode;
+ Topologyuri=topology;
+ }
+
+ @Ponder2op("remove:topology:")
+ public void RemoveVirtualNodeMO(String vnode,String topology) {
+ System.out.println("Removing the VirtualNode with uri "+ vnode + " from Slice " + topology);
+ Uri=vnode;
+ Topologyuri=topology;
+ try {
+ this.finalize();
+ } catch (Throwable e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+
+ @Ponder2op("getTopo:")
+ String getTopo(String vnode) {
+ return Topologyuri;
+ }
+
+ @Ponder2op("access:")
+ String access(String vnode) {
+ return "AUTH_for_Vnode";
+ }
+
+ @Ponder2op("urifailure:")
+ void urifailure(String failure) {
+ System.out.println("We have the failure of the Virtual node "+ Uri +" of topology "+ Topologyuri);
+
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/mission/Interface.java b/ponder2/src/main/java/eu/novi/ponder2/mission/Interface.java
new file mode 100644
index 0000000..020fcef
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/mission/Interface.java
@@ -0,0 +1,356 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Feb 14, 2008
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.mission;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.SelfManagedCell;
+import eu.novi.ponder2.Util;
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.exception.Ponder2ArgumentException;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2OperationException;
+//import eu.novi.ponder2.mission.Command;
+import eu.novi.ponder2.objects.P2Array;
+import eu.novi.ponder2.objects.P2Object;
+
+/**
+ * Provides an interface to remote systems. Commands may be added to this
+ * managed object which are mapped into commands to other, local, managed
+ * objects. Objects may also be exported by this interface in which case they
+ * are addressed in the normal manner using pathnames through the interface or
+ * by using the command "at:"
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class Interface implements ManagedObject {
+
+ /**
+ * List of events handles by this interface
+ */
+ Map<String, P2Object> events;
+ /**
+ * List of accepted events
+ */
+ Set<String> acceptsEvents;
+ /**
+ * List of events exported by this interface
+ */
+ Set<String> providesEvents;
+ /**
+ * List of proxy commands exposed by this Interface
+ */
+ Map<String, Command> commands;
+ /**
+ * List of objects exposed through this Interface
+ */
+ Map<String, P2Object> objects;
+ /**
+ * The internal domain holding events
+ */
+ P2Object eventDomain;
+
+ Set<P2Object> eventSubscribers;
+ private P2Object myP2Object;
+ private P2Object eventForwarder;
+ private static P2Object eventForwarderFactory = null;
+
+ boolean dafaultListen = true;
+
+ /**
+ * Creates a new Interface object
+ *
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("create")
+ Interface(P2Object myP2Object) throws Ponder2Exception {
+ this.myP2Object = myP2Object;
+ events = new HashMap<String, P2Object>();
+ acceptsEvents = new HashSet<String>();
+ providesEvents = new HashSet<String>();
+ objects = new HashMap<String, P2Object>();
+ commands = new HashMap<String, Command>();
+ eventSubscribers = new HashSet<P2Object>();
+
+ // Put in the default Mission Controller
+ try {
+ objects.put("missioncontroller",
+ Util.resolve("root/mission/missioncontroller"));
+ } catch (Ponder2OperationException e) {
+ System.out
+ .println("Warning: Interface, no default mission controller found");
+ }
+
+ // Get a domain for the events and add it as an object
+ P2Object domainFactory = SelfManagedCell.RootDomain.operation(
+ myP2Object, "load:", P2Object.create("Domain"));
+ eventDomain = domainFactory.operation(myP2Object, "create");
+ mapToObject("event", eventDomain);
+
+ // Sort out an Event Forwarder
+ if (eventForwarderFactory == null) {
+ eventForwarderFactory = SelfManagedCell.RootDomain.operation(
+ myP2Object, "load:", P2Object.create("EventForwarder"));
+ }
+ eventForwarder = eventForwarderFactory.operation(myP2Object, "create");
+ eventForwarder.operation(myP2Object, "active:", P2Object.create(true));
+
+ // Set up default listener
+ eventForwarder.operation(myP2Object, "attachTo:",
+ SelfManagedCell.RootDomain);
+
+ }
+
+ @Ponder2op("listenTo:")
+ void listenTo(P2Object anObject) throws Ponder2Exception {
+ eventForwarder.operation(myP2Object, "attachTo:", anObject);
+ }
+
+ /**
+ * Set the Interface's mission controller to be aMissionController.
+ *
+ * @param aMissionController
+ */
+ @Ponder2op("missionController:")
+ void setMissionController(P2Object aMissionController) {
+ objects.put("missioncontroller", aMissionController);
+ }
+
+ /**
+ * Maps aName to anEventType. This name may be used in the
+ * <b>acceptsEvent:</b> or <b>sendsEvent:</b> Interface commands.
+ * <p>
+ * Events appear as objects in the interface under the pseudo domain
+ * <i>event</i>. Thus they may be accessed as
+ * <b>interface/event/eventName</b>
+ *
+ * @param aName
+ * @param anEventType
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("event:is:")
+ void eventIs(String aName, P2Object anEventType) throws Ponder2Exception {
+ events.put(aName, anEventType);
+ }
+
+ /**
+ * Makes sure that the event is mapped and the event is included in the
+ * interface's event domain
+ *
+ * @param aName
+ * @throws Ponder2Exception
+ */
+ private void installEvent(String aName) throws Ponder2Exception {
+ if (!events.containsKey(aName)) {
+ events.put(aName, Util.resolve("root/event/" + aName));
+ }
+ P2Object anEventType = events.get(aName);
+ eventDomain.operation(myP2Object, "at:put:", P2Object.create(aName),
+ anEventType);
+ }
+
+ /**
+ * Tells the Interface that it can accept events previously defined with
+ * anEventName
+ *
+ * @param anEventName
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("acceptsEvent:")
+ void acceptsEvents(String anEventName) throws Ponder2Exception {
+ installEvent(anEventName);
+ acceptsEvents(anEventName, SelfManagedCell.RootDomain);
+ }
+
+ /**
+ * Tells the Interface that it can accept events previously defined with
+ * anEventName
+ *
+ * @param anEventName
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("acceptsEvent:from:")
+ void acceptsEvents(String anEventName, P2Object anObject)
+ throws Ponder2Exception {
+ installEvent(anEventName);
+ acceptsEvents.add(anEventName);
+ }
+
+ @Ponder2op("raise:")
+ void raise(P2Object source, String eventName) throws Ponder2Exception {
+ if (acceptsEvents.contains(eventName)) {
+ P2Object event = events.get(eventName);
+ event.operation(myP2Object, "create");
+ } else
+ throw new Ponder2ArgumentException("Interface: unknown event "
+ + eventName);
+ }
+ @Ponder2op("raise:with:")
+ void raise(P2Object source, String eventName, P2Array anArray) throws Ponder2Exception {
+ if (acceptsEvents.contains(eventName)) {
+ P2Object event = events.get(eventName);
+ event.operation(myP2Object, "create:", anArray);
+ }
+ else
+ throw new Ponder2ArgumentException("Interface: unknown event " + eventName);
+ }
+ /**
+ * Tells the Interface that it can propagate events previously defined with
+ * anEventName
+ *
+ * @param anEventName
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("providesEvent:")
+ void providesEvent(String anEventName) throws Ponder2Exception {
+ installEvent(anEventName);
+ providesEvents.add(anEventName);
+ }
+
+ @Ponder2op("subscribe:")
+ void subscriberTo(P2Object anObject) throws Ponder2Exception {
+ eventForwarder.operation(myP2Object, "forwardTo:", anObject);
+ }
+
+ /**
+ * Maps aCommand to anObject. aCommand appears as part of the external
+ * interface of this Interface. Answers with the result of the command
+ *
+ * @param aCommand
+ * the command to be recognised
+ * @param anObject
+ * the destination managed object to receive the command
+ */
+ @Ponder2op("map:to:")
+ void mapTo(String aCommand, P2Object anObject) {
+ mapToAs(aCommand, anObject, aCommand);
+ }
+
+ /**
+ * Maps aCommand to anObject as anotherCommand. aCommand appears as part of
+ * the external interface of this Interface. Answers with the result of the
+ * command
+ *
+ * @param aCommand
+ * the command to be recognised
+ * @param anObject
+ * the destination managed object to receive the command
+ * @param anotherCommand
+ * the actual command to sent to anObject
+ */
+ @Ponder2op("map:to:as:")
+ void mapToAs(String aCommand, P2Object anObject, String anotherCommand) {
+ commands.put(aCommand, new Command(anObject, anotherCommand));
+ }
+
+ /**
+ * Exports anObject with aName. The Interface appears to be a domain with
+ * aName inside it
+ *
+ * @param aName
+ * the name of the object to export
+ * @param anObject
+ * the object to be exported
+ */
+ @Ponder2op("map:toObject:")
+ void mapToObject(String aName, P2Object anObject) {
+ objects.put(aName, anObject);
+ }
+
+ // Commands used by the system to implement the interface
+
+ /**
+ * Returns the exported object called aName
+ *
+ * @param aName
+ * the name of the required object
+ * @return the exported object
+ * @throws Ponder2OperationException
+ */
+ @Ponder2op("at:")
+ P2Object at(String aName) throws Ponder2OperationException {
+ P2Object object;
+ object = objects.get(aName);
+ if (object == null)
+ throw new Ponder2OperationException("Interface: object \"" + aName
+ + "\" not found");
+ return object;
+ }
+
+ /**
+ * For internal use. Maps any command to the correct object and command.
+ * Answers with the answer produced by executing the command. Throws an
+ * error if the command is not found.
+ *
+ * @param source
+ * the source object that generated the command
+ * @param op
+ * the operation (command) to be performed
+ * @param args
+ * the arguments for the command
+ * @return the result of the command
+ * @throws Ponder2Exception
+ * if the command is not found
+ */
+ @Ponder2op(Ponder2op.WILDCARD)
+ protected P2Object obj_operation(P2Object source, String op,
+ P2Object... args) throws Ponder2Exception {
+ // We have to send something to an object
+ Command command = commands.get(op);
+ if (command == null)
+ throw new Ponder2OperationException(
+ "Interface: Received bad operation " + op);
+ return command.operation(source, args);
+ }
+
+ class Command {
+
+ P2Object object;
+ String command;
+
+ /**
+ * @param object
+ * @param command
+ */
+ public Command(P2Object object, String command) {
+ this.object = object;
+ this.command = command;
+ }
+
+ P2Object operation(P2Object source, P2Object... args)
+ throws Ponder2Exception {
+ return object.operation(source, command, args);
+ }
+
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/mission/Mission.java b/ponder2/src/main/java/eu/novi/ponder2/mission/Mission.java
new file mode 100644
index 0000000..bcc74aa
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/mission/Mission.java
@@ -0,0 +1,183 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Apr 2, 2008
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.mission;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.objects.P2Object;
+
+/**
+ * Describes a mission which can be instantiated at a Mission Controller with a
+ * set of given interfaces.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class Mission implements ManagedObject {
+
+ @SuppressWarnings("unused")
+ private String name;
+ Map<String, P2Object> policies;
+ P2Object startBlock;
+ P2Object stopBlock;
+ String pname = "policy";
+ int pnumber = 1;
+ private Set<String> interfaces;
+
+ /**
+ * Creates a new mission with no values set
+ *
+ */
+ @Ponder2op("create")
+ public Mission() {
+ name = "unknown";
+ policies = new HashMap<String, P2Object>();
+ interfaces = new HashSet<String>();
+ startBlock = stopBlock = P2Object.create();
+ }
+
+ /**
+ * Names the mission aName
+ *
+ * @param aName
+ */
+ @Ponder2op("name:")
+ void name(String aName) {
+ name = aName;
+ }
+
+ /**
+ * Adds an interface requirement to the mission
+ *
+ * @param anInterface
+ */
+ @Ponder2op("interface:")
+ void addInterface(String anInterface) {
+ interfaces.add(anInterface);
+ ;
+ }
+
+ /**
+ * Returns the set of interfaces specified to the mission
+ *
+ * @return
+ */
+ @Ponder2op("interfaces")
+ P2Object getInterfaces() {
+ return P2Object
+ .create(interfaces.toArray(new String[interfaces.size()]));
+ }
+
+ /**
+ * Adds an unnamed policy in the form of aBlock to the mission
+ *
+ * @param aBlock
+ */
+ @Ponder2op("policy:")
+ void policy(P2Object aBlock) {
+ policyIs(pname + pnumber++, aBlock);
+ }
+
+ /**
+ * Adds a policy block, aBlock, with the name aName
+ *
+ * @param aName
+ * @param aBlock
+ */
+ @Ponder2op("policy:is:")
+ protected void policyIs(String aName, P2Object aBlock) {
+ policies.put(aName, aBlock);
+ }
+
+ /**
+ * Returns a hash of policies given to the mission. The has is indexed by
+ * the policy name
+ *
+ * @return
+ */
+ @Ponder2op("policies")
+ P2Object policies() {
+ return P2Object.create(policies);
+ }
+
+ /**
+ * executes aBlock when the mission is started
+ *
+ * @param aBlock
+ */
+ @Ponder2op("onStart:")
+ void startBlock(P2Object aBlock) {
+ startBlock = aBlock;
+ }
+
+ /**
+ * returns the start block
+ *
+ * @return
+ */
+ @Ponder2op("onStart")
+ P2Object startBlock() {
+ return startBlock;
+ }
+
+ /**
+ * executes aBlock when the mission is stopped
+ *
+ * @param aBlock
+ */
+ @Ponder2op("onStop:")
+ void stopBlock(P2Object aBlock) {
+ stopBlock = aBlock;
+ }
+
+ /**
+ * returns the stop block
+ *
+ * @return
+ */
+ @Ponder2op("onStop")
+ P2Object stopBlock() {
+ return stopBlock;
+ }
+
+ /**
+ * Returns the policy with the name aName
+ *
+ * @param aName
+ * @return
+ */
+ @Ponder2op("at:")
+ P2Object at(String aName) {
+ return policies.get(aName);
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/mission/MissionController.java b/ponder2/src/main/java/eu/novi/ponder2/mission/MissionController.java
new file mode 100644
index 0000000..63dc095
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/mission/MissionController.java
@@ -0,0 +1,224 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Apr 7, 2008
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.mission;
+
+import java.util.Map;
+
+
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.exception.Ponder2ArgumentException;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.objects.P2Array;
+import eu.novi.ponder2.objects.P2Hash;
+import eu.novi.ponder2.objects.P2Null;
+import eu.novi.ponder2.objects.P2Object;
+
+/**
+ * A MissionController is responsible for managing missions in its SMC. It can
+ * load, unload, start and stop missions.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class MissionController implements ManagedObject {
+
+ private int missionNumber = 0;
+ private String mname = "Mission";
+ private P2Object missionDomain;
+ private P2Object policyfactory;
+ private P2Object domainFactory;
+ private P2Object myP2Object;
+
+ /**
+ * Creates a MissionController using aDomain as the main mission root.
+ *
+ * @throws Ponder2Exception
+ *
+ */
+ @Ponder2op("domainFactory:policyFactory:")
+ public MissionController(P2Object myP2Object, P2Object aDomainFactory,
+ P2Object anEcaPolicyFactory) throws Ponder2Exception {
+ this.myP2Object = myP2Object;
+ policyfactory = anEcaPolicyFactory;
+ domainFactory = aDomainFactory;
+ missionDomain = domainFactory.operation(myP2Object, "create");
+ }
+
+ /**
+ * Loads aMission into the local SMC and returns the mission name
+ *
+ * @param aMission
+ * @return
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("load:")
+ String load(P2Object aMission) throws Ponder2Exception {
+ return load(aMission, new P2Hash());
+ }
+
+ /**
+ * Loads aMission into the local SMC and returns the mission name.
+ * Interfaces are supplied in aHash.
+ *
+ * @param aMission
+ * @param aHash
+ * @return
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("load:with:")
+ String load(P2Object aMission, P2Object aHash) throws Ponder2Exception {
+ // Get a copy of the hash, we don't want to alter the original
+ P2Hash argHash = new P2Hash(aHash.asHash().asMap());
+ missionNumber++;
+ String missionName = mname + missionNumber;
+
+ // Make up a new domain
+ P2Object domain = domainFactory.operation(myP2Object, "create");
+ missionDomain.operation(myP2Object, "at:put:",
+ P2Object.create(missionName), domain);
+
+ // Set up a chroot environment
+ argHash.put("root", domain);
+ argHash.put("missionroot", domain);
+ // Check that the needed interfaces are present and subscribe to their
+ // events
+ for (P2Object anInterface : aMission
+ .operation(myP2Object, "interfaces").asArray()) {
+ if (argHash.asHash().containsKey(anInterface.asString())) {
+ P2Object iface = argHash.asHash().get(anInterface.asString());
+ iface.operation(myP2Object, "subscribe:", domain);
+ } else {
+ throw new Ponder2ArgumentException("Mission " + missionName
+ + " missing interface \"" + anInterface + "\"");
+ }
+ }
+ // Grab the policies from the mission and instantiate them
+ P2Hash policies = (P2Hash) aMission.operation(myP2Object, "policies");
+ for (Map.Entry<String, P2Object> entry : policies.asMap().entrySet()) {
+ String pname = entry.getKey();
+ P2Object pblock = entry.getValue();
+ // Create a new policy
+ P2Object newPolicy = policyfactory.operation(myP2Object, "create");
+ argHash.operation_at_put("policy", newPolicy);
+ // Attach it to the domain for receiving events
+ newPolicy.operation(myP2Object, "attach:", domain);
+ // Build the policy using the block from the mission
+ pblock.operation(myP2Object, "valueHash:", argHash);
+ domain.operation(myP2Object, "at:put:", P2Object.create(pname),
+ newPolicy);
+ newPolicy.operation(myP2Object, "active:", P2Object.create(true));
+ }
+
+ // start(missionName);
+ P2Object block = aMission.operation(myP2Object, "onStart");
+ if (block != P2Null.Null)
+ block.operation(myP2Object, "valueHash:", argHash);
+
+ return missionName;
+ }
+
+ /**
+ * Unloads aMissionName from the SMC. If the mission is running then it is
+ * stopped first.
+ *
+ * @param aMissionName
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("unload:")
+ void unload(String aMissionName) throws Ponder2Exception {
+ stop(aMissionName);
+ }
+
+ /**
+ * Starts aMissionName running. This involves making sure all the policies
+ * are hooked up to the event bus and that all the policies active.
+ *
+ * @param aMissionName
+ * @throws Ponder2Exception
+ */
+/* @Ponder2op("start:")
+ void start(String aMissionName) throws Ponder2Exception {
+ P2Object mission = missionDomain.operation(myP2Object, "at:",
+ P2Object.create(aMissionName));
+ mission.operation(myP2Object, "start");
+ }*/
+ @Ponder2op("start:")
+ void start(String aMissionName) throws Ponder2Exception {
+ P2Object domain = missionDomain.operation(myP2Object, "at:", P2Object.create(aMissionName));
+ //then find the policies in the domain (list them and then activate them)
+ System.out.println( domain.operation(myP2Object, "listNames"));
+ P2Array thepolicies = (P2Array) domain.operation(myP2Object, "listNames");
+ for (int i = 0; i < thepolicies.size(); i++) {
+ System.out.println(thepolicies.at(i).toString());
+ P2Object oldPolicy = domain.operation(myP2Object, "at:", thepolicies.at(i).toString());
+ oldPolicy.operation(myP2Object, "active:", P2Object.create(true));
+ }
+
+ }
+ /**
+ * Stops aMissionName. This involves making all the policies inactive.
+ *
+ * @param aMissionName
+ * @throws Ponder2Exception
+ */
+ /*@Ponder2op("stop:")
+ void stop(String aMissionName) throws Ponder2Exception {
+ missionDomain.operation(myP2Object, "at:",
+ P2Object.create(aMissionName));
+ }*/
+
+ @Ponder2op("stop:")
+ void stop(String aMissionName) throws Ponder2Exception {
+ //We have to get the domain
+ P2Object domain = missionDomain.operation(myP2Object, "at:", P2Object.create(aMissionName));
+ //then find the policies in the domain (list them and then deactivate them)
+ System.out.println( domain.operation(myP2Object, "listNames"));
+ P2Array thepolicies = (P2Array) domain.operation(myP2Object, "listNames");
+ for (int i = 0; i < thepolicies.size(); i++) {
+ System.out.println(thepolicies.at(i).toString());
+ P2Object oldPolicy = domain.operation(myP2Object, "at:", thepolicies.at(i).toString());
+ oldPolicy.operation(myP2Object, "active:", P2Object.create(false));
+ }
+ }
+
+ /**
+ * Answers an array containing all the loaded mission names
+ *
+ * @return
+ */
+ /*@Ponder2op("missions")
+ P2Object missions() {
+ return P2Object.create();
+ }*/
+ @Ponder2op("missions")
+ P2Object missions() throws Ponder2Exception {
+ return missionDomain.operation(myP2Object,"listNames");
+ }
+
+
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/objects/P2Array.java b/ponder2/src/main/java/eu/novi/ponder2/objects/P2Array.java
new file mode 100644
index 0000000..b33364e
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/objects/P2Array.java
@@ -0,0 +1,379 @@
+/**
+ * Copyright 2006 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Jan 6, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.objects;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.Vector;
+
+
+import eu.novi.ponder2.objects.P2Array;
+import eu.novi.ponder2.objects.P2Block;
+import eu.novi.ponder2.objects.P2Hash;
+import eu.novi.ponder2.objects.P2Object;
+
+import com.twicom.qdparser.TaggedElement;
+
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.comms.P2Serializable;
+import eu.novi.ponder2.exception.Ponder2ArgumentException;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2OperationException;
+
+/**
+ * Holds a collection of Ponder2 objects. An array may be returned from sending
+ * a message to an object or or may be created in PonderTalk with the
+ *
+ * <pre>
+ * #( obj1 obj2 obj3)
+ * </pre>
+ *
+ * syntax.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class P2Array extends P2Object implements ManagedObject {
+
+ // This is held as a list because we might want to alter it eg. add:
+ Vector<P2Object> values;
+
+ /**
+ * creates an empty P2Array
+ */
+ public P2Array() {
+ this.values = new Vector<P2Object>();
+ }
+
+ /**
+ * creates a P2Array initialised with values
+ *
+ * @param values
+ * the values to use to initialise the array
+ */
+ public P2Array(P2Object... values) {
+ this.values = new Vector<P2Object>(Arrays.asList(values));
+ }
+
+ /**
+ * creates a P2Array initialised with string values
+ *
+ * @param values
+ * the values to use to initialise the array
+ */
+ public P2Array(String... values) {
+ this.values = new Vector<P2Object>();
+ for (String value : values)
+ this.values.add(P2Object.create(value));
+ }
+
+ /**
+ * creates a P2Array initialised with int values
+ *
+ * @param values
+ * the values to use to initialise the array
+ */
+ public P2Array(int... values) {
+ this.values = new Vector<P2Object>();
+ for (int value : values)
+ this.values.add(P2Object.create(value));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.novi.ponder2.parser.P2Value#asString()
+ */
+ @Override
+ public P2Object[] asArray() throws Ponder2ArgumentException {
+ return values.toArray(new P2Object[values.size()]);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.novi.ponder2.objects.P2Object#asP2Array()
+ */
+ @Override
+ public P2Array asP2Array() throws Ponder2ArgumentException {
+ return this;
+ }
+
+ /**
+ * Returns a Hash comprising of the array contents taken as key, value pairs
+ *
+ * @see eu.novi.ponder2.objects.P2Object#asHash()
+ */
+ @Override
+ @Ponder2op("asHash")
+ public P2Hash asHash() throws Ponder2ArgumentException,
+ Ponder2OperationException {
+ if ((values.size() % 2) != 0)
+ throw new Ponder2ArgumentException(
+ "P2Array cannot convert to P2Hash, odd number of elements");
+ P2Hash hash = new P2Hash();
+ for (Iterator<P2Object> it = values.iterator(); it.hasNext();) {
+ P2Object name = it.next();
+ P2Object value = it.next();
+ hash.operation_at_put(name.asString(), value);
+ }
+ return hash;
+ }
+
+ /**
+ * for each object in the array executes aBlock with the object given as an
+ * argument to the block. Answers the receiver
+ *
+ * @param source
+ * the originator of the command
+ * @param aBlock
+ * the block to be executed
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("do:")
+ public void operation_do(P2Object source, P2Block aBlock)
+ throws Ponder2Exception {
+ for (Iterator<P2Object> iter = values.iterator(); iter.hasNext();) {
+ P2Object value = iter.next();
+ aBlock.execute(source, value);
+ }
+ }
+
+ /**
+ * for each entry in the array executes aBlock with the entry given as an
+ * argument to the block. Answers an array of answers built from each
+ * execution of the block.
+ *
+ * @param source
+ * the originator of the command
+ * @param aBlock
+ * the block to be executed
+ * @return an array with the results of the block executions
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("collect:")
+ public P2Array operation_collect(P2Object source, P2Block aBlock)
+ throws Ponder2Exception {
+ P2Array result = new P2Array();
+ for (Iterator<P2Object> iter = values.iterator(); iter.hasNext();) {
+ P2Object value = iter.next();
+ result.add(aBlock.execute(source, value));
+ }
+ return result;
+ }
+
+ /**
+ * adds a aP2Object to the receiver. Answers the receiver
+ *
+ * @param aP2Object
+ * the object to be added to the array
+ */
+ @Ponder2op("add:")
+ public void add(P2Object aP2Object) {
+ values.add(aP2Object);
+ }
+
+ /**
+ * adds all objects in anArray to the receiver. Answers the receiver
+ *
+ * @param anArray
+ * the array to be added to this object
+ * @throws Ponder2ArgumentException
+ */
+ @Ponder2op("addAll:")
+ public void addAll(P2Array anArray) throws Ponder2ArgumentException {
+ P2Object[] array = anArray.asArray();
+ for (int i = 0; i < array.length; i++) {
+ values.add(array[i]);
+ }
+
+ }
+
+ /**
+ * returns the object at anIndex
+ *
+ * @param anIndex
+ * the index of the required object
+ * @return the object located by anIndex
+ */
+ @Ponder2op("at:")
+ public P2Object at(int anIndex) {
+ return values.elementAt(anIndex);
+ }
+
+ /**
+ * inserts aP2Object at anIndex posiion in the array. Returns the object
+ * added.
+ *
+ * @param anIndex
+ * the index of the object to be added
+ * @param aP2Object
+ * the object to be added
+ * @return the object that was added
+ */
+ @Ponder2op("at:put:")
+ public P2Object atput(int anIndex, P2Object aP2Object) {
+ if (anIndex < 0)
+ anIndex = 0;
+ if (anIndex > values.size())
+ anIndex = values.size();
+ values.set(anIndex, aP2Object);
+ return aP2Object;
+ }
+
+ /**
+ * returns the number of elements in the receiver
+ *
+ * @return the number of elements held
+ */
+ @Ponder2op("size")
+ public int size() {
+ return values.size();
+ }
+
+ /**
+ * returns true if the array an element at anIndex. This is really here to
+ * compliment the other collections and the remove: operations.
+ *
+ * @param anIndex
+ * the object to be checked
+ * @return true if the object is in the array
+ */
+ @Ponder2op("has:")
+ public boolean has(int anIndex) {
+ return (anIndex >= 0) && (anIndex < values.size());
+ }
+
+ /**
+ * returns true if the array contains aP2Object
+ *
+ * @param aP2Object
+ * the object to be checked
+ * @return true if the object is in the array
+ */
+ @Ponder2op("hasObject:")
+ public boolean hasObject(P2Object aP2Object) {
+ return values.contains(aP2Object);
+ }
+
+ /**
+ * Answer the value associated with the given index and remove it from the
+ * receiver.
+ */
+ @Ponder2op("remove:")
+ protected P2Object remove(int anIndex) {
+ return values.remove(anIndex);
+ }
+
+ /**
+ * Removes anObject from the receiver. All copies of anObject will be
+ * removed. Answers true if one or more were removed.
+ *
+ * @param anObject
+ * the object to be removed
+ * @return true if the an object was removed
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("removeObject:")
+ protected boolean removeObject(P2Object anObject) throws Ponder2Exception {
+ // The object may be here more than once
+ boolean removed = values.remove(anObject);
+ boolean result = removed;
+ while (removed) {
+ removed = values.remove(anObject);
+ }
+ return result;
+ }
+
+ /**
+ * Removes all objects stored in the receiver. Answers self.
+ */
+ @Ponder2op("removeAll")
+ protected void operation_removeAll() {
+ values.clear();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.novi.ponder2.objects.P2Object#writeXml()
+ */
+ @Override
+ public TaggedElement writeXml(Set<P2Object> written)
+ throws Ponder2OperationException {
+ TaggedElement xml = super.writeXml(written);
+ if (xml.getAttribute("written") != null) {
+ return xml;
+ }
+ xml.setAttribute("size", "" + values.size());
+ for (Iterator<P2Object> iter = values.iterator(); iter.hasNext();) {
+ P2Object value = iter.next();
+ xml.add(value.writeXml(written));
+ }
+ return xml;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * eu.novi.ponder2.objects.P2Object#readXml(com.twicom.qdparser.TaggedElement
+ * )
+ */
+ @Override
+ public P2Object readXml(TaggedElement xml, Map<Integer, P2Serializable> read)
+ throws Ponder2OperationException, Ponder2ArgumentException {
+ int size = Integer.parseInt(xml.getAttribute("size"));
+ values = new Vector<P2Object>(size);
+ for (int i = 0; i < size; i++) {
+ TaggedElement e = (TaggedElement) xml.getChild(i);
+ values.add(P2Object.fromXml(e, read));
+ }
+ return this;
+ }
+
+ /**
+ * Returns all the values in the array as a Vector
+ *
+ * @return the values
+ */
+ public Vector<P2Object> getValues() {
+ return values;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return values.toString();
+ }
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/objects/P2Block.java b/ponder2/src/main/java/eu/novi/ponder2/objects/P2Block.java
new file mode 100644
index 0000000..9cebc46
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/objects/P2Block.java
@@ -0,0 +1,463 @@
+/**
+ * Copyright 2006 Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Jan 6, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.objects;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+
+import eu.novi.ponder2.objects.P2Array;
+import eu.novi.ponder2.objects.P2Block;
+import eu.novi.ponder2.objects.P2Boolean;
+import eu.novi.ponder2.objects.P2Hash;
+import eu.novi.ponder2.objects.P2Object;
+
+import com.twicom.qdparser.TaggedElement;
+
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.comms.P2Serializable;
+import eu.novi.ponder2.exception.Ponder2ArgumentException;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2OperationException;
+import eu.novi.ponder2.parser.XMLParser;
+
+/**
+ * Acts as a closure encompassing PonderTalk statements. Any variables used by
+ * the statements within the block are untouched once the block is created.
+ * Blocks may have arguments that are handed in when they are executed. When a
+ * block is executed it returns returns the value of the last statement executed
+ * within the block. c.f. function calls.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class P2Block extends P2Object implements ManagedObject {
+
+ private Map<String, P2Object> variables;
+ private Map<String, P2Object> testVariables;
+ private P2Hash extraVars;
+ private TaggedElement block;
+
+ // Optimisation information. We only need to work these values out once. We
+ // can do them when the block is first executed.
+ private boolean firstTime;
+ private int argCount;
+ private String[] argName;
+ private TaggedElement code;
+ private P2Block errorBlock;
+
+ /**
+ * constructor for Ponder2 serialisation
+ */
+ protected P2Block() {
+ }
+
+ public P2Block(Map<String, P2Object> variables, TaggedElement block) {
+ this.variables = new HashMap<String, P2Object>(variables);
+ this.testVariables = null;
+ this.block = block;
+ this.firstTime = true;
+ this.errorBlock = null;
+ this.extraVars = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.novi.ponder2.parser.P2Value#asString()
+ */
+ @Override
+ public P2Block asBlock() throws Ponder2ArgumentException {
+ return this;
+ }
+
+ /**
+ * Returns true if aHash contains entries that match all the names of the
+ * arguments that the block requires. Otherwise returns false.
+ *
+ * @param aHash
+ * the named arguments for the block
+ * @return a Ponder2 boolean, true if the arguments match the hash
+ * @throws Ponder2ArgumentException
+ */
+ @Ponder2op("hasArgs:")
+ protected boolean operation_hasArgs(P2Object source, P2Object aHash)
+ throws Ponder2Exception {
+ setup();
+ for (int i = 0; i < argName.length; i++) {
+ if (!(aHash.operation(source, "has:", argName[i]).asBoolean()))
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * The block is executed with the values of its arguments being taken by
+ * name from aHash. Answers the value of the last statement executed by the
+ * block. Throws an error if aHash does not satisfy the block's arguments.
+ *
+ * @param aHash
+ * the named arguments for the block
+ * @return the result of the block execution
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("valueHash:")
+ public P2Object operation_valueHash(P2Object source, P2Object aHash)
+ throws Ponder2Exception {
+ setup();
+ P2Object[] args = new P2Object[argCount];
+ try {
+ for (int i = 0; i < argCount; i++) {
+ args[i] = aHash.operation(source, "at:", argName[i]);
+ }
+ return execute(source, args);
+ } catch (Ponder2ArgumentException e) {
+ e.addXML(block);
+ throw e;
+ }
+ }
+
+ /**
+ * The block is executed with the values in aHash being added to the block's
+ * environment variables. Variables in aHash will overwrite environment
+ * variables with the same name. The values are added for this call only and
+ * do not persist. Answers the value of the last statement executed by the
+ * block.
+ *
+ * @param aHash
+ * the named arguments for the block
+ * @return the result of the block execution
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("valueVars:")
+ public P2Object operation_valueVars(P2Object source, P2Object aHash)
+ throws Ponder2Exception {
+ setup();
+ try {
+ if (aHash instanceof P2Hash) {
+ extraVars = (P2Hash) aHash;
+ } else {
+ P2Array array = (P2Array) aHash.operation(source, "asArray");
+ extraVars = array.asHash();
+ }
+ return execute(source);
+ } catch (Ponder2ArgumentException e) {
+ e.addXML(block);
+ throw e;
+ }
+ }
+
+ /**
+ * executes the block with no arguments. Answers with the result of the last
+ * statement executed by the block.
+ *
+ * @param source
+ * the originator of the command
+ * @return the result of the block execution
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("value")
+ public P2Object operation_value0(P2Object source) throws Ponder2Exception {
+ return execute(source);
+ }
+
+ /**
+ * Executes the block with one argument: arg0. Answers with the result of
+ * the last statement executed by the block.
+ *
+ * @param source
+ * the originator of the command
+ * @param arg0
+ * the first argument
+ * @return the result of the block execution
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("value:")
+ public P2Object operation_value1(P2Object source, P2Object arg0)
+ throws Ponder2Exception {
+ return execute(source, arg0);
+ }
+
+ /**
+ * Executes the block with two arguments: arg0 and arg1. Answers with the
+ * result of the last statement executed by the block.
+ *
+ * @param source
+ * the originator of the command
+ * @param arg0
+ * the first argument
+ * @param arg1
+ * the second argument
+ * @return the result of the block execution
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("value:value:")
+ public P2Object operation_value2(P2Object source, P2Object arg0,
+ P2Object arg1) throws Ponder2Exception {
+ return execute(source, arg0, arg1);
+ }
+
+ /**
+ * Executes the block with three arguments: arg0, arg1 and arg2. Answers
+ * with the result of the last statement executed by the block.
+ *
+ * @param source
+ * the originator of the command
+ * @param arg0
+ * the first argument
+ * @param arg1
+ * the second argument
+ * @param arg2
+ * the third argument
+ * @return the result of the block execution
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("value:value:value:")
+ public P2Object operation_value3(P2Object source, P2Object arg0,
+ P2Object arg1, P2Object arg2) throws Ponder2Exception {
+ return execute(source, arg0, arg1, arg2);
+ }
+
+ /**
+ * Executes the block with anArray of arguments. Answers with the result of
+ * the last statement executed by the block.
+ *
+ * @param source
+ * the originator of the command
+ * @param anArray
+ * the Ponder2 array of arguments to be used
+ * @return the result of the block execution
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("values:")
+ public P2Object operation_array(P2Object source, P2Array anArray)
+ throws Ponder2Exception {
+ return execute(source, anArray.asArray());
+ }
+
+ /**
+ * Executes the block with anArray of arguments. Answers with the result of
+ * the last statement executed by the block.
+ *
+ * @param source
+ * the originator of the command
+ * @param vars
+ * extra vars to be added to the environment
+ * @param anArray
+ * the Ponder2 array of arguments to be used
+ * @return the result of the block execution
+ * @throws Ponder2Exception
+ */
+ public P2Object operation_array(P2Object source, P2Hash vars,
+ P2Array anArray) throws Ponder2Exception {
+ extraVars = vars;
+ return execute(source, anArray.asArray());
+ }
+
+ /**
+ * While the receiver is true, keep executing aBlock with no arguments
+ *
+ * @param source
+ * the originator of the command
+ * @param aBlock
+ * the block to be executed
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("whileTrue:")
+ protected void whileTrue(P2Object source, P2Object aBlock)
+ throws Ponder2Exception {
+ while (execute(source) == P2Boolean.True)
+ aBlock.operation(source, "value");
+ }
+
+ /**
+ * While the receiver is false, keep executing aBlock with no arguments
+ *
+ * @param source
+ * the originator of the command
+ * @param aBlock
+ * the block to be executed
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("whileFalse:")
+ protected void whileFalse(P2Object source, P2Object aBlock)
+ throws Ponder2Exception {
+ while (execute(source) == P2Boolean.False)
+ aBlock.operation(source, "value");
+ }
+
+ /**
+ * Executes the block with anArray of arguments. Answers with the result of
+ * the last statement executed by the block.
+ *
+ * @param source
+ * the originator of the command
+ * @param args
+ * the array of arguments to be used
+ * @return the result of the block execution
+ * @throws Ponder2Exception
+ */
+ protected P2Object execute(P2Object source, P2Object... args)
+ throws Ponder2Exception {
+ setup();
+ // Copy the closure information
+ P2Hash variables = new P2Hash(this.variables);
+ testVariables = variables;
+ variables.put("Variables", variables);
+ // Add extra variables, if any
+ if (extraVars != null) {
+ variables.putAll(extraVars);
+ // only use them once
+ extraVars = null;
+ }
+ // Get the args (if any) for the xml code
+ if (argCount > 0) {
+ // We should have args, grab them
+ if (args.length < argCount)
+ throw new Ponder2ArgumentException(
+ "Not enough arguments for block. " + args.length
+ + " given, " + argCount + " expected.");
+ // Set the args up as variables for the parser
+ for (int i = 0; i < argCount; i++) {
+ variables.put(argName[i], args[i]);
+ }
+ }
+ P2Object result;
+ try {
+ result = new XMLParser(variables).execute(source, code);
+ } catch (Ponder2Exception e) {
+ if (errorBlock == null)
+ throw e;
+ result = errorBlock.operation(source, "value:", P2Object.create(e));
+ }
+ return result;
+ }
+
+ /**
+ * associates anErrorBlock with the receiver. The error block is executed if
+ * a Ponder2 error occurs in the receiver. The error block is given one
+ * P2Error argument which contains the error details.
+ *
+ * @param anErrorBlock
+ */
+ @Ponder2op("onError:")
+ protected P2Object onError(P2Block anErrorBlock) {
+ this.errorBlock = anErrorBlock;
+ return this;
+ }
+
+ /**
+ * Sets up the local fields for faster future execution. Is only called when
+ * the block is to be executed. If it is never executed then this method
+ * need never be called.
+ *
+ */
+ private void setup() {
+ if (!firstTime)
+ return;
+ firstTime = false;
+
+ // Get and save the code block
+ code = (TaggedElement) block.getChild(1);
+
+ // Ok, grab the argument block
+ TaggedElement child = (TaggedElement) block.getChild(0);
+ argCount = child.elements();
+ if (argCount == 0)
+ return;
+
+ // We have some args, get the names into an array for fast access later
+ argName = new String[argCount];
+ for (int i = 0; i < argCount; i++) {
+ TaggedElement arginfo = (TaggedElement) child.getChild(i);
+ argName[i] = arginfo.getAttribute("name");
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.novi.ponder2.objects.P2Object#writeXml()
+ */
+ @Override
+ public TaggedElement writeXml(Set<P2Object> written)
+ throws Ponder2OperationException {
+ TaggedElement xml = super.writeXml(written);
+ if (xml.getAttribute("written") != null) {
+ return xml;
+ }
+ xml.add(P2Object.create(variables).writeXml(written));
+ xml.add(block);
+ return xml;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * eu.novi.ponder2.objects.P2Object#readXml(com.twicom.qdparser.TaggedElement
+ * )
+ */
+ @Override
+ public P2Object readXml(TaggedElement xml, Map<Integer, P2Serializable> read)
+ throws Ponder2OperationException, Ponder2ArgumentException {
+ variables = new HashMap<String, P2Object>();
+ TaggedElement child = (TaggedElement) xml.getChild(0);
+ P2Object obj = P2Object.fromXml(child, read);
+ variables = obj.asHash().asMap();
+ block = (TaggedElement) xml.getChild(1);
+ firstTime = true;
+ return this;
+ }
+
+ /**
+ * Used for testing. Returns the value of the named variable.
+ *
+ * @param var
+ * the name of the variable
+ * @return the value of the named variable
+ */
+ public P2Object getVariable(String var) {
+ return testVariables.get(var);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ // Need to work out how to dump the variables properly without stack
+ // overflow
+ // return variables.toString() + block.toString();
+ // Need toString(Set<P2Object> track);
+ return block.toString();
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/objects/P2Boolean.java b/ponder2/src/main/java/eu/novi/ponder2/objects/P2Boolean.java
new file mode 100644
index 0000000..a8a7cdb
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/objects/P2Boolean.java
@@ -0,0 +1,270 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Jan 10, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.objects;
+
+import java.util.Map;
+import java.util.Set;
+
+
+import com.twicom.qdparser.TaggedElement;
+
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.comms.P2Serializable;
+import eu.novi.ponder2.exception.Ponder2ArgumentException;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2OperationException;
+
+import eu.novi.ponder2.objects.P2Block;
+import eu.novi.ponder2.objects.P2Boolean;
+import eu.novi.ponder2.objects.P2Number;
+import eu.novi.ponder2.objects.P2Object;
+
+/**
+ * A boolean object.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class P2Boolean extends P2Object implements ManagedObject {
+
+ static public final P2Boolean True = new P2Boolean(true);
+ static public final P2Boolean False = new P2Boolean(false);
+
+ /**
+ * constructor for Ponder2 serialisation
+ */
+ protected P2Boolean() {
+ }
+
+ public static P2Boolean from(String string) throws Ponder2ArgumentException {
+ if (string.equals("true"))
+ return True;
+ if (string.equals("false"))
+ return False;
+ throw new Ponder2ArgumentException("Bad boolean string '" + string
+ + "'");
+ }
+
+ private boolean value;
+
+ /**
+ * @param value
+ */
+ private P2Boolean(boolean value) {
+ this.value = value;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.novi.ponder2.objects.P2Object#asBoolean()
+ */
+ @Override
+ public boolean asBoolean() throws Ponder2ArgumentException {
+ return value;
+ }
+
+ /**
+ * Answers a boolean being the logical NOT operator applied to the receiver
+ *
+ * @return NOT this
+ */
+ @Ponder2op("not")
+ protected boolean not() {
+ return !value;
+ }
+
+ /**
+ * Answers a boolean being the receiver AND aBoolean
+ *
+ * @param aBoolean
+ * the value for the AND operation
+ * @return this and aBoolean
+ */
+ @Ponder2op("&")
+ protected boolean and(boolean aBoolean) {
+ return value & aBoolean;
+ }
+
+ /**
+ * Answers a boolean being the receiver OR aBoolean
+ *
+ * @param aBoolean
+ * the value for the OR operation
+ * @return this or aBoolean
+ */
+ @Ponder2op("|")
+ protected boolean or(boolean aBoolean) {
+ return value | aBoolean;
+ }
+
+ /**
+ * Answers with a random boolean value
+ *
+ * @return a random boolean value
+ */
+ @Ponder2op("random")
+ protected boolean random() {
+ return P2Number.random.nextBoolean();
+ }
+
+ /**
+ * Answers a boolean being the receiver AND the value of aBlock if the
+ * receiver is true. The block is not evaluated if the receiver is false.
+ * The block must return a boolean.
+ *
+ * @param aBlock
+ * the block to be executed if this is true
+ * @return this and aBlock
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("and:")
+ protected boolean and(P2Object source, P2Block aBlock)
+ throws Ponder2Exception {
+ return value ? aBlock.execute(source).asBoolean() : false;
+ }
+
+ /**
+ * Answers a boolean being the receiver OR the value of aBlock if the
+ * receiver is false. The block is not evaluated if the receiver is true.
+ * The block must return a boolean.
+ *
+ * @param aBlock
+ * the block to be executed if this is false
+ * @return this or aBlock
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("or:")
+ protected boolean or(P2Object source, P2Block aBlock)
+ throws Ponder2Exception {
+ return value ? true : aBlock.execute(source).asBoolean();
+ }
+
+ /**
+ * Executes aBlock if the receiver is true. Answers the value of aBlock or
+ * Nil. No arguments are given to the block.
+ *
+ * @param aBlock
+ * the block to be executed if this is true
+ * @return boolean or nil
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("ifTrue:")
+ protected P2Object ifTrue(P2Object source, P2Block aBlock)
+ throws Ponder2Exception {
+ return value ? aBlock.execute(source) : P2Object.create();
+ }
+
+ /**
+ * Executes aBlock if the receiver is false. Answers the value of aBlock or
+ * Nil. No arguments are given to the block.
+ *
+ * @param aBlock
+ * the block to be executed if this is false
+ * @return boolean or nil
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("ifFalse:")
+ protected P2Object ifFalse(P2Object source, P2Block aBlock)
+ throws Ponder2Exception {
+ return value ? P2Object.create() : aBlock.execute(source);
+ }
+
+ /**
+ * Executes aBlockTrue if the receiver is true otherwise aBlockFalse is
+ * executed. Answers the return value of the block that is executed. No
+ * arguments are given to the block to be executed.
+ *
+ * @param aBlockTrue
+ * the block to be executed if this is true
+ * @param aBlockFalse
+ * the block to be executed if this is false
+ * @return the result of the block executed
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("ifTrue:ifFalse:")
+ protected P2Object ifTrueifFalse(P2Object source, P2Block aBlockTrue,
+ P2Block aBlockFalse) throws Ponder2Exception {
+ return value ? aBlockTrue.execute(source) : aBlockFalse.execute(source);
+ }
+
+ /**
+ * Executes aBlockFalse if the receiver is false otherwise aBlockTrue is
+ * executed. Answers the return value of the block that is executed. No
+ * arguments are given to the block to be executed.
+ *
+ * @param aBlockFalse
+ * the block to be executed if this is false
+ * @param aBlockTrue
+ * the block to be executed if this is true
+ * @return the result of the block executed
+ * @throws Ponder2Exception
+ */
+ @Ponder2op("ifFalse:ifTrue:")
+ protected P2Object ifFalseifTrue(P2Object source, P2Block aBlockFalse,
+ P2Block aBlockTrue) throws Ponder2Exception {
+ return value ? aBlockTrue.execute(source) : aBlockFalse.execute(source);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.novi.ponder2.objects.P2Object#writeXml()
+ */
+ @Override
+ public TaggedElement writeXml(Set<P2Object> written)
+ throws Ponder2OperationException {
+ TaggedElement xml = super.writeXml(written);
+ xml.setAttribute("value", toString());
+ return xml;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * eu.novi.ponder2.objects.P2Object#readXml(com.twicom.qdparser.TaggedElement
+ * )
+ */
+ @Override
+ public P2Object readXml(TaggedElement xml, Map<Integer, P2Serializable> read)
+ throws Ponder2OperationException {
+ boolean bool = Boolean.parseBoolean(xml.getAttribute("value"));
+ return bool ? True : False;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return Boolean.toString(value);
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/objects/P2Class.java b/ponder2/src/main/java/eu/novi/ponder2/objects/P2Class.java
new file mode 100644
index 0000000..81f5a22
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/objects/P2Class.java
@@ -0,0 +1,92 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Mar 15, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.objects;
+
+import java.util.Map;
+import java.util.Set;
+
+import eu.novi.ponder2.objects.P2Object;
+
+import com.twicom.qdparser.TaggedElement;
+
+import eu.novi.ponder2.comms.P2Serializable;
+import eu.novi.ponder2.exception.Ponder2ArgumentException;
+import eu.novi.ponder2.exception.Ponder2OperationException;
+
+/**
+ * TODO Description
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class P2Class extends P2Object {
+
+ private Class<?> myClass;
+
+ P2Class(Class<?> myClass) {
+ this.myClass = myClass;
+ }
+
+ @Override
+ public Class<?> asClass() throws Ponder2ArgumentException {
+ return myClass;
+ }
+
+ @Override
+ public String toString() {
+ String className = myClass.getSimpleName();
+ if (className.endsWith("P2Adaptor"))
+ className = className.substring(0, className.length() - 9);
+ return className;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.novi.ponder2.objects.P2Object#writeXml()
+ */
+ @Override
+ public TaggedElement writeXml(Set<P2Object> written)
+ throws Ponder2OperationException {
+ throw new Ponder2OperationException(
+ "P2Class cannot be passed externally");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * eu.novi.ponder2.objects.P2Object#readXml(com.twicom.qdparser.TaggedElement
+ * )
+ */
+ @Override
+ public P2Object readXml(TaggedElement xml, Map<Integer, P2Serializable> read)
+ throws Ponder2OperationException, Ponder2ArgumentException {
+ throw new Ponder2OperationException(
+ "P2Class cannot be passed externally");
+ }
+
+}
diff --git a/ponder2/src/main/java/eu/novi/ponder2/objects/P2Error.java b/ponder2/src/main/java/eu/novi/ponder2/objects/P2Error.java
new file mode 100644
index 0000000..b44fb24
--- /dev/null
+++ b/ponder2/src/main/java/eu/novi/ponder2/objects/P2Error.java
@@ -0,0 +1,154 @@
+/**
+ * Copyright 2007 Kevin Twidle, Imperial College, London, England.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Contact: Kevin Twidle <kpt@doc.ic.ac.uk>
+ *
+ * Created on Jan 10, 2007
+ *
+ * $Log:$
+ */
+
+package eu.novi.ponder2.objects;
+
+import java.util.Map;
+import java.util.Set;
+
+
+import eu.novi.ponder2.objects.P2Object;
+
+import com.twicom.qdparser.TaggedElement;
+
+import eu.novi.ponder2.ManagedObject;
+import eu.novi.ponder2.apt.Ponder2op;
+import eu.novi.ponder2.comms.P2Serializable;
+import eu.novi.ponder2.exception.Ponder2Exception;
+import eu.novi.ponder2.exception.Ponder2OperationException;
+
+/**
+ * Object containing error details created when an error is thrown in the code.
+ * Attributes include an error message and the PonderTalk source file name, line
+ * number and character number.
+ * <p>
+ * This is the argument received by the block onError: message.
+ *
+ * @author Kevin Twidle
+ * @version $Id:$
+ */
+public class P2Error extends P2Object implements ManagedObject {
+
+ private String message;
+ private String source;
+ private String line;
+ private String character;
+
+ /**
+ * constructor for Ponder2 serialisation
+ */
+ protected P2Error(Ponder2Exception exception) {
+ message = exception.getMessage();
+ source = exception.getSource();
+ String linechar = exception.getLine();
+ int colon = linechar.indexOf(':', 0);
+ if (colon >= 0) {
+ line = linechar.substring(0, colon);
+ character = linechar.substring(colon + 1);
+ } else {
+ line = linechar;
+ character = "";
+ }
+ }
+
+ /**
+ * Returns the source file name
+ *
+ * @return the source file name
+ */
+ @Ponder2op("source")
+ protected String source() {
+ return source;
+ }
+
+ /**
+ * returns the source line number
+ *
+ * @return the source line number
+ */
+ @Ponder2op("line")
+ protected String line() {
+ return line;
+ }
+
+ /**
+ * returns the source character number
+ *
+ * @return the source character number
+ */
+ @Ponder2op("char")
+ protected String character() {
+ return character;
+ }
+
+ /**
+ * returns the error message
+ *
+ * @return the error message
+ */
+ @Ponder2op("message")
+ protected String message() {
+ return message;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.novi.ponder2.objects.P2Object#writeXml()
+ */
+ @Override
+ public TaggedElement writeXml(Set<P2Object> written)
+ throws Ponder2OperationException {
+ TaggedElement xml = super.writeXml(written);
+ xml.setAttribute("source", source);
+ xml.setAttribute("line",