SlideShare a Scribd company logo
1 of 22
Download to read offline
Managing the Evolution
  of Aspect-Oriented Software
  with Model-based Pointcuts
Andy Kellens Kim Mens   Johan Brichau Kris Gybels




                                                    1
Crosscutting Concerns
                                                                                                                                                                                                     */
                                                                                                                                                                                                    public class FileDownload {




                                                                                                                                                                                                                                                                                                                                 Synchronisation
                                                                                                                                                                                                                    public static void download(String address, String localFileName) {
                                                                                                                                                                                                                                    OutputStream out = null;
                                                                                                                                                                                                                                    URLConnection conn = null;
                                                                                                                                                                                                                                    InputStream in = null;
                                                                                                                                                                                                                                    try {
                                                                                                                                                                                                                                                    URL url = new URL(address);
                                                                                                                                                                                                                                                    out = new BufferedOutputStream(
                                                                                                                                                                                                                                                                    new FileOutputStream(localFileName));
import java.io.*;
import java.util.zip.*;
                                                                                                                                                                                                                                                    conn = url.openConnection();
                                                                                                                                                                                                                                                    in = conn.getInputStream();
/**
  * Command line program to copy a file to another directory.
                                                                                                                                                                                                                                                    byte[] buffer = new byte[1024];
  * @author Marco Schmidt
                                                                                                                                                                                                                                                    int numRead;
  */
public class CopyFile {
                                                                                                                                                                                                                                                    long numWritten = 0;

                       // constant values for the override option
                                                                                                                                                                                                                                                    while ((numRead = in.read(buffer)) != -1) {

                       public static final int OVERWRITE_ALWAYS = 1;

                       public static final int OVERWRITE_NEVER = 2;
                                                                                                                                                                                                                                                                    out.write(buffer, 0, numRead);

                       public static final int OVERWRITE_ASK = 3;
                                                                                                                                                                                                                                                                    numWritten += numRead;

                         // program options initialized to default values
                                                                                                                                                                                                                                                    }

                         private static int bufferSize = 4 * 1024;
                                                                                                                                                                                                                                                    System.out.println(localFileName + quot;tquot; + numWritten);

                         private static boolean clock = true;

                         private static boolean copyOriginalTimestamp = true;
                                                                                                                                                                                                                                    } catch (Exception exception) {

                         private static boolean verify = true;
                                                                                                                                                                                                                                                    exception.printStackTrace();

                         private static int override = OVERWRITE_ASK;
                                                                                                                                                                                                                                    } finally {

                         public static Long copyFile(File srcFile, File destFile)
                                                                                                                                                                                                                                                    try {

                         
                      throws IOException {

                         
                      InputStream in = new FileInputStream(srcFile);
                                                                                                                                                                                                                                                                    if (in != null) {

                         
                      OutputStream out = new FileOutputStream(destFile);
                                                                                                                                                                                                                                                                                    in.close();

                         
                      long millis = System.currentTimeMillis();




                                                                                                                                                                                                                                                                                                                                 UI dependency

                         
                      CRC32 checksum = null;
                                                                                                                                                                                                                                                                    }

                         
                      if (verify) {
                                                                                                                                                                                                                                                                    if (out != null) {

                         
                      
                       checksum = new CRC32();

                         
                      
                       checksum.reset();
                                                                                                                                                                                                                                                                                    out.close();

                         
                      }
                                                                                                                                                                                                                                                                    }

                         
                      byte[] buffer = new byte[bufferSize];

                         
                      int bytesRead;
                                                                                                                                                                                                                                                    } catch (IOException ioe) {

                         
                      while ((bytesRead = in.read(buffer)) >= 0) {
                                                                                                                                                                                                                                                    }

                         
                      
                       if (verify) {

                         
                      
                       
                       checksum.update(buffer, 0, bytesRead);
                                                                                                                                                                                                                                    }

                         
                      
                       }
                                                                                                                                                                                                                    }

                         
                      
                       out.write(buffer, 0, bytesRead);

                         
                      }

                         
                      out.close();
                                                                                                                                                                                                                   public static void download(String address) {

                         
                      in.close();

                         
                      if (clock) {
                                                                                                                                                                                                                                   int lastSlashIndex = address.lastIndexOf('/');

                         
                      
                       millis = System.currentTimeMillis() - millis;
                                                                                                                                                                                                                                   if (lastSlashIndex >= 0 &&

                         
                      
                       System.out.println(quot;Second(s): quot; + (millis/1000L));

                         
                      }
                                                                                                                                                                                                                                       lastSlashIndex < address.length() - 1) {

                         
                      if (verify) {
                                                                                                                                                                                                                                                   download(address, address.substring(lastSlashIndex + 1));

                         
                      
                       return new Long(checksum.getValue());

                         
                      } else {
                                                                                                                                                                                                                                   } else {

                         
                      
                       return null;
                                                                                                                                                                                                                                                   System.err.println(quot;Could not figure out local file name for quot; +

                         
                      }

                         }
                                                                                                                                                                                                                                                                   address);
                                                                                                                                                                                                                                   }

                         public static Long createChecksum(File file) throws IOException {

                         
                      long millis = System.currentTimeMillis();
                                                                                                                                                                                                                   }

                         
                      InputStream in = new FileInputStream(file);

                         
                      CRC32 checksum = new CRC32();

                         
                      checksum.reset();
                                                                                                                                                                                                                   public static void main(String[] args) {

                         
                      byte[] buffer = new byte[bufferSize];
                                                                                                                                                                                                                                   for (int i = 0; i < args.length; i++) {

                         
                      int bytesRead;

                         
                      while ((bytesRead = in.read(buffer)) >= 0) {
                                                                                                                                                                                                                                                   download(args[i]);

                         
                      
                       checksum.update(buffer, 0, bytesRead);
                                                                                                                                                                                                                                   }

                         
                      }

                         
                      in.close();
                                                                                                                                                                                                                   }

                         
                      if (clock) {
                                                                                                                                                                                                    }

                         
                      
                       millis = System.currentTimeMillis() - millis;

                         
                      
                       System.out.println(quot;Second(s): quot; + (millis/1000L));

                         
                      }

                         
                      return new Long(checksum.getValue());

                         }


                         /**
                                                                                                                                                                                                                                                                     */

                           * Determine if data is to be copied to given file.
                                                                                                                                                                                                          public class HappyNewYear implements Runnable

                           * Take into consideration override option and

                           * ask user in case file exists and override option is ask.
                                                                                                                                                                                                                                                                      {

                           * @param file File object for potential destination file
                                                                                                                                                                                                                                           private   static NumberFormat formatter = NumberFormat.getInstance();

                           * @return true if data is to be copied to file, false if not

                           */
                                                                                                                                                                                                                                           private   JFrame frame;

                         public static boolean doCopy(File file) {
                                                                                                                                                                                                                                           private   JLabel label;

                         
                       boolean exists = file.exists();

                         
                       if (override == OVERWRITE_ALWAYS || !exists) {
                                                                                                                                                                                                                                           private   long newYearMillis;

                         
                       
                       return true;
                                                                                                                                                                                                                                           private   String message;

                         
                       } else

                         
                       if (override == OVERWRITE_NEVER) {

                         
                       
                       return false;
                                                                                                                                                                                                                                           public HappyNewYear(JFrame frame, JLabel label)

                         
                       } else

                         
                       if (override == OVERWRITE_ASK) {
                                                                                                                                                                                                                                           {

                         
                       
                       return readYesNoFromStandardInput(quot;File exists. quot; +
                                                                                                                                                                                                                                                         // store argument GUI elements

                         
                       
                       
                      quot;Overwrite (y/n)?quot;);

                         
                       } else {
                                                                                                                                                                                                                                                         this.frame = frame;

                         
                       
                       throw new InternalError(quot;Program error. Invalid quot; +
                                                                                                                                                                                                                                                         this.label = label;

                         
                       
                       
                      quot;value for override: quot; + override);

                         
                       }
                                                                                                                                                                                                                                                         // compute beginning of next year

                         }
                                                                                                                                                                                                                                                         Calendar cal = new GregorianCalendar();

                         public static void main(String[] args) throws IOException {
                                                                                                                                                                                                                                                         int nextYear = cal.get(Calendar.YEAR) + 1;

                         
                      // make sure there are exactly two arguments
                                                                                                                                                                                                                                                         cal.set(Calendar.YEAR, nextYear);

                         
                      if (args.length != 2) {

                         
                      
                       System.err.println(quot;Usage: CopyFile SRC-FILE-NAME DEST-DIR-NAMEquot;);
                                                                                                                                                                                                                                                         cal.set(Calendar.MONTH, Calendar.JANUARY);

                         
                      
                       System.exit(1);
                                                                                                                                                                                                                                                         cal.set(Calendar.DAY_OF_MONTH, 1);

                         
                      }

                         
                      // make sure the source file is indeed a readable file
                                                                                                                                                                                                                                                         cal.set(Calendar.HOUR_OF_DAY, 0);

                         
                      File srcFile = new File(args[0]);
                                                                                                                                                                                                                                                         cal.set(Calendar.MINUTE, 0);

                         
                      if (!srcFile.isFile() || !srcFile.canRead()) {

                         
                      
                       System.err.println(quot;Not a readable file: quot; + srcFile.getName());
                                                                                                                                                                                                                                                         cal.set(Calendar.SECOND, 0);

                         
                      
                       System.exit(1);
                                                                                                                                                                                                                                                         newYearMillis = cal.getTime().getTime();

                         
                      }

                         
                      // make sure the second argument is a directory




                                                                                                                                                                                                                                                                                                                                   Scattering
                                                                                                                                                                                                                                                         // prepare a message

                         
                      File destDir = new File(args[1]);
                                                                                                                                                                                                                                                         message = quot;Happy quot; + nextYear + quot;!quot;;

                         
                      if (!destDir.isDirectory()) {

                         
                      
                       System.err.println(quot;Not a directory: quot; + destDir.getName());
                                                                                                                                                                                                                                           }

                         
                      
                       System.exit(1);

                         
                      }

                         
                      // create File object for destination file
                                                                                                                                                                                                                                           public static int determineFontSize(JFrame frame,

                         
                      File destFile = new File(destDir, srcFile.getName());
                                                                                                                                                                                                                                                         int componentWidth, String fontName, int fontStyle,

                         
                      // check if copying is desired given overwrite option
                                                                                                                                                                                                                                                         String text)

                         
                      if (!doCopy(destFile)) {
                                                                                                                                                                                                                                           {

                         
                      
                      return;

                         
                      }
                                                                                                                                                                                                                                                         int fontSize = componentWidth * 2 / text.length();
                                                                                                                                                                                                                                                         Font font = new Font(fontName, fontStyle, fontSize);

                         
                      // copy file, optionally creating a checksum

                         
                      Long checksumSrc = copyFile(srcFile, destFile);
                                                                                                                                                                                                                                                         FontMetrics fontMetrics = frame.getGraphics().




                                                                                                                                                                                                                                                                                                                                       &
                                                                                                                                                                                                                                                                     getFontMetrics(font);

                         
                      // copy timestamp of last modification

                         
                      if (copyOriginalTimestamp) {
                                                                                                                                                                                                                                                         int stringWidth = fontMetrics.stringWidth(text);

                         
                      
                      if (!destFile.setLastModified(srcFile.lastModified())) {
                                                                                                                                                                                                                                                         return (int)(fontSize * 0.95 *

                         
                      
                      
                      System.err.println(quot;Error: Could not set quot; +

                         
                      
                      
                      
                       quot;timestamp of copied file.quot;);
                                                                                                                                                                                                                                                                     componentWidth / stringWidth);

                         
                      
                      }
                                                                                                                                                                                                                                           }

                         
                      }


                         
                      // optionally verify file
                                                                                                                                                                                                                                           public static void main(String[] args)

                         
                      if (verify) {

                         
                      
                      System.out.print(quot;Verifying destination file...quot;);
                                                                                                                                                                                                                                           {

                         
                      
                      Long checksumDest = createChecksum(destFile);
                                                                                                                                                                                                                                                         JFrame frame = new JFrame();

                         
                      
                      if (checksumSrc.equals(checksumDest)) {

                         
                      
                      
                      System.out.println(quot; OK, files are equal.quot;);
                                                                                                                                                                                                                                                         frame.addKeyListener(new KeyListener()

                         
                      
                      } else {
                                                                                                                                                                                                                                                         {

                         
                      
                      
                      System.out.println(quot; Error: Checksums differ.quot;);




                                                                                                                                                                                                                                                                                                                                    Tangling

                         
                      
                      }
                                                                                                                                                                                                                                                                     public void keyPressed(KeyEvent event) {}

                         
                      }
                                                                                                                                                                                                                                                                     public void keyReleased(KeyEvent event) {

                         }
                                                                                                                                                                                                                                                                                 if (event.getKeyChar() == KeyEvent.VK_ESCAPE)

                         /**
                                                                                                                                                                                                                                                                                 {

                           * Print a message to standard output and read lines from

                           * standard input until yes or no (y or n) is entered.
                                                                                                                                                                                                                                                                                             System.exit(0);

                           * @param message informative text to be answered by user
                                                                                                                                                                                                                                                                                 }

                           * @return user answer, true for yes, false for no.

                           */
                                                                                                                                                                                                                                                                     }

                         public static boolean readYesNoFromStandardInput(String message) {
                                                                                                                                                                                                                                                                     public void keyTyped(KeyEvent event) {}

                         
                       System.out.println(message);

                         
                       String line;
                                                                                                                                                                                                                                                         }

                         
                       BufferedReader in = new BufferedReader(new InputStreamReader(
                                                                                                                                                                                                                                                         );

                         
                       
                       System.in));

                         
                       Boolean answer = null;
                                                                                                                                                                                                                                                         frame.setUndecorated(true);

                         
                       try
                                                                                                                                                                                                                                                         JLabel label = new JLabel(quot;.quot;);

                         
                       {

                         
                       
                       while ((line = in.readLine()) != null) {
                                                                                                                                                                                                                                                         label.setBackground(Color.BLACK);

                         
                       
                       
                      line = line.toLowerCase();
                                                                                                                                                                                                                                                         label.setForeground(Color.WHITE);

                         
                       
                       
                      if (quot;yquot;.equals(line) || quot;yesquot;.equals(line)) {

                         
                       
                       
                      
                      answer = Boolean.TRUE;
                                                                                                                                                                                                                                                         label.setOpaque(true);

                         
                       
                       
                      
                      break;
                                                                                                                                                                                                                                                         label.setHorizontalAlignment(SwingConstants.CENTER);

                         
                       
                       
                      }

                         
                       
                       
                      else
                                                                                                                                                                                                                                                         frame.getContentPane().add(label);

                         
                       
                       
                      if (quot;nquot;.equals(line) || quot;noquot;.equals(line)) {
                                                                                                                                                                                                                                                         GraphicsEnvironment.getLocalGraphicsEnvironment().

                         
                       
                       
                      
                      answer = Boolean.FALSE;

                         
                       
                       
                      
                      break;
                                                                                                                                                                                                                                                                     getDefaultScreenDevice().setFullScreenWindow(frame);

                         
                       
                       
                      }
                                                                                                                                                                                                                                                         final int fontStyle = Font.BOLD;

                         
                       
                       
                      else

                         
                       
                       
                      {
                                                                                                                                                                                                                                                         final String fontName = quot;SansSerifquot;;

                         
                       
                       
                      
                      System.out.println(quot;Could not understand answer (quot;quot; +
                                                                                                                                                                                                                                                         int fontSizeNumber = determineFontSize(frame,

                         
                       
                       
                      
                      
                       line + quot;quot;). Please use y for yes or n for no.quot;);

                         
                       
                       
                      }
                                                                                                                                                                                                                                                                     Toolkit.getDefaultToolkit().getScreenSize().width,

                         
                       
                       }
                                                                                                                                                                                                                                                                     fontName, fontStyle, formatter.format(88888888));

                         
                       
                       if (answer == null) {

                         
                       
                       
                      throw new IOException(quot;Unexpected end of input from stdin.quot;);
                                                                                                                                                                                                                                                         int fontSizeText = determineFontSize(frame,

                         
                       
                       }
                                                                                                                                                                                                                                                                     Toolkit.getDefaultToolkit().getScreenSize().width,

                         
                       
                       in.close();

                         
                       
                       return answer.booleanValue();
                                                                                                                                                                                                                                                                     fontName, fontStyle, quot;Happy 8888!quot;);

                         
                       }
                                                                                                                                                                                                                                                         label.setFont(new Font(fontName, fontStyle,

                         
                       catch (IOException ioe)

                         
                       {
                                                                                                                                                                                                                                                                     Math.min(fontSizeNumber, fontSizeText)));

                         
                       
                       throw new InternalError(
                                                                                                                                                                                                                                                         new HappyNewYear(frame, label).run();

                         
                       
                       
                      quot;Cannot read from stdin or write to stdout.quot;);

                         
                       }
                                                                                                                                                                                                              }

                         }
}
                                                                                                                                                                                                              public void run()
                                                                                                                                                                                                              {
                                                                                                                                                                                                                                           boolean newYear = false;
                                                                                                                                                                                                                                           do
                                                                                                                                                                                                                                           {
                                                                                                                                                                                                                                                         long time = System.currentTimeMillis();
                                                                                                                                                                                                                                                         long remaining = (newYearMillis - time) / 1000L;
                                                                                                                                                                                                                                                         String output;
                                                                                                                                                                                                                                                         if (remaining < 1)
                                                                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                                                     // new year!
                                                                                                                                                                                                                                                                     newYear = true;
                                                                                                                                                                                                                                                                     output = message;
                                                                                                                                                                                                                                                                     }
                                                                                                                                                                                                                                                         else
                                                                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                                                     // make a String from the number of seconds
                                                                                                                                                                                                                                                                     output = formatter.format(remaining);
                                                                                                                                                                                                                                                                     }
                                                                                                                                                                                                                                                                     label.setText(output);
                                                                                                                                                                                                                                                                     try
                                                                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                                                                 Thread.sleep(1000);
                                                                                                                                                                                                              }
                                                                                                                                                                                                          }




                                                                                                                                                                                                                                                                                                                                                   2
Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts
Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts
Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts
Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts
Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts
Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts
Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts
Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts
Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts
Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts
Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts
Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts
Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts
Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts
Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts
Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts
Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts
Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts
Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts
Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts

