public void testCreateContextWithPathAndBindings() throws Exception {
    String oxmString = "org/eclipse/persistence/testing/jaxb/jaxbcontext/eclipselink-oxm.xml";
    InputStream oxm = ClassLoader.getSystemClassLoader().getResourceAsStream(oxmString);

    Map<String, Object> props = new HashMap<String, Object>();
    props.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, oxm);

    // Specify some other, unrelated context path -- we want to ensure that we don't fail
    // due to lack of ObjectFactory/jaxb.index
    JAXBContext ctx =
        JAXBContext.newInstance(
            "org.eclipse.persistence.testing.oxm.jaxb", ClassLoader.getSystemClassLoader(), props);

    Employee e = new Employee();
    e.id = 6;
    e.name = "Jeeves Sobs";
    e.put("tag", "tag-value");

    Document marshalDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();

    Marshaller m = ctx.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    m.marshal(e, marshalDoc);

    // Make sure OXM was picked up, "tag" property should have been added.
    Employee e2 = (Employee) ctx.createUnmarshaller().unmarshal(marshalDoc);
    assertEquals(
        "OXM file was not processed during context creation.", e.get("tag"), e2.get("tag"));
  }
示例#2
0
 public Object objectFromByteBuffer(byte[] buf, int offset, int length) throws Exception {
   if (buf == null || (offset == 0 && length == buf.length))
     return marshaller.objectFromByteBuffer(buf);
   byte[] tmp = new byte[length];
   System.arraycopy(buf, offset, tmp, 0, length);
   return marshaller.objectFromByteBuffer(tmp);
 }
示例#3
0
  /**
   * Marshalls a scenario object and writes into output XML file
   *
   * @throws JAXBException, SiriusException
   */
  public void marshallIntoXML(Scenario scenarioToWrite)
      throws JAXBException, FileNotFoundException, BeatsException {

    JAXBContext jaxbContext = JAXBContext.newInstance("edu.berkeley.path.beats.jaxb");
    Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
    jaxbMarshaller.setSchema(this.getSchema());
    jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    jaxbMarshaller.marshal(scenarioToWrite, new File(this.outputFileName));
  }
示例#4
0
    Context(Class clazz) {
      try {
        jaxbContext = JAXBContext.newInstance(clazz);

        marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.setSchema(null);

        unmarshaller = jaxbContext.createUnmarshaller();
        unmarshaller.setSchema(null);
      } catch (JAXBException e) {
        e.printStackTrace();
      }
    }
示例#5
0
  /**
   * Message contains MethodCall. Execute it against *this* object and return result. Use
   * MethodCall.invoke() to do this. Return result.
   */
  public Object handle(Message req) throws Exception {
    if (server_obj == null) {
      log.error(Util.getMessage("NoMethodHandlerIsRegisteredDiscardingRequest"));
      return null;
    }

    if (req == null || req.getLength() == 0) {
      log.error(Util.getMessage("MessageOrMessageBufferIsNull"));
      return null;
    }

    Object body =
        req_marshaller != null
            ? req_marshaller.objectFromBuffer(req.getRawBuffer(), req.getOffset(), req.getLength())
            : req.getObject();

    if (!(body instanceof MethodCall))
      throw new IllegalArgumentException("message does not contain a MethodCall object");

    MethodCall method_call = (MethodCall) body;

    if (log.isTraceEnabled()) log.trace("[sender=%s], method_call: %s", req.getSrc(), method_call);

    if (method_call.getMode() == MethodCall.ID) {
      if (method_lookup == null)
        throw new Exception(
            String.format(
                "MethodCall uses ID=%d, but method_lookup has not been set", method_call.getId()));
      Method m = method_lookup.findMethod(method_call.getId());
      if (m == null) throw new Exception("no method found for " + method_call.getId());
      method_call.setMethod(m);
    }

    return method_call.invoke(server_obj);
  }
