/**
  * INTERNAL: Convert all the class-name-based settings in this mapping to actual class-based
  * settings. This method is used when converting a project that has been built with class names to
  * a project with classes.
  */
 @Override
 public void convertClassNamesToClasses(ClassLoader classLoader) {
   super.convertClassNamesToClasses(classLoader);
   Iterator iterator = getTypeIndicatorNameTranslation().entrySet().iterator();
   this.typeIndicatorTranslation = new HashMap();
   while (iterator.hasNext()) {
     Map.Entry entry = (Map.Entry) iterator.next();
     String referenceClassName = (String) entry.getKey();
     Object indicator = entry.getValue();
     Class referenceClass = null;
     try {
       if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
         try {
           referenceClass =
               (Class)
                   AccessController.doPrivileged(
                       new PrivilegedClassForName(referenceClassName, true, classLoader));
         } catch (PrivilegedActionException exception) {
           throw ValidationException.classNotFoundWhileConvertingClassNames(
               referenceClassName, exception.getException());
         }
       } else {
         referenceClass =
             PrivilegedAccessHelper.getClassForName(referenceClassName, true, classLoader);
       }
     } catch (ClassNotFoundException exception) {
       throw ValidationException.classNotFoundWhileConvertingClassNames(
           referenceClassName, exception);
     }
     addClassIndicator(referenceClass, indicator);
   }
 }
 /**
  * INTERNAL: Convert all the class-name-based settings in this InheritancePolicy to actual
  * class-based settings. This method is used when converting a project that has been built with
  * class names to a project with classes. It will also convert referenced classes to the versions
  * of the classes from the classLoader.
  */
 public void convertClassNamesToClasses(ClassLoader classLoader) {
   Vector newParentInterfaces = new Vector();
   for (Iterator iterator = getParentInterfaceNames().iterator(); iterator.hasNext(); ) {
     String interfaceName = (String) iterator.next();
     Class interfaceClass = null;
     try {
       if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
         try {
           interfaceClass =
               (Class)
                   AccessController.doPrivileged(
                       new PrivilegedClassForName(interfaceName, true, classLoader));
         } catch (PrivilegedActionException exception) {
           throw ValidationException.classNotFoundWhileConvertingClassNames(
               interfaceName, exception.getException());
         }
       } else {
         interfaceClass =
             org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getClassForName(
                 interfaceName, true, classLoader);
       }
     } catch (ClassNotFoundException exc) {
       throw ValidationException.classNotFoundWhileConvertingClassNames(interfaceName, exc);
     }
     newParentInterfaces.add(interfaceClass);
   }
   this.parentInterfaces = newParentInterfaces;
 }
 /**
  * Parse constraints file (referenced in validation.xml). Add all classes declared under <bean
  * class="clazz"> to {@link
  * org.eclipse.persistence.jaxb.BeanValidationHelper#constraintsOnClasses} with value {@link
  * Boolean#TRUE}.
  */
 private void parseConstraintFile(String constraintsFile, DefaultHandler referencedFileHandler) {
   InputStream constraintsXml = null;
   if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
     try {
       constraintsXml =
           AccessController.doPrivileged(
                   new PrivilegedGetContextClassLoader(Thread.currentThread()))
               .getResourceAsStream(constraintsFile);
     } catch (PrivilegedActionException e) {
       String msg =
           "Loading of custom constraints file: "
               + constraintsFile
               + " failed. Exception: "
               + e.getMessage();
       LOGGER.warning(msg);
     }
   } else {
     constraintsXml =
         Thread.currentThread().getContextClassLoader().getResourceAsStream(constraintsFile);
   }
   try {
     //noinspection ConstantConditions
     saxParser.parse(constraintsXml, referencedFileHandler);
   } catch (SAXException | IOException | NullPointerException e) {
     String msg =
         "Loading of custom constraints file: "
             + constraintsFile
             + " failed. Exception: "
             + e.getMessage();
     LOGGER.warning(msg);
   }
 }
 /**
  * INTERNAL: Convert all the class-name-based settings to actual class-based settings. This method
  * is used when converting a project that has been built with class names to a project with
  * classes.
  */
 public void convertClassNamesToClasses(ClassLoader classLoader) {
   if (getPartitioningClasName() == null) {
     setPartitioningClasName("");
   }
   try {
     if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
       Class partitioningClass =
           (Class)
               AccessController.doPrivileged(
                   new PrivilegedClassForName(getPartitioningClasName(), true, classLoader));
       this.policy =
           (PartitioningPolicy)
               AccessController.doPrivileged(
                   new PrivilegedNewInstanceFromClass(partitioningClass));
     } else {
       Class partitioningClass =
           PrivilegedAccessHelper.getClassForName(getPartitioningClasName(), true, classLoader);
       this.policy =
           (PartitioningPolicy) PrivilegedAccessHelper.newInstanceFromClass(partitioningClass);
     }
   } catch (PrivilegedActionException exception) {
     throw ValidationException.classNotFoundWhileConvertingClassNames(
         getPartitioningClasName(), exception.getException());
   } catch (ClassNotFoundException exception) {
     throw ValidationException.classNotFoundWhileConvertingClassNames(
         getPartitioningClasName(), exception);
   } catch (IllegalAccessException exception) {
     throw ValidationException.reflectiveExceptionWhileCreatingClassInstance(
         getPartitioningClasName(), exception);
   } catch (InstantiationException exception) {
     throw ValidationException.reflectiveExceptionWhileCreatingClassInstance(
         getPartitioningClasName(), exception);
   }
 }
 /** INTERNAL: Load a class from a given class name. (XMLEntityMappings calls this one) */
 public static Class getClassForName(String classname, ClassLoader loader) {
   try {
     if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
       try {
         return (Class)
             AccessController.doPrivileged(new PrivilegedClassForName(classname, true, loader));
       } catch (PrivilegedActionException exception) {
         throw ValidationException.unableToLoadClass(classname, exception.getException());
       }
     } else {
       return PrivilegedAccessHelper.getClassForName(classname, true, loader);
     }
   } catch (ClassNotFoundException exception) {
     if (classname.indexOf('$') != -1) {
       String outer = classname.substring(0, classname.indexOf('$'));
       Class outerClass = getClassForName(outer, loader);
       for (int index = 0; index < outerClass.getClasses().length; index++) {
         if (outerClass.getClasses()[index].getName().equals(classname)) {
           return outerClass.getClasses()[index];
         }
       }
     }
     throw ValidationException.unableToLoadClass(classname, exception);
   }
 }
 /**
  * Internal: Helper to load class. Please do not make this method protected or public else it
  * would expose a security hole that would allow malicious code to use this method to load any
  * class without security permission
  *
  * @param className Fully qualified class name
  * @param classLoader ClassLoader to be used for loading the class
  * @return Loaded Class
  * @throws java.security.PrivilegedActionException
  * @throws ClassNotFoundException
  */
 private Class loadClass(String className, ClassLoader classLoader)
     throws PrivilegedActionException, ClassNotFoundException {
   Class loadedClass = null;
   if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
     loadedClass =
         AccessController.doPrivileged(new PrivilegedClassForName(className, true, classLoader));
   } else {
     loadedClass = PrivilegedAccessHelper.getClassForName(className, true, classLoader);
   }
   return loadedClass;
 }
 /**
  * @return true if someone is just not letting the async thread do anything or if we possibly
  *     failed due to using jdk executor and not having access to resources managed by container.
  */
 static boolean asyncAttemptFailed() {
   try {
     return !didSomething
         || (possibleResourceVisibilityFail
             && (PrivilegedAccessHelper.shouldUsePrivilegedAccess()
                     ? AccessController.doPrivileged(
                             new PrivilegedGetContextClassLoader(Thread.currentThread()))
                         .getResource(VALIDATION_XML)
                     : Thread.currentThread().getContextClassLoader().getResource(VALIDATION_XML))
                 != null);
   } catch (PrivilegedActionException exception) {
     return true;
   }
 }
Пример #8
0
  /** INTERNAL: Return a new instance of the class provided. */
  public Object getClassInstance(Class cls) {
    if (cls != null) {
      try {
        if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
          return AccessController.doPrivileged(new PrivilegedNewInstanceFromClass(cls));
        } else {
          return org.eclipse.persistence.internal.security.PrivilegedAccessHelper
              .newInstanceFromClass(cls);
        }
      } catch (Exception e) {
        throw ValidationException.reflectiveExceptionWhileCreatingClassInstance(cls.getName(), e);
      }
    }

    return null;
  }
 /** INTERNAL: Create a new instance of the class given. */
 static Object getClassInstance(Class cls) {
   try {
     if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
       try {
         return AccessController.doPrivileged(new PrivilegedNewInstanceFromClass(cls));
       } catch (PrivilegedActionException exception) {
         throw ValidationException.errorInstantiatingClass(cls, exception.getException());
       }
     } else {
       return PrivilegedAccessHelper.newInstanceFromClass(cls);
     }
   } catch (IllegalAccessException exception) {
     throw ValidationException.errorInstantiatingClass(cls, exception);
   } catch (InstantiationException exception) {
     throw ValidationException.errorInstantiatingClass(cls, exception);
   }
 }
 /**
  * INTERNAL: Convert all the class-name-based settings in this Descriptor to actual class-based
  * settings. This method is used when converting a project that has been built with class names to
  * a project with classes.
  *
  * @param classLoader
  */
 public void convertClassNamesToClasses(ClassLoader classLoader) {
   if (this.type == null) {
     try {
       if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
         try {
           this.type =
               AccessController.doPrivileged(
                   new PrivilegedClassForName(this.typeName, true, classLoader));
         } catch (PrivilegedActionException exception) {
           throw ValidationException.classNotFoundWhileConvertingClassNames(
               this.typeName, exception.getException());
         }
       } else {
         this.type =
             org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getClassForName(
                 this.typeName, true, classLoader);
       }
     } catch (ClassNotFoundException exc) {
       throw ValidationException.classNotFoundWhileConvertingClassNames(this.typeName, exc);
     }
     if (this.items != null) {
       for (ATTRIBUTE_ITEM item : this.items.values()) {
         item.convertClassNamesToClasses(classLoader);
       }
     }
     if (this.allsubclasses != null) {
       Map<Object, CoreAttributeGroup> allGroups = new HashMap<Object, CoreAttributeGroup>();
       this.subClasses = new HashSet<CoreAttributeGroup>();
       for (CoreAttributeGroup subClass : allsubclasses.values()) {
         subClass.convertClassNamesToClasses(classLoader);
         allGroups.put(subClass.getType(), subClass);
       }
       this.allsubclasses = allGroups;
       for (CoreAttributeGroup subClass : allsubclasses.values()) {
         if (CoreAttributeItem.orderInheritance(subClass, allGroups)) {
           this.insertSubClass(subClass);
         }
       }
     }
   }
 }
  public static ArchiveFactory getArchiveFactory(ClassLoader loader) {
    if (ARCHIVE_FACTORY != null) {
      return ARCHIVE_FACTORY;
    }

    ArchiveFactory factory = null;
    String factoryClassName = System.getProperty(SystemProperties.ARCHIVE_FACTORY, null);

    if (factoryClassName == null) {
      return new ArchiveFactoryImpl();
    } else {
      try {
        if (loader != null) {
          Class archiveClass = loader.loadClass(factoryClassName);
          if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
            try {
              factory =
                  (ArchiveFactory)
                      AccessController.doPrivileged(
                          new PrivilegedNewInstanceFromClass(archiveClass));
            } catch (PrivilegedActionException exception) {
              throw PersistenceUnitLoadingException.exceptionCreatingArchiveFactory(
                  factoryClassName, exception);
            }
          } else {
            factory = (ArchiveFactory) PrivilegedAccessHelper.newInstanceFromClass(archiveClass);
          }
        }
      } catch (ClassNotFoundException cnfe) {
        throw PersistenceUnitLoadingException.exceptionCreatingArchiveFactory(
            factoryClassName, cnfe);
      } catch (IllegalAccessException iae) {
        throw PersistenceUnitLoadingException.exceptionCreatingArchiveFactory(
            factoryClassName, iae);
      } catch (InstantiationException ie) {
        throw PersistenceUnitLoadingException.exceptionCreatingArchiveFactory(factoryClassName, ie);
      }
    }

    return factory;
  }
 private void parseValidationXML() throws SAXException, IOException {
   InputStream validationXml = null;
   if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
     try {
       validationXml =
           AccessController.doPrivileged(
                   new PrivilegedGetContextClassLoader(Thread.currentThread()))
               .getResourceAsStream(VALIDATION_XML);
     } catch (PrivilegedActionException e) {
       String msg = "Loading of " + VALIDATION_XML + " file failed. Exception: " + e.getMessage();
       LOGGER.warning(msg);
     }
   } else {
     validationXml =
         Thread.currentThread().getContextClassLoader().getResourceAsStream(VALIDATION_XML);
   }
   if (validationXml != null) {
     saxParser.parse(validationXml, validationHandler);
   } else if (jdkExecutor) {
     possibleResourceVisibilityFail = true;
   }
 }
 /**
  * INTERNAL: Lazy initialization of xmlTypeFactory allows to avoid loading xdb-dependent class
  * XMLTypeFactoryImpl unless xdb is used.
  *
  * @return XMLTypeFactory
  */
 protected XMLTypeFactory getXMLTypeFactory() {
   if (xmlTypeFactory == null) {
     String className =
         "org.eclipse.persistence.internal.platform.database.oracle.xdb.XMLTypeFactoryImpl";
     try {
       if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
         Class xmlTypeFactoryClass =
             (Class)
                 AccessController.doPrivileged(
                     new PrivilegedClassForName(
                         className, true, this.getClass().getClassLoader()));
         Constructor xmlTypeFactoryConstructor =
             (Constructor)
                 AccessController.doPrivileged(
                     new PrivilegedGetConstructorFor(xmlTypeFactoryClass, new Class[0], true));
         xmlTypeFactory =
             (XMLTypeFactory)
                 AccessController.doPrivileged(
                     new PrivilegedInvokeConstructor(xmlTypeFactoryConstructor, new Object[0]));
       } else {
         Class xmlTypeFactoryClass =
             PrivilegedAccessHelper.getClassForName(
                 className, true, this.getClass().getClassLoader());
         Constructor xmlTypeFactoryConstructor =
             PrivilegedAccessHelper.getConstructorFor(xmlTypeFactoryClass, new Class[0], true);
         xmlTypeFactory =
             (XMLTypeFactory)
                 PrivilegedAccessHelper.invokeConstructor(
                     xmlTypeFactoryConstructor, new Object[0]);
       }
     } catch (Exception e) {
       throw QueryException.reflectiveCallOnTopLinkClassFailed(className, e);
     }
   }
   return xmlTypeFactory;
 }
 /**
  * This method will be used to set a new type of identity map for a particular class type. If
  * objects of that class type are in use loss of object identity will result. For prevention
  * client may wish to initialize all identity maps first.
  *
  * @param className the fully qualified className to set the identity map for.
  * @param identityMapClassType the fully qualified class name of the new identity map type.
  * @param maxSize the maximum size to be specified for the new identity map.
  * @exception ClassNotFoundException thrown then the IdenityMap for that class name could not be
  *     found
  */
 public void setIdentityMapForClass(String className, String identityMapClassType, int maxSize)
     throws ClassNotFoundException {
   Class classToChange =
       (Class)
           getSession()
               .getDatasourcePlatform()
               .getConversionManager()
               .convertObject(className, ClassConstants.CLASS);
   Class identityMapClass = null;
   if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
     try {
       identityMapClass =
           (Class) AccessController.doPrivileged(new PrivilegedClassForName(identityMapClassType));
     } catch (PrivilegedActionException ex) {
       throw (RuntimeException) ex.getCause();
     }
   } else {
     identityMapClass = PrivilegedAccessHelper.getClassForName(identityMapClassType);
   }
   ClassDescriptor descriptor = getSession().getDescriptor(classToChange);
   descriptor.setIdentityMapClass(identityMapClass);
   descriptor.setIdentityMapSize(maxSize);
   getSession().getIdentityMapAccessorInstance().initializeIdentityMap(classToChange);
 }
Пример #15
0
  /**
   * Return the java.lang.reflect.Member for the represented attribute. In the case of property
   * access the get method will be returned
   *
   * @return corresponding java.lang.reflect.Member
   */
  @Override
  public Member getJavaMember() {
    AttributeAccessor accessor = getMapping().getAttributeAccessor();
    if (accessor.isMethodAttributeAccessor()) {
      // Method level access here
      Method aMethod = ((MethodAttributeAccessor) accessor).getGetMethod();
      if (null == aMethod) {
        // 316991: If the getMethod is not set - use a reflective call via the getMethodName
        String getMethodName = null;
        try {
          getMethodName =
              ((MethodAttributeAccessor) mapping.getAttributeAccessor()).getGetMethodName();
          if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
            aMethod =
                AccessController.doPrivileged(
                    new PrivilegedGetDeclaredMethod(
                        this.getManagedTypeImpl().getJavaType(), getMethodName, null));
          } else {
            aMethod =
                PrivilegedAccessHelper.getDeclaredMethod(
                    this.getManagedTypeImpl().getJavaType(), getMethodName, null);
          }
          // Exceptions are to be ignored for reflective calls - if the methodName is also null - it
          // will catch here
        } catch (PrivilegedActionException pae) {
          // pae.printStackTrace();
        } catch (NoSuchMethodException nsfe) {
          // nsfe.printStackTrace();
        }
      }
      return aMethod;
    }

    // Field level access here
    Member aMember = ((InstanceVariableAttributeAccessor) accessor).getAttributeField();
    // For primitive and basic types - we should not return null - the attributeAccessor on the
    // MappedSuperclass is not initialized - see
    // http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_95:_20091017:_Attribute.getJavaMember.28.29_returns_null_for_a_BasicType_on_a_MappedSuperclass_because_of_an_uninitialized_accessor
    // MappedSuperclasses need special handling to get their type from an inheriting subclass
    // Note: This code does not handle attribute overrides on any entity subclass tree - use
    // descriptor initialization instead
    if (null == aMember) {
      if (this.getManagedTypeImpl().isMappedSuperclass()) {
        // get inheriting subtype member (without handling @override annotations)
        AttributeImpl inheritingTypeMember =
            ((MappedSuperclassTypeImpl) this.getManagedTypeImpl())
                .getMemberFromInheritingType(mapping.getAttributeName());
        // 322166: If attribute is defined on this current ManagedType (and not on a superclass) -
        // do not attempt a reflective call on a superclass
        if (null != inheritingTypeMember) {
          // Verify we have an attributeAccessor
          aMember =
              ((InstanceVariableAttributeAccessor)
                      inheritingTypeMember.getMapping().getAttributeAccessor())
                  .getAttributeField();
        }
      }

      if (null == aMember) {
        // 316991: Handle Embeddable types
        // If field level access - perform a getDeclaredField call
        // Field level access
        // Check declaredFields in the case where we have no getMethod or getMethodName
        try {
          if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
            aMember =
                AccessController.doPrivileged(
                    new PrivilegedGetDeclaredField(
                        this.getManagedTypeImpl().getJavaType(),
                        mapping.getAttributeName(),
                        false));
          } else {
            aMember =
                PrivilegedAccessHelper.getDeclaredField(
                    this.getManagedTypeImpl().getJavaType(), mapping.getAttributeName(), false);
          }
          // Exceptions are to be ignored for reflective calls - if the methodName is also null - it
          // will catch here
        } catch (PrivilegedActionException pae) {
          // pae.printStackTrace();
        } catch (NoSuchFieldException nsfe) {
          // nsfe.printStackTrace();
        }
      }
    }

    // 303063: secondary check for attribute override case - this will show on code coverage
    if (null == aMember) {
      AbstractSessionLog.getLog()
          .log(
              SessionLog.FINEST,
              AbstractSessionLog.METAMODEL,
              "metamodel_attribute_getmember_is_null",
              this,
              this.getManagedTypeImpl(),
              this.getDescriptor());
    }

    return aMember;
  }