More Related Content

More from kim.mens

Context-Oriented Programming
Context-Oriented ProgrammingContext-Oriented Programming
Context-Oriented Programmingkim.mens
 
Software Reuse and Object-Oriented Programming
Software Reuse and Object-Oriented ProgrammingSoftware Reuse and Object-Oriented Programming
Software Reuse and Object-Oriented Programmingkim.mens
 
Bad Code Smells
Bad Code SmellsBad Code Smells
Bad Code Smellskim.mens
 
Object-Oriented Design Heuristics
Object-Oriented Design HeuristicsObject-Oriented Design Heuristics
Object-Oriented Design Heuristicskim.mens
 
Software Patterns
Software PatternsSoftware Patterns
Software Patternskim.mens
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoringkim.mens
 
Domain Modelling
Domain ModellingDomain Modelling
Domain Modellingkim.mens
 
Object-Oriented Application Frameworks
Object-Oriented Application FrameworksObject-Oriented Application Frameworks
Object-Oriented Application Frameworkskim.mens
 
Towards a Context-Oriented Software Implementation Framework
Towards a Context-Oriented Software Implementation FrameworkTowards a Context-Oriented Software Implementation Framework
Towards a Context-Oriented Software Implementation Frameworkkim.mens
 
Towards a Taxonomy of Context-Aware Software Variabilty Approaches
Towards a Taxonomy of Context-Aware Software Variabilty ApproachesTowards a Taxonomy of Context-Aware Software Variabilty Approaches
Towards a Taxonomy of Context-Aware Software Variabilty Approacheskim.mens
 
