示例#1
0
  /* (non-Javadoc)
   * @see org.glassfish.hk2.xml.api.XmlService#createEmptyHandle(java.lang.Class)
   */
  @Override
  public <T> XmlRootHandle<T> createEmptyHandle(
      Class<T> jaxbAnnotatedInterface, boolean advertiseInRegistry, boolean advertiseInHub) {
    if (!jaxbAnnotatedInterface.isInterface()) {
      throw new IllegalArgumentException(
          "Only an interface can be given to unmarshall: " + jaxbAnnotatedInterface.getName());
    }
    try {
      jaUtilities.convertRootAndLeaves(jaxbAnnotatedInterface, true);

      ModelImpl model = jaUtilities.getModel(jaxbAnnotatedInterface);

      return new XmlRootHandleImpl<T>(
          this,
          hub,
          null,
          model,
          null,
          advertiseInRegistry,
          advertiseInHub,
          new DynamicChangeInfo(
              jaUtilities,
              hub,
              this,
              ((advertiseInRegistry) ? dynamicConfigurationService : null),
              serviceLocator));
    } catch (RuntimeException re) {
      throw re;
    } catch (Exception e) {
      throw new MultiException(e);
    }
  }
示例#2
0
  /* (non-Javadoc)
   * @see org.glassfish.hk2.xml.api.XmlService#unmarshall(java.net.URI, java.lang.Class)
   */
  @Override
  public <T> XmlRootHandle<T> unmarshall(
      URI uri,
      Class<T> jaxbAnnotatedInterface,
      boolean advertiseInRegistry,
      boolean advertiseInHub) {
    if (uri == null || jaxbAnnotatedInterface == null) throw new IllegalArgumentException();
    if (!jaxbAnnotatedInterface.isInterface()) {
      throw new IllegalArgumentException(
          "Only an interface can be given to unmarshall: " + jaxbAnnotatedInterface.getName());
    }

    XmlServiceParser localParser = parser.get();
    if (localParser == null) {
      throw new IllegalStateException("There is no XmlServiceParser implementation");
    }

    try {
      boolean generateAll =
          PreGenerationRequirement.MUST_PREGENERATE.equals(
              localParser.getPreGenerationRequirement());
      jaUtilities.convertRootAndLeaves(jaxbAnnotatedInterface, generateAll);

      ModelImpl model = jaUtilities.getModel(jaxbAnnotatedInterface);

      return unmarshallClass(uri, model, localParser, null, advertiseInRegistry, advertiseInHub);
    } catch (RuntimeException re) {
      throw re;
    } catch (Throwable e) {
      throw new MultiException(e);
    }
  }
示例#3
0
  /* (non-Javadoc)
   * @see org.glassfish.hk2.xml.api.XmlService#createBean(java.lang.Class)
   */
  @SuppressWarnings("unchecked")
  @Override
  public <T> T createBean(Class<T> beanInterface) {
    if (!beanInterface.isInterface()) {
      throw new IllegalArgumentException(
          "Only an interface can be given to unmarshall: " + beanInterface.getName());
    }

    jaUtilities.convertRootAndLeaves(beanInterface, true);

    ModelImpl model = jaUtilities.getModel(beanInterface);

    T retVal = (T) Utilities.createBean(model.getProxyAsClass());

    BaseHK2JAXBBean base = (BaseHK2JAXBBean) retVal;

    base._setClassReflectionHelper(classReflectionHelper);
    base._setActive();

    return retVal;
  }
示例#4
0
  /* (non-Javadoc)
   * @see org.glassfish.hk2.xml.api.XmlService#unmarshall(javax.xml.stream.XMLStreamReader, java.lang.Class, boolean, boolean)
   */
  @Override
  public <T> XmlRootHandle<T> unmarshall(
      XMLStreamReader reader,
      Class<T> jaxbAnnotatedInterface,
      boolean advertiseInRegistry,
      boolean advertiseInHub) {
    if (reader == null || jaxbAnnotatedInterface == null) throw new IllegalArgumentException();
    if (!jaxbAnnotatedInterface.isInterface()) {
      throw new IllegalArgumentException(
          "Only an interface can be given to unmarshall: " + jaxbAnnotatedInterface.getName());
    }

    try {
      jaUtilities.convertRootAndLeaves(jaxbAnnotatedInterface, false);

      ModelImpl model = jaUtilities.getModel(jaxbAnnotatedInterface);

      return unmarshallClass(null, model, null, reader, advertiseInRegistry, advertiseInHub);
    } catch (RuntimeException re) {
      throw re;
    } catch (Throwable e) {
      throw new MultiException(e);
    }
  }