protected JavaTypeDescriptor makeTypeDescriptor(Name typeName) {
    final String classNameToLoad = typeName.fullName();

    if (isSafeClass(typeName)) {
      return makeTypeDescriptor(typeName, classLoaderService.classForName(classNameToLoad));
    } else {
      if (jpaTempClassLoader == null) {
        log.debug(
            "Request to makeTypeDescriptor(%s) - but passed class is not known to be "
                + "safe (it might be, it might not be). However, there was no "
                + "temp ClassLoader provided; we will use the live ClassLoader");
        try {
          // this reference is "safe" because it was loaded from the live ClassLoader
          return makeTypeDescriptor(typeName, classLoaderService.classForName(classNameToLoad));
        } catch (ClassLoadingException e) {
          return new NoSuchClassTypeDescriptor(typeName);
        }
      } else {
        log.debug(
            "Request to makeTypeDescriptor(%s) - passed class is not known to be "
                + "safe (it might be, it might not be). There was a temp ClassLoader "
                + "provided, so we will use that");
        // this is the Class reference that is unsafe to keep around...
        final Class unSafeReference;
        try {
          unSafeReference = jpaTempClassLoader.loadClass(classNameToLoad);
        } catch (ClassNotFoundException e) {
          return new NoSuchClassTypeDescriptor(typeName);
        }

        return makeTypeDescriptor(typeName, unSafeReference);
      }
    }
  }
 @Override
 @SuppressWarnings("unchecked")
 public Class<?> classForName(String name) {
   if (isSafeClass(name)) {
     return classLoaderService.classForName(name);
   } else {
     log.debugf("Not known whether passed class name [%s] is safe", name);
     if (jpaTempClassLoader == null) {
       log.debugf(
           "No temp ClassLoader provided; using live ClassLoader "
               + "for loading potentially unsafe class : %s",
           name);
       return classLoaderService.classForName(name);
     } else {
       log.debugf("Temp ClassLoader was provided, so we will use that : %s", name);
       try {
         return jpaTempClassLoader.loadClass(name);
       } catch (ClassNotFoundException e) {
         throw new ClassLoadingException(name);
       }
     }
   }
 }
Exemple #3
0
  public void setTypeName(String typeName) {
    if (typeName != null && typeName.startsWith(AttributeConverterTypeAdapter.NAME_PREFIX)) {
      final String converterClassName =
          typeName.substring(AttributeConverterTypeAdapter.NAME_PREFIX.length());
      final ClassLoaderService cls =
          getMetadata()
              .getMetadataBuildingOptions()
              .getServiceRegistry()
              .getService(ClassLoaderService.class);
      try {
        final Class<AttributeConverter> converterClass = cls.classForName(converterClassName);
        attributeConverterDefinition =
            new AttributeConverterDefinition(converterClass.newInstance(), false);
        return;
      } catch (Exception e) {
        log.logBadHbmAttributeConverterType(typeName, e.getMessage());
      }
    }

    this.typeName = typeName;
  }
Exemple #4
0
  private void createParameterImpl() {
    try {
      String[] columnsNames = new String[columns.size()];
      for (int i = 0; i < columns.size(); i++) {
        Selectable column = columns.get(i);
        if (column instanceof Column) {
          columnsNames[i] = ((Column) column).getName();
        }
      }

      final XProperty xProperty =
          (XProperty) typeParameters.get(DynamicParameterizedType.XPROPERTY);
      // todo : not sure this works for handling @MapKeyEnumerated
      final Annotation[] annotations = xProperty == null ? null : xProperty.getAnnotations();

      final ClassLoaderService classLoaderService =
          getMetadata()
              .getMetadataBuildingOptions()
              .getServiceRegistry()
              .getService(ClassLoaderService.class);
      typeParameters.put(
          DynamicParameterizedType.PARAMETER_TYPE,
          new ParameterTypeImpl(
              classLoaderService.classForName(
                  typeParameters.getProperty(DynamicParameterizedType.RETURNED_CLASS)),
              annotations,
              table.getCatalog(),
              table.getSchema(),
              table.getName(),
              Boolean.valueOf(typeParameters.getProperty(DynamicParameterizedType.IS_PRIMARY_KEY)),
              columnsNames));
    } catch (ClassLoadingException e) {
      throw new MappingException(
          "Could not create DynamicParameterizedType for type: " + typeName, e);
    }
  }