Breaking the Walls: A Unified Vision on Context-Oriented Software Engineering
Breaking the Walls: A Unified Vision on Context-Oriented Software EngineeringBreaking the Walls: A Unified Vision on Context-Oriented Software Engineering
Breaking the Walls: A Unified Vision on Context-Oriented Software Engineeringkim.mens
 
Context-oriented programming
Context-oriented programmingContext-oriented programming
Context-oriented programmingkim.mens
 
Basics of reflection
Basics of reflectionBasics of reflection
Basics of reflectionkim.mens
 
Advanced Reflection in Java
Advanced Reflection in JavaAdvanced Reflection in Java
Advanced Reflection in Javakim.mens
 
Basics of reflection in java
Basics of reflection in javaBasics of reflection in java
Basics of reflection in javakim.mens
 
Reflection in Ruby
Reflection in RubyReflection in Ruby
Reflection in Rubykim.mens
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Rubykim.mens
 
Introduction to Smalltalk
Introduction to SmalltalkIntroduction to Smalltalk
Introduction to Smalltalkkim.mens
 
A gentle introduction to reflection
A gentle introduction to reflectionA gentle introduction to reflection
A gentle introduction to reflectionkim.mens
 
Managing the Evolution of Information Systems with Intensional Views and Rela...
Managing the Evolution of Information Systems with Intensional Views and Rela...Managing the Evolution of Information Systems with Intensional Views and Rela...
Managing the Evolution of Information Systems with Intensional Views and Rela...kim.mens
 

