Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 79bddb620287fb370e347e625ca1a6ef6b88b5b9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*******************************************************************************
 * Copyright (c) 2009 Martin Lippert and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *   Martin Lippert               initial implementation      
 *******************************************************************************/

package org.eclipse.equinox.weaving.aspectj;

import java.lang.reflect.Method;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

/**
 * The main plugin class to be used in the desktop.
 */
public class AspectJWeavingActivator implements BundleActivator {

    private static final String CHECK_ASPECTJ_CLASS = "org.aspectj.weaver.loadtime.definition.Definition"; //$NON-NLS-1$

    private static final String REAL_ACTIVATOR_CLASS = "org.eclipse.equinox.weaving.aspectj.AspectJWeavingStarter"; //$NON-NLS-1$

    private Object starter; // to decouple the optional dependencies

    private Class<?> starterClass;

    /**
     * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
     */
    public void start(final BundleContext context) throws Exception {
        final ClassLoader loader = this.getClass().getClassLoader();

        try {
            final Class<?> aspectjClass = loader.loadClass(CHECK_ASPECTJ_CLASS);
            if (aspectjClass != null) {
                starterClass = loader.loadClass(REAL_ACTIVATOR_CLASS);
                starter = starterClass.newInstance();

                final Method startMethod = starterClass.getMethod("start",
                        BundleContext.class);
                startMethod.invoke(starter, context);
            }
        } catch (final Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
     */
    public void stop(final BundleContext context) throws Exception {
        if (starter != null) {
            final Method stopMethod = starterClass.getMethod("stop",
                    BundleContext.class);
            stopMethod.invoke(starter, context);
        }
    }

}

Back to the top