Package org.codehaus.aspectwerkz.advice

Examples of org.codehaus.aspectwerkz.advice.AbstractAdvice


                             final ClassLoader loader) {
        if (name == null) throw new IllegalArgumentException("advice name can not be null");
        if (className == null) throw new IllegalArgumentException("class name can not be null");
        if (deploymentModel == null) throw new IllegalArgumentException("deployment model can not be null");

        AbstractAdvice prototype = null;
        Class adviceClass = null;
        try {
            if (loader == null) {
                adviceClass = ContextClassLoader.loadClass(className);
            }
            else {
                adviceClass = loader.loadClass(className);
            }
            prototype = (AbstractAdvice)adviceClass.newInstance();
        }
        catch (Exception e) {
            StringBuffer cause = new StringBuffer();
            cause.append("could not deploy new prototype with name ");
            cause.append(name);
            cause.append(" and class ");
            cause.append(className);
            cause.append(" due to: ");
            cause.append(e);
            throw new RuntimeException(cause.toString());
        }

        prototype.setDeploymentModel(DeploymentModel.getDeploymentModelAsInt(deploymentModel));
        prototype.setName(name);
        prototype.setAdviceClass(prototype.getClass());

        prototype.setContainer(StartupManager.createAdviceContainer(prototype));

        // register the advice
        register(name, prototype);
    }
View Full Code Here


                             final ClassLoader loader) {
        if (name == null) throw new IllegalArgumentException("advice name can not be null");
        if (className == null) throw new IllegalArgumentException("class name can not be null");
        if (deploymentModel == null) throw new IllegalArgumentException("deployment model can not be null");

        AbstractAdvice prototype = null;
        Class adviceClass = null;
        try {
            if (loader == null) {
                adviceClass = ContextClassLoader.loadClass(className);
            }
            else {
                adviceClass = loader.loadClass(className);
            }
            prototype = (AbstractAdvice)adviceClass.newInstance();
        }
        catch (Exception e) {
            StringBuffer cause = new StringBuffer();
            cause.append("could not deploy new prototype with name ");
            cause.append(name);
            cause.append(" and class ");
            cause.append(className);
            cause.append(" due to: ");
            cause.append(e);
            throw new RuntimeException(cause.toString());
        }

        prototype.setDeploymentModel(DeploymentModel.getDeploymentModelAsInt(deploymentModel));
        prototype.setName(name);
        prototype.setAdviceClass(prototype.getClass());

        prototype.setContainer(StartupManager.createAdviceContainer(prototype));

        // register the advice
        register(name, prototype);
    }
View Full Code Here

        final String name = def.getName();

        try {
            final Class adviceClass = ContextClassLoader.loadClass(adviceClassName);

            final AbstractAdvice newAdvice = (AbstractAdvice)adviceClass.
                    getConstructor(new Class[]{}).
                    newInstance(new Object[]{});

            int deploymentModel;
            if (def.getDeploymentModel() == null || def.getDeploymentModel().equals("")) {
                deploymentModel = DeploymentModel.PER_JVM;
            }
            else {
                deploymentModel = DeploymentModel.getDeploymentModelAsInt(def.getDeploymentModel());
            }

            // TODO: use custom security to protect the [AbstractAspect.m_uuid] field from getting modified by the user, setting the field opens up for changes in other AspectWerkz system running in the same JVM
            Field field = AbstractAdvice.class.getDeclaredField("m_uuid");
            field.setAccessible(true);
            field.set(newAdvice, uuid);
            newAdvice.setName(def.getName());
            newAdvice.setAdviceClass(adviceClass);
            newAdvice.setDeploymentModel(deploymentModel);

            // handle the parameters passed to the advice
            for (Iterator it2 = def.getParameters().entrySet().iterator(); it2.hasNext();) {
                Map.Entry entry = (Map.Entry)it2.next();
                newAdvice.setParameter((String)entry.getKey(), (String)entry.getValue());
            }

            // create and set the container for the advice
            newAdvice.setContainer(createAdviceContainer(newAdvice));

            AspectWerkz.getSystem(uuid).register(name, newAdvice);
        }
        catch (ClassNotFoundException e) {
            throw new DefinitionException(adviceClassName + " could not be found in classpath");
View Full Code Here

TOP

Related Classes of org.codehaus.aspectwerkz.advice.AbstractAdvice

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.