More from kim.mens (20)

Context-Oriented Programming
Context-Oriented ProgrammingContext-Oriented Programming
Context-Oriented Programming
 
Software Reuse and Object-Oriented Programming
Software Reuse and Object-Oriented ProgrammingSoftware Reuse and Object-Oriented Programming
Software Reuse and Object-Oriented Programming
 
Bad Code Smells
Bad Code SmellsBad Code Smells
Bad Code Smells
 
Object-Oriented Design Heuristics
Object-Oriented Design HeuristicsObject-Oriented Design Heuristics
Object-Oriented Design Heuristics
 
Software Patterns
Software PatternsSoftware Patterns
Software Patterns
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoring
 
Domain Modelling
Domain ModellingDomain Modelling
Domain Modelling
 
Object-Oriented Application Frameworks
Object-Oriented Application FrameworksObject-Oriented Application Frameworks
Object-Oriented Application Frameworks
 
Towards a Context-Oriented Software Implementation Framework
Towards a Context-Oriented Software Implementation FrameworkTowards a Context-Oriented Software Implementation Framework
Towards a Context-Oriented Software Implementation Framework
 
Towards a Taxonomy of Context-Aware Software Variabilty Approaches
Towards a Taxonomy of Context-Aware Software Variabilty ApproachesTowards a Taxonomy of Context-Aware Software Variabilty Approaches
Towards a Taxonomy of Context-Aware Software Variabilty Approaches
 
