コード例 #1
0
  public static NodeModel createAddNodeAndRelCommand(
      DiagramEditPart diagramController,
      Artifact art,
      NodeModel mostRecentNavigation,
      int mostRecentLineNumber,
      Object selElement,
      CompoundCommand command) {
    DiagramModel diagram = (DiagramModel) diagramController.getModel();
    Resource resToAdd = art.elementRes;
    IJavaElement selectedElt = null;
    if (selElement instanceof IJavaElement) selectedElt = (IJavaElement) selElement;

    ReloRdfRepository repo = StoreUtil.getDefaultStoreRepository();
    IJavaElement elmtToAdd =
        selectedElt != null ? selectedElt : RJCore.resourceToJDTElement(repo, resToAdd);
    NodeModel addedNode = null;

    if (IJavaElement.TYPE == elmtToAdd.getElementType()) {
      addedNode =
          InstanceUtil.findOrCreateContainerInstanceModel(
              null, InstanceUtil.getClassName(resToAdd, repo), resToAdd, diagram, -1, command);
    } else if (elmtToAdd instanceof IMethod && elmtToAdd.getParent() instanceof IType) {
      if (mostRecentNavigation instanceof MethodBoxModel) {
        addMethodModelsAndConns(
            addedNode, resToAdd, mostRecentNavigation, mostRecentLineNumber, diagram, command);
      }
      if (addedNode == null) {
        IType containerClass = (IType) elmtToAdd.getParent();
        Resource classRes = RJCore.jdtElementToResource(repo, containerClass);
        InstanceModel instance =
            InstanceUtil.findOrCreateContainerInstanceModel(
                null, InstanceUtil.getClassName(classRes, repo), classRes, diagram, -1, command);

        IMethod method = (IMethod) elmtToAdd;
        addedNode = MethodUtil.findOrCreateMethodModel(method, resToAdd, instance, -1, command);
      }
    } else if (elmtToAdd instanceof IField && elmtToAdd.getParent() instanceof IType) {
      if (mostRecentNavigation instanceof MethodBoxModel) {
        addFieldModelsAndConns(
            addedNode, resToAdd, mostRecentNavigation, mostRecentLineNumber, diagram, command);
      }
      if (addedNode == null) {
        IType containerClass = (IType) elmtToAdd.getParent();
        Resource classRes = RJCore.jdtElementToResource(repo, containerClass);
        InstanceModel instance =
            InstanceUtil.findOrCreateContainerInstanceModel(
                null, InstanceUtil.getClassName(classRes, repo), classRes, diagram, -1, command);

        IField field = (IField) elmtToAdd;
        addedNode = FieldUtil.findOrCreateFieldModel(field, resToAdd, instance, -1, command);
      }
    }
    return addedNode;
  }
コード例 #2
0
  @Override
  public HttpGetClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
    HttpGetClientInvocation retVal = MethodUtil.createConformanceInvocation(getContext());

    if (theArgs != null) {
      for (int idx = 0; idx < theArgs.length; idx++) {
        IParameter nextParam = getParameters().get(idx);
        nextParam.translateClientArgumentIntoQueryArgument(getContext(), theArgs[idx], null, null);
      }
    }

    return retVal;
  }
コード例 #3
0
  private static void addMethodModelsAndConns(
      NodeModel addedNode,
      Resource resToAdd,
      NodeModel mostRecentNavigation,
      int mostRecentLineNumber,
      DiagramModel diagram,
      CompoundCommand command) {

    MethodBoxModel srcMethod = (MethodBoxModel) mostRecentNavigation;
    for (Invocation invocation : srcMethod.getCallsMade(null)) {

      Resource invocationRes =
          RJCore.jdtElementToResource(
              StoreUtil.getDefaultStoreRepository(), invocation.getMethodElement());
      int invocationLineNum =
          InstanceUtil.getLineNumber(srcMethod.getInstanceModel(), invocation.getStartPosition());
      if (resToAdd.equals(invocationRes) && invocationLineNum == mostRecentLineNumber) {

        // test whether call doesn't need to
        // be added because already in diagram
        for (MethodBoxModel child : srcMethod.getMethodChildren()) {
          if (invocation.getInvocation().equals(child.getASTNode())) {
            addedNode = child.getPartner();
            return;
          }
        }
        Resource classOfInstance =
            MethodUtil.getClassOfInstanceCalledOn(invocation, srcMethod.getInstanceModel());
        MethodBoxModel invocationModel =
            MethodUtil.createModelsForMethodRes(
                invocation, srcMethod, diagram, classOfInstance, null, false, command, null, false);
        addedNode = invocationModel.getPartner();
        return;
      }
    }
  }
コード例 #4
0
 @Override
 public MethodOutcome invokeClient(
     String theResponseMimeType,
     Reader theResponseReader,
     int theResponseStatusCode,
     Map<String, List<String>> theHeaders)
     throws BaseServerResponseException {
   if (theResponseStatusCode >= 200 && theResponseStatusCode < 300) {
     if (myReturnVoid) {
       return null;
     }
     MethodOutcome retVal =
         MethodUtil.process2xxResponse(
             getContext(),
             theResponseStatusCode,
             theResponseMimeType,
             theResponseReader,
             theHeaders);
     return retVal;
   } else {
     throw processNon2xxResponseAndReturnExceptionToThrow(
         theResponseStatusCode, theResponseMimeType, theResponseReader);
   }
 }
コード例 #5
0
  @Override
  public Object invokeClient(
      String theResponseMimeType,
      Reader theResponseReader,
      int theResponseStatusCode,
      Map<String, List<String>> theHeaders)
      throws IOException {
    IParser parser =
        createAppropriateParserForParsingResponse(
            theResponseMimeType, theResponseReader, theResponseStatusCode);

    switch (getReturnType()) {
      case BUNDLE:
        {
          Bundle bundle;
          if (myResourceType != null) {
            bundle = parser.parseBundle(myResourceType, theResponseReader);
          } else {
            bundle = parser.parseBundle(theResponseReader);
          }
          switch (getMethodReturnType()) {
            case BUNDLE:
              return bundle;
            case LIST_OF_RESOURCES:
              List<IResource> listOfResources;
              if (myResourceListCollectionType != null) {
                listOfResources = new ArrayList<IResource>();
                for (IResource next : bundle.toListOfResources()) {
                  if (!myResourceListCollectionType.isAssignableFrom(next.getClass())) {
                    ourLog.debug(
                        "Not returning resource of type {} because it is not a subclass or instance of {}",
                        next.getClass(),
                        myResourceListCollectionType);
                    continue;
                  }
                  listOfResources.add(next);
                }
              } else {
                listOfResources = bundle.toListOfResources();
              }
              return listOfResources;
            case RESOURCE:
              List<IResource> list = bundle.toListOfResources();
              if (list.size() == 0) {
                return null;
              } else if (list.size() == 1) {
                return list.get(0);
              } else {
                throw new InvalidResponseException(
                    theResponseStatusCode,
                    "FHIR server call returned a bundle with multiple resources, but this method is only able to returns one.");
              }
            case BUNDLE_PROVIDER:
              throw new IllegalStateException(
                  "Return type of "
                      + IBundleProvider.class.getSimpleName()
                      + " is not supported in clients");
          }
          break;
        }
      case RESOURCE:
        {
          IResource resource;
          if (myResourceType != null) {
            resource = parser.parseResource(myResourceType, theResponseReader);
          } else {
            resource = parser.parseResource(theResponseReader);
          }

          MethodUtil.parseClientRequestResourceHeaders(null, theHeaders, resource);

          switch (getMethodReturnType()) {
            case BUNDLE:
              return Bundle.withSingleResource(resource);
            case LIST_OF_RESOURCES:
              return Collections.singletonList(resource);
            case RESOURCE:
              return resource;
            case BUNDLE_PROVIDER:
              throw new IllegalStateException(
                  "Return type of "
                      + IBundleProvider.class.getSimpleName()
                      + " is not supported in clients");
          }
          break;
        }
    }

    throw new IllegalStateException("Should not get here!");
  }
コード例 #6
0
ファイル: TypeDiff.java プロジェクト: pauloortins/TCC
  protected void addDeclaration(SimpleNode decl, SimpleNode other, boolean added) {
    dubaj.tr.Ace.log("decl: " + decl);

    if (decl instanceof ASTClassOrInterfaceBodyDeclaration) {
      decl = TypeDeclarationUtil.getDeclaration((ASTClassOrInterfaceBodyDeclaration) decl);
    }

    if (decl instanceof ASTMethodDeclaration) {
      ASTMethodDeclaration method = (ASTMethodDeclaration) decl;
      String fullName = MethodUtil.getFullName(method);
      addDeclaration(
          added,
          METHOD_ADDED,
          METHOD_REMOVED,
          fullName,
          other,
          method,
          Relatorio.TipoDeclaracao.Metodo);
      if (added) {
        Relatorio.getMudancaClasse().incrementarMudancasMetodo(new MudancaMetodoAdicao(method));
      } else {
        Relatorio.getMudancaClasse().incrementarMudancasMetodo(new MudancaMetodoRemocao(method));
      }

    } else if (decl instanceof ASTFieldDeclaration) {
      ASTFieldDeclaration field = (ASTFieldDeclaration) decl;
      String names = FieldUtil.getNames(field);
      addDeclaration(
          added,
          FIELD_ADDED,
          FIELD_REMOVED,
          names,
          other,
          field,
          Relatorio.TipoDeclaracao.Atributo);

      if (added) {
        Relatorio.getMudancaClasse().incrementarMudancasAtributo();
      } else {
        Relatorio.getMudancaClasse().incrementarMudancasAtributo();
      }

    } else if (decl instanceof ASTConstructorDeclaration) {
      ASTConstructorDeclaration ctor = (ASTConstructorDeclaration) decl;
      String fullName = CtorUtil.getFullName(ctor);
      addDeclaration(
          added,
          CONSTRUCTOR_ADDED,
          CONSTRUCTOR_REMOVED,
          fullName,
          other,
          ctor,
          Relatorio.TipoDeclaracao.Construtor);
    } else if (decl instanceof ASTClassOrInterfaceDeclaration) {
      ASTClassOrInterfaceDeclaration coid = (ASTClassOrInterfaceDeclaration) decl;
      String name = ClassUtil.getName(coid).image;
      String addMsg = null;
      String remMsg = null;
      if (coid.isInterface()) {
        addMsg = INNER_INTERFACE_ADDED;
        remMsg = INNER_INTERFACE_REMOVED;
      } else {
        addMsg = INNER_CLASS_ADDED;
        remMsg = INNER_CLASS_REMOVED;
      }
      addDeclaration(
          added, addMsg, remMsg, name, other, coid, Relatorio.TipoDeclaracao.DeclaracaoClasse);
    } else if (decl == null) {
      // nothing.
    } else {
      dubaj.tr.Ace.stack(dubaj.tr.Ace.REVERSE, "WTF? decl: " + decl);
    }
  }