Package org.jbpm.wire

Examples of org.jbpm.wire.WireException


    if (className!=null) {
      try {
        ClassLoader classLoader = wireContext.getClassLoader();
        clazz = ReflectUtil.loadClass(classLoader, className);
      } catch (Exception e) {
        throw new WireException("couldn't create object"+(name!=null ? " '"+name+"'" : "")+": "+e.getMessage(), e);
      }

      if (methodName==null) {
        // plain instantiation
        try {
          Object[] args = getArgs(wireContext, argDescriptors);
          Constructor<?> constructor = ReflectUtil.findConstructor(clazz, argDescriptors, args);
          if (constructor==null) {
            throw new WireException("couldn't find constructor "+clazz.getName()+" with args "+ArrayUtil.toString(args));
          }
          object = constructor.newInstance(args);
        } catch (WireException e) {
          throw e;
        } catch (Exception e) {
          throw new WireException("couldn't create object '"+(name!=null ? name : className)+"': "+e.getMessage(), e);
        }
      }

    } else if (factoryObjectName!=null) {
      // referenced factory object
      object = wireContext.get(factoryObjectName, false);
      if (object==null) {
        throw new WireException("can't invoke method '"+methodName+"' on null, resulted from fetching object '"+factoryObjectName+"' from this wiring environment");
      }

    } else if (factoryDescriptor!=null) {
      // factory object descriptor
      object = wireContext.create(factoryDescriptor, false);
      if (object==null) {
        throw new WireException("created factory object is null, can't invoke method '"+methodName+"' on it");
      }
    }

    if (methodName!=null) {
      // method invocation on object or static method invocation in case object is null
      if (object!=null) {
        clazz = object.getClass();
      }
      try {
        Object[] args = ObjectDescriptor.getArgs(wireContext, argDescriptors);
        Method method = ReflectUtil.findMethod(clazz, methodName, argDescriptors, args);
        if (method==null) {
          // throw exception but first, generate decent message
          throw new WireException("method "+ReflectUtil.getSignature(methodName, argDescriptors, args)+" is not available on "+
              (object!=null ? "object "+object+" ("+clazz.getName()+")" : "class "+clazz.getName()));
        }
        if (object == null && (!Modifier.isStatic(method.getModifiers()))) {
          // A non static method is invoked on a null object
          throw new WireException("method "+ clazz.getName() + "." + ReflectUtil.getSignature(methodName, argDescriptors, args)+" is not static. It cannot be called on a null object.");
        }
        object = ReflectUtil.invoke(method, object, args);

      } catch (WireException e) {
        throw e;
      } catch (Exception e) {
        throw new WireException("couldn't invoke factory method "+methodName+": "+e.getMessage(), e);
      }
    }

    return object;
  }
View Full Code Here


        for(Operation operation: operations) {
          operation.apply(object, wireContext);
        }
      }
    } catch (Exception e) {
      throw new WireException("couldn't initialize object '"+(name!=null ? name : className)+"': "+e.getMessage(), e);
    }
  }
View Full Code Here

  public Class<?> getType(WireDefinition wireDefinition) {
    if (className!=null) {
      try {
        return ReflectUtil.loadClass(wireDefinition.getClassLoader(), className);
      } catch (JbpmReflectException e) {
        throw new WireException("couldn't create '"+(name!=null ? name : className)+"': "+e.getMessage(), e.getCause());
      }
    }
   
    Descriptor descriptor = null;
    if (factoryDescriptor!=null) {
View Full Code Here

  private static final long serialVersionUID = 1L;

  public Object construct(WireContext wireContext) {
    CommandService commandService = wireContext.get(CommandService.class);
    if (commandService==null) {
      throw new WireException("no command-service available");
    }
    return new PvmServiceImpl(commandService);
  }
View Full Code Here

        }
        load(object, inputStream);
      }
     
    } catch (Exception e) {
      throw new WireException("couldn't read properties from "+description, e);
    }
   
    super.initialize(object, wireContext);
  }
View Full Code Here

      session = (Session) wireContext.get(sessionName);
    } else {
      session = wireContext.get(Session.class);
    }
    if (session==null) {
      throw new WireException("couldn't find hibernate-session "+(sessionName!=null ? "'"+sessionName+"'" : "by type ")+"to create pvm-db-session");
    }
   
    // create the pvm-db-session
    return new HibernatePvmDbSession(session);
  }