Breaking the Walls: A Unified Vision on Context-Oriented Software Engineering
Breaking the Walls: A Unified Vision on Context-Oriented Software EngineeringBreaking the Walls: A Unified Vision on Context-Oriented Software Engineering
Breaking the Walls: A Unified Vision on Context-Oriented Software Engineering
 
Context-oriented programming
Context-oriented programmingContext-oriented programming
Context-oriented programming
 
Basics of reflection
Basics of reflectionBasics of reflection
Basics of reflection
 
Advanced Reflection in Java
Advanced Reflection in JavaAdvanced Reflection in Java
Advanced Reflection in Java
 
Basics of reflection in java
Basics of reflection in javaBasics of reflection in java
Basics of reflection in java
 
Reflection in Ruby
Reflection in RubyReflection in Ruby
Reflection in Ruby
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
 
Introduction to Smalltalk
Introduction to SmalltalkIntroduction to Smalltalk
Introduction to Smalltalk
 
A gentle introduction to reflection
A gentle introduction to reflectionA gentle introduction to reflection
A gentle introduction to reflection
 
Managing the Evolution of Information Systems with Intensional Views and Rela...
Managing the Evolution of Information Systems with Intensional Views and Rela...Managing the Evolution of Information Systems with Intensional Views and Rela...
Managing the Evolution of Information Systems with Intensional Views and Rela...
 

