示例#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);
    }
  }
示例#5
0
 public String getGeneratedId() {
   return jaUtilities.getUniqueId();
 }
示例#6
0
  private <T> XmlRootHandle<T> unmarshallClass(
      URI uri,
      ModelImpl model,
      XmlServiceParser localParser,
      XMLStreamReader reader,
      boolean advertise,
      boolean advertiseInHub)
      throws Exception {
    long elapsedUpToJAXB = 0;
    if (JAUtilities.DEBUG_GENERATION_TIMING) {
      elapsedUpToJAXB = System.currentTimeMillis();
    }

    Hk2JAXBUnmarshallerListener listener =
        new Hk2JAXBUnmarshallerListener(jaUtilities, classReflectionHelper);

    long jaxbUnmarshallElapsedTime = 0L;
    if (JAUtilities.DEBUG_GENERATION_TIMING) {
      jaxbUnmarshallElapsedTime = System.currentTimeMillis();
      elapsedUpToJAXB = jaxbUnmarshallElapsedTime - elapsedUpToJAXB;
      Logger.getLogger()
          .debug("Time up to parsing " + uri + " is " + elapsedUpToJAXB + " milliseconds");
    }

    T root;
    if (localParser != null) {
      root = localParser.parseRoot(model, uri, listener);
    } else {
      root = XmlStreamImpl.parseRoot(this, model, reader, listener);
    }

    long elapsedJAXBToAdvertisement = 0;
    if (JAUtilities.DEBUG_GENERATION_TIMING) {
      elapsedJAXBToAdvertisement = System.currentTimeMillis();
      jaxbUnmarshallElapsedTime = elapsedJAXBToAdvertisement - jaxbUnmarshallElapsedTime;
      Logger.getLogger()
          .debug(
              "Time parsing "
                  + uri
                  + " is "
                  + jaxbUnmarshallElapsedTime
                  + " milliseconds "
                  + ", now with "
                  + jaUtilities.getNumGenerated()
                  + " proxies generated and "
                  + jaUtilities.getNumPreGenerated()
                  + " pre generated proxies loaded");
    }

    DynamicChangeInfo changeControl =
        new DynamicChangeInfo(
            jaUtilities,
            ((advertiseInHub) ? hub : null),
            this,
            ((advertise) ? dynamicConfigurationService : null),
            serviceLocator);

    for (BaseHK2JAXBBean base : listener.getAllBeans()) {
      String instanceName = Utilities.createInstanceName(base);
      base._setInstanceName(instanceName);

      base._setDynamicChangeInfo(changeControl);

      if (DEBUG_PARSING) {
        Logger.getLogger().debug("XmlServiceDebug found bean " + base);
      }
    }
    if (DEBUG_PARSING) {
      Logger.getLogger().debug("XmlServiceDebug after parsing all beans in " + uri);
    }

    long elapsedPreAdvertisement = 0L;
    if (JAUtilities.DEBUG_GENERATION_TIMING) {
      elapsedPreAdvertisement = System.currentTimeMillis();
      elapsedJAXBToAdvertisement = elapsedPreAdvertisement - elapsedJAXBToAdvertisement;
      Logger.getLogger()
          .debug(
              "Time from parsing to PreAdvertisement "
                  + uri
                  + " is "
                  + elapsedJAXBToAdvertisement
                  + " milliseconds");
    }

    DynamicConfiguration config =
        (advertise) ? dynamicConfigurationService.createDynamicConfiguration() : null;
    WriteableBeanDatabase wdb = (advertiseInHub) ? hub.getWriteableDatabaseCopy() : null;

    LinkedList<BaseHK2JAXBBean> allBeans = listener.getAllBeans();
    List<ActiveDescriptor<?>> addedDescriptors =
        new ArrayList<ActiveDescriptor<?>>(allBeans.size());
    for (BaseHK2JAXBBean bean : allBeans) {
      ActiveDescriptor<?> added = Utilities.advertise(wdb, config, bean);
      if (added != null) {
        addedDescriptors.add(added);
      }
    }

    long elapsedHK2Advertisement = 0L;
    if (JAUtilities.DEBUG_GENERATION_TIMING) {
      elapsedHK2Advertisement = System.currentTimeMillis();
      elapsedPreAdvertisement = elapsedHK2Advertisement - elapsedPreAdvertisement;
      Logger.getLogger()
          .debug(
              "Time from JAXB to PreAdvertisement "
                  + uri
                  + " is "
                  + elapsedPreAdvertisement
                  + " milliseconds");
    }

    if (config != null) {
      config.commit();
    }

    long elapsedHubAdvertisement = 0L;
    if (JAUtilities.DEBUG_GENERATION_TIMING) {
      elapsedHubAdvertisement = System.currentTimeMillis();
      elapsedHK2Advertisement = elapsedHubAdvertisement - elapsedHK2Advertisement;
      Logger.getLogger()
          .debug(
              "Time to advertise "
                  + uri
                  + " in HK2 is "
                  + elapsedHK2Advertisement
                  + " milliseconds");
    }

    if (wdb != null) {
      wdb.commit(new XmlHubCommitMessage() {});
    }

    // The following is put here so that InstanceLifecycleListeners will get invoked at this time
    // rather than later so that defaulting can be done now.  It doesn't hurt because these are
    // all constant descriptors
    for (ActiveDescriptor<?> ad : addedDescriptors) {
      serviceLocator.getServiceHandle(ad).getService();
    }

    if (JAUtilities.DEBUG_GENERATION_TIMING) {
      elapsedHubAdvertisement = System.currentTimeMillis() - elapsedHubAdvertisement;
      Logger.getLogger()
          .debug(
              "Time to advertise "
                  + uri
                  + " in Hub is "
                  + elapsedHubAdvertisement
                  + " milliseconds");
    }

    return new XmlRootHandleImpl<T>(
        this, hub, root, model, uri, advertise, advertiseInHub, changeControl);
  }