View Full Code Here

    ClassLoader classLoader = wireContext.getClassLoader();
    try {
      return ReflectUtil.loadClass(classLoader, text);
    } catch (JbpmReflectException e) {
      Throwable cause = e.getCause();
      throw new WireException("couldn't load class '"+text+"': "+cause.getMessage(), cause);
    }
  }
View Full Code Here

    try {
      Object[] args = ObjectDescriptor.getArgs(wireContext, argDescriptors);
      Class<?> clazz = target.getClass();
      Method method = ReflectUtil.findMethod(clazz, methodName, argDescriptors, args);
      if(method == null) {
        throw new WireException("method "+ReflectUtil.getSignature(methodName, argDescriptors, args)+" unavailable for "+target);
      }
      ReflectUtil.invoke(method, target, args);
    } catch (WireException e) {
      throw e;
    } catch (Exception e) {
      throw new WireException("couldn't invoke listener method "+methodName+": "+e.getMessage(), e);
    }
  }
View Full Code Here

      );
    } else {
      try {
        listener = (Listener) target;
      } catch (ClassCastException e) {
        throw new WireException("couldn't subscribe object "+target+ " because it is not a Listener");
      }
    }

    // if there is a filter specified on the event names
    if ( (eventNames!=null)
         && (! eventNames.isEmpty())
       ) {
      listener = new FilterListener(listener, eventNames);
    }

    // identify the wireContext
    WireContext wireContext = null;
    if (contextName!=null) {
      Environment environment = targetWireContext.getEnvironment();
      if (environment!=null) {
        try {
          wireContext = (WireContext) environment.getContext(contextName);
          if (wireContext==null) {
            throw new WireException("couldn't subscribe because context "+contextName+" doesn't exist");
          }
        } catch (ClassCastException e) {
          throw new WireException("couldn't subscribe because context "+contextName+" is not a WireContext", e);
        }
      } else {
        throw new WireException("couldn't get context "+contextName+" for subscribe because no environment available in context "+targetWireContext);
      }
    } else {
      wireContext = targetWireContext;
    }

    if (wireEvents) {
      WireDefinition wireDefinition = wireContext.getWireDefinition();
     
      // if there are objectNames specified
      if (objectNames!=null) {
        // subscribe to the descriptors for the all objectNames
        for (String objectName: objectNames) {
          Descriptor descriptor = wireDefinition.getDescriptor(objectName);
          subscribe(listener, descriptor);
        }
       
      // if no objectNames are specified, subscribe to all the descriptors
      } else {
        Set<Descriptor> descriptors = new HashSet<Descriptor>(wireDefinition.getDescriptors().values());
        for(Descriptor descriptor: descriptors) {
          subscribe(listener, descriptor);
        }
      }

    } else if ( (objectNames!=null)
                && (!objectNames.isEmpty())
              ) {
      // for every objectName
      for (String objectName: objectNames) {
        // subscribe to the objects themselves
        Object object = wireContext.get(objectName);
        if (object==null) {
          throw new WireException("couldn't subscribe to object in context "+wireContext.getName()+": object "+objectName+" unavailable");
        }
        if (! (object instanceof Observable)) {
          throw new WireException("couldn't subscribe to object in context "+wireContext.getName()+": object "+objectName+" ("+object.getClass().getName()+") isn't "+Observable.class.getName());
        }
        subscribe(listener, (Observable)object);
      }

    } else {
View Full Code Here

   * @throws WireException if this operation is applied on an object which is not a resource
   * or if the specified transaction cannot be found.
   */
  public void apply(Object target, WireContext wireContext) {
    if (! (target instanceof Resource)) {
      throw new WireException("operation enlist can only be applied on objects that implement "+Resource.class.getName()+": "+target+(target!=null ? " ("+target.getClass().getName()+")" : ""));
    }

    Object object = null;
    if (transactionName!=null) {
      object = wireContext.get(transactionName);
    } else {
      object = wireContext.getEnvironment().getTransaction();
    }

    if ( (object==null)
         || (! (object instanceof StandardTransaction))
       ) {
      throw new WireException("couldn't find "+StandardTransaction.class.getName()+" "+(transactionName!=null ? "'"+transactionName+"'" : "by type")+" to enlist resource "+target);
    }

    StandardTransaction standardTransaction = (StandardTransaction) object;

    log.finest("enlisting resource "+target+" with transaction");
View Full Code Here

TOP

Related Classes of org.jbpm.wire.WireException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.