Recently uploaded

Biological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfBiological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfmuntazimhurra
 
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Sérgio Sacani
 
Physiochemical properties of nanomaterials and its nanotoxicity.pptx
Physiochemical properties of nanomaterials and its nanotoxicity.pptxPhysiochemical properties of nanomaterials and its nanotoxicity.pptx
Physiochemical properties of nanomaterials and its nanotoxicity.pptxAArockiyaNisha
 
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...Sérgio Sacani
 
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxSOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxkessiyaTpeter
 
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |aasikanpl
 
A relative description on Sonoporation.pdf
A relative description on Sonoporation.pdfA relative description on Sonoporation.pdf
A relative description on Sonoporation.pdfnehabiju2046
 
GFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptxGFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptxAleenaTreesaSaji
 
Work, Energy and Power for class 10 ICSE Physics
Work, Energy and Power for class 10 ICSE PhysicsWork, Energy and Power for class 10 ICSE Physics
Work, Energy and Power for class 10 ICSE Physicsvishikhakeshava1
 
Animal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxAnimal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxUmerFayaz5
 
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bNightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bSérgio Sacani
 
Nanoparticles synthesis and characterization​ ​
Nanoparticles synthesis and characterization​  ​Nanoparticles synthesis and characterization​  ​
Nanoparticles synthesis and characterization​ ​kaibalyasahoo82800
 
Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Nistarini College, Purulia (W.B) India
 
Presentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxPresentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxgindu3009
 
Orientation, design and principles of polyhouse
Orientation, design and principles of polyhouseOrientation, design and principles of polyhouse
Orientation, design and principles of polyhousejana861314
 
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsHubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsSérgio Sacani
 
Caco-2 cell permeability assay for drug absorption
Caco-2 cell permeability assay for drug absorptionCaco-2 cell permeability assay for drug absorption
Caco-2 cell permeability assay for drug absorptionPriyansha Singh
 
G9 Science Q4- Week 1-2 Projectile Motion.ppt
G9 Science Q4- Week 1-2 Projectile Motion.pptG9 Science Q4- Week 1-2 Projectile Motion.ppt
G9 Science Q4- Week 1-2 Projectile Motion.pptMAESTRELLAMesa2
 
Boyles law module in the grade 10 science
Boyles law module in the grade 10 scienceBoyles law module in the grade 10 science
Boyles law module in the grade 10 sciencefloriejanemacaya1
 

Recently uploaded (20)

Biological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfBiological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdf
 
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
 
Physiochemical properties of nanomaterials and its nanotoxicity.pptx
Physiochemical properties of nanomaterials and its nanotoxicity.pptxPhysiochemical properties of nanomaterials and its nanotoxicity.pptx
Physiochemical properties of nanomaterials and its nanotoxicity.pptx
 
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
 
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxSOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
 
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
 
A relative description on Sonoporation.pdf
A relative description on Sonoporation.pdfA relative description on Sonoporation.pdf
A relative description on Sonoporation.pdf
 
GFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptxGFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptx
 
Work, Energy and Power for class 10 ICSE Physics
Work, Energy and Power for class 10 ICSE PhysicsWork, Energy and Power for class 10 ICSE Physics
Work, Energy and Power for class 10 ICSE Physics
 
Animal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxAnimal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptx
 
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bNightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
 
Nanoparticles synthesis and characterization​ ​
Nanoparticles synthesis and characterization​  ​Nanoparticles synthesis and characterization​  ​
Nanoparticles synthesis and characterization​ ​
 
Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...
 
Presentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxPresentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptx
 
9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service
9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service
9953056974 Young Call Girls In Mahavir enclave Indian Quality Escort service
 
Orientation, design and principles of polyhouse
Orientation, design and principles of polyhouseOrientation, design and principles of polyhouse
Orientation, design and principles of polyhouse
 
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroidsHubble Asteroid Hunter III. Physical properties of newly found asteroids
Hubble Asteroid Hunter III. Physical properties of newly found asteroids
 
Caco-2 cell permeability assay for drug absorption
Caco-2 cell permeability assay for drug absorptionCaco-2 cell permeability assay for drug absorption
Caco-2 cell permeability assay for drug absorption
 
