Example usage for org.aspectj.bridge AbortException getMessage

List of usage examples for org.aspectj.bridge AbortException getMessage

Introduction

In this page you can find the example usage for org.aspectj.bridge AbortException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Get message for this AbortException, either associated explicitly as message or implicitly as IMessage message or its thrown message.

Usage

From source file:org.caesarj.compiler.aspectj.CaesarWeaver.java

License:Open Source License

public void performWeaving(CaesarBcelWorld world, final IWeaveRequestor listener)
        throws IOException, PositionedError, UnpositionedError {
    try {/*from   w ww . j  ava2  s  . co m*/
        /*
        // Create an array containing the unwoven files...
        UnwovenClassFile unwovenClassFiles[] = 
          (UnwovenClassFile[])unwovenClasses.toArray(new UnwovenClassFile[0]);
        BcelWeaver   weaver = new BcelWeaver(world.getWorld());
        // ... and feed it into the waever ...
        for (int i = 0; i < unwovenClassFiles.length; i++)
          weaver.addClassFile(unwovenClassFiles[i]);
        // ... to do the weaving!
        weaver.weave(); */

        // Changed for version 1.2.1 of aspectj weaver
        BcelWeaver weaver = new CaesarBcelWeaver(world.getWorld());

        weaver.setReweavableMode(true, false);
        for (int i = 0; i < unwovenClasses.size(); i++)
            weaver.addClassFile((UnwovenClassFile) unwovenClasses.get(i));
        weaver.prepareForWeave();

        IClassFileProvider provider = new IClassFileProvider() {

            public Iterator getClassFileIterator() {
                return unwovenClasses.iterator();
            }

            public IWeaveRequestor getRequestor() {
                return new IWeaveRequestor() {
                    public void acceptResult(UnwovenClassFile result) {

                        if (result != null) {
                            String className = result.getClassName().replace('.', '/');
                            try {
                                BufferedOutputStream os = FileUtil
                                        .makeOutputStream(new File(destination + "/" + className + ".class"));
                                os.write(result.getBytes());
                                os.close();
                            } catch (IOException ex) {
                                ex.printStackTrace();
                            }
                        }
                        if (listener != null)
                            listener.acceptResult(result);
                    }

                    public void processingReweavableState() {
                        if (listener != null)
                            listener.processingReweavableState();
                    }

                    public void addingTypeMungers() {
                        if (listener != null)
                            listener.addingTypeMungers();
                    }

                    public void weavingAspects() {
                        if (listener != null)
                            listener.weavingAspects();
                    }

                    public void weavingClasses() {
                        if (listener != null)
                            listener.weavingClasses();
                    }

                    public void weaveCompleted() {
                        if (listener != null)
                            listener.weaveCompleted();
                    }
                };
            }
        };
        weaver.weave(provider);

    } catch (AbortException e) {
        // Create a wrapper for the catched exception
        if (e.getIMessage() != null && e.getIMessage().getSourceLocation() != null) {
            throw new PositionedError(
                    new TokenReference(e.getIMessage().getSourceLocation().getSourceFile().getName(),
                            e.getIMessage().getSourceLocation().getLine()),
                    new Message(CaesarMessages.WEAVER_ERROR, e.getMessage()));
        } else {
            throw new UnpositionedError(new Message(CaesarMessages.WEAVER_ERROR, e.getMessage()));
        }
    }
}