--  $Id: java_utility_functions.ty,v 1.2 99/08/05 11:15:07 mrusso Exp $
program java_utility_functions is
use java;
use PSP;

import diff ( _, _ ) from  prolog() ;

import
   setVariableIntoAPairList (
      Identifier, Val |- Pairs -> Pairs, Bool )
   from java_expr_evaluation;

   set setAttributesValues is
   judgement OptTypeName, Pairs |- Objects => Objects;
   judgement ObjectId, Pairs |- Objects -> Objects;
   --iJ
   judgement Pairs |- Pairs -> Pairs;

   LookForTheRightClass_RecursiveRule:
      ClName1, AttrL |- ObjL1 => Obj1_1
      --------------------------------
      ClName1, AttrL |-
       objects[object(OID, ClName2, A, L, WS, Act).ObjL1] => objects[object(OID, ClName2, A, L, WS, Act).Obj1_1]  ; 
               provided diff( ClName1, ClName2 );

   IsTheRightClass:
      AttrL1 |- AttrL2 -> AttrL2_1
      --------------------------------
      ClName, AttrL1 |-
       objects[object(OID, ClName, AttrL2, L, WS, Act).ObjL] => objects[object(OID, ClName, AttrL2_1, L, WS, Act).ObjL]  ; 

   LookForTheRightObject_RecursiveRule:
      ObjId1, AttrL |- ObjL1 -> Obj1_1
      --------------------------------
      ObjId1, AttrL |-
       objects[object(ObjId2, ClName2, A, L, WS, Act).ObjL1] -> objects[object(ObjId2, ClName2, A, L, WS, Act).Obj1_1]  ; 
               provided diff( ObjId1, ObjId2 );

   IsTheRightObject:
      AttrL1 |- AttrL2 -> AttrL2_1
      --------------------------------
      ObjId, AttrL1 |-
       objects[object(ObjId, ClName, AttrL2, L, WS, Act).ObjL1] ->
          objects[object(ObjId, ClName, AttrL2_1, L, WS, Act).ObjL1]  ; 

   SetAttributeValue:
      setVariableIntoAPairList(
         AttrName, Val |- AttrL2 -> AttrL3, TF )  &
      AttrL1 |- AttrL3 -> AttrL3_1
      --------------------------------
      pairs[pair(AttrName, Val).AttrL1] |- AttrL2 -> AttrL3_1  ; 

   NoMoreAttributeToUpdate: pairs[] |- AttrL -> AttrL  ; 
   end setAttributesValues; 

   set setAttributeValue is
   judgement ObjectId, Identifier, ValOrVals |- Objects -> Objects;

   LookForTheRightObject_RecursiveRule:
      ObjId1, AttrName, Value |- ObjL1 -> Obj1_1
      --------------------------------
      ObjId1, AttrName, Value |-
       objects[object(ObjId2, Cl, A, L, WS, Act).ObjL1] -> objects[object(ObjId2, Cl, A, L, WS, Act).Obj1_1]  ; 
               provided diff( ObjId1, ObjId2 );

   IsTheRightObject_updateAttributeValue:
      setVariableIntoAPairList(
         AttrName, Value |- AttrL1 -> AttrL1_1, TF )
      --------------------------------
      ObjId, AttrName, Value |-
       objects[object(ObjId, Cl, AttrL1, L, WS, Act).ObjL1] -> objects[object(ObjId, Cl, AttrL1_1, L, WS, Act).ObjL1]  ; 
   end setAttributeValue; 

   set or is
   judgement |- Bool, Bool -> Bool;

   True: |- true(), _ -> true()  ; 

   True: |- _, true() -> true()  ; 

   False: |- false(), false() -> false()  ; 
   end or; 

   set and is
   judgement |- Bool, Bool -> Bool;

   True: |- true(), true() -> true()  ; 

   False: |- false(), _ -> false()  ; 

   False: |- _, false() -> false()  ; 
   end and; 
end java_utility_functions