示例#1
0
  /**
   * Converts a JSIDL pop to a CJSIDL pop transition
   *
   * @param pop - a JSIDL pop
   * @param parentTrans - the parent transition
   * @return - resulting CJSIDL object
   */
  public static popTransition convert(Pop pop, transition parentTrans) {
    CjsidlFactoryImpl factory = new CjsidlFactoryImpl();
    org.jts.eclipse.cjsidl.popTransition output = factory.createpopTransition();
    output.setComment(JSIDLInterpToCJSIDLComment(pop.getInterpretation()));

    EList<org.jts.eclipse.cjsidl.guardParam> paramlist = output.getParam();
    if (pop.getArgument() != null) {
      java.util.List<org.jts.jsidl.binding.Argument> args = pop.getArgument();
      for (org.jts.jsidl.binding.Argument arg : args) {
        guardParam gp = factory.createguardParam();
        if (arg.getValue().contains("'")) {
          gp.setGuardConst(arg.getValue());
        } else {
          if (parentTrans != null) {
            gp.setParameter(
                (transParam)
                    Conversion.referenceHelper.getEObjectFromTransition(
                        arg.getValue(), parentTrans));
          } else {
            Logger.getLogger("CJSIDL").log(Level.SEVERE, "Unexpected parameter found in guard.");
          }
        }

        paramlist.add(gp);
      }
    }

    // need to have the reference set, but the object may not exist yet, so post-process
    String transName = pop.getTransition();
    if (transName != null && !transName.isEmpty()) {
      DefaultState.secondaryTransitionMap.put(transName, output);
    }

    return output;
  }
  /**
   * Converts a JSIDL data binding to a CJSIDL object
   *
   * @param declaredMessageDef - JSIDL data binding
   * @return - resulting CJSIDL object
   */
  public static messageRef convert(
      org.jts.jsidl.binding.DeclaredMessageDef declaredMessageDef, EObject root) {
    CjsidlFactoryImpl factory = new CjsidlFactoryImpl();
    messageRef ref = factory.createmessageRef();
    ref.setName(declaredMessageDef.getName());

    // need to extract the EObject from the model
    String refName = declaredMessageDef.getDeclaredTypeRef();
    ref.setRef(
        (org.jts.eclipse.cjsidl.messageDef)
            Conversion.referenceHelper.getEObjectByName(refName, root));
    ref.setComment(JSIDLInterpToCJSIDLComment(declaredMessageDef.getInterpretation()));

    return ref;
  }
  /**
   * Converts a JSIDL message reference into a messageRef or messageScopedRef
   *
   * @param declDef - the input JSIDL message reference
   * @param root - the root object containing the message reference
   * @return - the corresponding CJSIDL object
   */
  public static EObject convertToRef(
      org.jts.jsidl.binding.DeclaredMessageDef declDef, EObject root) {
    String typename = declDef.getDeclaredTypeRef();
    String tmpArr[] = typename.split("[.]");
    if (tmpArr.length == 1) {
      // local type reference, convert to typeReference
      CjsidlFactoryImpl factory = new CjsidlFactoryImpl();
      org.jts.eclipse.cjsidl.messageRef ref = factory.createmessageRef();

      ref.setComment(JSIDLInterpToCJSIDLComment(declDef.getInterpretation()));
      String name = declDef.getName();
      EObject tmpobj = Conversion.referenceHelper.getEObjectByName(name, root);
      if (tmpobj != null || name.equals(typename)) {
        name = name + ConversionUtil.mangled;
      }
      ref.setName(name);
      EObject result = Conversion.referenceHelper.getEObjectByName(typename, root);

      if (result instanceof messageDef) {
        ref.setRef((messageDef) result);
      } else if (result == null) {
        MessageSet.messageMap.put(ref, typename);
      } else {
        Logger.getLogger("CJSIDL")
            .log(
                Level.SEVERE,
                "Unexpected object type: expecting messageDef \""
                    + typename
                    + "\" to have been declared before this line.  No definition was found.");
      }

      return ref;

    } else {
      // reference located in a different file, convert to scopedTypeId
      CjsidlFactoryImpl factory = new CjsidlFactoryImpl();
      org.jts.eclipse.cjsidl.messageScopedRef ref = factory.createmessageScopedRef();

      ref.setComment(JSIDLInterpToCJSIDLComment(declDef.getInterpretation()));
      ref.setName(declDef.getName());
      EList<EObject> scopeList = ref.getScopes();
      EObject currentObj = root;
      EObject referenceObject = null;

      // convert array to array list
      java.util.List<String> subnames = new ArrayList<String>();
      for (int i = 0; i < tmpArr.length; i++) {
        subnames.add(tmpArr[i]);
      }
      String typeName = null;
      for (String subname : subnames) {
        // the last subname is the name of the type, so its not a root object reference
        if (subnames.indexOf(subname) == subnames.size() - 1) {
          typeName = subname;
          continue;
        }
        // this is the first name and is only separate from the rest of the names
        // to avoid making a fix to the grammar and scope provider
        else if (subnames.indexOf(subname) == 0) {
          referenceObject = Conversion.referenceHelper.getEObjectByRef(subname, currentObj);
          EObject refObj = Conversion.referenceHelper.findRefEObject(subname, currentObj);
          ref.setScope(refObj);
        } else {
          currentObj = referenceObject;
          referenceObject = Conversion.referenceHelper.getEObjectByRef(subname, referenceObject);
          EObject refObj = Conversion.referenceHelper.findRefEObject(subname, currentObj);
          scopeList.add(refObj);
        }
      }
      EObject result = Conversion.referenceHelper.findEObject(typeName, referenceObject);
      if (result instanceof messageDef) {
        ref.setRef((messageDef) result);
      }

      return ref;
    }
  }