Esempio n. 1
0
 /**
  * @param token
  * @return
  * @throws IllegalActionException
  */
 public Token convertTokenForMe(Token token) throws IllegalActionException {
   Token converted = token;
   if ((getContainer() instanceof Actor)
       && (PasserelleType.PASSERELLE_MSG_TYPE.equals(getType()))) {
     // Need to check/convert for ManagedMessage
     // The extra check on the port type should allow someone
     // to define ports with other types on a Passerelle actor
     // although this is not officially supported/advised
     if (token != null) {
       Class expectedContentType = null;
       if (getExpectedMessageContentType() == null && (token instanceof PasserelleToken)) {
         return token;
       } else {
         // we may need some conversion
         expectedContentType = getExpectedMessageContentType();
       }
       try {
         converted =
             TypeConversionChain.getInstance()
                 .convertPtolemyTokenToPasserelleToken(token, expectedContentType);
       } catch (UnsupportedOperationException e) {
         // do nothing
         // the user will get loads of Ptolemy errors anyway
       } catch (PasserelleException e) {
         throw new IllegalActionException(this, e, "token type conversion failed");
       }
     }
   }
   return converted;
 }
Esempio n. 2
0
 /**
  * @param token
  * @param farPort
  * @return
  * @throws IllegalActionException
  */
 private Token convertTokenForFarPort(Token token, TypedIOPort farPort)
     throws IllegalActionException {
   Object farActor = farPort.getContainer();
   Object localActor = getContainer();
   Token newToken = token;
   // now decide when Passerelle2Ptolemy conversions are required
   if (localActor instanceof Actor) {
     // ok, our container is a Passerelle Actor
     if (!(farActor instanceof Actor)
         || !PasserelleType.PASSERELLE_MSG_TYPE.equals(farPort.getType())) {
       Token converted = null;
       try {
         // token should be a PasserelleToken
         converted =
             TypeConversionChain.getInstance()
                 .convertPasserelleTokenToPtolemyToken((PasserelleToken) token, farPort.getType());
       } catch (UnsupportedOperationException e) {
         // do nothing
         // the user will get loads of Ptolemy errors anyway
       } catch (Exception e) {
         throw new IllegalActionException(this, e, "token type conversion failed");
       }
       if (converted != null) {
         newToken = converted;
       }
     }
     //      else {
     // the far port is a Passerelle Port and expecting Passerelle
     // messages
     // now we just need to check if there's any need for conversions
     // on the body contents...
     // but how????
     //      }
   } else {
     // will normally not happen, but one never knows
     // that someone develops a plain Ptolemy actor,
     // using Passerelle Ports !?
     // In that case, just try the default conversion
     // as in a standard Ptolemy TypedIOPort...
     newToken = farPort.convert(token);
   }
   return newToken;
 }