示例#6
0
  /**
   * Invokes a method in all members and expects responses from members contained in dests (or all
   * members if dests is null).
   *
   * @param dests A list of addresses. If null, we'll wait for responses from all cluster members
   * @param method_call The method (plus args) to be invoked
   * @param options A collection of call options, e.g. sync versus async, timeout etc
   * @param listener A FutureListener which will be registered (if non null) with the future
   *     <em>before</em> the call is invoked
   * @return NotifyingFuture A future from which the results can be fetched
   * @throws Exception If the sending of the message threw an exception. Note that <em>no</em>
   *     exception will be thrown if any of the target members threw an exception; such an exception
   *     will be in the Rsp element for the particular member in the RspList
   */
  public <T> NotifyingFuture<RspList<T>> callRemoteMethodsWithFuture(
      Collection<Address> dests,
      MethodCall method_call,
      RequestOptions options,
      FutureListener<RspList<T>> listener)
      throws Exception {
    if (dests != null && dests.isEmpty()) { // don't send if dest list is empty
      if (log.isTraceEnabled())
        log.trace(
            "destination list of %s() is empty: no need to send message", method_call.getName());
      return new NullFuture<>(new RspList());
    }

    if (log.isTraceEnabled())
      log.trace("dests=%s, method_call=%s, options=%s", dests, method_call, options);

    Buffer buf =
        req_marshaller != null
            ? req_marshaller.objectToBuffer(method_call)
            : Util.objectToBuffer(method_call);
    Message msg = new Message().setBuffer(buf);

    NotifyingFuture<RspList<T>> retval = super.castMessageWithFuture(dests, msg, options, listener);
    if (log.isTraceEnabled()) log.trace("responses: %s", retval);
    return retval;
  }
示例#7
0
 /**
  * Invokes a method in a cluster member and - if blocking - returns the result
  *
  * @param dest The target member on which to invoke the method
  * @param call The call to be invoked, including method are arguments
  * @param options The options (e.g. blocking, timeout etc)
  * @param listener A FutureListener which will be registered (if non null) with the future
  *     <em>before</em> the call is invoked
  * @return A future from which the result can be fetched. If the callee threw an invocation, an
  *     ExecutionException will be thrown on calling Future.get().
  * @throws Exception Thrown if the method invocation threw an exception
  */
 public <T> NotifyingFuture<T> callRemoteMethodWithFuture(
     Address dest, MethodCall call, RequestOptions options, FutureListener<T> listener)
     throws Exception {
   if (log.isTraceEnabled()) log.trace("dest=%s, method_call=%s, options=%s", dest, call, options);
   Buffer buf =
       req_marshaller != null ? req_marshaller.objectToBuffer(call) : Util.objectToBuffer(call);
   Message msg = new Message(dest, null, null).setBuffer(buf);
   return super.sendMessageWithFuture(msg, options, listener);
 }
示例#8
0
  /**
   * Invokes a method in a cluster member and - if blocking - returns the result
   *
   * @param dest The target member on which to invoke the method
   * @param call The call to be invoked, including method are arguments
   * @param options The options (e.g. blocking, timeout etc)
   * @return The result
   * @throws Exception Thrown if the method invocation threw an exception, either at the caller or
   *     the callee
   */
  public <T> T callRemoteMethod(Address dest, MethodCall call, RequestOptions options)
      throws Exception {
    if (log.isTraceEnabled()) log.trace("dest=%s, method_call=%s, options=%s", dest, call, options);

    Buffer buf =
        req_marshaller != null ? req_marshaller.objectToBuffer(call) : Util.objectToBuffer(call);
    Message msg = new Message(dest, null, null).setBuffer(buf);

    T retval = super.sendMessage(msg, options);
    if (log.isTraceEnabled()) log.trace("retval: %s", retval);
    return retval;
  }
示例#9
0
 public void marshal(Object object, Writer writer) throws JAXBException {
   marshaller.marshal(object, writer);
 }
示例#10
0
 public Buffer objectToBuffer(Object obj) throws Exception {
   byte[] buf = marshaller.objectToByteBuffer(obj);
   return new Buffer(buf, 0, buf.length);
 }
示例#11
0
 public Object objectFromByteBuffer(byte[] buf) throws Exception {
   return buf == null ? null : marshaller.objectFromByteBuffer(buf);
 }
示例#12
0
 public byte[] objectToByteBuffer(Object obj) throws Exception {
   return marshaller.objectToByteBuffer(obj);
 }