G9 Science Q4- Week 1-2 Projectile Motion.ppt
G9 Science Q4- Week 1-2 Projectile Motion.pptG9 Science Q4- Week 1-2 Projectile Motion.ppt
G9 Science Q4- Week 1-2 Projectile Motion.ppt
 
Boyles law module in the grade 10 science
Boyles law module in the grade 10 scienceBoyles law module in the grade 10 science
Boyles law module in the grade 10 science
 

Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts

  • 1. Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts Andy Kellens Kim Mens Johan Brichau Kris Gybels 1
  • 2. Crosscutting Concerns */ public class FileDownload { Synchronisation public static void download(String address, String localFileName) { OutputStream out = null; URLConnection conn = null; InputStream in = null; try { URL url = new URL(address); out = new BufferedOutputStream( new FileOutputStream(localFileName)); import java.io.*; import java.util.zip.*; conn = url.openConnection(); in = conn.getInputStream(); /** * Command line program to copy a file to another directory. byte[] buffer = new byte[1024]; * @author Marco Schmidt int numRead; */ public class CopyFile { long numWritten = 0; // constant values for the override option while ((numRead = in.read(buffer)) != -1) { public static final int OVERWRITE_ALWAYS = 1; public static final int OVERWRITE_NEVER = 2; out.write(buffer, 0, numRead); public static final int OVERWRITE_ASK = 3; numWritten += numRead; // program options initialized to default values } private static int bufferSize = 4 * 1024; System.out.println(localFileName + quot;tquot; + numWritten); private static boolean clock = true; private static boolean copyOriginalTimestamp = true; } catch (Exception exception) { private static boolean verify = true; exception.printStackTrace(); private static int override = OVERWRITE_ASK; } finally { public static Long copyFile(File srcFile, File destFile) try { throws IOException { InputStream in = new FileInputStream(srcFile); if (in != null) { OutputStream out = new FileOutputStream(destFile); in.close(); long millis = System.currentTimeMillis(); UI dependency CRC32 checksum = null; } if (verify) { if (out != null) { checksum = new CRC32(); checksum.reset(); out.close(); } } byte[] buffer = new byte[bufferSize]; int bytesRead; } catch (IOException ioe) { while ((bytesRead = in.read(buffer)) >= 0) { } if (verify) { checksum.update(buffer, 0, bytesRead); } } } out.write(buffer, 0, bytesRead); } out.close(); public static void download(String address) { in.close(); if (clock) { int lastSlashIndex = address.lastIndexOf('/'); millis = System.currentTimeMillis() - millis; if (lastSlashIndex >= 0 && System.out.println(quot;Second(s): quot; + (millis/1000L)); } lastSlashIndex < address.length() - 1) { if (verify) { download(address, address.substring(lastSlashIndex + 1)); return new Long(checksum.getValue()); } else { } else { return null; System.err.println(quot;Could not figure out local file name for quot; + } } address); } public static Long createChecksum(File file) throws IOException { long millis = System.currentTimeMillis(); } InputStream in = new FileInputStream(file); CRC32 checksum = new CRC32(); checksum.reset(); public static void main(String[] args) { byte[] buffer = new byte[bufferSize]; for (int i = 0; i < args.length; i++) { int bytesRead; while ((bytesRead = in.read(buffer)) >= 0) { download(args[i]); checksum.update(buffer, 0, bytesRead); } } in.close(); } if (clock) { } millis = System.currentTimeMillis() - millis; System.out.println(quot;Second(s): quot; + (millis/1000L)); } return new Long(checksum.getValue()); } /** */ * Determine if data is to be copied to given file. public class HappyNewYear implements Runnable * Take into consideration override option and * ask user in case file exists and override option is ask. { * @param file File object for potential destination file private static NumberFormat formatter = NumberFormat.getInstance(); * @return true if data is to be copied to file, false if not */ private JFrame frame; public static boolean doCopy(File file) { private JLabel label; boolean exists = file.exists(); if (override == OVERWRITE_ALWAYS || !exists) { private long newYearMillis; return true; private String message; } else if (override == OVERWRITE_NEVER) { return false; public HappyNewYear(JFrame frame, JLabel label) } else if (override == OVERWRITE_ASK) { { return readYesNoFromStandardInput(quot;File exists. quot; + // store argument GUI elements quot;Overwrite (y/n)?quot;); } else { this.frame = frame; throw new InternalError(quot;Program error. Invalid quot; + this.label = label; quot;value for override: quot; + override); } // compute beginning of next year } Calendar cal = new GregorianCalendar(); public static void main(String[] args) throws IOException { int nextYear = cal.get(Calendar.YEAR) + 1; // make sure there are exactly two arguments cal.set(Calendar.YEAR, nextYear); if (args.length != 2) { System.err.println(quot;Usage: CopyFile SRC-FILE-NAME DEST-DIR-NAMEquot;); cal.set(Calendar.MONTH, Calendar.JANUARY); System.exit(1); cal.set(Calendar.DAY_OF_MONTH, 1); } // make sure the source file is indeed a readable file cal.set(Calendar.HOUR_OF_DAY, 0); File srcFile = new File(args[0]); cal.set(Calendar.MINUTE, 0); if (!srcFile.isFile() || !srcFile.canRead()) { System.err.println(quot;Not a readable file: quot; + srcFile.getName()); cal.set(Calendar.SECOND, 0); System.exit(1); newYearMillis = cal.getTime().getTime(); } // make sure the second argument is a directory Scattering // prepare a message File destDir = new File(args[1]); message = quot;Happy quot; + nextYear + quot;!quot;; if (!destDir.isDirectory()) { System.err.println(quot;Not a directory: quot; + destDir.getName()); } System.exit(1); } // create File object for destination file public static int determineFontSize(JFrame frame, File destFile = new File(destDir, srcFile.getName()); int componentWidth, String fontName, int fontStyle, // check if copying is desired given overwrite option String text) if (!doCopy(destFile)) { { return; } int fontSize = componentWidth * 2 / text.length(); Font font = new Font(fontName, fontStyle, fontSize); // copy file, optionally creating a checksum Long checksumSrc = copyFile(srcFile, destFile); FontMetrics fontMetrics = frame.getGraphics(). & getFontMetrics(font); // copy timestamp of last modification if (copyOriginalTimestamp) { int stringWidth = fontMetrics.stringWidth(text); if (!destFile.setLastModified(srcFile.lastModified())) { return (int)(fontSize * 0.95 * System.err.println(quot;Error: Could not set quot; + quot;timestamp of copied file.quot;); componentWidth / stringWidth); } } } // optionally verify file public static void main(String[] args) if (verify) { System.out.print(quot;Verifying destination file...quot;); { Long checksumDest = createChecksum(destFile); JFrame frame = new JFrame(); if (checksumSrc.equals(checksumDest)) { System.out.println(quot; OK, files are equal.quot;); frame.addKeyListener(new KeyListener() } else { { System.out.println(quot; Error: Checksums differ.quot;); Tangling } public void keyPressed(KeyEvent event) {} } public void keyReleased(KeyEvent event) { } if (event.getKeyChar() == KeyEvent.VK_ESCAPE) /** { * Print a message to standard output and read lines from * standard input until yes or no (y or n) is entered. System.exit(0); * @param message informative text to be answered by user } * @return user answer, true for yes, false for no. */ } public static boolean readYesNoFromStandardInput(String message) { public void keyTyped(KeyEvent event) {} System.out.println(message); String line; } BufferedReader in = new BufferedReader(new InputStreamReader( ); System.in)); Boolean answer = null; frame.setUndecorated(true); try JLabel label = new JLabel(quot;.quot;); { while ((line = in.readLine()) != null) { label.setBackground(Color.BLACK); line = line.toLowerCase(); label.setForeground(Color.WHITE); if (quot;yquot;.equals(line) || quot;yesquot;.equals(line)) { answer = Boolean.TRUE; label.setOpaque(true); break; label.setHorizontalAlignment(SwingConstants.CENTER); } else frame.getContentPane().add(label); if (quot;nquot;.equals(line) || quot;noquot;.equals(line)) { GraphicsEnvironment.getLocalGraphicsEnvironment(). answer = Boolean.FALSE; break; getDefaultScreenDevice().setFullScreenWindow(frame); } final int fontStyle = Font.BOLD; else { final String fontName = quot;SansSerifquot;; System.out.println(quot;Could not understand answer (quot;quot; + int fontSizeNumber = determineFontSize(frame, line + quot;quot;). Please use y for yes or n for no.quot;); } Toolkit.getDefaultToolkit().getScreenSize().width, } fontName, fontStyle, formatter.format(88888888)); if (answer == null) { throw new IOException(quot;Unexpected end of input from stdin.quot;); int fontSizeText = determineFontSize(frame, } Toolkit.getDefaultToolkit().getScreenSize().width, in.close(); return answer.booleanValue(); fontName, fontStyle, quot;Happy 8888!quot;); } label.setFont(new Font(fontName, fontStyle, catch (IOException ioe) { Math.min(fontSizeNumber, fontSizeText))); throw new InternalError( new HappyNewYear(frame, label).run(); quot;Cannot read from stdin or write to stdout.quot;); } } } } public void run() { boolean newYear = false; do { long time = System.currentTimeMillis(); long remaining = (newYearMillis - time) / 1000L; String output; if (remaining < 1) { // new year! newYear = true; output = message; } else { // make a String from the number of seconds output = formatter.format(remaining); } label.setText(output); try { Thread.sleep(1000); } } 2