예제 #1
0
  public ArrayList<String> findClass(String expression) {
    ArrayList<String> classInfo = new ArrayList<String>();

    try {
      Class theClass = Thread.currentThread().getContextClassLoader().loadClass(expression);
      for (Field field : theClass.getFields()) {
        classInfo.add(field.getName() + "/" + expression + "/field/");
      }

      for (Method method : theClass.getMethods()) {
        StringBuffer paramStmt = new StringBuffer("(");
        String sep = "";
        for (Class paramCls : method.getParameterTypes()) {
          String clsNameOnly = UEngineUtil.getClassNameOnly(paramCls);
          clsNameOnly =
              sep
                  + clsNameOnly.substring(0, 1).toLowerCase()
                  + clsNameOnly.substring(1, clsNameOnly.length());
          paramStmt.append(clsNameOnly);
          sep = ", ";
        }
        paramStmt.append(")");

        classInfo.add(method.getName() + paramStmt + "/" + expression + "/method/");
      }
    } catch (Exception e) {
    }

    return classInfo;
  }
예제 #2
0
  public Object deserialize(InputStream is, Hashtable extendedContext) throws Exception {

    // getting deserializer
    Class targetCls = (Class) extendedContext.get("targetClass");
    Object objectOfTargetCls = targetCls.newInstance();
    TypeDesc desc =
        (TypeDesc)
            objectOfTargetCls
                .getClass()
                .getMethod("getTypeDesc", new Class[] {})
                .invoke(objectOfTargetCls, new Object[] {});
    final QName xmlType; // = desc.getXmlType();
    xmlType =
        new QName(
            "http://" + objectOfTargetCls.getClass().getName(),
            org.uengine.util.UEngineUtil.getClassNameOnly(objectOfTargetCls.getClass()));
    Deserializer dser =
        (Deserializer)
            objectOfTargetCls
                .getClass()
                .getMethod("getDeserializer", new Class[] {String.class, Class.class, QName.class})
                .invoke(
                    objectOfTargetCls, new Object[] {"", objectOfTargetCls.getClass(), xmlType});
    // end
    System.out.println("dser:" + dser);

    DeserializationContext context =
        new DeserializationContextImpl(
            new org.xml.sax.InputSource(is),
            /*			new MessageContext(null){
            	public String getEncodingStyle(){
            		return xmlType.getNamespaceURI();
            	}
            },*/
            new MessageContext(new AxisClient()),
            // Message.RESPONSE
            "PurchaseOrder");

    boolean oldVal = context.isDoneParsing();
    ((DeserializationContextImpl) context).deserializing(true);
    context.pushElementHandler(new EnvelopeHandler((SOAPHandler) dser));

    //	        context.getRecorder().replay(0, -1, (org.xml.sax.ContentHandler)context);
    context.getRecorder().replay(0, -1, (org.xml.sax.ContentHandler) context);

    ((DeserializationContextImpl) context).deserializing(oldVal);

    context.parse();

    return dser.getValue();
  }
예제 #3
0
  public void serialize(Object sourceObj, OutputStream os, Hashtable extendedContext)
      throws Exception {

    try {
      final ClassLoader urlClassLoader = GlobalContext.getComponentClassLoader();
      /* this will replace the default system class loader with the new custom classloader, so that XMLEncoder will use the new custom classloader to lookup a class */
      Thread.currentThread().setContextClassLoader(urlClassLoader);
    } catch (Exception e) {
      System.out.println("can't replace classloader");
    }

    try {
      TypeDesc desc =
          (TypeDesc)
              sourceObj
                  .getClass()
                  .getMethod("getTypeDesc", new Class[] {})
                  .invoke(sourceObj, new Object[] {});
      QName xmlType = desc.getXmlType();
      //
      // xmlType = (QName)extendedContext.get("qName");
      //
      xmlType =
          new QName(
              "http://" + sourceObj.getClass().getName(),
              org.uengine.util.UEngineUtil.getClassNameOnly(sourceObj.getClass()));
      //			xmlType = new QName(Constants.URI_SOAP11_ENV, Constants.ELEM_ENVELOPE );

      org.apache.axis.encoding.Serializer ser =
          (org.apache.axis.encoding.Serializer)
              sourceObj
                  .getClass()
                  .getMethod("getSerializer", new Class[] {String.class, Class.class, QName.class})
                  .invoke(sourceObj, new Object[] {"", sourceObj.getClass(), xmlType});

      // Writer w = new OutputStreamWriter(os);
      StringWriter w = new StringWriter();
      SerializationContext context =
          new SerializationContextImpl(w) {
            public MessageContext getMessageContext() {
              return new MessageContext(null) {
                public String getEncodingStyle() {
                  return "";
                }
              };
            }
          };
      ser.serialize(xmlType, (org.xml.sax.Attributes) null, sourceObj, context);

      // System.out.println(w);
      // w.write("SdfasdfsadfA");

      BufferedOutputStream bao = new BufferedOutputStream(os);

      bao.write(w.toString().getBytes());

      bao.flush();
      bao.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }