Search in sources :

Example 31 with ClassLoaderResolverImpl

use of org.datanucleus.ClassLoaderResolverImpl in project datanucleus-core by datanucleus.

the class PluginParserTest method testRequireBundleLogged.

public void testRequireBundleLogged() {
    final java.util.Set messages = new HashSet();
    Logger.getLogger("DataNucleus.General").addAppender(new Appender() {

        public void setName(String arg0) {
        }

        public void setLayout(Layout arg0) {
        }

        public void setErrorHandler(ErrorHandler arg0) {
        }

        public boolean requiresLayout() {
            return false;
        }

        public String getName() {
            return "testappender123";
        }

        public Layout getLayout() {
            return null;
        }

        public Filter getFilter() {
            return null;
        }

        public ErrorHandler getErrorHandler() {
            return null;
        }

        public void doAppend(LoggingEvent arg0) {
            if (arg0.getRenderedMessage().indexOf("but it cannot be resolved") > 0) {
                messages.add(arg0.getRenderedMessage());
            }
        }

        public void close() {
        }

        public void clearFilters() {
        }

        public void addFilter(Filter arg0) {
        }
    });
    ClassLoaderResolver clr = new ClassLoaderResolverImpl();
    NonManagedPluginRegistry mgr = new NonManagedPluginRegistry(clr, "EXCEPTION", true);
    assertEquals(0, mgr.getExtensionPoints().length);
    mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST3.MF", null));
    mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST4.MF", null));
    mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST5.MF", null));
    mgr.resolveConstraints();
    try {
        assertEquals(2, messages.size());
        assertTrue(messages.contains("Bundle \"org.datanucleus.plugin.test5\" requires \"org.datanucleus.plugin.test6\" but it cannot be resolved."));
        assertTrue(messages.contains("Bundle \"org.datanucleus.plugin.test5\" has an optional dependency to \"org.datanucleus.plugin.test7\" but it cannot be resolved"));
    } finally {
        Logger.getLogger("DataNucleus.General").removeAppender("testappender123");
    }
}
Also used : Appender(org.apache.log4j.Appender) LoggingEvent(org.apache.log4j.spi.LoggingEvent) ErrorHandler(org.apache.log4j.spi.ErrorHandler) Layout(org.apache.log4j.Layout) Filter(org.apache.log4j.spi.Filter) NonManagedPluginRegistry(org.datanucleus.plugin.NonManagedPluginRegistry) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) HashSet(java.util.HashSet) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 32 with ClassLoaderResolverImpl

use of org.datanucleus.ClassLoaderResolverImpl in project datanucleus-core by datanucleus.

the class TypeManagerTest method setUp.

/**
 * Create a TypeManager for testing.
 */
protected void setUp() throws Exception {
    ClassLoaderResolver clr = new ClassLoaderResolverImpl();
    Properties props = new Properties();
    props.setProperty("bundle-check-action", "EXCEPTION");
    PluginManager pluginMgr = new PluginManager(null, clr, props);
    NucleusContext nucCtx = new PersistenceNucleusContextImpl(null, null, pluginMgr);
    typeMgr = nucCtx.getTypeManager();
}
Also used : PluginManager(org.datanucleus.plugin.PluginManager) NucleusContext(org.datanucleus.NucleusContext) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) Properties(java.util.Properties) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 33 with ClassLoaderResolverImpl

use of org.datanucleus.ClassLoaderResolverImpl in project datanucleus-core by datanucleus.

the class PluginManager method createPluginManager.

/**
 * Convenience method that will create and return a PluginManager using any passed in properties.
 * Supports the following properties
 * <ul>
 * <li>datanucleus.primaryClassLoader</li>
 * <li>datanucleus.plugin.pluginRegistryClassName</li>
 * <li>datanucleus.plugin.pluginRegistryBundleCheck</li>
 * <li>datanucleus.plugin.allowUserBundles</li>
 * <li>datanucleus.plugin.validatePlugins</li>
 * </ul>
 * @param props Any properties defining the plugin manager capabilities
 * @param loader Any class loader to make use of when loading
 * @return The PluginManager
 */
public static PluginManager createPluginManager(Map props, ClassLoader loader) {
    ClassLoaderResolver clr = loader != null ? new ClassLoaderResolverImpl(loader) : new ClassLoaderResolverImpl();
    if (props != null) {
        clr.registerUserClassLoader((ClassLoader) props.get(PropertyNames.PROPERTY_CLASSLOADER_PRIMARY));
    }
    Properties pluginProps = new Properties();
    String registryClassName = null;
    if (props != null) {
        registryClassName = (String) props.get(PropertyNames.PROPERTY_PLUGIN_REGISTRY_CLASSNAME);
        if (props.containsKey(PropertyNames.PROPERTY_PLUGIN_REGISTRYBUNDLECHECK)) {
            pluginProps.setProperty("bundle-check-action", (String) props.get(PropertyNames.PROPERTY_PLUGIN_REGISTRYBUNDLECHECK));
        }
        if (props.containsKey(PropertyNames.PROPERTY_PLUGIN_ALLOW_USER_BUNDLES)) {
            pluginProps.setProperty("allow-user-bundles", (String) props.get(PropertyNames.PROPERTY_PLUGIN_ALLOW_USER_BUNDLES));
        }
        if (props.containsKey(PropertyNames.PROPERTY_PLUGIN_VALIDATEPLUGINS)) {
            pluginProps.setProperty("validate-plugins", (String) props.get(PropertyNames.PROPERTY_PLUGIN_VALIDATEPLUGINS));
        }
    }
    return new PluginManager(registryClassName, clr, pluginProps);
}
Also used : ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) Properties(java.util.Properties) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 34 with ClassLoaderResolverImpl

use of org.datanucleus.ClassLoaderResolverImpl in project datanucleus-core by datanucleus.

the class ImplementationGenerator method enhance.

/**
 * Enhance the implementation of the class/interface.
 * @param clr ClassLoader resolver
 */
public void enhance(final ClassLoaderResolver clr) {
    // define the generated class in the classloader so we populate the metadata
    final EnhancerClassLoader loader = new EnhancerClassLoader();
    loader.defineClass(fullClassName, getBytes(), clr);
    // Create MetaData for implementation of interface
    final ClassLoaderResolver genclr = new ClassLoaderResolverImpl(loader);
    final ClassMetaData implementationCmd;
    if (inputCmd instanceof InterfaceMetaData) {
        implementationCmd = new ClassMetaData((InterfaceMetaData) inputCmd, className, true);
    } else {
        implementationCmd = new ClassMetaData((ClassMetaData) inputCmd, className);
    }
    // Do as PrivilegedAction since populate()/initialise() use reflection to get additional fields
    AccessController.doPrivileged(new PrivilegedAction() {

        public Object run() {
            implementationCmd.populate(genclr, null, metaDataMgr);
            implementationCmd.initialise(genclr);
            return null;
        }
    });
    // enhance the class and update the byte definition
    ClassEnhancer gen = new ClassEnhancerImpl(implementationCmd, genclr, metaDataMgr, JDOEnhancementNamer.getInstance(), getBytes());
    gen.enhance();
    bytes = gen.getClassBytes();
}
Also used : PrivilegedAction(java.security.PrivilegedAction) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) InterfaceMetaData(org.datanucleus.metadata.InterfaceMetaData) ClassEnhancerImpl(org.datanucleus.enhancer.ClassEnhancerImpl) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 35 with ClassLoaderResolverImpl

use of org.datanucleus.ClassLoaderResolverImpl in project tests by datanucleus.

the class AnnotationTest method testEmbeddable.

/**
 * Test of JPA @Embeddable.
 */
public void testEmbeddable() {
    NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
    MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
    // Retrieve the metadata from the MetaDataManager (populates and initialises everything)
    ClassLoaderResolver clr = new ClassLoaderResolverImpl();
    ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(DepartmentPK.class.getName(), clr);
    assertNotNull(cmd1);
}
Also used : JPAMetaDataManager(org.datanucleus.api.jpa.metadata.JPAMetaDataManager) NucleusContext(org.datanucleus.NucleusContext) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) JPAMetaDataManager(org.datanucleus.api.jpa.metadata.JPAMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) ClassMetaData(org.datanucleus.metadata.ClassMetaData) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Aggregations

ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)53 PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)35 MetaDataManager (org.datanucleus.metadata.MetaDataManager)31 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)27 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)23 JDOMetaDataManager (org.datanucleus.api.jdo.metadata.JDOMetaDataManager)22 NucleusContext (org.datanucleus.NucleusContext)14 ClassMetaData (org.datanucleus.metadata.ClassMetaData)14 JPAMetaDataManager (org.datanucleus.api.jpa.metadata.JPAMetaDataManager)12 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)10 FetchPlan (org.datanucleus.FetchPlan)7 FetchPlanForClass (org.datanucleus.FetchPlanForClass)7 JDOFetchPlan (org.datanucleus.api.jdo.JDOFetchPlan)7 BitSet (java.util.BitSet)6 NonManagedPluginRegistry (org.datanucleus.plugin.NonManagedPluginRegistry)6 HashSet (java.util.HashSet)3 Properties (java.util.Properties)3 JDOPersistenceManagerFactory (org.datanucleus.api.jdo.JDOPersistenceManagerFactory)3 Bundle (org.datanucleus.plugin.Bundle)3 ArrayList (java.util.ArrayList)2