SlideShare ist ein Scribd-Unternehmen logo
1 von 59
Downloaden Sie, um offline zu lesen
Application-Specific Models
and Pointcuts using a Logic
Meta Language
Andy Kellens Kim MensJohan Brichau Kris Gybels
Robert Hirschfeld Theo D’Hondt
Crosscutting Concerns
import java.io.*;
import java.util.zip.*;
/**
* Command line program to copy a file to another directory.
* @author Marco Schmidt
*/
public class CopyFile {
	

 // constant values for the override option
	

 public static final int OVERWRITE_ALWAYS = 1;
	

 public static final int OVERWRITE_NEVER = 2;
	

 public static final int OVERWRITE_ASK = 3;
	

 // program options initialized to default values
	

 private static int bufferSize = 4 * 1024;
	

 private static boolean clock = true;
	

 private static boolean copyOriginalTimestamp = true;
	

 private static boolean verify = true;
	

 private static int override = OVERWRITE_ASK;
	

 public static Long copyFile(File srcFile, File destFile)
	

 	

 throws IOException {
	

 	

 InputStream in = new FileInputStream(srcFile);
	

 	

 OutputStream out = new FileOutputStream(destFile);
	

 	

 long millis = System.currentTimeMillis();
	

 	

 CRC32 checksum = null;
	

 	

 if (verify) {
	

 	

 	

 checksum = new CRC32();
	

 	

 	

 checksum.reset();
	

 	

 }
	

 	

 byte[] buffer = new byte[bufferSize];
	

 	

 int bytesRead;
	

 	

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

 	

 	

 if (verify) {
	

 	

 	

 	

 checksum.update(buffer, 0, bytesRead);
	

 	

 	

 }
	

 	

 	

 out.write(buffer, 0, bytesRead);
	

 	

 }
	

 	

 out.close();
	

 	

 in.close();
	

 	

 if (clock) {
	

 	

 	

 millis = System.currentTimeMillis() - millis;
	

 	

 	

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

 	

 }
	

 	

 if (verify) {
	

 	

 	

 return new Long(checksum.getValue());
	

 	

 } else {
	

 	

 	

 return null;
	

 	

 }
	

 }
	

 public static Long createChecksum(File file) throws IOException {
	

 	

 long millis = System.currentTimeMillis();
	

 	

 InputStream in = new FileInputStream(file);
	

 	

 CRC32 checksum = new CRC32();
	

 	

 checksum.reset();
	

 	

 byte[] buffer = new byte[bufferSize];
	

 	

 int bytesRead;
	

 	

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

 	

 	

 checksum.update(buffer, 0, bytesRead);
	

 	

 }
	

 	

 in.close();
	

 	

 if (clock) {
	

 	

 	

 millis = System.currentTimeMillis() - millis;
	

 	

 	

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

 	

 }
	

 	

 return new Long(checksum.getValue());
	

 }
	

 /**
	

 * Determine if data is to be copied to given file.
	

 * 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
	

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

 */
	

 public static boolean doCopy(File file) {
	

 	

 boolean exists = file.exists();
	

 	

 if (override == OVERWRITE_ALWAYS || !exists) {
	

 	

 	

 return true;
	

 	

 } else
	

 	

 if (override == OVERWRITE_NEVER) {
	

 	

 	

 return false;
	

 	

 } else
	

 	

 if (override == OVERWRITE_ASK) {
	

 	

 	

 return readYesNoFromStandardInput("File exists. " +
	

 	

 	

 	

 "Overwrite (y/n)?");
	

 	

 } else {
	

 	

 	

 throw new InternalError("Program error. Invalid " +
	

 	

 	

 	

 "value for override: " + override);
	

 	

 }
	

 }
	

 public static void main(String[] args) throws IOException {
	

 	

 // make sure there are exactly two arguments
	

 	

 if (args.length != 2) {
	

 	

 	

 System.err.println("Usage: CopyFile SRC-FILE-NAME DEST-DIR-NAME");
	

 	

 	

 System.exit(1);
	

 	

 }
	

 	

 // make sure the source file is indeed a readable file
	

 	

 File srcFile = new File(args[0]);
	

 	

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

 	

 	

 System.err.println("Not a readable file: " + srcFile.getName());
	

 	

 	

 System.exit(1);
	

 	

 }
	

 	

 // make sure the second argument is a directory
	

 	

 File destDir = new File(args[1]);
	

 	

 if (!destDir.isDirectory()) {
	

 	

 	

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

 	

 	

 System.exit(1);
	

 	

 }
	

 	

 // create File object for destination file
	

 	

 File destFile = new File(destDir, srcFile.getName());
	

 	

 // check if copying is desired given overwrite option
	

 	

 if (!doCopy(destFile)) {
	

 	

 	

 return;
	

 	

 }
	

 	

 // copy file, optionally creating a checksum
	

 	

 Long checksumSrc = copyFile(srcFile, destFile);
	

 	

 // copy timestamp of last modification
	

 	

 if (copyOriginalTimestamp) {
	

 	

 	

 if (!destFile.setLastModified(srcFile.lastModified())) {
	

 	

 	

 	

 System.err.println("Error: Could not set " +
	

 	

 	

 	

 	

 "timestamp of copied file.");
	

 	

 	

 }
	

 	

 }
	

 	

 // optionally verify file
	

 	

 if (verify) {
	

 	

 	

 System.out.print("Verifying destination file...");
	

 	

 	

 Long checksumDest = createChecksum(destFile);
	

 	

 	

 if (checksumSrc.equals(checksumDest)) {
	

 	

 	

 	

 System.out.println(" OK, files are equal.");
	

 	

 	

 } else {
	

 	

 	

 	

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

 	

 	

 }
	

 	

 }
	

 }
	

 /**
	

 * Print a message to standard output and read lines from
	

 * standard input until yes or no (y or n) is entered.
	

 * @param message informative text to be answered by user
	

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

 */
	

 public static boolean readYesNoFromStandardInput(String message) {
	

 	

 System.out.println(message);
	

 	

 String line;
	

 	

 BufferedReader in = new BufferedReader(new InputStreamReader(
	

 	

 	

 System.in));
	

 	

 Boolean answer = null;
	

 	

 try
	

 	

 {
	

 	

 	

 while ((line = in.readLine()) != null) {
	

 	

 	

 	

 line = line.toLowerCase();
	

 	

 	

 	

 if ("y".equals(line) || "yes".equals(line)) {
	

 	

 	

 	

 	

 answer = Boolean.TRUE;
	

 	

 	

 	

 	

 break;
	

 	

 	

 	

 }
	

 	

 	

 	

 else
	

 	

 	

 	

 if ("n".equals(line) || "no".equals(line)) {
	

 	

 	

 	

 	

 answer = Boolean.FALSE;
	

 	

 	

 	

 	

 break;
	

 	

 	

 	

 }
	

 	

 	

 	

 else
	

 	

 	

 	

 {
	

 	

 	

 	

 	

 System.out.println("Could not understand answer ("" +
	

 	

 	

 	

 	

 	

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

 	

 	

 	

 }
	

 	

 	

 }
	

 	

 	

 if (answer == null) {
	

 	

 	

 	

 throw new IOException("Unexpected end of input from stdin.");
	

 	

 	

 }
	

 	

 	

 in.close();
	

 	

 	

 return answer.booleanValue();
	

 	

 }
	

 	

 catch (IOException ioe)
	

 	

 {
	

 	

 	

 throw new InternalError(
	

 	

 	

 	

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

 	

 }
	

 }
}
*/
public class FileDownload {
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));
conn = url.openConnection();
in = conn.getInputStream();
byte[] buffer = new byte[1024];
int numRead;
long numWritten = 0;
while ((numRead = in.read(buffer)) != -1) {
out.write(buffer, 0, numRead);
numWritten += numRead;
}
System.out.println(localFileName + "t" + numWritten);
} catch (Exception exception) {
exception.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
} catch (IOException ioe) {
}
}
}
public static void download(String address) {
int lastSlashIndex = address.lastIndexOf('/');
if (lastSlashIndex >= 0 &&
lastSlashIndex < address.length() - 1) {
download(address, address.substring(lastSlashIndex + 1));
} else {
System.err.println("Could not figure out local file name for " +
address);
}
}
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
download(args[i]);
}
}
}
*/
public class HappyNewYear implements Runnable
{
private static NumberFormat formatter = NumberFormat.getInstance();
private JFrame frame;
private JLabel label;
private long newYearMillis;
private String message;
public HappyNewYear(JFrame frame, JLabel label)
{
// store argument GUI elements
this.frame = frame;
this.label = label;
// compute beginning of next year
Calendar cal = new GregorianCalendar();
int nextYear = cal.get(Calendar.YEAR) + 1;
cal.set(Calendar.YEAR, nextYear);
cal.set(Calendar.MONTH, Calendar.JANUARY);
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
newYearMillis = cal.getTime().getTime();
// prepare a message
message = "Happy " + nextYear + "!";
}
public static int determineFontSize(JFrame frame,
int componentWidth, String fontName, int fontStyle,
String text)
{
int fontSize = componentWidth * 2 / text.length();
Font font = new Font(fontName, fontStyle, fontSize);
FontMetrics fontMetrics = frame.getGraphics().
getFontMetrics(font);
int stringWidth = fontMetrics.stringWidth(text);
return (int)(fontSize * 0.95 *
componentWidth / stringWidth);
}
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.addKeyListener(new KeyListener()
{
public void keyPressed(KeyEvent event) {}
public void keyReleased(KeyEvent event) {
if (event.getKeyChar() == KeyEvent.VK_ESCAPE)
{
System.exit(0);
}
}
public void keyTyped(KeyEvent event) {}
}
);
frame.setUndecorated(true);
JLabel label = new JLabel(".");
label.setBackground(Color.BLACK);
label.setForeground(Color.WHITE);
label.setOpaque(true);
label.setHorizontalAlignment(SwingConstants.CENTER);
frame.getContentPane().add(label);
GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().setFullScreenWindow(frame);
final int fontStyle = Font.BOLD;
final String fontName = "SansSerif";
int fontSizeNumber = determineFontSize(frame,
Toolkit.getDefaultToolkit().getScreenSize().width,
fontName, fontStyle, formatter.format(88888888));
int fontSizeText = determineFontSize(frame,
Toolkit.getDefaultToolkit().getScreenSize().width,
fontName, fontStyle, "Happy 8888!");
label.setFont(new Font(fontName, fontStyle,
Math.min(fontSizeNumber, fontSizeText)));
new HappyNewYear(frame, label).run();
}
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
Crosscutting Concerns
import java.io.*;
import java.util.zip.*;
/**
* Command line program to copy a file to another directory.
* @author Marco Schmidt
*/
public class CopyFile {
	

 // constant values for the override option
	

 public static final int OVERWRITE_ALWAYS = 1;
	

 public static final int OVERWRITE_NEVER = 2;
	

 public static final int OVERWRITE_ASK = 3;
	

 // program options initialized to default values
	

 private static int bufferSize = 4 * 1024;
	

 private static boolean clock = true;
	

 private static boolean copyOriginalTimestamp = true;
	

 private static boolean verify = true;
	

 private static int override = OVERWRITE_ASK;
	

 public static Long copyFile(File srcFile, File destFile)
	

 	

 throws IOException {
	

 	

 InputStream in = new FileInputStream(srcFile);
	

 	

 OutputStream out = new FileOutputStream(destFile);
	

 	

 long millis = System.currentTimeMillis();
	

 	

 CRC32 checksum = null;
	

 	

 if (verify) {
	

 	

 	

 checksum = new CRC32();
	

 	

 	

 checksum.reset();
	

 	

 }
	

 	

 byte[] buffer = new byte[bufferSize];
	

 	

 int bytesRead;
	

 	

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

 	

 	

 if (verify) {
	

 	

 	

 	

 checksum.update(buffer, 0, bytesRead);
	

 	

 	

 }
	

 	

 	

 out.write(buffer, 0, bytesRead);
	

 	

 }
	

 	

 out.close();
	

 	

 in.close();
	

 	

 if (clock) {
	

 	

 	

 millis = System.currentTimeMillis() - millis;
	

 	

 	

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

 	

 }
	

 	

 if (verify) {
	

 	

 	

 return new Long(checksum.getValue());
	

 	

 } else {
	

 	

 	

 return null;
	

 	

 }
	

 }
	

 public static Long createChecksum(File file) throws IOException {
	

 	

 long millis = System.currentTimeMillis();
	

 	

 InputStream in = new FileInputStream(file);
	

 	

 CRC32 checksum = new CRC32();
	

 	

 checksum.reset();
	

 	

 byte[] buffer = new byte[bufferSize];
	

 	

 int bytesRead;
	

 	

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

 	

 	

 checksum.update(buffer, 0, bytesRead);
	

 	

 }
	

 	

 in.close();
	

 	

 if (clock) {
	

 	

 	

 millis = System.currentTimeMillis() - millis;
	

 	

 	

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

 	

 }
	

 	

 return new Long(checksum.getValue());
	

 }
	

 /**
	

 * Determine if data is to be copied to given file.
	

 * 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
	

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

 */
	

 public static boolean doCopy(File file) {
	

 	

 boolean exists = file.exists();
	

 	

 if (override == OVERWRITE_ALWAYS || !exists) {
	

 	

 	

 return true;
	

 	

 } else
	

 	

 if (override == OVERWRITE_NEVER) {
	

 	

 	

 return false;
	

 	

 } else
	

 	

 if (override == OVERWRITE_ASK) {
	

 	

 	

 return readYesNoFromStandardInput("File exists. " +
	

 	

 	

 	

 "Overwrite (y/n)?");
	

 	

 } else {
	

 	

 	

 throw new InternalError("Program error. Invalid " +
	

 	

 	

 	

 "value for override: " + override);
	

 	

 }
	

 }
	

 public static void main(String[] args) throws IOException {
	

 	

 // make sure there are exactly two arguments
	

 	

 if (args.length != 2) {
	

 	

 	

 System.err.println("Usage: CopyFile SRC-FILE-NAME DEST-DIR-NAME");
	

 	

 	

 System.exit(1);
	

 	

 }
	

 	

 // make sure the source file is indeed a readable file
	

 	

 File srcFile = new File(args[0]);
	

 	

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

 	

 	

 System.err.println("Not a readable file: " + srcFile.getName());
	

 	

 	

 System.exit(1);
	

 	

 }
	

 	

 // make sure the second argument is a directory
	

 	

 File destDir = new File(args[1]);
	

 	

 if (!destDir.isDirectory()) {
	

 	

 	

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

 	

 	

 System.exit(1);
	

 	

 }
	

 	

 // create File object for destination file
	

 	

 File destFile = new File(destDir, srcFile.getName());
	

 	

 // check if copying is desired given overwrite option
	

 	

 if (!doCopy(destFile)) {
	

 	

 	

 return;
	

 	

 }
	

 	

 // copy file, optionally creating a checksum
	

 	

 Long checksumSrc = copyFile(srcFile, destFile);
	

 	

 // copy timestamp of last modification
	

 	

 if (copyOriginalTimestamp) {
	

 	

 	

 if (!destFile.setLastModified(srcFile.lastModified())) {
	

 	

 	

 	

 System.err.println("Error: Could not set " +
	

 	

 	

 	

 	

 "timestamp of copied file.");
	

 	

 	

 }
	

 	

 }
	

 	

 // optionally verify file
	

 	

 if (verify) {
	

 	

 	

 System.out.print("Verifying destination file...");
	

 	

 	

 Long checksumDest = createChecksum(destFile);
	

 	

 	

 if (checksumSrc.equals(checksumDest)) {
	

 	

 	

 	

 System.out.println(" OK, files are equal.");
	

 	

 	

 } else {
	

 	

 	

 	

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

 	

 	

 }
	

 	

 }
	

 }
	

 /**
	

 * Print a message to standard output and read lines from
	

 * standard input until yes or no (y or n) is entered.
	

 * @param message informative text to be answered by user
	

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

 */
	

 public static boolean readYesNoFromStandardInput(String message) {
	

 	

 System.out.println(message);
	

 	

 String line;
	

 	

 BufferedReader in = new BufferedReader(new InputStreamReader(
	

 	

 	

 System.in));
	

 	

 Boolean answer = null;
	

 	

 try
	

 	

 {
	

 	

 	

 while ((line = in.readLine()) != null) {
	

 	

 	

 	

 line = line.toLowerCase();
	

 	

 	

 	

 if ("y".equals(line) || "yes".equals(line)) {
	

 	

 	

 	

 	

 answer = Boolean.TRUE;
	

 	

 	

 	

 	

 break;
	

 	

 	

 	

 }
	

 	

 	

 	

 else
	

 	

 	

 	

 if ("n".equals(line) || "no".equals(line)) {
	

 	

 	

 	

 	

 answer = Boolean.FALSE;
	

 	

 	

 	

 	

 break;
	

 	

 	

 	

 }
	

 	

 	

 	

 else
	

 	

 	

 	

 {
	

 	

 	

 	

 	

 System.out.println("Could not understand answer ("" +
	

 	

 	

 	

 	

 	

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

 	

 	

 	

 }
	

 	

 	

 }
	

 	

 	

 if (answer == null) {
	

 	

 	

 	

 throw new IOException("Unexpected end of input from stdin.");
	

 	

 	

 }
	

 	

 	

 in.close();
	

 	

 	

 return answer.booleanValue();
	

 	

 }
	

 	

 catch (IOException ioe)
	

 	

 {
	

 	

 	

 throw new InternalError(
	

 	

 	

 	

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

 	

 }
	

 }
}
*/
public class FileDownload {
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));
conn = url.openConnection();
in = conn.getInputStream();
byte[] buffer = new byte[1024];
int numRead;
long numWritten = 0;
while ((numRead = in.read(buffer)) != -1) {
out.write(buffer, 0, numRead);
numWritten += numRead;
}
System.out.println(localFileName + "t" + numWritten);
} catch (Exception exception) {
exception.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
} catch (IOException ioe) {
}
}
}
public static void download(String address) {
int lastSlashIndex = address.lastIndexOf('/');
if (lastSlashIndex >= 0 &&
lastSlashIndex < address.length() - 1) {
download(address, address.substring(lastSlashIndex + 1));
} else {
System.err.println("Could not figure out local file name for " +
address);
}
}
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
download(args[i]);
}
}
}
*/
public class HappyNewYear implements Runnable
{
private static NumberFormat formatter = NumberFormat.getInstance();
private JFrame frame;
private JLabel label;
private long newYearMillis;
private String message;
public HappyNewYear(JFrame frame, JLabel label)
{
// store argument GUI elements
this.frame = frame;
this.label = label;
// compute beginning of next year
Calendar cal = new GregorianCalendar();
int nextYear = cal.get(Calendar.YEAR) + 1;
cal.set(Calendar.YEAR, nextYear);
cal.set(Calendar.MONTH, Calendar.JANUARY);
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
newYearMillis = cal.getTime().getTime();
// prepare a message
message = "Happy " + nextYear + "!";
}
public static int determineFontSize(JFrame frame,
int componentWidth, String fontName, int fontStyle,
String text)
{
int fontSize = componentWidth * 2 / text.length();
Font font = new Font(fontName, fontStyle, fontSize);
FontMetrics fontMetrics = frame.getGraphics().
getFontMetrics(font);
int stringWidth = fontMetrics.stringWidth(text);
return (int)(fontSize * 0.95 *
componentWidth / stringWidth);
}
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.addKeyListener(new KeyListener()
{
public void keyPressed(KeyEvent event) {}
public void keyReleased(KeyEvent event) {
if (event.getKeyChar() == KeyEvent.VK_ESCAPE)
{
System.exit(0);
}
}
public void keyTyped(KeyEvent event) {}
}
);
frame.setUndecorated(true);
JLabel label = new JLabel(".");
label.setBackground(Color.BLACK);
label.setForeground(Color.WHITE);
label.setOpaque(true);
label.setHorizontalAlignment(SwingConstants.CENTER);
frame.getContentPane().add(label);
GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().setFullScreenWindow(frame);
final int fontStyle = Font.BOLD;
final String fontName = "SansSerif";
int fontSizeNumber = determineFontSize(frame,
Toolkit.getDefaultToolkit().getScreenSize().width,
fontName, fontStyle, formatter.format(88888888));
int fontSizeText = determineFontSize(frame,
Toolkit.getDefaultToolkit().getScreenSize().width,
fontName, fontStyle, "Happy 8888!");
label.setFont(new Font(fontName, fontStyle,
Math.min(fontSizeNumber, fontSizeText)));
new HappyNewYear(frame, label).run();
}
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);
}
}
Synchronization
2
Crosscutting Concerns
import java.io.*;
import java.util.zip.*;
/**
* Command line program to copy a file to another directory.
* @author Marco Schmidt
*/
public class CopyFile {
	

