Ejemplo n.º 1
0
  protected void parseChild(
      Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    Element parent = (Element) element.getParentNode();
    String serviceName = parent.getAttribute(ATTRIBUTE_NAME);
    builder.addPropertyReference("service", serviceName);

    // Create a BeanDefinition for the nested object factory and set it a
    // property value for the component
    AbstractBeanDefinition objectFactoryBeanDefinition = new GenericBeanDefinition();
    objectFactoryBeanDefinition.setBeanClass(OBJECT_FACTORY_TYPE);
    objectFactoryBeanDefinition
        .getPropertyValues()
        .addPropertyValue(AbstractObjectFactory.ATTRIBUTE_OBJECT_CLASS, componentInstanceClass);
    objectFactoryBeanDefinition.setInitMethodName(Initialisable.PHASE_NAME);
    objectFactoryBeanDefinition.setDestroyMethodName(Disposable.PHASE_NAME);
    Map props = new HashMap();
    for (int i = 0; i < element.getAttributes().getLength(); i++) {
      Node n = element.getAttributes().item(i);
      props.put(n.getLocalName(), n.getNodeValue());
    }
    String returnData = null;

    NodeList list = element.getChildNodes();
    for (int i = 0; i < list.getLength(); i++) {
      if ("return-data".equals(list.item(i).getLocalName())) {
        Element rData = (Element) list.item(i);
        if (StringUtils.isNotEmpty(rData.getAttribute("file"))) {
          String file = rData.getAttribute("file");
          try {
            returnData = IOUtils.getResourceAsString(file, getClass());
          } catch (IOException e) {
            throw new BeanCreationException("Failed to load test-data resource: " + file, e);
          }
        } else {
          returnData = rData.getTextContent();
        }
      } else if ("callback".equals(list.item(i).getLocalName())) {
        Element ele = (Element) list.item(i);
        String c = ele.getAttribute("class");
        try {
          EventCallback cb = (EventCallback) ClassUtils.instanciateClass(c);
          props.put("eventCallback", cb);

        } catch (Exception e) {
          throw new BeanCreationException("Failed to load event-callback: " + c, e);
        }
      }
    }

    if (returnData != null) {
      props.put("returnData", returnData);
    }
    objectFactoryBeanDefinition.getPropertyValues().addPropertyValue("properties", props);

    builder.addPropertyValue("objectFactory", objectFactoryBeanDefinition);

    super.parseChild(element, parserContext, builder);
  }
Ejemplo n.º 2
0
  @Override
  protected void doInitialise() throws InitialisationException {
    logger.debug("Initialising transformer: " + this);
    try {
      // Only load the file once at initialize time
      if (xslFile != null) {
        this.xslt = IOUtils.getResourceAsString(xslFile, getClass());
      }

      if (uriResolver == null) {
        this.uriResolver = new LocalURIResolver(xslFile);
      }

      transformerPool.addObject();
    } catch (Throwable te) {
      throw new InitialisationException(te, this);
    }
  }
Ejemplo n.º 3
0
 public static String toString(String resource) throws IOException {
   return IOUtils.getResourceAsString(resource, XMLTestUtils.class);
 }