Esempio n. 1
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;
  }
Esempio n. 2
0
    private DifferenceKey(BaseHK2JAXBBean bean) {
      xmlPath = bean._getXmlPath();
      instanceName = bean._getInstanceName();

      hash = xmlPath.hashCode() ^ instanceName.hashCode();
    }
Esempio n. 3
0
  /** Prints very pretty version of modifications */
  @Override
  public String toString() {
    StringBuffer sb =
        new StringBuffer(
            "Differences(num=" + differences.size() + ",cost=" + getDifferenceCost() + "\n");

    int lcv = 1;
    for (Difference d : differences.values()) {
      BaseHK2JAXBBean source = d.getSource();

      String xmlPath = source._getXmlPath();
      String instanceName = source._getInstanceName();

      List<PropertyChangeEvent> events = d.getNonChildChanges();
      sb.append(
          lcv + ". Modified Bean sourcePath=" + xmlPath + " sourceInstance=" + instanceName + "\n");

      for (PropertyChangeEvent event : events) {
        sb.append(
            "\tCHANGED: "
                + event.getPropertyName()
                + " from "
                + event.getOldValue()
                + " to "
                + event.getNewValue()
                + "\n");
      }

      Map<String, AddRemoveMoveDifference> childChanges = d.getChildChanges();

      for (Map.Entry<String, AddRemoveMoveDifference> childEntry : childChanges.entrySet()) {
        String propertyName = childEntry.getKey();

        sb.append("  CHANGED CHILD: " + propertyName + "\n");
        AddRemoveMoveDifference arm = childEntry.getValue();

        for (AddData ad : arm.getAdds()) {
          BaseHK2JAXBBean added = ad.getToAdd();
          int index = ad.getIndex();

          String addedXmlPath = added._getXmlPath();
          String addedInstanceName = added._getInstanceName();

          sb.append(
              "    ADDED: addedPath="
                  + addedXmlPath
                  + " addedInstanceName="
                  + addedInstanceName
                  + " addedIndex="
                  + index
                  + "\n");
        }

        for (RemoveData rd : arm.getRemoves()) {
          String removedXmlPath = rd.getChild()._getXmlPath();
          String removedInstanceName = rd.getChild()._getInstanceName();

          sb.append(
              "    REMOVED: removedPath="
                  + removedXmlPath
                  + " removedInstanceName="
                  + removedInstanceName
                  + "\n");
        }

        for (MoveData md : arm.getMoves()) {
          sb.append(
              "    MOVED: oldIndex=" + md.getOldIndex() + " newIndex=" + md.getNewIndex() + "\n");
        }
      }

      lcv++;
    }

    return sb.toString() + "\n," + System.identityHashCode(this) + ")";
  }
Esempio n. 4
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);
  }