 // constant values for the override option
	

 public static final int OVERWRITE_ALWAYS = 1;
	

 public static final int OVERWRITE_NEVER = 2;
	

 public static final int OVERWRITE_ASK = 3;
	

 // program options initialized to default values
	

 private static int bufferSize = 4 * 1024;
	

 private static boolean clock = true;
	

 private static boolean copyOriginalTimestamp = true;
	

 private static boolean verify = true;
	

 private static int override = OVERWRITE_ASK;
	

 public static Long copyFile(File srcFile, File destFile)
	

 	

 throws IOException {
	

 	

 InputStream in = new FileInputStream(srcFile);
	

 	

 OutputStream out = new FileOutputStream(destFile);
	

 	

 long millis = System.currentTimeMillis();
	

 	

 CRC32 checksum = null;
	

 	

 if (verify) {
	

 	

 	

 checksum = new CRC32();
	

 	

 	

 checksum.reset();
	

 	

 }
	

 	

 byte[] buffer = new byte[bufferSize];
	

 	

 int bytesRead;
	

 	

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

 	

 	

 if (verify) {
	

 	

 	

 	

 checksum.update(buffer, 0, bytesRead);
	

 	

 	

 }
	

 	

 	

 out.write(buffer, 0, bytesRead);
	

 	

 }
	

 	

 out.close();
	

 	

 in.close();
	

 	

 if (clock) {
	

 	

 	

 millis = System.currentTimeMillis() - millis;
	

 	

 	

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

 	

 }
	

 	

 if (verify) {
	

 	

 	

 return new Long(checksum.getValue());
	

 	

 } else {
	

 	

 	

 return null;
	

 	

 }
	

 }
	

 public static Long createChecksum(File file) throws IOException {
	

 	

 long millis = System.currentTimeMillis();
	

 	

 InputStream in = new FileInputStream(file);
	

 	

 CRC32 checksum = new CRC32();
	

 	

 checksum.reset();
	

 	

 byte[] buffer = new byte[bufferSize];
	

 	

 int bytesRead;
	

 	

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

 	

 	

 checksum.update(buffer, 0, bytesRead);
	

 	

 }
	

 	

 in.close();
	

 	

 if (clock) {
	

 	

 	

 millis = System.currentTimeMillis() - millis;
	

 	

 	

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

 	

 }
	

 	

 return new Long(checksum.getValue());
	

 }
	

 /**
	

 * Determine if data is to be copied to given file.
	

 * 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
	

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

 */
	

 public static boolean doCopy(File file) {
	

 	

 boolean exists = file.exists();
	

 	

 if (override == OVERWRITE_ALWAYS || !exists) {
	

 	

 	

 return true;
	

 	

 } else
	

 	

 if (override == OVERWRITE_NEVER) {
	

 	

 	

 return false;
	

 	

 } else
	

 	

 if (override == OVERWRITE_ASK) {
	

 	

 	

 return readYesNoFromStandardInput("File exists. " +
	

 	

 	

 	

 "Overwrite (y/n)?");
	

 	

 } else {
	

 	

 	

 throw new InternalError("Program error. Invalid " +
	

 	

 	

 	

 "value for override: " + override);
	

 	

 }
	

 }
	

 public static void main(String[] args) throws IOException {
	

 	

 // make sure there are exactly two arguments
	

 	

 if (args.length != 2) {
	

 	

 	

 System.err.println("Usage: CopyFile SRC-FILE-NAME DEST-DIR-NAME");
	

 	

 	

 System.exit(1);
	

 	

 }
	

 	

 // make sure the source file is indeed a readable file
	

 	

 File srcFile = new File(args[0]);
	

 	

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

 	

 	

 System.err.println("Not a readable file: " + srcFile.getName());
	

 	

 	

 System.exit(1);
	

 	

 }
	

 	

 // make sure the second argument is a directory
	

 	

 File destDir = new File(args[1]);
	

 	

 if (!destDir.isDirectory()) {
	

 	

 	

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

 	

 	

 System.exit(1);
	

 	

 }
	

 	

 // create File object for destination file
	

 	

 File destFile = new File(destDir, srcFile.getName());
	

 	

 // check if copying is desired given overwrite option
	

 	

 if (!doCopy(destFile)) {
	

 	

 	

 return;
	

 	

 }
	

 	

 // copy file, optionally creating a checksum
	

 	

 Long checksumSrc = copyFile(srcFile, destFile);
	

 	

 // copy timestamp of last modification
	

 	

 if (copyOriginalTimestamp) {
	

 	

 	

 if (!destFile.setLastModified(srcFile.lastModified())) {
	

 	

 	

 	

 System.err.println("Error: Could not set " +
	

 	

 	

 	

 	

 "timestamp of copied file.");
	

 	

 	

 }
	

 	

 }
	

 	

 // optionally verify file
	

 	

 if (verify) {
	

 	

 	

 System.out.print("Verifying destination file...");
	

 	

 	

 Long checksumDest = createChecksum(destFile);
	

 	

 	

 if (checksumSrc.equals(checksumDest)) {
	

 	

 	

 	

 System.out.println(" OK, files are equal.");
	

 	

 	

 } else {
	

 	

 	

 	

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

 	

 	

 }
	

 	

 }
	

 }
	

 /**
	

 * Print a message to standard output and read lines from
	

 * standard input until yes or no (y or n) is entered.
	

 * @param message informative text to be answered by user
	

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

 */
	

 public static boolean readYesNoFromStandardInput(String message) {
	

 	

 System.out.println(message);
	

 	

 String line;
	

 	

 BufferedReader in = new BufferedReader(new InputStreamReader(
	

 	

 	

 System.in));
	

 	

 Boolean answer = null;
	

 	

 try
	

 	

 {
	

 	

 	

 while ((line = in.readLine()) != null) {
	

 	

 	

 	

 line = line.toLowerCase();
	

 	

 	

 	

 if ("y".equals(line) || "yes".equals(line)) {
	

 	

 	

 	

 	

 answer = Boolean.TRUE;
	

 	

 	

 	

 	

 break;
	

 	

 	

 	

 }
	

 	

 	

 	

 else
	

 	

 	

 	

 if ("n".equals(line) || "no".equals(line)) {
	

 	

 	

 	

 	

 answer = Boolean.FALSE;
	

 	

 	

 	

 	

 break;
	

 	

 	

 	

 }
	

 	

 	

 	

 else
	

 	

 	

 	

 {
	

 	

 	

 	

 	

 System.out.println("Could not understand answer ("" +
	

 	

 	

 	

 	

 	

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

 	

 	

 	

 }
	

 	

 	

 }
	

 	

 	

 if (answer == null) {
	

 	

 	

 	

 throw new IOException("Unexpected end of input from stdin.");
	

 	

 	

 }
	

 	

 	

 in.close();
	

 	

 	

 return answer.booleanValue();
	

 	

 }
	

 	

 catch (IOException ioe)
	

 	

 {
	

 	

 	

 throw new InternalError(
	

 	

 	

 	

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

 	

 }
	

 }
}
*/
public class FileDownload {
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));
conn = url.openConnection();
in = conn.getInputStream();
byte[] buffer = new byte[1024];
int numRead;
long numWritten = 0;
while ((numRead = in.read(buffer)) != -1) {
out.write(buffer, 0, numRead);
numWritten += numRead;
}
System.out.println(localFileName + "t" + numWritten);
} catch (Exception exception) {
exception.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
} catch (IOException ioe) {
}
}
}
public static void download(String address) {
int lastSlashIndex = address.lastIndexOf('/');
if (lastSlashIndex >= 0 &&
lastSlashIndex < address.length() - 1) {
download(address, address.substring(lastSlashIndex + 1));
} else {
System.err.println("Could not figure out local file name for " +
address);
}
}
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
download(args[i]);
}
}
}
*/
public class HappyNewYear implements Runnable
{
private static NumberFormat formatter = NumberFormat.getInstance();
private JFrame frame;
private JLabel label;
private long newYearMillis;
private String message;
public HappyNewYear(JFrame frame, JLabel label)
{
// store argument GUI elements
this.frame = frame;
this.label = label;
// compute beginning of next year
Calendar cal = new GregorianCalendar();
int nextYear = cal.get(Calendar.YEAR) + 1;
cal.set(Calendar.YEAR, nextYear);
cal.set(Calendar.MONTH, Calendar.JANUARY);
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
newYearMillis = cal.getTime().getTime();
// prepare a message
message = "Happy " + nextYear + "!";
}
public static int determineFontSize(JFrame frame,
int componentWidth, String fontName, int fontStyle,
String text)
{
int fontSize = componentWidth * 2 / text.length();
Font font = new Font(fontName, fontStyle, fontSize);
FontMetrics fontMetrics = frame.getGraphics().
getFontMetrics(font);
int stringWidth = fontMetrics.stringWidth(text);
return (int)(fontSize * 0.95 *
componentWidth / stringWidth);
}
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.addKeyListener(new KeyListener()
{
public void keyPressed(KeyEvent event) {}
public void keyReleased(KeyEvent event) {
if (event.getKeyChar() == KeyEvent.VK_ESCAPE)
{
System.exit(0);
}
}
public void keyTyped(KeyEvent event) {}
}
);
frame.setUndecorated(true);
JLabel label = new JLabel(".");
label.setBackground(Color.BLACK);
label.setForeground(Color.WHITE);
label.setOpaque(true);
label.setHorizontalAlignment(SwingConstants.CENTER);
frame.getContentPane().add(label);
GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().setFullScreenWindow(frame);
final int fontStyle = Font.BOLD;
final String fontName = "SansSerif";
int fontSizeNumber = determineFontSize(frame,
Toolkit.getDefaultToolkit().getScreenSize().width,
fontName, fontStyle, formatter.format(88888888));
int fontSizeText = determineFontSize(frame,
Toolkit.getDefaultToolkit().getScreenSize().width,
fontName, fontStyle, "Happy 8888!");
label.setFont(new Font(fontName, fontStyle,
Math.min(fontSizeNumber, fontSizeText)));
new HappyNewYear(frame, label).run();
}
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);
}
}
Synchronization
UI dependency
2
Crosscutting Concerns
import java.io.*;
import java.util.zip.*;
/**
* Command line program to copy a file to another directory.
* @author Marco Schmidt
*/
public class CopyFile {
	

 // constant values for the override option
	

 public static final int OVERWRITE_ALWAYS = 1;
	

 public static final int OVERWRITE_NEVER = 2;
	

 public static final int OVERWRITE_ASK = 3;
	

 // program options initialized to default values
	

 private static int bufferSize = 4 * 1024;
	

 private static boolean clock = true;
	

 private static boolean copyOriginalTimestamp = true;
	

 private static boolean verify = true;
	

 private static int override = OVERWRITE_ASK;
	

 public static Long copyFile(File srcFile, File destFile)
	

 	

 throws IOException {
	

 	

 InputStream in = new FileInputStream(srcFile);
	

 	

 OutputStream out = new FileOutputStream(destFile);
	

 	

 long millis = System.currentTimeMillis();
	

 	

 CRC32 checksum = null;
	

 	

 if (verify) {
	

 	

 	

 checksum = new CRC32();
	

 	

 	

 checksum.reset();
	

 	

 }
	

 	

 byte[] buffer = new byte[bufferSize];
	

 	

 int bytesRead;
	

 	

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

 	

 	

 if (verify) {
	

 	

 	

 	

 checksum.update(buffer, 0, bytesRead);
	

 	

 	

 }
	

 	

 	

 out.write(buffer, 0, bytesRead);
	

 	

 }
	

 	

 out.close();
	

 	

 in.close();
	

 	

 if (clock) {
	

 	

 	

 millis = System.currentTimeMillis() - millis;
	

 	

 	

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

 	

 }
	

 	

 if (verify) {
	

 	

 	

 return new Long(checksum.getValue());
	

 	

 } else {
	

 	

 	

 return null;
	

 	

 }
	

 }
	

 public static Long createChecksum(File file) throws IOException {
	

 	

 long millis = System.currentTimeMillis();
	

 	

 InputStream in = new FileInputStream(file);
	

 	

 CRC32 checksum = new CRC32();
	

 	

 checksum.reset();
	

 	

 byte[] buffer = new byte[bufferSize];
	

 	

 int bytesRead;
	

 	

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

 	

 	

 checksum.update(buffer, 0, bytesRead);
	

 	

 }
	

 	

 in.close();
	

 	

 if (clock) {
	

 	

 	

 millis = System.currentTimeMillis() - millis;
	

 	

 	

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

 	

 }
	

 	

 return new Long(checksum.getValue());
	

 }
	

 /**
	

 * Determine if data is to be copied to given file.
	

 * 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
	

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

 */
	

 public static boolean doCopy(File file) {
	

 	

 boolean exists = file.exists();
	

 	

 if (override == OVERWRITE_ALWAYS || !exists) {
	

 	

 	

 return true;
	

 	

 } else
	

 	

 if (override == OVERWRITE_NEVER) {
	

 	

 	

 return false;
	

 	

 } else
	

 	

 if (override == OVERWRITE_ASK) {
	

 	

 	

 return readYesNoFromStandardInput("File exists. " +
	

 	

 	

 	

 "Overwrite (y/n)?");
	

 	

 } else {
	

 	

 	

 throw new InternalError("Program error. Invalid " +
	

 	

 	

 	

 "value for override: " + override);
	

 	

 }
	

 }
	

 public static void main(String[] args) throws IOException {
	

 	

 // make sure there are exactly two arguments
	

 	

 if (args.length != 2) {
	

 	

 	

 System.err.println("Usage: CopyFile SRC-FILE-NAME DEST-DIR-NAME");
	

 	

 	

 System.exit(1);
	

 	

 }
	

 	

 // make sure the source file is indeed a readable file
	

 	

 File srcFile = new File(args[0]);
	

 	

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

 	

 	

 System.err.println("Not a readable file: " + srcFile.getName());
	

 	

 	

 System.exit(1);
	

 	

 }
	

 	

 // make sure the second argument is a directory
	

 	

 File destDir = new File(args[1]);
	

 	

 if (!destDir.isDirectory()) {
	

 	

 	

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

 	

 	

 System.exit(1);
	

 	

 }
	

 	

 // create File object for destination file
	

 	

 File destFile = new File(destDir, srcFile.getName());
	

 	

 // check if copying is desired given overwrite option
	

 	

 if (!doCopy(destFile)) {
	

 	

 	

 return;
	

 	

 }
	

 	

 // copy file, optionally creating a checksum
	

 	

 Long checksumSrc = copyFile(srcFile, destFile);
	

 	

 // copy timestamp of last modification
	

 	

 if (copyOriginalTimestamp) {
	

 	

 	

 if (!destFile.setLastModified(srcFile.lastModified())) {
	

 	

 	

 	

 System.err.println("Error: Could not set " +
	

 	

 	

 	

 	

 "timestamp of copied file.");
	

 	

 	

 }
	

 	

 }
	

 	

 // optionally verify file
	

 	

 if (verify) {
	

 	

 	

 System.out.print("Verifying destination file...");
	

 	

 	

 Long checksumDest = createChecksum(destFile);
	

 	

 	

 if (checksumSrc.equals(checksumDest)) {
	

 	

 	

 	

 System.out.println(" OK, files are equal.");
	

 	

 	

 } else {
	

 	

 	

 	

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

 	

 	

 }
	

 	

 }
	

 }
	

 /**
	

 * Print a message to standard output and read lines from
	

 * standard input until yes or no (y or n) is entered.
	

 * @param message informative text to be answered by user
	

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

 */
	

 public static boolean readYesNoFromStandardInput(String message) {
	

 	

 System.out.println(message);
	

 	

 String line;
	

 	

 BufferedReader in = new BufferedReader(new InputStreamReader(
	

 	

 	

 System.in));
	

 	

 Boolean answer = null;
	

 	

 try
	

 	

 {
	

 	

 	

 while ((line = in.readLine()) != null) {
	

 	

 	

 	

 line = line.toLowerCase();
	

 	

 	

 	

 if ("y".equals(line) || "yes".equals(line)) {
	

 	

 	

 	

 	

 answer = Boolean.TRUE;
	

 	

 	

 	

 	

 break;
	

 	

 	

 	

 }
	

 	

 	

 	

 else
	

 	

 	

 	

 if ("n".equals(line) || "no".equals(line)) {
	

 	

 	

 	

 	

 answer = Boolean.FALSE;
	

 	

 	

 	

 	

 break;
	

 	

 	

 	

 }
	

 	

 	

 	

 else
	

 	

 	

 	

 {
	

 	

 	

 	

 	

 System.out.println("Could not understand answer ("" +
	

 	

 	

 	

 	

 	

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

 	

 	

 	

 }
	

 	

 	

 }
	

 	

 	

 if (answer == null) {
	

 	

 	

 	

 throw new IOException("Unexpected end of input from stdin.");
	

 	

 	

 }
	

 	

 	

 in.close();
	

 	

 	

 return answer.booleanValue();
	

 	

 }
	

 	

 catch (IOException ioe)
	

 	

 {
	

 	

 	

 throw new InternalError(
	

 	

 	

 	

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

 	

 }
	

 }
}
*/
public class FileDownload {
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));
conn = url.openConnection();
in = conn.getInputStream();
byte[] buffer = new byte[1024];
int numRead;
long numWritten = 0;
while ((numRead = in.read(buffer)) != -1) {
out.write(buffer, 0, numRead);
numWritten += numRead;
}
System.out.println(localFileName + "t" + numWritten);
} catch (Exception exception) {
exception.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
} catch (IOException ioe) {
}
}
}
public static void download(String address) {
int lastSlashIndex = address.lastIndexOf('/');
if (lastSlashIndex >= 0 &&
lastSlashIndex < address.length() - 1) {
download(address, address.substring(lastSlashIndex + 1));
} else {
System.err.println("Could not figure out local file name for " +
address);
}
}
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
download(args[i]);
}
}
}
*/
public class HappyNewYear implements Runnable
{
private static NumberFormat formatter = NumberFormat.getInstance();
private JFrame frame;
private JLabel label;
private long newYearMillis;
private String message;
public HappyNewYear(JFrame frame, JLabel label)
{
// store argument GUI elements
this.frame = frame;
this.label = label;
// compute beginning of next year
Calendar cal = new GregorianCalendar();
int nextYear = cal.get(Calendar.YEAR) + 1;
cal.set(Calendar.YEAR, nextYear);
cal.set(Calendar.MONTH, Calendar.JANUARY);
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
newYearMillis = cal.getTime().getTime();
// prepare a message
message = "Happy " + nextYear + "!";
}
public static int determineFontSize(JFrame frame,
int componentWidth, String fontName, int fontStyle,
String text)
{
int fontSize = componentWidth * 2 / text.length();
Font font = new Font(fontName, fontStyle, fontSize);
FontMetrics fontMetrics = frame.getGraphics().
getFontMetrics(font);
int stringWidth = fontMetrics.stringWidth(text);
return (int)(fontSize * 0.95 *
componentWidth / stringWidth);
}
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.addKeyListener(new KeyListener()
{
public void keyPressed(KeyEvent event) {}
public void keyReleased(KeyEvent event) {
if (event.getKeyChar() == KeyEvent.VK_ESCAPE)
{
System.exit(0);
}
}
public void keyTyped(KeyEvent event) {}
}
);
frame.setUndecorated(true);
JLabel label = new JLabel(".");
label.setBackground(Color.BLACK);
label.setForeground(Color.WHITE);
label.setOpaque(true);
label.setHorizontalAlignment(SwingConstants.CENTER);
frame.getContentPane().add(label);
GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().setFullScreenWindow(frame);
final int fontStyle = Font.BOLD;
final String fontName = "SansSerif";
int fontSizeNumber = determineFontSize(frame,
Toolkit.getDefaultToolkit().getScreenSize().width,
fontName, fontStyle, formatter.format(88888888));
int fontSizeText = determineFontSize(frame,
Toolkit.getDefaultToolkit().getScreenSize().width,
fontName, fontStyle, "Happy 8888!");
label.setFont(new Font(fontName, fontStyle,
Math.min(fontSizeNumber, fontSizeText)));
new HappyNewYear(frame, label).run();
}
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);
}
}
Scattering
&
Tangling
Synchronization
UI dependency
2
AOP
import java.io.*;
import java.util.zip.*;
/**
* Command line program to copy a file to another directory.
* @author Marco Schmidt
*/
public class CopyFile {
	

