protected InvocationResult invokeComponent(
     String componentName,
     Class<?> componentClass,
     String operation,
     Object[] params,
     String[] listeners,
     Object[] updates,
     String[] results,
     String conversationId) {
   RemotingMessage callMessage = new RemotingMessage();
   callMessage.setDestination("spring");
   callMessage.setOperation("invokeComponent");
   Object[] args = new Object[5];
   args[0] = componentName;
   args[1] = componentClass != null ? componentClass.getName() : null;
   args[2] = operation;
   args[3] = params;
   InvocationCall call = new InvocationCall();
   if (listeners != null) call.setListeners(Arrays.asList(listeners));
   else call.setListeners(new ArrayList<String>());
   List<ContextUpdate> cus = new ArrayList<ContextUpdate>();
   if (updates != null) {
     for (int i = 0; i < updates.length; i++) {
       Object[] u = (Object[]) updates[i];
       boolean inConv = u.length > 3 ? (Boolean) u[3] : false;
       ContextUpdate cu =
           new ContextUpdate((String) u[0], (String) u[1], u[2], inConv ? 2 : 1, false);
       cus.add(cu);
     }
   }
   call.setUpdates(cus);
   Object[] res = results != null ? new Object[results.length] : new Object[] {};
   if (results != null) {
     for (int i = 0; i < results.length; i++) {
       int idx = results[i].indexOf(".");
       if (idx > 0)
         res[i] = new ContextResult(results[i].substring(0, idx), results[i].substring(idx + 1));
       else res[i] = new ContextResult(results[i], null);
     }
   }
   call.setResults(res);
   args[4] = call;
   callMessage.setBody(args);
   return (InvocationResult)
       springServiceFactory.getServiceInstance(callMessage).invoke(callMessage);
 };
Esempio n. 2
0
  /** Invoke the Object.method() called through FlashRemoting */
  public Object invoke(Message message) {
    Object results = null;

    if (message instanceof RemotingMessage) {
      // RemotingDestinationControl remotingDestination =
      // (RemotingDestinationControl)this.getControl().getParentControl();//destination;
      RemotingMessage remotingMessage = (RemotingMessage) message;

      // re-map our special "loadDpProxy" to the user defined hibernate
      // load method.
      if ("loadDPProxy".equals(remotingMessage.getOperation())) {
        try {
          remotingMessage.setOperation(getLoadMethodName());
          List paramArray = remotingMessage.getParameters();
          List args = new ArrayList();

          args.add(Class.forName(paramArray.get(1).getClass().getName()));
          args.add(paramArray.get(0));

          remotingMessage.setParameters(args);
        } catch (ClassNotFoundException ex) {
          ex.printStackTrace();
        } catch (Exception ex) {
          ex.printStackTrace();
        }
      }

      /*
       * // Add support for the source="" attribute of the RemoteObject
       * tag. This give developer the option // of using a single
       * destination for all java calls, and defining the java class in
       * their mxml // note: This can be turned off at the desination
       * level by defined a <source/> other then "*" try { FactoryInstance
       * factoryInstance = remotingDestination.getFactoryInstance();
       * String className = factoryInstance.getSource();
       *  // check for * wildcard in destination, and if exists use source
       * defined in mxml if( "*".equals(className) ) { sourceClass =
       * remotingMessage.getSource();
       * factoryInstance.setSource(sourceClass); } }catch( Throwable ex ){
       * ex.printStackTrace();}
       */
      System.out.println("{operation})****************" + remotingMessage.getOperation());
      // Deserialize the incoming object data
      List inArgs = remotingMessage.getParameters();
      if (inArgs != null && inArgs.size() > 0) {
        try {
          long s1 = new Date().getTime();
          Object o =
              SerializationFactory.getDeserializer(SerializationFactory.HIBERNATESERIALIZER)
                  .translate(
                      this,
                      (RemotingMessage) remotingMessage.clone(),
                      getLoadMethodName(),
                      property_hibernateSessionFactoryClass,
                      property_getCurrentSessionMethod,
                      inArgs);
          remotingMessage.setParameters((List) o);
          long e1 = new Date().getTime();
          System.out.println("{deserialize} " + (e1 - s1));
          // remotingMessage.setBody(body);
        } catch (Exception ex) {
          ex.printStackTrace();
          // throw error back to flex
          // todo: replace with custom exception
          RuntimeException re = new RuntimeException(ex.getMessage());
          re.setStackTrace(ex.getStackTrace());
          throw re;
        }
      }

      long s2 = new Date().getTime();
      // invoke the user class.method()
      results = super.invoke(remotingMessage);
      long e2 = new Date().getTime();
      System.out.println("{invoke} " + (e2 - s2));

      // serialize the result out
      try {
        long s3 = new Date().getTime();
        results =
            SerializationFactory.getSerializer(SerializationFactory.HIBERNATESERIALIZER)
                .translate(
                    property_hibernateSessionFactoryClass,
                    property_getCurrentSessionMethod,
                    results);
        long e3 = new Date().getTime();
        System.out.println("{serialize} " + (e3 - s3));
      } catch (Exception ex) {
        ex.printStackTrace();
        // throw error back to flex
        // todo: replace with custom exception
        RuntimeException re = new RuntimeException(ex.getMessage());
        re.setStackTrace(ex.getStackTrace());
        throw re;
      }
    }

    return results;
  }