 // constant values for the override option
	

 public static final int OVERWRITE_ALWAYS = 1;
	

 public static final int OVERWRITE_NEVER = 2;
	

 public static final int OVERWRITE_ASK = 3;
	

 // program options initialized to default values
	

 private static int bufferSize = 4 * 1024;
	

 private static boolean clock = true;
	

 public static Long copyFile(File srcFile, File destFile)
	

 	

 throws IOException {
	

 	

 }
	

 	

 byte[] buffer = new byte[bufferSize];
	

 	

 int bytesRead;
	

 	

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

 	

 	

 if (verify) {
	

 	

 	

 	

 checksum.update(buffer, 0, bytesRead);
	

 	

 	

 }
	

 	

 	

 return new Long(checksum.getValue());
	

 	

 } else {
	

 	

 	

 return null;
	

 	

 }
	

 }
	

 public static Long createChecksum(File file) throws IOException {
	

 	

 long millis = System.currentTimeMillis();
	

 	

 InputStream in = new FileInputStream(file);
	

 	

 byte[] buffer = new byte[bufferSize];
	

 	

 int bytesRead;
	

 	

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

 	

 	

 checksum.update(buffer, 0, bytesRead);
	

 	

 }
	

 	

 in.close();
	

 	

 if (clock) {
	

 	

 	

 millis = System.currentTimeMillis() - millis;
	

 	

 	

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

 	

 }
	

 	

 return new Long(checksum.getValue());
	

 }
	

 /**
	

 * Determine if data is to be copied to given file.
	

 * @param file File object for potential destination file
	

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

 */
	

 public static boolean doCopy(File file) {
	

 	

 boolean exists = file.exists();
	

 	

 if (override == OVERWRITE_ALWAYS || !exists) {
	

 	

 	

 return true;
	

 	

 } else
	

 	

 } else {
	

 	

 	

 throw new InternalError("Program error. Invalid " +
	

 	

 	

 	

 "value for override: " + override);
	

 	

 }
	

 }
	

 public static void main(String[] args) throws IOException {
	

 	

 // make sure there are exactly two arguments
	

 	

 if (args.length != 2) {
	

 	

 	

 System.err.println("Usage: CopyFile SRC-FILE-NAME DEST-DIR-NAME");
	

 	

 	

 System.exit(1);
	

 	

 }
	

 	

 // make sure the source file is indeed a readable file
	

 	

 File srcFile = new File(args[0]);
	

 	

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

 	

 	

 System.err.println("Not a readable file: " + srcFile.getName());
	

 	

 	

 System.exit(1);
	

 	

 }
	

 	

 // make sure the second argument is a directory
	

 	

 File destDir = new File(args[1]);
	

 	

 if (!destDir.isDirectory()) {
	

 	

 	

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

 	

 	

 System.exit(1);
	

 	

 }
	

 	

 // create File object for destination file
	

 	

 File destFile = new File(destDir, srcFile.getName());
	

 	

 // check if copying is desired given overwrite option
	

 	

 if (!doCopy(destFile)) {
	

 	

 	

 return;
	

 	

 }
	

 	

 // copy timestamp of last modification
	

 }
	

 /**
	

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

 */
	

 public static boolean readYesNoFromStandardInput(String message) {
	

 	

 System.out.println(message);
	

 	

 String line;
	

 	

 BufferedReader in = new BufferedReader(new InputStreamReader(
	

 	

 	

 System.in));
	

 	

 Boolean answer = null;
	

 	

 try
	

 	

 {
	

 	

 	

 while ((line = in.readLine()) != null) {
	

 	

 	

 	

 line = line.toLowerCase();
	

 	

 	

 	

 if ("y".equals(line) || "yes".equals(line)) {
	

 	

 	

 	

 	

 answer = Boolean.TRUE;
	

 	

 	

 	

 	

 break;
	

 	

 	

 	

 }
	

 	

 	

 	

 else
	

 	

 	

 	

 if ("n".equals(line) || "no".equals(line)) {
	

 	

 	

 	

 	

 answer = Boolean.FALSE;
	

 	

 	

 	

 	

 break;
	

 	

 	

 	

 }
	

 	

 	

 	

 else
	

 	

 	

 	

 {
	

 	

 	

 	

 	

 System.out.println("Could not understand answer ("" +
	

 	

 	

 	

 	

 	

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

 	

 	

 	

 }
	

 	

 	

	

 	

 }
	

 	

 catch (IOException ioe)
	

 	

 {
	

 	

 	

	

 	

 }
	

 }
}
*/
public class FileDownload {
public static void download(String address, String localFileName) {
OutputStream out = null;
URLConnection conn = null;
InputStream in = null;
try {
conn = url.openConnection();
in = conn.getInputStream();
byte[] buffer = new byte[1024];
int numRead;
long numWritten = 0;
while ((numRead = in.read(buffer)) != -1) {
out.write(buffer, 0, numRead);
numWritten += numRead;
} finally {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
} catch (IOException ioe) {
}
}
}
public static void download(String address) {
int lastSlashIndex = address.lastIndexOf('/');
System.err.println("Could not figure out local file name for " +
address);
}
}
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
download(args[i]);
}
}
}
*/
public class HappyNewYear implements Runnable
{
private static NumberFormat formatter = NumberFormat.getInstance();
private JFrame frame;
private JLabel label;
private long newYearMillis;
private String message;
public HappyNewYear(JFrame frame, JLabel label)
{
cal.set(Calendar.YEAR, nextYear);
cal.set(Calendar.MONTH, Calendar.JANUARY);
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
newYearMillis = cal.getTime().getTime();
// prepare a message
message = "Happy " + nextYear + "!";
}
public static int determineFontSize(JFrame frame,
int componentWidth, String fontName, int fontStyle,
String text)
{
return (int)(fontSize * 0.95 *
componentWidth / stringWidth);
}
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.addKeyListener(new KeyListener()
{
public void keyPressed(KeyEvent event) {}
public void keyReleased(KeyEvent event) {
if (event.getKeyChar() == KeyEvent.VK_ESCAPE)
{
System.exit(0);
}
}
public void keyTyped(KeyEvent event) {}
}
);
frame.setUndecorated(true);
JLabel label = new JLabel(".");
label.setBackground(Color.BLACK);
label.setForeground(Color.WHITE);
label.setOpaque(true);
label.setHorizontalAlignment(SwingConstants.CENTER);
frame.getContentPane().add(label);
GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().setFullScreenWindow(frame);
final int fontStyle = Font.BOLD;
label.setFont(new Font(fontName, fontStyle,
Math.min(fontSizeNumber, fontSizeText)));
new HappyNewYear(frame, label).run();
}
public void run()
{
boolean newYear = false;
do
{
newYear = true;
output = message;
}
else
{
// make a String from the number of seconds
output = formatter.format(remaining);
}
label.setText(output);
try
{
Thread.sleep(1000);
}
}
Modularized
	

 public static Long createChecksum(File file) throws IOException {
	

 	

 long millis = System.currentTimeMillis();
	

 	

 InputStream in = new FileInputStream(file);
	

 	

 byte[] buffer = new byte[bufferSize];
	

 	

 int bytesRead;
	

 	

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

 	

 	

 checksum.update(buffer, 0, bytesRead);
	

 	

 }
	

 	

 in.close();
	

 	

 if (clock) {
	

 	

 	

 millis = System.currentTimeMillis() - millis;
	

 	

 	

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

 	

 }
	

 	

 return new Long(checksum.getValue());
	

 }
	

 public static Long createChecksum(File file) throws IOException {
	

public HappyNewYear(JFrame frame, JLabel label)
{
cal.set(Calendar.YEAR, nextYear);
cal.set(Calendar.MONTH, Calendar.JANUARY);
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
newYearMillis = cal.getTime().getTime();
// prepare a message
message = "Happy " + nextYear + "!";
}
3
Pointcuts
import java.io.*;
import java.util.zip.*;
/**
* Command line program to copy a file to another directory.
* @author Marco Schmidt
*/
public class CopyFile {
	

 // constant values for the override option
	

 public static final int OVERWRITE_ALWAYS = 1;
	

 public static final int OVERWRITE_NEVER = 2;
	

 public static final int OVERWRITE_ASK = 3;
	

 // program options initialized to default values
	

 private static int bufferSize = 4 * 1024;
	

 private static boolean clock = true;
	

 public static Long copyFile(File srcFile, File destFile)
	

 	

 throws IOException {
	

 	

 }
	

 	

 byte[] buffer = new byte[bufferSize];
	

 	

 int bytesRead;
	

 	

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

 	

 	

 if (verify) {
	

 	

 	

 	

 checksum.update(buffer, 0, bytesRead);
	

 	

 	

 }
	

 	

 	

 return new Long(checksum.getValue());
	

 	

 } else {
	

 	

 	

 return null;
	

 	

 }
	

 }
	

 public static Long createChecksum(File file) throws IOException {
	

 	

 long millis = System.currentTimeMillis();
	

 	

 InputStream in = new FileInputStream(file);
	

 	

 byte[] buffer = new byte[bufferSize];
	

 	

 int bytesRead;
	

 	

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

 	

 	

 checksum.update(buffer, 0, bytesRead);
	

 	

 }
	

 	

 in.close();
	

 	

 if (clock) {
	

 	

 	

 millis = System.currentTimeMillis() - millis;
	

 	

 	

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

 	

 }
	

 	

 return new Long(checksum.getValue());
	

 }
	

 /**
	

 * Determine if data is to be copied to given file.
	

 * @param file File object for potential destination file
	

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

 */
	

 public static boolean doCopy(File file) {
	

 	

 boolean exists = file.exists();
	

 	

 if (override == OVERWRITE_ALWAYS || !exists) {
	

 	

 	

 return true;
	

 	

 } else
	

 	

 } else {
	

 	

 	

 throw new InternalError("Program error. Invalid " +
	

 	

 	

 	

 "value for override: " + override);
	

 	

 }
	

 }
	

 public static void main(String[] args) throws IOException {
	

 	

 // make sure there are exactly two arguments
	

 	

 if (args.length != 2) {
	

 	

 	

 System.err.println("Usage: CopyFile SRC-FILE-NAME DEST-DIR-NAME");
	

 	

 	

 System.exit(1);
	

 	

 }
	

 	

 // make sure the source file is indeed a readable file
	

 	

 File srcFile = new File(args[0]);
	

 	

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

 	

 	

 System.err.println("Not a readable file: " + srcFile.getName());
	

 	

 	

 System.exit(1);
	

 	

 }
	

 	

 // make sure the second argument is a directory
	

 	

 File destDir = new File(args[1]);
	

 	

 if (!destDir.isDirectory()) {
	

 	

 	

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

 	

 	

 System.exit(1);
	

 	

 }
	

 	

 // create File object for destination file
	

 	

 File destFile = new File(destDir, srcFile.getName());
	

 	

 // check if copying is desired given overwrite option
	

 	

 if (!doCopy(destFile)) {
	

 	

 	

 return;
	

 	

 }
	

 	

 // copy timestamp of last modification
	

 }
	

 /**
	

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

 */
	

 public static boolean readYesNoFromStandardInput(String message) {
	

 	

 System.out.println(message);
	

 	

 String line;
	

 	

 BufferedReader in = new BufferedReader(new InputStreamReader(
	

 	

 	

 System.in));
	

 	

 Boolean answer = null;
	

 	

 try
	

 	

 {
	

 	

 	

 while ((line = in.readLine()) != null) {
	

 	

 	

 	

 line = line.toLowerCase();
	

 	

 	

 	

 if ("y".equals(line) || "yes".equals(line)) {
	

 	

 	

 	

 	

 answer = Boolean.TRUE;
	

 	

 	

 	

 	

 break;
	

 	

 	

 	

 }
	

 	

 	

 	

 else
	

 	

 	

 	

 if ("n".equals(line) || "no".equals(line)) {
	

 	

 	

 	

 	

 answer = Boolean.FALSE;
	

 	

 	

 	

 	

 break;
	

 	

 	

 	

 }
	

 	

 	

 	

 else
	

 	

 	

 	

 {
	

 	

 	

 	

 	

 System.out.println("Could not understand answer ("" +
	

 	

 	

 	

 	

 	

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

 	

 	

 	

 }
	

 	

 	

	

 	

 }
	

 	

 catch (IOException ioe)
	

 	

 {
	

 	

 	

	

 	

 }
	

 }
}
*/
public class FileDownload {
public static void download(String address, String localFileName) {
OutputStream out = null;
URLConnection conn = null;
InputStream in = null;
try {
conn = url.openConnection();
in = conn.getInputStream();
byte[] buffer = new byte[1024];
int numRead;
long numWritten = 0;
while ((numRead = in.read(buffer)) != -1) {
out.write(buffer, 0, numRead);
numWritten += numRead;
} finally {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
} catch (IOException ioe) {
}
}
}
public static void download(String address) {
int lastSlashIndex = address.lastIndexOf('/');
System.err.println("Could not figure out local file name for " +
address);
}
}
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
download(args[i]);
}
}
}
*/
public class HappyNewYear implements Runnable
{
private static NumberFormat formatter = NumberFormat.getInstance();
private JFrame frame;
private JLabel label;
private long newYearMillis;
private String message;
public HappyNewYear(JFrame frame, JLabel label)
{
cal.set(Calendar.YEAR, nextYear);
cal.set(Calendar.MONTH, Calendar.JANUARY);
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
newYearMillis = cal.getTime().getTime();
// prepare a message
message = "Happy " + nextYear + "!";
}
public static int determineFontSize(JFrame frame,
int componentWidth, String fontName, int fontStyle,
String text)
{
return (int)(fontSize * 0.95 *
componentWidth / stringWidth);
}
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.addKeyListener(new KeyListener()
{
public void keyPressed(KeyEvent event) {}
public void keyReleased(KeyEvent event) {
if (event.getKeyChar() == KeyEvent.VK_ESCAPE)
{
System.exit(0);
}
}
public void keyTyped(KeyEvent event) {}
}
);
frame.setUndecorated(true);
JLabel label = new JLabel(".");
label.setBackground(Color.BLACK);
label.setForeground(Color.WHITE);
label.setOpaque(true);
label.setHorizontalAlignment(SwingConstants.CENTER);
frame.getContentPane().add(label);
GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().setFullScreenWindow(frame);
final int fontStyle = Font.BOLD;
label.setFont(new Font(fontName, fontStyle,
Math.min(fontSizeNumber, fontSizeText)));
new HappyNewYear(frame, label).run();
}
public void run()
{
boolean newYear = false;
do
{
newYear = true;
output = message;
}
else
{
// make a String from the number of seconds
output = formatter.format(remaining);
}
label.setText(output);
try
{
Thread.sleep(1000);
}
}
	

 public static Long createChecksum(File file) throws IOException {
	

 	

 long millis = System.currentTimeMillis();
	

 	

 InputStream in = new FileInputStream(file);
	

 	

 byte[] buffer = new byte[bufferSize];
	

 	

 int bytesRead;
	

 	

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

 	

 	

 checksum.update(buffer, 0, bytesRead);
	

 	

 }
	

 	

 in.close();
	

 	

 if (clock) {
	

 	

 	

 millis = System.currentTimeMillis() - millis;
	

 	

 	

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

 	

 }
	

 	

 return new Long(checksum.getValue());
	

 }
	

 public static Long createChecksum(File file) throws IOException {
	

public HappyNewYear(JFrame frame, JLabel label)
{
cal.set(Calendar.YEAR, nextYear);
cal.set(Calendar.MONTH, Calendar.JANUARY);
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
newYearMillis = cal.getTime().getTime();
// prepare a message
message = "Happy " + nextYear + "!";
}
Often point to details in source code (e.g. names)
4
Pointcuts
import java.io.*;
import java.util.zip.*;
/**
* Command line program to copy a file to another directory.
* @author Marco Schmidt
*/
public class CopyFile {
	

 // constant values for the override option
	

 public static final int OVERWRITE_ALWAYS = 1;
	

 public static final int OVERWRITE_NEVER = 2;
	

 public static final int OVERWRITE_ASK = 3;
	

 // program options initialized to default values
	

 private static int bufferSize = 4 * 1024;
	

 private static boolean clock = true;
	

 public static Long copyFile(File srcFile, File destFile)
	

 	

 throws IOException {
	

 	

 }
	

 	

 byte[] buffer = new byte[bufferSize];
	

 	

 int bytesRead;
	

 	

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

 	

 	

 if (verify) {
	

 	

 	

 	

 checksum.update(buffer, 0, bytesRead);
	

 	

 	

 }
	

 	

 	

 return new Long(checksum.getValue());
	

 	

 } else {
	

 	

 	

 return null;
	

 	

 }
	

 }
	

 public static Long createChecksum(File file) throws IOException {
	

 	

 long millis = System.currentTimeMillis();
	

 	

 InputStream in = new FileInputStream(file);
	

 	

 byte[] buffer = new byte[bufferSize];
	

 	

 int bytesRead;
	

 	

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

 	

 	

 checksum.update(buffer, 0, bytesRead);
	

 	

 }
	

 	

 in.close();
	

 	

 if (clock) {
	

 	

 	

 millis = System.currentTimeMillis() - millis;
	

 	

 	

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

 	

 }
	

 	

 return new Long(checksum.getValue());
	

 }
	

 /**
	

 * Determine if data is to be copied to given file.
	

 * @param file File object for potential destination file
	

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

 */
	

 public static boolean doCopy(File file) {
	

 	

 boolean exists = file.exists();
	

 	

 if (override == OVERWRITE_ALWAYS || !exists) {
	

 	

 	

 return true;
	

 	

 } else
	

 	

 } else {
	

 	

 	

 throw new InternalError("Program error. Invalid " +
	

 	

 	

 	

 "value for override: " + override);
	

 	

 }
	

 }
	

 public static void main(String[] args) throws IOException {
	

 	

 // make sure there are exactly two arguments
	

 	

 if (args.length != 2) {
	

 	

 	

 System.err.println("Usage: CopyFile SRC-FILE-NAME DEST-DIR-NAME");
	

 	

 	

 System.exit(1);
	

 	

 }
	

 	

 // make sure the source file is indeed a readable file
	

 	

 File srcFile = new File(args[0]);
	

 	

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

 	

 	

 System.err.println("Not a readable file: " + srcFile.getName());
	

 	

 	

 System.exit(1);
	

 	

 }
	

 	

 // make sure the second argument is a directory
	

 	

 File destDir = new File(args[1]);
	

 	

 if (!destDir.isDirectory()) {
	

 	

 	

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

 	

 	

 System.exit(1);
	

 	

 }
	

 	

 // create File object for destination file
	

 	

 File destFile = new File(destDir, srcFile.getName());
	

 	

 // check if copying is desired given overwrite option
	

 	

 if (!doCopy(destFile)) {
	

 	

 	

 return;
	

 	

 }
	

 	

 // copy timestamp of last modification
	

 }
	

 /**
	

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

 */
	

 public static boolean readYesNoFromStandardInput(String message) {
	

 	

 System.out.println(message);
	

 	

 String line;
	

 	

 BufferedReader in = new BufferedReader(new InputStreamReader(
	

 	

 	

 System.in));
	

 	

 Boolean answer = null;
	

 	

 try
	

 	

 {
	

 	

 	

 while ((line = in.readLine()) != null) {
	

 	

 	

 	

 line = line.toLowerCase();
	

 	

 	

 	

 if ("y".equals(line) || "yes".equals(line)) {
	

 	

 	

 	

 	

 answer = Boolean.TRUE;
	

 	

 	

 	

 	

 break;
	

 	

 	

 	

 }
	

 	

 	

 	

 else
	

 	

 	

 	

 if ("n".equals(line) || "no".equals(line)) {
	

 	

 	

 	

 	

 answer = Boolean.FALSE;
	

 	

 	

 	

 	

 break;
	

 	

 	

 	

 }
	

 	

 	

 	

 else
	

 	

 	

 	

 {
	

 	

 	

 	

 	

 System.out.println("Could not understand answer ("" +
	

 	

 	

 	

 	

 	

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

 	

 	

 	

 }
	

 	

 	

	

 	

 }
	

 	

 catch (IOException ioe)
	

 	

 {
	

 	

 	

	

 	

 }
	

 }
}
*/
public class FileDownload {
public static void download(String address, String localFileName) {
OutputStream out = null;
URLConnection conn = null;
InputStream in = null;
try {
conn = url.openConnection();
in = conn.getInputStream();
byte[] buffer = new byte[1024];
int numRead;
long numWritten = 0;
while ((numRead = in.read(buffer)) != -1) {
out.write(buffer, 0, numRead);
numWritten += numRead;
} finally {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
} catch (IOException ioe) {
}
}
}
public static void download(String address) {
int lastSlashIndex = address.lastIndexOf('/');
System.err.println("Could not figure out local file name for " +
address);
}
}
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
download(args[i]);
}
}
}
*/
public class HappyNewYear implements Runnable
{
private static NumberFormat formatter = NumberFormat.getInstance();
private JFrame frame;
private JLabel label;
private long newYearMillis;
private String message;
public HappyNewYear(JFrame frame, JLabel label)
{
cal.set(Calendar.YEAR, nextYear);
cal.set(Calendar.MONTH, Calendar.JANUARY);
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
newYearMillis = cal.getTime().getTime();
// prepare a message
message = "Happy " + nextYear + "!";
}
public static int determineFontSize(JFrame frame,
int componentWidth, String fontName, int fontStyle,
String text)
{
return (int)(fontSize * 0.95 *
componentWidth / stringWidth);
}
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.addKeyListener(new KeyListener()
{
public void keyPressed(KeyEvent event) {}
public void keyReleased(KeyEvent event) {
if (event.getKeyChar() == KeyEvent.VK_ESCAPE)
{
System.exit(0);
}
}
public void keyTyped(KeyEvent event) {}
}
);
frame.setUndecorated(true);
JLabel label = new JLabel(".");
label.setBackground(Color.BLACK);
label.setForeground(Color.WHITE);
label.setOpaque(true);
label.setHorizontalAlignment(SwingConstants.CENTER);
frame.getContentPane().add(label);
GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().setFullScreenWindow(frame);
final int fontStyle = Font.BOLD;
label.setFont(new Font(fontName, fontStyle,
Math.min(fontSizeNumber, fontSizeText)));
new HappyNewYear(frame, label).run();
}
public void run()
{
boolean newYear = false;
do
{
newYear = true;
output = message;
}
else
{
// make a String from the number of seconds
output = formatter.format(remaining);
}
label.setText(output);
try
{
Thread.sleep(1000);
}
}
	

 public static Long createChecksum(File file) throws IOException {
	

 	

 long millis = System.currentTimeMillis();
	

 	

 InputStream in = new FileInputStream(file);
	

 	

 byte[] buffer = new byte[bufferSize];
	

 	

 int bytesRead;
	

 	

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

 	

 	

 checksum.update(buffer, 0, bytesRead);
	

 	

 }
	

 	

 in.close();
	

 	

 if (clock) {
	

 	

 	

 millis = System.currentTimeMillis() - millis;
	

 	

 	

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

 	

 }
	

 	

 return new Long(checksum.getValue());
	

 }
	

 public static Long createChecksum(File file) throws IOException {
	

public HappyNewYear(JFrame frame, JLabel label)
{
cal.set(Calendar.YEAR, nextYear);
cal.set(Calendar.MONTH, Calendar.JANUARY);
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
newYearMillis = cal.getTime().getTime();
// prepare a message
message = "Happy " + nextYear + "!";
}
Often point to details in source code (e.g. names)
4
AsBeforeAfterAdvice
qualifier:...
pointcut: [WindowSensor withAllSubclasses
select:
[:each includesSelector: #eventDoubleClick:]
thenCollect:[:each | AsJoinPointDescriptor
targetClass: each
targetSelector:#eventDoubleClick:]]
beforeBlock: [:receiver :args :aspect :client |
...]
Aspects in Smalltalk
5
AspectS
•Framework based
•Pointcut using Smalltalk
•Advice using block
AsBeforeAfterAdvice
qualifier:...
pointcut: [WindowSensor withAllSubclasses
select:
[:each includesSelector: #eventDoubleClick:]
thenCollect:[:each | AsJoinPointDescriptor
targetClass: each
targetSelector:#eventDoubleClick:]]
beforeBlock: [:receiver :args :aspect :client |
...]
Aspects in Smalltalk
5
AspectS
•Framework based
•Pointcut using Smalltalk
•Advice using block
Pointcut
AsBeforeAfterAdvice
qualifier:...
pointcut: [WindowSensor withAllSubclasses
select:
[:each includesSelector: #eventDoubleClick:]
thenCollect:[:each | AsJoinPointDescriptor
targetClass: each
targetSelector:#eventDoubleClick:]]
beforeBlock: [:receiver :args :aspect :client |
...]
Aspects in Smalltalk
5
AspectS
•Framework based
•Pointcut using Smalltalk
•Advice using block
Pointcut
Advice
after ?jp matching
reception(?jp, #eventDoubleClick:,?args),
within(?jp, ?class, ?selector),
classInHierarchyOf(?class,[WindowSensor])
do
Transcript show: ?class.
...
Aspects in Carma
6
Carma
•Pointcut language
•Declarative Meta Programming
•Based on SOUL
after ?jp matching
reception(?jp, #eventDoubleClick:,?args),
within(?jp, ?class, ?selector),
classInHierarchyOf(?class,[WindowSensor])
do
Transcript show: ?class.
...
Aspects in Carma
6
Carma
•Pointcut language
•Declarative Meta Programming
•Based on SOUL
•Declarative
•Unification
•Recursion
after ?jp matching
reception(?jp, #eventDoubleClick:,?args),
within(?jp, ?class, ?selector),
classInHierarchyOf(?class,[WindowSensor])
do
Transcript show: ?class.
...
Aspects in Carma
6
Carma
•Pointcut language
•Declarative Meta Programming
•Based on SOUL
Pointcut
•Declarative
•Unification
•Recursion
after ?jp matching
reception(?jp, #eventDoubleClick:,?args),
within(?jp, ?class, ?selector),
classInHierarchyOf(?class,[WindowSensor])
do
Transcript show: ?class.
...
Aspects in Carma
6
Carma
•Pointcut language
•Declarative Meta Programming
•Based on SOUL
Pointcut
Advice
•Declarative
•Unification
•Recursion
AspectSOUL
7
AspectS
•Framework
Carma
•Pointcuts
AspectSOUL
7
AspectS
•Framework
Carma
•Pointcuts
AsCARMABeforeAfterAdvice
qualifier:...
pointcutQuery: ‘reception(?jp, #eventDoubleClick:,?args),
within(?jp, ?class, ?selector),
classInHierarchyOf(?class,[WindowSensor])’
beforeBlock: [:receiver :args :aspect :client |
...]
AspectSOUL
7
AspectS
•Framework
Carma
•Pointcuts
AsCARMABeforeAfterAdvice
qualifier:...
pointcutQuery: ‘reception(?jp, #eventDoubleClick:,?args),
within(?jp, ?class, ?selector),
classInHierarchyOf(?class,[WindowSensor])’
beforeBlock: [:receiver :args :aspect :client |
...]
Pointcut
AspectSOUL
7
AspectS
•Framework
Carma
•Pointcuts
AsCARMABeforeAfterAdvice
qualifier:...
pointcutQuery: ‘reception(?jp, #eventDoubleClick:,?args),
within(?jp, ?class, ?selector),
classInHierarchyOf(?class,[WindowSensor])’
beforeBlock: [:receiver :args :aspect :client |
...]
Pointcut
Advice
Fragility
Person>>name
^name
Person>>name: anObject
name := anObject
8
1.accessing protocol
2.selector corresponds to
variable name
Fragility
Person>>name
^name
Person>>name: anObject
name := anObject
8
class(?class),
methodWithNameInClass(?method,?accessor,?class),
instanceVariableInClassChain(?accessor,?class),
methodInProtocol(?method,accessing),
reception(?joinpoint,?accessor,?args),
withinClass(?joinpoint,?class)
Synchronization
1.accessing protocol
2.selector corresponds to
variable name
Fragility
Person>>name
^name
Person>>name: anObject
name := anObject
8
class(?class),
methodWithNameInClass(?method,?accessor,?class),
instanceVariableInClassChain(?accessor,?class),
methodInProtocol(?method,accessing),
reception(?joinpoint,?accessor,?args),
withinClass(?joinpoint,?class)
Synchronization
1.accessing protocol
2.selector corresponds to
variable name
Person>>getName
^name
Person>>setName: anObject
name := anObject
Fragility
Person>>name
^name
Person>>name: anObject
name := anObject
8
1.accessing protocol
2.selector corresponds to
variable name
Person>>getName
^name
Person>>setName: anObject
name := anObject
X
class(?class),
methodWithNameInClass(?method,?accessor,?class),
instanceVariableInClassChain(?accessor,?class),
methodInProtocol(?method,accessing),
reception(?joinpoint,?accessor,?args),
withinClass(?joinpoint,?class)
Synchronization
? ?
Complexity
Person>>name
^name
Person>>name: anObject
name := anObject
9
1.accessor: return instance var
2.mutator: assign instance var
Complexity
Person>>name
^name
Person>>name: anObject
name := anObject
9
1.accessor: return instance var
2.mutator: assign instance var
class(?class),
methodWithNameInClass(?method,?accessor,?class),
instanceVariableInClassChain(?accessor,?class),
returnStatement(?method,variable(?var)),
reception(?joinpoint,?accessor,?args),
withinClass(?joinpoint,?class)
Synchronization
Complexity
Person>>name
^name
Person>>name: anObject
name := anObject
9
1.accessor: return instance var
2.mutator: assign instance var
class(?class),
methodWithNameInClass(?method,?accessor,?class),
instanceVariableInClassChain(?accessor,?class),
returnStatement(?method,variable(?var)),
reception(?joinpoint,?accessor,?args),
withinClass(?joinpoint,?class)
Synchronization
Person>>friends
^friends isNil
ifTrue:[friends := Set new]
ifFalse:[friends]
?
class(?class),
methodWithNameInClass(?method,?accessor,?class),
instanceVariableInClassChain(?accessor,?class),
returnStatement(?method,variable(?var)),
reception(?joinpoint,?accessor,?args),
withinClass(?joinpoint,?class)
Synchronisationclass(?class),
methodWithNameInClass(?method,?accessor,?class),
instanceVariableInClassChain(?accessor,?class),
returnStatement(?method,variable(?var)),
reception(?joinpoint,?accessor,?args),
withinClass(?joinpoint,?class)
Synchronisation
Complexity
Person>>name
^name
Person>>name: anObject
name := anObject
9
1.accessor: return instance var
2.mutator: assign instance var
class(?class),
methodWithNameInClass(?method,?accessor,?class),
instanceVariableInClassChain(?accessor,?class),
returnStatement(?method,variable(?var)),
reception(?joinpoint,?accessor,?args),
withinClass(?joinpoint,?class)
Synchronization
Person>>friends
^friends isNil
ifTrue:[friends := Set new]
ifFalse:[friends]
?
Problem Analysis
10
Source code based
pointcut
(defined directly in terms
of source code)
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
*
1
*
1
*
1
Source code
Base program developer Aspect developer
Problem Analysis
10
Source code based
pointcut
(defined directly in terms
of source code)
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
*
1
*
1
*
1
Source code
Tight
coupling
Base program developer Aspect developer
Problem Analysis
10
Source code based
pointcut
(defined directly in terms
of source code)
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
*
1
*
1
*
1
Source code
Tight
coupling Complex
Base program developer Aspect developer
Problem Analysis
10
Source code based
pointcut
(defined directly in terms
of source code)
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
*
1
*
1
*
1
Source code
Tight
coupling Complex Fragile
Base program developer Aspect developer
Application-specific
11
Source code based
pointcut
(defined directly in terms
of source code)
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
*
1
*
1
*
1
Source code
Base program developer Aspect developer
Application-specific
11
Source code based
pointcut
(defined directly in terms
of source code)
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
*
1
*
1
*
1
Source code
Base program developer Aspect developer
Model-based pointcut
(defined in terms of
application-specific
model)
Application-specific model
Application-specific
11
Source code based
pointcut
(defined directly in terms
of source code)
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
*
1
*
1
*
1
Source code
Base program developer Aspect developer
Model-based pointcut
(defined in terms of
application-specific
model)
Application-specific model
Explicit
Model
Application-specific
11
Source code based
pointcut
(defined directly in terms
of source code)
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
*
1
*
1
*
1
Source code
Base program developer Aspect developer
Model-based pointcut
(defined in terms of
application-specific
model)
Application-specific model
Explicit
Model
Expressed
in terms of
structure
Application-specific
11
Source code based
pointcut
(defined directly in terms
of source code)
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
Operations
Operations
Attributes
Attributes
Class
Name
*
1
*
1
*
1
Source code
Base program developer Aspect developer
Model-based pointcut
(defined in terms of
application-specific
model)
Application-specific model
Explicit
Model
Expressed
in terms of
structure
Contract
Requires
Provides
12
Application-specific pointcuts
in AspectSOUL
Logic Pointcuts Application-specific
model
Extensible
pointcut language Keep in sync with code
Logic representation
specialisation
parameters &
unification
12
Application-specific pointcuts
in AspectSOUL
Logic Pointcuts Application-specific
model
Extensible
pointcut language Keep in sync with code
Logic representation
specialisation
parameters &
unification
12
Application-specific pointcuts
in AspectSOUL
Logic Pointcuts Application-specific
model
Extensible
pointcut language Keep in sync with code
Logic representation
specialisation
parameters &
unification
Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts
Andy Kellens, Kim Mens, Johan Brichau, Kris Gybels
In "Proceedings of the 20th European Conference on Object-Oriented Programming (ECOOP)", 2006
Accessors
13
Pointcut
Model
Source
Person>>name
^name
Person>>name: anObject
name := anObject
Accessors
13
reception(?joinpoint,?selector,?args),
accessor(?class,?selector,?var),
withinClass(?joinpoint,?class)
Synchronization
Pointcut
Model
Source
Person>>name
^name
Person>>name: anObject
name := anObject
Accessors
13
reception(?joinpoint,?selector,?args),
accessor(?class,?selector,?var),
withinClass(?joinpoint,?class)
Synchronization
Pointcut
Model
accessor(?class,?method,?varname) if
class(?class),
instanceVariableInClassChain(?varName,?class),
methodWithNameInClass(?method,?varName,?class),
methodInProtocol(?method,accessing),
accessorForm(?method,?varname)
accessorForm(?method,?var) if
returnStatement(?method,variable(?var))
Source
Person>>name
^name
Person>>name: anObject
name := anObject
Model specialisation
14
Pointcut
Model
Source
Person>>name
^name
Person>>name: anObject
name := anObject
Model specialisation
14
Pointcut
Model
Source
Person>>name
^name
Person>>name: anObject
name := anObject
Person>>friends
^friends isNil
ifTrue:[friends := Set new]
ifFalse:[friends]
Model specialisation
14
reception(?joinpoint,?selector,?args),
accessor(?class,?selector,?var),
withinClass(?joinpoint,?class)
Synchronization
Pointcut
Model
Source
Person>>name
^name
Person>>name: anObject
name := anObject
Person>>friends
^friends isNil
ifTrue:[friends := Set new]
ifFalse:[friends]
Model specialisation
14
reception(?joinpoint,?selector,?args),
accessor(?class,?selector,?var),
withinClass(?joinpoint,?class)
Synchronization
Pointcut
Model
Source
Person>>name
^name
Person>>name: anObject
name := anObject
Person>>friends
^friends isNil
ifTrue:[friends := Set new]
ifFalse:[friends]
accessor(?class,?method,?varname) if
...
accessorForm(?method,?var) if
returnStatement(?method,send(?var))
accessorForm(?method,?var) if
returnStatement(?method,send(?check),<?true,?false>),
nilCheckStatement(?check),
statementsOfBlock(assign(?var,?varinit),?true),
statementsOfBlock(<?var>,?false)
Parameters & Unification
15
Parameters & Unification
15
reception(?joinpoint,?selector,?args),
accessor(?class,?selector,?var),
withinClass(?joinpoint,?class)
Synchronization
Parameters & Unification
15
reception(?joinpoint,?selector,?args),
accessor(?class,?selector,?var),
withinClass(?joinpoint,?class)
Synchronization
reception(?joinpoint,?selector,?args),
accessor(Array,at:put:,?var),
withinClass(?joinpoint,?class)
Synchronization
Parameters & Unification
15
reception(?joinpoint,?selector,?args),
accessor(?class,?selector,?var),
withinClass(?joinpoint,?class)
Synchronization
reception(?joinpoint,?selector,?args),
accessor(Array,at:put:,?var),
withinClass(?joinpoint,?class)
Synchronization
reception(?joinpoint,?selector,?args),
accessor(?class,?selector,address),
withinClass(?joinpoint,?class)
Synchronization
Drag & Drop
16
Drag Ok
Start Drag
Enter Drag
Over Drag
Drop
DragDrop
Manager
Drag & Drop
16
Drag Ok
Start Drag
Enter Drag
Over Drag
Drop
DragDrop
Manager
dragOkMethod(?class,?sel,?component)
dragEnterMethod(?class,?sel,?component)
dragSource(?dragdropmanager,?source)
draggedObject(?dragdropmanager,?object)
Drag & Drop
16
Drag Ok
Start Drag
Enter Drag
Over Drag
Drop
DragDrop
Manager
dragOkMethod(?class,?sel,?component)
dragEnterMethod(?class,?sel,?component)
dragSource(?dragdropmanager,?source)
draggedObject(?dragdropmanager,?object)
reception(?jp,?sel,?args),
dragEnterMethod(?class,?sel,?component),
equals(?args,<?dragdropmanager>),
dragSource(?dragdropmanager,?source),
instanceOf(?source,FigureManager),
draggedObject(?dragdropmanager,?object),
instanceOf(?object,Line)
Refactoring
17
Refactoring
transform
preconditions ...
......
Refactoring
17
Refactoring
transform
preconditions ...
......
transformMethod(?class,?sel,?refactoring)
preconditions(?refactoring,?preconditions)
refactoring(?refactoring,?class,?method)
Refactoring
17
Refactoring
transform
preconditions ...
...
transformMethod(?class,?sel,?refactoring)
preconditions(?refactoring,?preconditions)
refactoring(?refactoring,?class,?method)
affected entities
Refactoring
17
Refactoring
transform
preconditions ...
...
transformMethod(?class,?sel,?refactoring)
preconditions(?refactoring,?preconditions)
refactoring(?refactoring,?class,?method)
affected entities
affectedEntity(?ref,[PushUpMethod],?input,?entity) if
originalClassOfPushUpMethod(?input,?entity)
affectedEntity(?ref,[PushUpMethod],?input,?entity) if
originalClassOfPushUpMethod(?input,?class),
superclassOf(entity,?class)
Summary
18
AspectS + Carma = AspectSOUL
Pointcut in terms of application-specific model
Extensible pointcut language
Logic language to express model
Further integration of AspectS/Carma
Integration with support for fragile pointcuts
More information:
http://prog.vub.ac.be/carma/
Questions
19
?

Weitere ähnliche Inhalte

Was ist angesagt?

Writing Swift code with great testability
Writing Swift code with great testabilityWriting Swift code with great testability
Writing Swift code with great testabilityJohn Sundell
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File HandlingSunil OS
 
5. Ввод-вывод, доступ к файловой системе
5. Ввод-вывод, доступ к файловой системе5. Ввод-вывод, доступ к файловой системе
5. Ввод-вывод, доступ к файловой системеDEVTYPE
 
Non blocking io with netty
Non blocking io with nettyNon blocking io with netty
Non blocking io with nettyZauber
 
Apache Flink Training: DataStream API Part 2 Advanced
Apache Flink Training: DataStream API Part 2 Advanced Apache Flink Training: DataStream API Part 2 Advanced
Apache Flink Training: DataStream API Part 2 Advanced Flink Forward
 
The Ring programming language version 1.6 book - Part 28 of 189
The Ring programming language version 1.6 book - Part 28 of 189The Ring programming language version 1.6 book - Part 28 of 189
The Ring programming language version 1.6 book - Part 28 of 189Mahmoud Samir Fayed
 
Apache Flink Training: DataSet API Basics
Apache Flink Training: DataSet API BasicsApache Flink Training: DataSet API Basics
Apache Flink Training: DataSet API BasicsFlink Forward
 
Writing Domain-Specific Languages for BeepBeep
Writing Domain-Specific Languages for BeepBeepWriting Domain-Specific Languages for BeepBeep
Writing Domain-Specific Languages for BeepBeepSylvain Hallé
 
Refactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartRefactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartGabriele Lana
 
#5 (Remote Method Invocation)
#5 (Remote Method Invocation)#5 (Remote Method Invocation)
#5 (Remote Method Invocation)Ghadeer AlHasan
 
Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介Kiyotaka Oku
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and OutputEduardo Bergavera
 
Smarter Testing With Spock
Smarter Testing With SpockSmarter Testing With Spock
Smarter Testing With SpockIT Weekend
 

Was ist angesagt? (20)

Writing Swift code with great testability
Writing Swift code with great testabilityWriting Swift code with great testability
Writing Swift code with great testability
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
 
Hadoop
HadoopHadoop
Hadoop
 
5. Ввод-вывод, доступ к файловой системе
5. Ввод-вывод, доступ к файловой системе5. Ввод-вывод, доступ к файловой системе
5. Ввод-вывод, доступ к файловой системе
 
Non blocking io with netty
Non blocking io with nettyNon blocking io with netty
Non blocking io with netty
 
Java NIO.2
Java NIO.2Java NIO.2
Java NIO.2
 
Apache Flink Training: DataStream API Part 2 Advanced
Apache Flink Training: DataStream API Part 2 Advanced Apache Flink Training: DataStream API Part 2 Advanced
Apache Flink Training: DataStream API Part 2 Advanced
 
The Ring programming language version 1.6 book - Part 28 of 189
The Ring programming language version 1.6 book - Part 28 of 189The Ring programming language version 1.6 book - Part 28 of 189
The Ring programming language version 1.6 book - Part 28 of 189
 
Apache Flink Training: DataSet API Basics
Apache Flink Training: DataSet API BasicsApache Flink Training: DataSet API Basics
Apache Flink Training: DataSet API Basics
 
Python lec5
Python lec5Python lec5
Python lec5
 
Blockchain - a simple implementation
Blockchain - a simple implementationBlockchain - a simple implementation
Blockchain - a simple implementation
 
Writing Domain-Specific Languages for BeepBeep
Writing Domain-Specific Languages for BeepBeepWriting Domain-Specific Languages for BeepBeep
Writing Domain-Specific Languages for BeepBeep
 
Python lec4
Python lec4Python lec4
Python lec4
 
JAVA NIO
JAVA NIOJAVA NIO
JAVA NIO
 
Refactoring In Tdd The Missing Part
Refactoring In Tdd The Missing PartRefactoring In Tdd The Missing Part
Refactoring In Tdd The Missing Part
 
Java file
Java fileJava file
Java file
 
#5 (Remote Method Invocation)
#5 (Remote Method Invocation)#5 (Remote Method Invocation)
#5 (Remote Method Invocation)
 
Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and Output
 
Smarter Testing With Spock
Smarter Testing With SpockSmarter Testing With Spock
Smarter Testing With Spock
 

Andere mochten auch

DE TRELEW A EE.UU.
DE TRELEW A EE.UU.DE TRELEW A EE.UU.
DE TRELEW A EE.UU.Red RADAR
 
Welcome ESUG 2005
Welcome ESUG 2005Welcome ESUG 2005
Welcome ESUG 2005ESUG
 
trabalho 2
trabalho 2trabalho 2
trabalho 2nlopesr
 
Prototalk
PrototalkPrototalk
PrototalkESUG
 
Meta-Driven Browsers
Meta-Driven BrowsersMeta-Driven Browsers
Meta-Driven BrowsersESUG
 
Ocean
OceanOcean
OceanESUG
 
MBA Smalltalk: to manage your objects
MBA Smalltalk: to manage your objectsMBA Smalltalk: to manage your objects
MBA Smalltalk: to manage your objectsESUG
 
The Value of Smalltalk
The Value of SmalltalkThe Value of Smalltalk
The Value of SmalltalkESUG
 

Andere mochten auch (8)

DE TRELEW A EE.UU.
DE TRELEW A EE.UU.DE TRELEW A EE.UU.
DE TRELEW A EE.UU.
 
Welcome ESUG 2005
Welcome ESUG 2005Welcome ESUG 2005
Welcome ESUG 2005
 
trabalho 2
trabalho 2trabalho 2
trabalho 2
 
Prototalk
PrototalkPrototalk
Prototalk
 
Meta-Driven Browsers
Meta-Driven BrowsersMeta-Driven Browsers
Meta-Driven Browsers
 
Ocean
OceanOcean
Ocean
 
MBA Smalltalk: to manage your objects
MBA Smalltalk: to manage your objectsMBA Smalltalk: to manage your objects
MBA Smalltalk: to manage your objects
 
The Value of Smalltalk
The Value of SmalltalkThe Value of Smalltalk
The Value of Smalltalk
 

Ähnlich wie Application-Specific Models and Pointcuts using a Logic Meta Language

Modify the project so tat records are inserted into the random acess.pdf
Modify the project so tat records are inserted into the random acess.pdfModify the project so tat records are inserted into the random acess.pdf
Modify the project so tat records are inserted into the random acess.pdffcaindore
 
Create a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdfCreate a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdfshahidqamar17
 
Java programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswarJava programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswarROHIT JAISWAR
 
Exceptions and errors in Java
Exceptions and errors in JavaExceptions and errors in Java
Exceptions and errors in JavaManuela Grindei
 
source code which create file and write into it
source code which create file and write into itsource code which create file and write into it
source code which create file and write into itmelakusisay507
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streamsShahjahan Samoon
 
Session 23 - JDBC
Session 23 - JDBCSession 23 - JDBC
Session 23 - JDBCPawanMM
 
Exmaples of file handling
Exmaples of file handlingExmaples of file handling
Exmaples of file handlingsparkishpearl
 
Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4Sunil OS
 

Ähnlich wie Application-Specific Models and Pointcuts using a Logic Meta Language (20)

Inheritance
InheritanceInheritance
Inheritance
 
Oop lecture9 11
Oop lecture9 11Oop lecture9 11
Oop lecture9 11
 
Lab4
Lab4Lab4
Lab4
 
Anti patterns
Anti patternsAnti patterns
Anti patterns
 
Modify the project so tat records are inserted into the random acess.pdf
Modify the project so tat records are inserted into the random acess.pdfModify the project so tat records are inserted into the random acess.pdf
Modify the project so tat records are inserted into the random acess.pdf
 
Java 104
Java 104Java 104
Java 104
 
Create a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdfCreate a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdf
 
Java programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswarJava programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswar
 
Code red SUM
Code red SUMCode red SUM
Code red SUM
 
Bhaloo
BhalooBhaloo
Bhaloo
 
Exceptions and errors in Java
Exceptions and errors in JavaExceptions and errors in Java
Exceptions and errors in Java
 
source code which create file and write into it
source code which create file and write into itsource code which create file and write into it
source code which create file and write into it
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streams
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
 
srgoc
srgocsrgoc
srgoc
 
Session 23 - JDBC
Session 23 - JDBCSession 23 - JDBC
Session 23 - JDBC
 
Exmaples of file handling
Exmaples of file handlingExmaples of file handling
Exmaples of file handling
 
JavaExamples
JavaExamplesJavaExamples
JavaExamples
 
Oop lecture9 12
Oop lecture9 12Oop lecture9 12
Oop lecture9 12
 
Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4
 

Mehr von ESUG

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingESUG
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in PharoESUG
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapESUG
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoESUG
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...ESUG
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsESUG
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6ESUG
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationESUG
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingESUG
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesESUG
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportESUG
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsESUG
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector TuningESUG
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseESUG
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FutureESUG
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the DebuggerESUG
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing ScoreESUG
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptESUG
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocESUG
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsESUG
 

Mehr von ESUG (20)

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programming
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in Pharo
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and Roadmap
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in Pharo
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early results
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test Generation
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic Programming
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience Report
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIs
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector Tuning
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and Future
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the Debugger
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing Score
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design Mooc
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and Transformations
 

Kürzlich hochgeladen

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 

Kürzlich hochgeladen (20)

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 

Application-Specific Models and Pointcuts using a Logic Meta Language

  • 1. Application-Specific Models and Pointcuts using a Logic Meta Language Andy Kellens Kim MensJohan Brichau Kris Gybels Robert Hirschfeld Theo D’Hondt
  • 2. Crosscutting Concerns import java.io.*; import java.util.zip.*; /** * Command line program to copy a file to another directory. * @author Marco Schmidt */ public class CopyFile { // constant values for the override option public static final int OVERWRITE_ALWAYS = 1; public static final int OVERWRITE_NEVER = 2; public static final int OVERWRITE_ASK = 3; // program options initialized to default values private static int bufferSize = 4 * 1024; private static boolean clock = true; private static boolean copyOriginalTimestamp = true; private static boolean verify = true; private static int override = OVERWRITE_ASK; public static Long copyFile(File srcFile, File destFile) throws IOException { InputStream in = new FileInputStream(srcFile); OutputStream out = new FileOutputStream(destFile); long millis = System.currentTimeMillis(); CRC32 checksum = null; if (verify) { checksum = new CRC32(); checksum.reset(); } byte[] buffer = new byte[bufferSize]; int bytesRead; while ((bytesRead = in.read(buffer)) >= 0) { if (verify) { checksum.update(buffer, 0, bytesRead); } out.write(buffer, 0, bytesRead); } out.close(); in.close(); if (clock) { millis = System.currentTimeMillis() - millis; System.out.println("Second(s): " + (millis/1000L)); } if (verify) { return new Long(checksum.getValue()); } else { return null; } } public static Long createChecksum(File file) throws IOException { long millis = System.currentTimeMillis(); InputStream in = new FileInputStream(file); CRC32 checksum = new CRC32(); checksum.reset(); byte[] buffer = new byte[bufferSize]; int bytesRead; while ((bytesRead = in.read(buffer)) >= 0) { checksum.update(buffer, 0, bytesRead); } in.close(); if (clock) { millis = System.currentTimeMillis() - millis; System.out.println("Second(s): " + (millis/1000L)); } return new Long(checksum.getValue()); } /** * Determine if data is to be copied to given file. * 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 * @return true if data is to be copied to file, false if not */ public static boolean doCopy(File file) { boolean exists = file.exists(); if (override == OVERWRITE_ALWAYS || !exists) { return true; } else if (override == OVERWRITE_NEVER) { return false; } else if (override == OVERWRITE_ASK) { return readYesNoFromStandardInput("File exists. " + "Overwrite (y/n)?"); } else { throw new InternalError("Program error. Invalid " + "value for override: " + override); } } public static void main(String[] args) throws IOException { // make sure there are exactly two arguments if (args.length != 2) { System.err.println("Usage: CopyFile SRC-FILE-NAME DEST-DIR-NAME"); System.exit(1); } // make sure the source file is indeed a readable file File srcFile = new File(args[0]); if (!srcFile.isFile() || !srcFile.canRead()) { System.err.println("Not a readable file: " + srcFile.getName()); System.exit(1); } // make sure the second argument is a directory File destDir = new File(args[1]); if (!destDir.isDirectory()) { System.err.println("Not a directory: " + destDir.getName()); System.exit(1); } // create File object for destination file File destFile = new File(destDir, srcFile.getName()); // check if copying is desired given overwrite option if (!doCopy(destFile)) { return; } // copy file, optionally creating a checksum Long checksumSrc = copyFile(srcFile, destFile); // copy timestamp of last modification if (copyOriginalTimestamp) { if (!destFile.setLastModified(srcFile.lastModified())) { System.err.println("Error: Could not set " + "timestamp of copied file."); } } // optionally verify file if (verify) { System.out.print("Verifying destination file..."); Long checksumDest = createChecksum(destFile); if (checksumSrc.equals(checksumDest)) { System.out.println(" OK, files are equal."); } else { System.out.println(" Error: Checksums differ."); } } } /** * Print a message to standard output and read lines from * standard input until yes or no (y or n) is entered. * @param message informative text to be answered by user * @return user answer, true for yes, false for no. */ public static boolean readYesNoFromStandardInput(String message) { System.out.println(message); String line; BufferedReader in = new BufferedReader(new InputStreamReader( System.in)); Boolean answer = null; try { while ((line = in.readLine()) != null) { line = line.toLowerCase(); if ("y".equals(line) || "yes".equals(line)) { answer = Boolean.TRUE; break; } else if ("n".equals(line) || "no".equals(line)) { answer = Boolean.FALSE; break; } else { System.out.println("Could not understand answer ("" + line + ""). Please use y for yes or n for no."); } } if (answer == null) { throw new IOException("Unexpected end of input from stdin."); } in.close(); return answer.booleanValue(); } catch (IOException ioe) { throw new InternalError( "Cannot read from stdin or write to stdout."); } } } */ public class FileDownload { 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)); conn = url.openConnection(); in = conn.getInputStream(); byte[] buffer = new byte[1024]; int numRead; long numWritten = 0; while ((numRead = in.read(buffer)) != -1) { out.write(buffer, 0, numRead); numWritten += numRead; } System.out.println(localFileName + "t" + numWritten); } catch (Exception exception) { exception.printStackTrace(); } finally { try { if (in != null) { in.close(); } if (out != null) { out.close(); } } catch (IOException ioe) { } } } public static void download(String address) { int lastSlashIndex = address.lastIndexOf('/'); if (lastSlashIndex >= 0 && lastSlashIndex < address.length() - 1) { download(address, address.substring(lastSlashIndex + 1)); } else { System.err.println("Could not figure out local file name for " + address); } } public static void main(String[] args) { for (int i = 0; i < args.length; i++) { download(args[i]); } } } */ public class HappyNewYear implements Runnable { private static NumberFormat formatter = NumberFormat.getInstance(); private JFrame frame; private JLabel label; private long newYearMillis; private String message; public HappyNewYear(JFrame frame, JLabel label) { // store argument GUI elements this.frame = frame; this.label = label; // compute beginning of next year Calendar cal = new GregorianCalendar(); int nextYear = cal.get(Calendar.YEAR) + 1; cal.set(Calendar.YEAR, nextYear); cal.set(Calendar.MONTH, Calendar.JANUARY); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); newYearMillis = cal.getTime().getTime(); // prepare a message message = "Happy " + nextYear + "!"; } public static int determineFontSize(JFrame frame, int componentWidth, String fontName, int fontStyle, String text) { int fontSize = componentWidth * 2 / text.length(); Font font = new Font(fontName, fontStyle, fontSize); FontMetrics fontMetrics = frame.getGraphics(). getFontMetrics(font); int stringWidth = fontMetrics.stringWidth(text); return (int)(fontSize * 0.95 * componentWidth / stringWidth); } public static void main(String[] args) { JFrame frame = new JFrame(); frame.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent event) {} public void keyReleased(KeyEvent event) { if (event.getKeyChar() == KeyEvent.VK_ESCAPE) { System.exit(0); } } public void keyTyped(KeyEvent event) {} } ); frame.setUndecorated(true); JLabel label = new JLabel("."); label.setBackground(Color.BLACK); label.setForeground(Color.WHITE); label.setOpaque(true); label.setHorizontalAlignment(SwingConstants.CENTER); frame.getContentPane().add(label); GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().setFullScreenWindow(frame); final int fontStyle = Font.BOLD; final String fontName = "SansSerif"; int fontSizeNumber = determineFontSize(frame, Toolkit.getDefaultToolkit().getScreenSize().width, fontName, fontStyle, formatter.format(88888888)); int fontSizeText = determineFontSize(frame, Toolkit.getDefaultToolkit().getScreenSize().width, fontName, fontStyle, "Happy 8888!"); label.setFont(new Font(fontName, fontStyle, Math.min(fontSizeNumber, fontSizeText))); new HappyNewYear(frame, label).run(); } 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
  • 3. Crosscutting Concerns import java.io.*; import java.util.zip.*; /** * Command line program to copy a file to another directory. * @author Marco Schmidt */ public class CopyFile { // constant values for the override option public static final int OVERWRITE_ALWAYS = 1; public static final int OVERWRITE_NEVER = 2; public static final int OVERWRITE_ASK = 3; // program options initialized to default values private static int bufferSize = 4 * 1024; private static boolean clock = true; private static boolean copyOriginalTimestamp = true; private static boolean verify = true; private static int override = OVERWRITE_ASK; public static Long copyFile(File srcFile, File destFile) throws IOException { InputStream in = new FileInputStream(srcFile); OutputStream out = new FileOutputStream(destFile); long millis = System.currentTimeMillis(); CRC32 checksum = null; if (verify) { checksum = new CRC32(); checksum.reset(); } byte[] buffer = new byte[bufferSize]; int bytesRead; while ((bytesRead = in.read(buffer)) >= 0) { if (verify) { checksum.update(buffer, 0, bytesRead); } out.write(buffer, 0, bytesRead); } out.close(); in.close(); if (clock) { millis = System.currentTimeMillis() - millis; System.out.println("Second(s): " + (millis/1000L)); } if (verify) { return new Long(checksum.getValue()); } else { return null; } } public static Long createChecksum(File file) throws IOException { long millis = System.currentTimeMillis(); InputStream in = new FileInputStream(file); CRC32 checksum = new CRC32(); checksum.reset(); byte[] buffer = new byte[bufferSize]; int bytesRead; while ((bytesRead = in.read(buffer)) >= 0) { checksum.update(buffer, 0, bytesRead); } in.close(); if (clock) { millis = System.currentTimeMillis() - millis; System.out.println("Second(s): " + (millis/1000L)); } return new Long(checksum.getValue()); } /** * Determine if data is to be copied to given file. * 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 * @return true if data is to be copied to file, false if not */ public static boolean doCopy(File file) { boolean exists = file.exists(); if (override == OVERWRITE_ALWAYS || !exists) { return true; } else if (override == OVERWRITE_NEVER) { return false; } else if (override == OVERWRITE_ASK) { return readYesNoFromStandardInput("File exists. " + "Overwrite (y/n)?"); } else { throw new InternalError("Program error. Invalid " + "value for override: " + override); } } public static void main(String[] args) throws IOException { // make sure there are exactly two arguments if (args.length != 2) { System.err.println("Usage: CopyFile SRC-FILE-NAME DEST-DIR-NAME"); System.exit(1); } // make sure the source file is indeed a readable file File srcFile = new File(args[0]); if (!srcFile.isFile() || !srcFile.canRead()) { System.err.println("Not a readable file: " + srcFile.getName()); System.exit(1); } // make sure the second argument is a directory File destDir = new File(args[1]); if (!destDir.isDirectory()) { System.err.println("Not a directory: " + destDir.getName()); System.exit(1); } // create File object for destination file File destFile = new File(destDir, srcFile.getName()); // check if copying is desired given overwrite option if (!doCopy(destFile)) { return; } // copy file, optionally creating a checksum Long checksumSrc = copyFile(srcFile, destFile); // copy timestamp of last modification if (copyOriginalTimestamp) { if (!destFile.setLastModified(srcFile.lastModified())) { System.err.println("Error: Could not set " + "timestamp of copied file."); } } // optionally verify file if (verify) { System.out.print("Verifying destination file..."); Long checksumDest = createChecksum(destFile); if (checksumSrc.equals(checksumDest)) { System.out.println(" OK, files are equal."); } else { System.out.println(" Error: Checksums differ."); } } } /** * Print a message to standard output and read lines from * standard input until yes or no (y or n) is entered. * @param message informative text to be answered by user * @return user answer, true for yes, false for no. */ public static boolean readYesNoFromStandardInput(String message) { System.out.println(message); String line; BufferedReader in = new BufferedReader(new InputStreamReader( System.in)); Boolean answer = null; try { while ((line = in.readLine()) != null) { line = line.toLowerCase(); if ("y".equals(line) || "yes".equals(line)) { answer = Boolean.TRUE; break; } else if ("n".equals(line) || "no".equals(line)) { answer = Boolean.FALSE; break; } else { System.out.println("Could not understand answer ("" + line + ""). Please use y for yes or n for no."); } } if (answer == null) { throw new IOException("Unexpected end of input from stdin."); } in.close(); return answer.booleanValue(); } catch (IOException ioe) { throw new InternalError( "Cannot read from stdin or write to stdout."); } } } */ public class FileDownload { 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)); conn = url.openConnection(); in = conn.getInputStream(); byte[] buffer = new byte[1024]; int numRead; long numWritten = 0; while ((numRead = in.read(buffer)) != -1) { out.write(buffer, 0, numRead); numWritten += numRead; } System.out.println(localFileName + "t" + numWritten); } catch (Exception exception) { exception.printStackTrace(); } finally { try { if (in != null) { in.close(); } if (out != null) { out.close(); } } catch (IOException ioe) { } } } public static void download(String address) { int lastSlashIndex = address.lastIndexOf('/'); if (lastSlashIndex >= 0 && lastSlashIndex < address.length() - 1) { download(address, address.substring(lastSlashIndex + 1)); } else { System.err.println("Could not figure out local file name for " + address); } } public static void main(String[] args) { for (int i = 0; i < args.length; i++) { download(args[i]); } } } */ public class HappyNewYear implements Runnable { private static NumberFormat formatter = NumberFormat.getInstance(); private JFrame frame; private JLabel label; private long newYearMillis; private String message; public HappyNewYear(JFrame frame, JLabel label) { // store argument GUI elements this.frame = frame; this.label = label; // compute beginning of next year Calendar cal = new GregorianCalendar(); int nextYear = cal.get(Calendar.YEAR) + 1; cal.set(Calendar.YEAR, nextYear); cal.set(Calendar.MONTH, Calendar.JANUARY); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); newYearMillis = cal.getTime().getTime(); // prepare a message message = "Happy " + nextYear + "!"; } public static int determineFontSize(JFrame frame, int componentWidth, String fontName, int fontStyle, String text) { int fontSize = componentWidth * 2 / text.length(); Font font = new Font(fontName, fontStyle, fontSize); FontMetrics fontMetrics = frame.getGraphics(). getFontMetrics(font); int stringWidth = fontMetrics.stringWidth(text); return (int)(fontSize * 0.95 * componentWidth / stringWidth); } public static void main(String[] args) { JFrame frame = new JFrame(); frame.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent event) {} public void keyReleased(KeyEvent event) { if (event.getKeyChar() == KeyEvent.VK_ESCAPE) { System.exit(0); } } public void keyTyped(KeyEvent event) {} } ); frame.setUndecorated(true); JLabel label = new JLabel("."); label.setBackground(Color.BLACK); label.setForeground(Color.WHITE); label.setOpaque(true); label.setHorizontalAlignment(SwingConstants.CENTER); frame.getContentPane().add(label); GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().setFullScreenWindow(frame); final int fontStyle = Font.BOLD; final String fontName = "SansSerif"; int fontSizeNumber = determineFontSize(frame, Toolkit.getDefaultToolkit().getScreenSize().width, fontName, fontStyle, formatter.format(88888888)); int fontSizeText = determineFontSize(frame, Toolkit.getDefaultToolkit().getScreenSize().width, fontName, fontStyle, "Happy 8888!"); label.setFont(new Font(fontName, fontStyle, Math.min(fontSizeNumber, fontSizeText))); new HappyNewYear(frame, label).run(); } 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); } } Synchronization 2
  • 4. Crosscutting Concerns import java.io.*; import java.util.zip.*; /** * Command line program to copy a file to another directory. * @author Marco Schmidt */ public class CopyFile { // constant values for the override option public static final int OVERWRITE_ALWAYS = 1; public static final int OVERWRITE_NEVER = 2; public static final int OVERWRITE_ASK = 3; // program options initialized to default values private static int bufferSize = 4 * 1024; private static boolean clock = true; private static boolean copyOriginalTimestamp = true; private static boolean verify = true; private static int override = OVERWRITE_ASK; public static Long copyFile(File srcFile, File destFile) throws IOException { InputStream in = new FileInputStream(srcFile); OutputStream out = new FileOutputStream(destFile); long millis = System.currentTimeMillis(); CRC32 checksum = null; if (verify) { checksum = new CRC32(); checksum.reset(); } byte[] buffer = new byte[bufferSize]; int bytesRead; while ((bytesRead = in.read(buffer)) >= 0) { if (verify) { checksum.update(buffer, 0, bytesRead); } out.write(buffer, 0, bytesRead); } out.close(); in.close(); if (clock) { millis = System.currentTimeMillis() - millis; System.out.println("Second(s): " + (millis/1000L)); } if (verify) { return new Long(checksum.getValue()); } else { return null; } } public static Long createChecksum(File file) throws IOException { long millis = System.currentTimeMillis(); InputStream in = new FileInputStream(file); CRC32 checksum = new CRC32(); checksum.reset(); byte[] buffer = new byte[bufferSize]; int bytesRead; while ((bytesRead = in.read(buffer)) >= 0) { checksum.update(buffer, 0, bytesRead); } in.close(); if (clock) { millis = System.currentTimeMillis() - millis; System.out.println("Second(s): " + (millis/1000L)); } return new Long(checksum.getValue()); } /** * Determine if data is to be copied to given file. * 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 * @return true if data is to be copied to file, false if not */ public static boolean doCopy(File file) { boolean exists = file.exists(); if (override == OVERWRITE_ALWAYS || !exists) { return true; } else if (override == OVERWRITE_NEVER) { return false; } else if (override == OVERWRITE_ASK) { return readYesNoFromStandardInput("File exists. " + "Overwrite (y/n)?"); } else { throw new InternalError("Program error. Invalid " + "value for override: " + override); } } public static void main(String[] args) throws IOException { // make sure there are exactly two arguments if (args.length != 2) { System.err.println("Usage: CopyFile SRC-FILE-NAME DEST-DIR-NAME"); System.exit(1); } // make sure the source file is indeed a readable file File srcFile = new File(args[0]); if (!srcFile.isFile() || !srcFile.canRead()) { System.err.println("Not a readable file: " + srcFile.getName()); System.exit(1); } // make sure the second argument is a directory File destDir = new File(args[1]); if (!destDir.isDirectory()) { System.err.println("Not a directory: " + destDir.getName()); System.exit(1); } // create File object for destination file File destFile = new File(destDir, srcFile.getName()); // check if copying is desired given overwrite option if (!doCopy(destFile)) { return; } // copy file, optionally creating a checksum Long checksumSrc = copyFile(srcFile, destFile); // copy timestamp of last modification if (copyOriginalTimestamp) { if (!destFile.setLastModified(srcFile.lastModified())) { System.err.println("Error: Could not set " + "timestamp of copied file."); } } // optionally verify file if (verify) { System.out.print("Verifying destination file..."); Long checksumDest = createChecksum(destFile); if (checksumSrc.equals(checksumDest)) { System.out.println(" OK, files are equal."); } else { System.out.println(" Error: Checksums differ."); } } } /** * Print a message to standard output and read lines from * standard input until yes or no (y or n) is entered. * @param message informative text to be answered by user * @return user answer, true for yes, false for no. */ public static boolean readYesNoFromStandardInput(String message) { System.out.println(message); String line; BufferedReader in = new BufferedReader(new InputStreamReader( System.in)); Boolean answer = null; try { while ((line = in.readLine()) != null) { line = line.toLowerCase(); if ("y".equals(line) || "yes".equals(line)) { answer = Boolean.TRUE; break; } else if ("n".equals(line) || "no".equals(line)) { answer = Boolean.FALSE; break; } else { System.out.println("Could not understand answer ("" + line + ""). Please use y for yes or n for no."); } } if (answer == null) { throw new IOException("Unexpected end of input from stdin."); } in.close(); return answer.booleanValue(); } catch (IOException ioe) { throw new InternalError( "Cannot read from stdin or write to stdout."); } } } */ public class FileDownload { 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)); conn = url.openConnection(); in = conn.getInputStream(); byte[] buffer = new byte[1024]; int numRead; long numWritten = 0; while ((numRead = in.read(buffer)) != -1) { out.write(buffer, 0, numRead); numWritten += numRead; } System.out.println(localFileName + "t" + numWritten); } catch (Exception exception) { exception.printStackTrace(); } finally { try { if (in != null) { in.close(); } if (out != null) { out.close(); } } catch (IOException ioe) { } } } public static void download(String address) { int lastSlashIndex = address.lastIndexOf('/'); if (lastSlashIndex >= 0 && lastSlashIndex < address.length() - 1) { download(address, address.substring(lastSlashIndex + 1)); } else { System.err.println("Could not figure out local file name for " + address); } } public static void main(String[] args) { for (int i = 0; i < args.length; i++) { download(args[i]); } } } */ public class HappyNewYear implements Runnable { private static NumberFormat formatter = NumberFormat.getInstance(); private JFrame frame; private JLabel label; private long newYearMillis; private String message; public HappyNewYear(JFrame frame, JLabel label) { // store argument GUI elements this.frame = frame; this.label = label; // compute beginning of next year Calendar cal = new GregorianCalendar(); int nextYear = cal.get(Calendar.YEAR) + 1; cal.set(Calendar.YEAR, nextYear); cal.set(Calendar.MONTH, Calendar.JANUARY); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); newYearMillis = cal.getTime().getTime(); // prepare a message message = "Happy " + nextYear + "!"; } public static int determineFontSize(JFrame frame, int componentWidth, String fontName, int fontStyle, String text) { int fontSize = componentWidth * 2 / text.length(); Font font = new Font(fontName, fontStyle, fontSize); FontMetrics fontMetrics = frame.getGraphics(). getFontMetrics(font); int stringWidth = fontMetrics.stringWidth(text); return (int)(fontSize * 0.95 * componentWidth / stringWidth); } public static void main(String[] args) { JFrame frame = new JFrame(); frame.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent event) {} public void keyReleased(KeyEvent event) { if (event.getKeyChar() == KeyEvent.VK_ESCAPE) { System.exit(0); } } public void keyTyped(KeyEvent event) {} } ); frame.setUndecorated(true); JLabel label = new JLabel("."); label.setBackground(Color.BLACK); label.setForeground(Color.WHITE); label.setOpaque(true); label.setHorizontalAlignment(SwingConstants.CENTER); frame.getContentPane().add(label); GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().setFullScreenWindow(frame); final int fontStyle = Font.BOLD; final String fontName = "SansSerif"; int fontSizeNumber = determineFontSize(frame, Toolkit.getDefaultToolkit().getScreenSize().width, fontName, fontStyle, formatter.format(88888888)); int fontSizeText = determineFontSize(frame, Toolkit.getDefaultToolkit().getScreenSize().width, fontName, fontStyle, "Happy 8888!"); label.setFont(new Font(fontName, fontStyle, Math.min(fontSizeNumber, fontSizeText))); new HappyNewYear(frame, label).run(); } 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); } } Synchronization UI dependency 2
  • 5. Crosscutting Concerns import java.io.*; import java.util.zip.*; /** * Command line program to copy a file to another directory. * @author Marco Schmidt */ public class CopyFile { // constant values for the override option public static final int OVERWRITE_ALWAYS = 1; public static final int OVERWRITE_NEVER = 2; public static final int OVERWRITE_ASK = 3; // program options initialized to default values private static int bufferSize = 4 * 1024; private static boolean clock = true; private static boolean copyOriginalTimestamp = true; private static boolean verify = true; private static int override = OVERWRITE_ASK; public static Long copyFile(File srcFile, File destFile) throws IOException { InputStream in = new FileInputStream(srcFile); OutputStream out = new FileOutputStream(destFile); long millis = System.currentTimeMillis(); CRC32 checksum = null; if (verify) { checksum = new CRC32(); checksum.reset(); } byte[] buffer = new byte[bufferSize]; int bytesRead; while ((bytesRead = in.read(buffer)) >= 0) { if (verify) { checksum.update(buffer, 0, bytesRead); } out.write(buffer, 0, bytesRead); } out.close(); in.close(); if (clock) { millis = System.currentTimeMillis() - millis; System.out.println("Second(s): " + (millis/1000L)); } if (verify) { return new Long(checksum.getValue()); } else { return null; } } public static Long createChecksum(File file) throws IOException { long millis = System.currentTimeMillis(); InputStream in = new FileInputStream(file); CRC32 checksum = new CRC32(); checksum.reset(); byte[] buffer = new byte[bufferSize]; int bytesRead; while ((bytesRead = in.read(buffer)) >= 0) { checksum.update(buffer, 0, bytesRead); } in.close(); if (clock) { millis = System.currentTimeMillis() - millis; System.out.println("Second(s): " + (millis/1000L)); } return new Long(checksum.getValue()); } /** * Determine if data is to be copied to given file. * 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 * @return true if data is to be copied to file, false if not */ public static boolean doCopy(File file) { boolean exists = file.exists(); if (override == OVERWRITE_ALWAYS || !exists) { return true; } else if (override == OVERWRITE_NEVER) { return false; } else if (override == OVERWRITE_ASK) { return readYesNoFromStandardInput("File exists. " + "Overwrite (y/n)?"); } else { throw new InternalError("Program error. Invalid " + "value for override: " + override); } } public static void main(String[] args) throws IOException { // make sure there are exactly two arguments if (args.length != 2) { System.err.println("Usage: CopyFile SRC-FILE-NAME DEST-DIR-NAME"); System.exit(1); } // make sure the source file is indeed a readable file File srcFile = new File(args[0]); if (!srcFile.isFile() || !srcFile.canRead()) { System.err.println("Not a readable file: " + srcFile.getName()); System.exit(1); } // make sure the second argument is a directory File destDir = new File(args[1]); if (!destDir.isDirectory()) { System.err.println("Not a directory: " + destDir.getName()); System.exit(1); } // create File object for destination file File destFile = new File(destDir, srcFile.getName()); // check if copying is desired given overwrite option if (!doCopy(destFile)) { return; } // copy file, optionally creating a checksum Long checksumSrc = copyFile(srcFile, destFile); // copy timestamp of last modification if (copyOriginalTimestamp) { if (!destFile.setLastModified(srcFile.lastModified())) { System.err.println("Error: Could not set " + "timestamp of copied file."); } } // optionally verify file if (verify) { System.out.print("Verifying destination file..."); Long checksumDest = createChecksum(destFile); if (checksumSrc.equals(checksumDest)) { System.out.println(" OK, files are equal."); } else { System.out.println(" Error: Checksums differ."); } } } /** * Print a message to standard output and read lines from * standard input until yes or no (y or n) is entered. * @param message informative text to be answered by user * @return user answer, true for yes, false for no. */ public static boolean readYesNoFromStandardInput(String message) { System.out.println(message); String line; BufferedReader in = new BufferedReader(new InputStreamReader( System.in)); Boolean answer = null; try { while ((line = in.readLine()) != null) { line = line.toLowerCase(); if ("y".equals(line) || "yes".equals(line)) { answer = Boolean.TRUE; break; } else if ("n".equals(line) || "no".equals(line)) { answer = Boolean.FALSE; break; } else { System.out.println("Could not understand answer ("" + line + ""). Please use y for yes or n for no."); } } if (answer == null) { throw new IOException("Unexpected end of input from stdin."); } in.close(); return answer.booleanValue(); } catch (IOException ioe) { throw new InternalError( "Cannot read from stdin or write to stdout."); } } } */ public class FileDownload { 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)); conn = url.openConnection(); in = conn.getInputStream(); byte[] buffer = new byte[1024]; int numRead; long numWritten = 0; while ((numRead = in.read(buffer)) != -1) { out.write(buffer, 0, numRead); numWritten += numRead; } System.out.println(localFileName + "t" + numWritten); } catch (Exception exception) { exception.printStackTrace(); } finally { try { if (in != null) { in.close(); } if (out != null) { out.close(); } } catch (IOException ioe) { } } } public static void download(String address) { int lastSlashIndex = address.lastIndexOf('/'); if (lastSlashIndex >= 0 && lastSlashIndex < address.length() - 1) { download(address, address.substring(lastSlashIndex + 1)); } else { System.err.println("Could not figure out local file name for " + address); } } public static void main(String[] args) { for (int i = 0; i < args.length; i++) { download(args[i]); } } } */ public class HappyNewYear implements Runnable { private static NumberFormat formatter = NumberFormat.getInstance(); private JFrame frame; private JLabel label; private long newYearMillis; private String message; public HappyNewYear(JFrame frame, JLabel label) { // store argument GUI elements this.frame = frame; this.label = label; // compute beginning of next year Calendar cal = new GregorianCalendar(); int nextYear = cal.get(Calendar.YEAR) + 1; cal.set(Calendar.YEAR, nextYear); cal.set(Calendar.MONTH, Calendar.JANUARY); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); newYearMillis = cal.getTime().getTime(); // prepare a message message = "Happy " + nextYear + "!"; } public static int determineFontSize(JFrame frame, int componentWidth, String fontName, int fontStyle, String text) { int fontSize = componentWidth * 2 / text.length(); Font font = new Font(fontName, fontStyle, fontSize); FontMetrics fontMetrics = frame.getGraphics(). getFontMetrics(font); int stringWidth = fontMetrics.stringWidth(text); return (int)(fontSize * 0.95 * componentWidth / stringWidth); } public static void main(String[] args) { JFrame frame = new JFrame(); frame.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent event) {} public void keyReleased(KeyEvent event) { if (event.getKeyChar() == KeyEvent.VK_ESCAPE) { System.exit(0); } } public void keyTyped(KeyEvent event) {} } ); frame.setUndecorated(true); JLabel label = new JLabel("."); label.setBackground(Color.BLACK); label.setForeground(Color.WHITE); label.setOpaque(true); label.setHorizontalAlignment(SwingConstants.CENTER); frame.getContentPane().add(label); GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().setFullScreenWindow(frame); final int fontStyle = Font.BOLD; final String fontName = "SansSerif"; int fontSizeNumber = determineFontSize(frame, Toolkit.getDefaultToolkit().getScreenSize().width, fontName, fontStyle, formatter.format(88888888)); int fontSizeText = determineFontSize(frame, Toolkit.getDefaultToolkit().getScreenSize().width, fontName, fontStyle, "Happy 8888!"); label.setFont(new Font(fontName, fontStyle, Math.min(fontSizeNumber, fontSizeText))); new HappyNewYear(frame, label).run(); } 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); } } Scattering & Tangling Synchronization UI dependency 2
  • 6. AOP import java.io.*; import java.util.zip.*; /** * Command line program to copy a file to another directory. * @author Marco Schmidt */ public class CopyFile { // constant values for the override option public static final int OVERWRITE_ALWAYS = 1; public static final int OVERWRITE_NEVER = 2; public static final int OVERWRITE_ASK = 3; // program options initialized to default values private static int bufferSize = 4 * 1024; private static boolean clock = true; public static Long copyFile(File srcFile, File destFile) throws IOException { } byte[] buffer = new byte[bufferSize]; int bytesRead; while ((bytesRead = in.read(buffer)) >= 0) { if (verify) { checksum.update(buffer, 0, bytesRead); } return new Long(checksum.getValue()); } else { return null; } } public static Long createChecksum(File file) throws IOException { long millis = System.currentTimeMillis(); InputStream in = new FileInputStream(file); byte[] buffer = new byte[bufferSize]; int bytesRead; while ((bytesRead = in.read(buffer)) >= 0) { checksum.update(buffer, 0, bytesRead); } in.close(); if (clock) { millis = System.currentTimeMillis() - millis; System.out.println("Second(s): " + (millis/1000L)); } return new Long(checksum.getValue()); } /** * Determine if data is to be copied to given file. * @param file File object for potential destination file * @return true if data is to be copied to file, false if not */ public static boolean doCopy(File file) { boolean exists = file.exists(); if (override == OVERWRITE_ALWAYS || !exists) { return true; } else } else { throw new InternalError("Program error. Invalid " + "value for override: " + override); } } public static void main(String[] args) throws IOException { // make sure there are exactly two arguments if (args.length != 2) { System.err.println("Usage: CopyFile SRC-FILE-NAME DEST-DIR-NAME"); System.exit(1); } // make sure the source file is indeed a readable file File srcFile = new File(args[0]); if (!srcFile.isFile() || !srcFile.canRead()) { System.err.println("Not a readable file: " + srcFile.getName()); System.exit(1); } // make sure the second argument is a directory File destDir = new File(args[1]); if (!destDir.isDirectory()) { System.err.println("Not a directory: " + destDir.getName()); System.exit(1); } // create File object for destination file File destFile = new File(destDir, srcFile.getName()); // check if copying is desired given overwrite option if (!doCopy(destFile)) { return; } // copy timestamp of last modification } /** * @return user answer, true for yes, false for no. */ public static boolean readYesNoFromStandardInput(String message) { System.out.println(message); String line; BufferedReader in = new BufferedReader(new InputStreamReader( System.in)); Boolean answer = null; try { while ((line = in.readLine()) != null) { line = line.toLowerCase(); if ("y".equals(line) || "yes".equals(line)) { answer = Boolean.TRUE; break; } else if ("n".equals(line) || "no".equals(line)) { answer = Boolean.FALSE; break; } else { System.out.println("Could not understand answer ("" + line + ""). Please use y for yes or n for no."); } } catch (IOException ioe) { } } } */ public class FileDownload { public static void download(String address, String localFileName) { OutputStream out = null; URLConnection conn = null; InputStream in = null; try { conn = url.openConnection(); in = conn.getInputStream(); byte[] buffer = new byte[1024]; int numRead; long numWritten = 0; while ((numRead = in.read(buffer)) != -1) { out.write(buffer, 0, numRead); numWritten += numRead; } finally { try { if (in != null) { in.close(); } if (out != null) { out.close(); } } catch (IOException ioe) { } } } public static void download(String address) { int lastSlashIndex = address.lastIndexOf('/'); System.err.println("Could not figure out local file name for " + address); } } public static void main(String[] args) { for (int i = 0; i < args.length; i++) { download(args[i]); } } } */ public class HappyNewYear implements Runnable { private static NumberFormat formatter = NumberFormat.getInstance(); private JFrame frame; private JLabel label; private long newYearMillis; private String message; public HappyNewYear(JFrame frame, JLabel label) { cal.set(Calendar.YEAR, nextYear); cal.set(Calendar.MONTH, Calendar.JANUARY); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); newYearMillis = cal.getTime().getTime(); // prepare a message message = "Happy " + nextYear + "!"; } public static int determineFontSize(JFrame frame, int componentWidth, String fontName, int fontStyle, String text) { return (int)(fontSize * 0.95 * componentWidth / stringWidth); } public static void main(String[] args) { JFrame frame = new JFrame(); frame.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent event) {} public void keyReleased(KeyEvent event) { if (event.getKeyChar() == KeyEvent.VK_ESCAPE) { System.exit(0); } } public void keyTyped(KeyEvent event) {} } ); frame.setUndecorated(true); JLabel label = new JLabel("."); label.setBackground(Color.BLACK); label.setForeground(Color.WHITE); label.setOpaque(true); label.setHorizontalAlignment(SwingConstants.CENTER); frame.getContentPane().add(label); GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().setFullScreenWindow(frame); final int fontStyle = Font.BOLD; label.setFont(new Font(fontName, fontStyle, Math.min(fontSizeNumber, fontSizeText))); new HappyNewYear(frame, label).run(); } public void run() { boolean newYear = false; do { newYear = true; output = message; } else { // make a String from the number of seconds output = formatter.format(remaining); } label.setText(output); try { Thread.sleep(1000); } } Modularized public static Long createChecksum(File file) throws IOException { long millis = System.currentTimeMillis(); InputStream in = new FileInputStream(file); byte[] buffer = new byte[bufferSize]; int bytesRead; while ((bytesRead = in.read(buffer)) >= 0) { checksum.update(buffer, 0, bytesRead); } in.close(); if (clock) { millis = System.currentTimeMillis() - millis; System.out.println("Second(s): " + (millis/1000L)); } return new Long(checksum.getValue()); } public static Long createChecksum(File file) throws IOException { public HappyNewYear(JFrame frame, JLabel label) { cal.set(Calendar.YEAR, nextYear); cal.set(Calendar.MONTH, Calendar.JANUARY); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); newYearMillis = cal.getTime().getTime(); // prepare a message message = "Happy " + nextYear + "!"; } 3
  • 7. Pointcuts import java.io.*; import java.util.zip.*; /** * Command line program to copy a file to another directory. * @author Marco Schmidt */ public class CopyFile { // constant values for the override option public static final int OVERWRITE_ALWAYS = 1; public static final int OVERWRITE_NEVER = 2; public static final int OVERWRITE_ASK = 3; // program options initialized to default values private static int bufferSize = 4 * 1024; private static boolean clock = true; public static Long copyFile(File srcFile, File destFile) throws IOException { } byte[] buffer = new byte[bufferSize]; int bytesRead; while ((bytesRead = in.read(buffer)) >= 0) { if (verify) { checksum.update(buffer, 0, bytesRead); } return new Long(checksum.getValue()); } else { return null; } } public static Long createChecksum(File file) throws IOException { long millis = System.currentTimeMillis(); InputStream in = new FileInputStream(file); byte[] buffer = new byte[bufferSize]; int bytesRead; while ((bytesRead = in.read(buffer)) >= 0) { checksum.update(buffer, 0, bytesRead); } in.close(); if (clock) { millis = System.currentTimeMillis() - millis; System.out.println("Second(s): " + (millis/1000L)); } return new Long(checksum.getValue()); } /** * Determine if data is to be copied to given file. * @param file File object for potential destination file * @return true if data is to be copied to file, false if not */ public static boolean doCopy(File file) { boolean exists = file.exists(); if (override == OVERWRITE_ALWAYS || !exists) { return true; } else } else { throw new InternalError("Program error. Invalid " + "value for override: " + override); } } public static void main(String[] args) throws IOException { // make sure there are exactly two arguments if (args.length != 2) { System.err.println("Usage: CopyFile SRC-FILE-NAME DEST-DIR-NAME"); System.exit(1); } // make sure the source file is indeed a readable file File srcFile = new File(args[0]); if (!srcFile.isFile() || !srcFile.canRead()) { System.err.println("Not a readable file: " + srcFile.getName()); System.exit(1); } // make sure the second argument is a directory File destDir = new File(args[1]); if (!destDir.isDirectory()) { System.err.println("Not a directory: " + destDir.getName()); System.exit(1); } // create File object for destination file File destFile = new File(destDir, srcFile.getName()); // check if copying is desired given overwrite option if (!doCopy(destFile)) { return; } // copy timestamp of last modification } /** * @return user answer, true for yes, false for no. */ public static boolean readYesNoFromStandardInput(String message) { System.out.println(message); String line; BufferedReader in = new BufferedReader(new InputStreamReader( System.in)); Boolean answer = null; try { while ((line = in.readLine()) != null) { line = line.toLowerCase(); if ("y".equals(line) || "yes".equals(line)) { answer = Boolean.TRUE; break; } else if ("n".equals(line) || "no".equals(line)) { answer = Boolean.FALSE; break; } else { System.out.println("Could not understand answer ("" + line + ""). Please use y for yes or n for no."); } } catch (IOException ioe) { } } } */ public class FileDownload { public static void download(String address, String localFileName) { OutputStream out = null; URLConnection conn = null; InputStream in = null; try { conn = url.openConnection(); in = conn.getInputStream(); byte[] buffer = new byte[1024]; int numRead; long numWritten = 0; while ((numRead = in.read(buffer)) != -1) { out.write(buffer, 0, numRead); numWritten += numRead; } finally { try { if (in != null) { in.close(); } if (out != null) { out.close(); } } catch (IOException ioe) { } } } public static void download(String address) { int lastSlashIndex = address.lastIndexOf('/'); System.err.println("Could not figure out local file name for " + address); } } public static void main(String[] args) { for (int i = 0; i < args.length; i++) { download(args[i]); } } } */ public class HappyNewYear implements Runnable { private static NumberFormat formatter = NumberFormat.getInstance(); private JFrame frame; private JLabel label; private long newYearMillis; private String message; public HappyNewYear(JFrame frame, JLabel label) { cal.set(Calendar.YEAR, nextYear); cal.set(Calendar.MONTH, Calendar.JANUARY); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); newYearMillis = cal.getTime().getTime(); // prepare a message message = "Happy " + nextYear + "!"; } public static int determineFontSize(JFrame frame, int componentWidth, String fontName, int fontStyle, String text) { return (int)(fontSize * 0.95 * componentWidth / stringWidth); } public static void main(String[] args) { JFrame frame = new JFrame(); frame.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent event) {} public void keyReleased(KeyEvent event) { if (event.getKeyChar() == KeyEvent.VK_ESCAPE) { System.exit(0); } } public void keyTyped(KeyEvent event) {} } ); frame.setUndecorated(true); JLabel label = new JLabel("."); label.setBackground(Color.BLACK); label.setForeground(Color.WHITE); label.setOpaque(true); label.setHorizontalAlignment(SwingConstants.CENTER); frame.getContentPane().add(label); GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().setFullScreenWindow(frame); final int fontStyle = Font.BOLD; label.setFont(new Font(fontName, fontStyle, Math.min(fontSizeNumber, fontSizeText))); new HappyNewYear(frame, label).run(); } public void run() { boolean newYear = false; do { newYear = true; output = message; } else { // make a String from the number of seconds output = formatter.format(remaining); } label.setText(output); try { Thread.sleep(1000); } } public static Long createChecksum(File file) throws IOException { long millis = System.currentTimeMillis(); InputStream in = new FileInputStream(file); byte[] buffer = new byte[bufferSize]; int bytesRead; while ((bytesRead = in.read(buffer)) >= 0) { checksum.update(buffer, 0, bytesRead); } in.close(); if (clock) { millis = System.currentTimeMillis() - millis; System.out.println("Second(s): " + (millis/1000L)); } return new Long(checksum.getValue()); } public static Long createChecksum(File file) throws IOException { public HappyNewYear(JFrame frame, JLabel label) { cal.set(Calendar.YEAR, nextYear); cal.set(Calendar.MONTH, Calendar.JANUARY); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); newYearMillis = cal.getTime().getTime(); // prepare a message message = "Happy " + nextYear + "!"; } Often point to details in source code (e.g. names) 4
  • 8. Pointcuts import java.io.*; import java.util.zip.*; /** * Command line program to copy a file to another directory. * @author Marco Schmidt */ public class CopyFile { // constant values for the override option public static final int OVERWRITE_ALWAYS = 1; public static final int OVERWRITE_NEVER = 2; public static final int OVERWRITE_ASK = 3; // program options initialized to default values private static int bufferSize = 4 * 1024; private static boolean clock = true; public static Long copyFile(File srcFile, File destFile) throws IOException { } byte[] buffer = new byte[bufferSize]; int bytesRead; while ((bytesRead = in.read(buffer)) >= 0) { if (verify) { checksum.update(buffer, 0, bytesRead); } return new Long(checksum.getValue()); } else { return null; } } public static Long createChecksum(File file) throws IOException { long millis = System.currentTimeMillis(); InputStream in = new FileInputStream(file); byte[] buffer = new byte[bufferSize]; int bytesRead; while ((bytesRead = in.read(buffer)) >= 0) { checksum.update(buffer, 0, bytesRead); } in.close(); if (clock) { millis = System.currentTimeMillis() - millis; System.out.println("Second(s): " + (millis/1000L)); } return new Long(checksum.getValue()); } /** * Determine if data is to be copied to given file. * @param file File object for potential destination file * @return true if data is to be copied to file, false if not */ public static boolean doCopy(File file) { boolean exists = file.exists(); if (override == OVERWRITE_ALWAYS || !exists) { return true; } else } else { throw new InternalError("Program error. Invalid " + "value for override: " + override); } } public static void main(String[] args) throws IOException { // make sure there are exactly two arguments if (args.length != 2) { System.err.println("Usage: CopyFile SRC-FILE-NAME DEST-DIR-NAME"); System.exit(1); } // make sure the source file is indeed a readable file File srcFile = new File(args[0]); if (!srcFile.isFile() || !srcFile.canRead()) { System.err.println("Not a readable file: " + srcFile.getName()); System.exit(1); } // make sure the second argument is a directory File destDir = new File(args[1]); if (!destDir.isDirectory()) { System.err.println("Not a directory: " + destDir.getName()); System.exit(1); } // create File object for destination file File destFile = new File(destDir, srcFile.getName()); // check if copying is desired given overwrite option if (!doCopy(destFile)) { return; } // copy timestamp of last modification } /** * @return user answer, true for yes, false for no. */ public static boolean readYesNoFromStandardInput(String message) { System.out.println(message); String line; BufferedReader in = new BufferedReader(new InputStreamReader( System.in)); Boolean answer = null; try { while ((line = in.readLine()) != null) { line = line.toLowerCase(); if ("y".equals(line) || "yes".equals(line)) { answer = Boolean.TRUE; break; } else if ("n".equals(line) || "no".equals(line)) { answer = Boolean.FALSE; break; } else { System.out.println("Could not understand answer ("" + line + ""). Please use y for yes or n for no."); } } catch (IOException ioe) { } } } */ public class FileDownload { public static void download(String address, String localFileName) { OutputStream out = null; URLConnection conn = null; InputStream in = null; try { conn = url.openConnection(); in = conn.getInputStream(); byte[] buffer = new byte[1024]; int numRead; long numWritten = 0; while ((numRead = in.read(buffer)) != -1) { out.write(buffer, 0, numRead); numWritten += numRead; } finally { try { if (in != null) { in.close(); } if (out != null) { out.close(); } } catch (IOException ioe) { } } } public static void download(String address) { int lastSlashIndex = address.lastIndexOf('/'); System.err.println("Could not figure out local file name for " + address); } } public static void main(String[] args) { for (int i = 0; i < args.length; i++) { download(args[i]); } } } */ public class HappyNewYear implements Runnable { private static NumberFormat formatter = NumberFormat.getInstance(); private JFrame frame; private JLabel label; private long newYearMillis; private String message; public HappyNewYear(JFrame frame, JLabel label) { cal.set(Calendar.YEAR, nextYear); cal.set(Calendar.MONTH, Calendar.JANUARY); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); newYearMillis = cal.getTime().getTime(); // prepare a message message = "Happy " + nextYear + "!"; } public static int determineFontSize(JFrame frame, int componentWidth, String fontName, int fontStyle, String text) { return (int)(fontSize * 0.95 * componentWidth / stringWidth); } public static void main(String[] args) { JFrame frame = new JFrame(); frame.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent event) {} public void keyReleased(KeyEvent event) { if (event.getKeyChar() == KeyEvent.VK_ESCAPE) { System.exit(0); } } public void keyTyped(KeyEvent event) {} } ); frame.setUndecorated(true); JLabel label = new JLabel("."); label.setBackground(Color.BLACK); label.setForeground(Color.WHITE); label.setOpaque(true); label.setHorizontalAlignment(SwingConstants.CENTER); frame.getContentPane().add(label); GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().setFullScreenWindow(frame); final int fontStyle = Font.BOLD; label.setFont(new Font(fontName, fontStyle, Math.min(fontSizeNumber, fontSizeText))); new HappyNewYear(frame, label).run(); } public void run() { boolean newYear = false; do { newYear = true; output = message; } else { // make a String from the number of seconds output = formatter.format(remaining); } label.setText(output); try { Thread.sleep(1000); } } public static Long createChecksum(File file) throws IOException { long millis = System.currentTimeMillis(); InputStream in = new FileInputStream(file); byte[] buffer = new byte[bufferSize]; int bytesRead; while ((bytesRead = in.read(buffer)) >= 0) { checksum.update(buffer, 0, bytesRead); } in.close(); if (clock) { millis = System.currentTimeMillis() - millis; System.out.println("Second(s): " + (millis/1000L)); } return new Long(checksum.getValue()); } public static Long createChecksum(File file) throws IOException { public HappyNewYear(JFrame frame, JLabel label) { cal.set(Calendar.YEAR, nextYear); cal.set(Calendar.MONTH, Calendar.JANUARY); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); newYearMillis = cal.getTime().getTime(); // prepare a message message = "Happy " + nextYear + "!"; } Often point to details in source code (e.g. names) 4
  • 9. AsBeforeAfterAdvice qualifier:... pointcut: [WindowSensor withAllSubclasses select: [:each includesSelector: #eventDoubleClick:] thenCollect:[:each | AsJoinPointDescriptor targetClass: each targetSelector:#eventDoubleClick:]] beforeBlock: [:receiver :args :aspect :client | ...] Aspects in Smalltalk 5 AspectS •Framework based •Pointcut using Smalltalk •Advice using block
  • 10. AsBeforeAfterAdvice qualifier:... pointcut: [WindowSensor withAllSubclasses select: [:each includesSelector: #eventDoubleClick:] thenCollect:[:each | AsJoinPointDescriptor targetClass: each targetSelector:#eventDoubleClick:]] beforeBlock: [:receiver :args :aspect :client | ...] Aspects in Smalltalk 5 AspectS •Framework based •Pointcut using Smalltalk •Advice using block Pointcut
  • 11. AsBeforeAfterAdvice qualifier:... pointcut: [WindowSensor withAllSubclasses select: [:each includesSelector: #eventDoubleClick:] thenCollect:[:each | AsJoinPointDescriptor targetClass: each targetSelector:#eventDoubleClick:]] beforeBlock: [:receiver :args :aspect :client | ...] Aspects in Smalltalk 5 AspectS •Framework based •Pointcut using Smalltalk •Advice using block Pointcut Advice
  • 12. after ?jp matching reception(?jp, #eventDoubleClick:,?args), within(?jp, ?class, ?selector), classInHierarchyOf(?class,[WindowSensor]) do Transcript show: ?class. ... Aspects in Carma 6 Carma •Pointcut language •Declarative Meta Programming •Based on SOUL
  • 13. after ?jp matching reception(?jp, #eventDoubleClick:,?args), within(?jp, ?class, ?selector), classInHierarchyOf(?class,[WindowSensor]) do Transcript show: ?class. ... Aspects in Carma 6 Carma •Pointcut language •Declarative Meta Programming •Based on SOUL •Declarative •Unification •Recursion
  • 14. after ?jp matching reception(?jp, #eventDoubleClick:,?args), within(?jp, ?class, ?selector), classInHierarchyOf(?class,[WindowSensor]) do Transcript show: ?class. ... Aspects in Carma 6 Carma •Pointcut language •Declarative Meta Programming •Based on SOUL Pointcut •Declarative •Unification •Recursion
  • 15. after ?jp matching reception(?jp, #eventDoubleClick:,?args), within(?jp, ?class, ?selector), classInHierarchyOf(?class,[WindowSensor]) do Transcript show: ?class. ... Aspects in Carma 6 Carma •Pointcut language •Declarative Meta Programming •Based on SOUL Pointcut Advice •Declarative •Unification •Recursion
  • 17. AspectSOUL 7 AspectS •Framework Carma •Pointcuts AsCARMABeforeAfterAdvice qualifier:... pointcutQuery: ‘reception(?jp, #eventDoubleClick:,?args), within(?jp, ?class, ?selector), classInHierarchyOf(?class,[WindowSensor])’ beforeBlock: [:receiver :args :aspect :client | ...]
  • 18. AspectSOUL 7 AspectS •Framework Carma •Pointcuts AsCARMABeforeAfterAdvice qualifier:... pointcutQuery: ‘reception(?jp, #eventDoubleClick:,?args), within(?jp, ?class, ?selector), classInHierarchyOf(?class,[WindowSensor])’ beforeBlock: [:receiver :args :aspect :client | ...] Pointcut
  • 19. AspectSOUL 7 AspectS •Framework Carma •Pointcuts AsCARMABeforeAfterAdvice qualifier:... pointcutQuery: ‘reception(?jp, #eventDoubleClick:,?args), within(?jp, ?class, ?selector), classInHierarchyOf(?class,[WindowSensor])’ beforeBlock: [:receiver :args :aspect :client | ...] Pointcut Advice
  • 20. Fragility Person>>name ^name Person>>name: anObject name := anObject 8 1.accessing protocol 2.selector corresponds to variable name
  • 21. Fragility Person>>name ^name Person>>name: anObject name := anObject 8 class(?class), methodWithNameInClass(?method,?accessor,?class), instanceVariableInClassChain(?accessor,?class), methodInProtocol(?method,accessing), reception(?joinpoint,?accessor,?args), withinClass(?joinpoint,?class) Synchronization 1.accessing protocol 2.selector corresponds to variable name
  • 22. Fragility Person>>name ^name Person>>name: anObject name := anObject 8 class(?class), methodWithNameInClass(?method,?accessor,?class), instanceVariableInClassChain(?accessor,?class), methodInProtocol(?method,accessing), reception(?joinpoint,?accessor,?args), withinClass(?joinpoint,?class) Synchronization 1.accessing protocol 2.selector corresponds to variable name Person>>getName ^name Person>>setName: anObject name := anObject
  • 23. Fragility Person>>name ^name Person>>name: anObject name := anObject 8 1.accessing protocol 2.selector corresponds to variable name Person>>getName ^name Person>>setName: anObject name := anObject X class(?class), methodWithNameInClass(?method,?accessor,?class), instanceVariableInClassChain(?accessor,?class), methodInProtocol(?method,accessing), reception(?joinpoint,?accessor,?args), withinClass(?joinpoint,?class) Synchronization ? ?
  • 24. Complexity Person>>name ^name Person>>name: anObject name := anObject 9 1.accessor: return instance var 2.mutator: assign instance var
  • 25. Complexity Person>>name ^name Person>>name: anObject name := anObject 9 1.accessor: return instance var 2.mutator: assign instance var class(?class), methodWithNameInClass(?method,?accessor,?class), instanceVariableInClassChain(?accessor,?class), returnStatement(?method,variable(?var)), reception(?joinpoint,?accessor,?args), withinClass(?joinpoint,?class) Synchronization
  • 26. Complexity Person>>name ^name Person>>name: anObject name := anObject 9 1.accessor: return instance var 2.mutator: assign instance var class(?class), methodWithNameInClass(?method,?accessor,?class), instanceVariableInClassChain(?accessor,?class), returnStatement(?method,variable(?var)), reception(?joinpoint,?accessor,?args), withinClass(?joinpoint,?class) Synchronization Person>>friends ^friends isNil ifTrue:[friends := Set new] ifFalse:[friends] ?
  • 27. class(?class), methodWithNameInClass(?method,?accessor,?class), instanceVariableInClassChain(?accessor,?class), returnStatement(?method,variable(?var)), reception(?joinpoint,?accessor,?args), withinClass(?joinpoint,?class) Synchronisationclass(?class), methodWithNameInClass(?method,?accessor,?class), instanceVariableInClassChain(?accessor,?class), returnStatement(?method,variable(?var)), reception(?joinpoint,?accessor,?args), withinClass(?joinpoint,?class) Synchronisation Complexity Person>>name ^name Person>>name: anObject name := anObject 9 1.accessor: return instance var 2.mutator: assign instance var class(?class), methodWithNameInClass(?method,?accessor,?class), instanceVariableInClassChain(?accessor,?class), returnStatement(?method,variable(?var)), reception(?joinpoint,?accessor,?args), withinClass(?joinpoint,?class) Synchronization Person>>friends ^friends isNil ifTrue:[friends := Set new] ifFalse:[friends] ?
  • 28. Problem Analysis 10 Source code based pointcut (defined directly in terms of source code) Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name * 1 * 1 * 1 Source code Base program developer Aspect developer
  • 29. Problem Analysis 10 Source code based pointcut (defined directly in terms of source code) Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name * 1 * 1 * 1 Source code Tight coupling Base program developer Aspect developer
  • 30. Problem Analysis 10 Source code based pointcut (defined directly in terms of source code) Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name * 1 * 1 * 1 Source code Tight coupling Complex Base program developer Aspect developer
  • 31. Problem Analysis 10 Source code based pointcut (defined directly in terms of source code) Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name * 1 * 1 * 1 Source code Tight coupling Complex Fragile Base program developer Aspect developer
  • 32. Application-specific 11 Source code based pointcut (defined directly in terms of source code) Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name * 1 * 1 * 1 Source code Base program developer Aspect developer
  • 33. Application-specific 11 Source code based pointcut (defined directly in terms of source code) Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name * 1 * 1 * 1 Source code Base program developer Aspect developer Model-based pointcut (defined in terms of application-specific model) Application-specific model
  • 34. Application-specific 11 Source code based pointcut (defined directly in terms of source code) Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name * 1 * 1 * 1 Source code Base program developer Aspect developer Model-based pointcut (defined in terms of application-specific model) Application-specific model Explicit Model
  • 35. Application-specific 11 Source code based pointcut (defined directly in terms of source code) Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name * 1 * 1 * 1 Source code Base program developer Aspect developer Model-based pointcut (defined in terms of application-specific model) Application-specific model Explicit Model Expressed in terms of structure
  • 36. Application-specific 11 Source code based pointcut (defined directly in terms of source code) Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name Operations Operations Attributes Attributes Class Name * 1 * 1 * 1 Source code Base program developer Aspect developer Model-based pointcut (defined in terms of application-specific model) Application-specific model Explicit Model Expressed in terms of structure Contract Requires Provides
  • 37. 12 Application-specific pointcuts in AspectSOUL Logic Pointcuts Application-specific model Extensible pointcut language Keep in sync with code Logic representation specialisation parameters & unification
  • 38. 12 Application-specific pointcuts in AspectSOUL Logic Pointcuts Application-specific model Extensible pointcut language Keep in sync with code Logic representation specialisation parameters & unification
  • 39. 12 Application-specific pointcuts in AspectSOUL Logic Pointcuts Application-specific model Extensible pointcut language Keep in sync with code Logic representation specialisation parameters & unification Managing the Evolution of Aspect-Oriented Software with Model-based Pointcuts Andy Kellens, Kim Mens, Johan Brichau, Kris Gybels In "Proceedings of the 20th European Conference on Object-Oriented Programming (ECOOP)", 2006
  • 44. Model specialisation 14 Pointcut Model Source Person>>name ^name Person>>name: anObject name := anObject Person>>friends ^friends isNil ifTrue:[friends := Set new] ifFalse:[friends]
  • 46. Model specialisation 14 reception(?joinpoint,?selector,?args), accessor(?class,?selector,?var), withinClass(?joinpoint,?class) Synchronization Pointcut Model Source Person>>name ^name Person>>name: anObject name := anObject Person>>friends ^friends isNil ifTrue:[friends := Set new] ifFalse:[friends] accessor(?class,?method,?varname) if ... accessorForm(?method,?var) if returnStatement(?method,send(?var)) accessorForm(?method,?var) if returnStatement(?method,send(?check),<?true,?false>), nilCheckStatement(?check), statementsOfBlock(assign(?var,?varinit),?true), statementsOfBlock(<?var>,?false)
  • 51. Drag & Drop 16 Drag Ok Start Drag Enter Drag Over Drag Drop DragDrop Manager
  • 52. Drag & Drop 16 Drag Ok Start Drag Enter Drag Over Drag Drop DragDrop Manager dragOkMethod(?class,?sel,?component) dragEnterMethod(?class,?sel,?component) dragSource(?dragdropmanager,?source) draggedObject(?dragdropmanager,?object)
  • 53. Drag & Drop 16 Drag Ok Start Drag Enter Drag Over Drag Drop DragDrop Manager dragOkMethod(?class,?sel,?component) dragEnterMethod(?class,?sel,?component) dragSource(?dragdropmanager,?source) draggedObject(?dragdropmanager,?object) reception(?jp,?sel,?args), dragEnterMethod(?class,?sel,?component), equals(?args,<?dragdropmanager>), dragSource(?dragdropmanager,?source), instanceOf(?source,FigureManager), draggedObject(?dragdropmanager,?object), instanceOf(?object,Line)
  • 57. Refactoring 17 Refactoring transform preconditions ... ... transformMethod(?class,?sel,?refactoring) preconditions(?refactoring,?preconditions) refactoring(?refactoring,?class,?method) affected entities affectedEntity(?ref,[PushUpMethod],?input,?entity) if originalClassOfPushUpMethod(?input,?entity) affectedEntity(?ref,[PushUpMethod],?input,?entity) if originalClassOfPushUpMethod(?input,?class), superclassOf(entity,?class)
  • 58. Summary 18 AspectS + Carma = AspectSOUL Pointcut in terms of application-specific model Extensible pointcut language Logic language to express model Further integration of AspectS/Carma Integration with support for fragile pointcuts