www.carfield.com.hk
PracticalJMS.doc
2008-09-10T15:33:28Z
2008-09-10T15:33:28Z
<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2008-09-10T15:33:28Z
ObjectTemplate.pm
2008-03-17T17:25:12Z
2008-03-17T17:25:12Z
<br/><TEXTAREA name="code" class="pm" rows="16" cols="100">
package ObjectTemplate;
require Exporter;
@ObjectTemplate::ISA = qw(Exporter);
@ObjectTemplate::EXPORT = qw(attributes);
my $debugging = 0; # assign 1 to it to see code generated on the fly
# Create accessor functions, and new()
sub attributes {
my ($pkg) = caller;
@{"${pkg}::_ATTRIBUTES_"} = @_;
my $code = "";
foreach my $attr (get_attribute_names($pkg)) {
# If a field name is "color", create a global list in the
# calling package called @color
@{"${pkg}::_$attr"} = ();
# Define accessor only if it is not already present
unless ($pkg->can("$attr")) {
$code .= _define_accessor ($pkg, $attr);
}
}
$code .= _define_constructor($pkg);
eval $code;
if ($@) {
die "ERROR defining constructor and attributes for '$pkg':"
. "\n\t$@\n"
. "-----------------------------------------------------"
. $code;
}
}
# $obj->set_attributes (name => 'John', age => 23);
# Or, $obj->set_attributes (['name', 'age'], ['John', 23]);
sub set_attributes {
my $obj = shift;
my $attr_name;
if (ref($_[0])) {
my ($attr_name_list, $attr_value_list) = @_;
my $i = 0;
foreach $attr_name (@$attr_name_list) {
$obj->$attr_name($attr_value_list->[$i++]);
}
} else {
my ($attr_name, $attr_value);
while (@_) {
$attr_name = shift;
$attr_value = shift;
$obj->$attr_name($attr_value);
}
}
}
# @attrs = $obj->get_attributes (qw(name age));
sub get_attributes {
my $obj = shift;
my (@retval);
map $obj->${_}(), @_;
}
sub get_attribute_names {
my $pkg = shift;
$pkg = ref($pkg) if ref($pkg);
my @result = @{"${pkg}::_ATTRIBUTES_"};
if (defined (@{"${pkg}::ISA"})) {
foreach my $base_pkg (@{"${pkg}::ISA"}) {
push (@result, get_attribute_names($base_pkg));
}
}
@result;
}
sub set_attribute {
my ($obj, $attr_name, $attr_value) = @_;
my ($pkg) = ref($obj);
${"${pkg}::_$attr_name"}[$$obj] = $attr_value;
}
sub get_attribute {
my ($obj, $attr_name, $attr_value) = @_;
my ($pkg) = ref($obj);
return ${"${pkg}::_$attr_name"}[$$obj];
}
sub DESTROY {
# release id back to free list
my $obj = $_[0];
my $pkg = ref($obj);
local *_free = *{"${pkg}::_free"};
my $inst_id = $$obj;
# Release all the attributes in that row
local(*attributes) = *{"${pkg}::_ATTRIBUTES_"};
foreach my $attr (@attributes) {
undef ${"${pkg}::_$attr"}[$inst_id];
}
$_free[$inst_id] = $_free;
$_free = $inst_id;
}
sub initialize { }; # dummy method, if subclass doesn�t define one.
#################################################################
sub _define_constructor {
my $pkg = shift;
my $code = qq {
package $pkg;
sub new {
my \$class = shift;
my \$inst_id;
if (defined(\$_free[\$_free])) {
\$inst_id = \$_free;
\$_free = \$_free[\$_free];
undef \$_free[\$inst_id];
} else {
\$inst_id = \$_free++;
}
my \$obj = bless \\\$inst_id, \$class;
\$obj->set_attributes(\@_) if \@_;
\$obj->initialize;
\$obj;
}
};
$code;
}
sub _define_accessor {
my ($pkg, $attr) = @_;
# This code creates an accessor method for a given
# attribute name. This method returns the attribute value
# if given no args, and modifies it if given one arg.
# Either way, it returns the latest value of that attribute
# qq makes this block behave like a double-quoted string
my $code = qq{
package $pkg;
sub $attr { # Accessor ...
\@_ > 1 ? \$_${attr} \[\${\$_[0]}] = \$_[1] # set
: \$_${attr} \[\${\$_[0]}]; # get
}
if (!defined \$_free) {
# Alias the first attribute column to _free
\*_free = \*_$attr;
\$_free = 0;
};
};
$code;
}
1;
</TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2008-03-17T17:25:12Z
col.pl
2008-03-17T17:25:12Z
2008-03-17T17:25:12Z
<br/><TEXTAREA name="code" class="pl" rows="16" cols="100">#!/opt/bin/perl
# Extracts columns of text from a file
# Usage : col [-s<n>] col-range1, col-range2, files ...
# where col-range is specified as col1-col2 (column 1 through column2)
# or col1+n, where n is the number of columns.
$size = 0; # 0 => line-oriented input, else fixed format.
@files = (); # List of files
$open_new_file = 1; # Force get_next_line() to open the first file
$debugging = 0; # Enable with -d commmand line flag
generate_part1();
generate_part2();
generate_part3();
col(); # sub col has now been generated. Call it !
exit(0);
#------------------------------------------------------------------
sub generate_part1 {
# Generate the initial invariant code of sub col()
$code = 'sub col { my $tmp;'; # Note the single quotes
$code .= 'while (1) {$s = get_next_line(); $col = "";';
$delimiter = '|';
}
#------------------------------------------------------------------
sub generate_part2 {
# Process arguments
foreach $arg (@ARGV) {
if (($col1, $col2) = ($arg =~ /^(\d+)-(\d+)/)) {
$col1--;# Make it 0 based
$offset = $col2 - $col1;
add_range($col1, $offset);
} elsif (($col1, $offset) = ($arg =~ /^(\d+)\+(\d+)/)) {
$col1--;
add_range($col1, $offset);
} elsif ($size = ($arg =~ /-s(\d+)/)) {
# noop
} elsif ($arg =~ /^-d/) {
$debugging = 1;
} else {
# Must be a file name
push (@files, $arg);
}
}
}
#------------------------------------------------------------------
sub generate_part3 {
$code .= 'print $col, "\n";}}';
print $code if $debugging; # -d flag enables debugging.
eval $code;
if ($@) {
die "Error ...........\n $@\n $code \n";
}
}
#------------------------------------------------------------------
sub add_range {
my ($col1, $numChars) = @_;
# substr complains (under -w) if we look past the end of a string
# To prevent this, pad the string with spaces if necessary.
$code .= "\$s .= ' ' x ($col1 + $numChars - length(\$s))";
$code .= " if (length(\$s) < ($col1+$numChars));";
$code .= "\$tmp = substr(\$s, $col1, $numChars);";
$code .= '$tmp .= " " x (' . $numChars . ' - length($tmp));';
$code .= "\$col .= '$delimiter' . \$tmp; ";
}
#------------------------------------------------------------------
sub get_next_line {
my($buf);
NEXTFILE:
if ($open_new_file) {
$file = shift @files || exit(0);
open (F, $file) || die "$@ \n";
$open_new_file = 0;
}
if ($size) {
read(F, $buf, $size);
} else {
$buf = <F>;
}
if (! $buf) {
close(F);
$open_new_file = 1;
goto NEXTFILE;
}
chomp($buf);
# Convert tabs to spaces (assume tab stop width == 8)
# expand leading tabs first � the common case
$buf =~ s/^(\t+)/' ' x (8 * length($1))/e;
# Now look for nested tabs. Have to expand them one at a time - hence
# the while loop. In each iteration, a tab is replaced by the number of
# spaces left till the next tab-stop. The loop exits when there are
# no more tabs left
1 while ($buf =~ s/\t/' ' x (8 - length($`)%8)/e);
$buf;
}
</TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2008-03-17T17:25:12Z
METRICS.JAVA
2008-03-17T17:25:10Z
2008-03-17T17:25:10Z
<br/><TEXTAREA name="code" class="JAVA" rows="16" cols="100">// This example is from the book _Java AWT Reference_ by John Zukowski.
// Written by John Zukowski. Copyright (c) 1997 O'Reilly & Associates.
// You may study, use, modify, and distribute this example for any purpose.
// This example is provided WITHOUT WARRANTY either expressed or
import java.awt.*;
public class metrics extends Frame {
metrics () {
super ("metrics");
setFont (new Font ("TimesRoman", Font.BOLD | Font.ITALIC, 48));
resize (225, 175);
}
public boolean handleEvent (Event e) {
if (e.id == Event.WINDOW_DESTROY) {
dispose();
System.exit (1);
}
return super.handleEvent (e);
}
public void update (Graphics g) {
paint(g);
}
public void paint (Graphics g) {
g.translate (insets().left, insets().top);
FontMetrics fm = null;
int ascent, descent, leading, width1, width2, height;
String string1 = "O'Reilly";
String string2 = "紑eilly";
int xPos = 25, yPos = 50;
fm = g.getFontMetrics();
ascent = fm.getAscent();
descent = fm.getDescent();
leading = fm.getLeading();
height = fm.getHeight();
width1 = fm.stringWidth (string1);
width2 = fm.stringWidth (string2);
g.drawString (string1, xPos, yPos);
g.drawLine (xPos, yPos - ascent - leading,
xPos + width1, yPos - ascent - leading);
g.drawLine (xPos, yPos - ascent,
xPos + width1, yPos - ascent);
g.drawLine (xPos, yPos,
xPos + width1, yPos);
g.drawLine (xPos, yPos + descent,
xPos + width1, yPos + descent);
g.drawString (string2, xPos, yPos+height);
g.drawLine (xPos, yPos - ascent - leading + height,
xPos + width2, yPos - ascent - leading + height);
g.drawLine (xPos, yPos - ascent + height,
xPos + width2, yPos - ascent + height);
g.drawLine (xPos, yPos + height,
xPos + width2, yPos + height);
g.drawLine (xPos, yPos + descent + height,
xPos + width2, yPos + descent + height);
}
public static void main (String[] args) {
Frame f = new metrics ();
f.show();
}
}
</TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2008-03-17T17:25:10Z
team-list.html
2007-04-25T09:21:28Z
2007-04-25T09:21:28Z
<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2007-04-25T09:21:28Z
using-plugins.html
2007-04-25T09:21:28Z
2007-04-25T09:21:28Z
<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2007-04-25T09:21:28Z
writing-plugins.html
2007-04-25T09:21:28Z
2007-04-25T09:21:28Z
<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2007-04-25T09:21:28Z
simple-project.html
2007-04-25T09:21:26Z
2007-04-25T09:21:26Z
<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2007-04-25T09:21:26Z
site-generation.html
2007-04-25T09:21:26Z
2007-04-25T09:21:26Z
<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2007-04-25T09:21:26Z
source-repository.html
2007-04-25T09:21:26Z
2007-04-25T09:21:26Z
<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2007-04-25T09:21:26Z
reporting.html
2007-04-25T09:21:24Z
2007-04-25T09:21:24Z
<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2007-04-25T09:21:24Z
repository.html
2007-04-25T09:21:24Z
2007-04-25T09:21:24Z
<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2007-04-25T09:21:24Z
settings-details.html
2007-04-25T09:21:24Z
2007-04-25T09:21:24Z
<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2007-04-25T09:21:24Z
project-info.html
2007-04-25T09:21:22Z
2007-04-25T09:21:22Z
<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2007-04-25T09:21:22Z
project-summary.html
2007-04-25T09:21:22Z
2007-04-25T09:21:22Z
<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2007-04-25T09:21:22Z
properties.html
2007-04-25T09:21:22Z
2007-04-25T09:21:22Z
<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2007-04-25T09:21:22Z
pom-details.html
2007-04-25T09:21:20Z
2007-04-25T09:21:20Z
<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2007-04-25T09:21:20Z
pom-relationships.html
2007-04-25T09:21:20Z
2007-04-25T09:21:20Z
<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2007-04-25T09:21:20Z
profiles.html
2007-04-25T09:21:20Z
2007-04-25T09:21:20Z
<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2007-04-25T09:21:20Z
lifecycle.html
2007-04-25T09:21:18Z
2007-04-25T09:21:18Z
<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2007-04-25T09:21:18Z
mail-lists.html
2007-04-25T09:21:18Z
2007-04-25T09:21:18Z
<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2007-04-25T09:21:18Z
plugin-apis.html
2007-04-25T09:21:18Z
2007-04-25T09:21:18Z
<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2007-04-25T09:21:18Z
introduction.html
2007-04-25T09:21:16Z
2007-04-25T09:21:16Z
<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2007-04-25T09:21:16Z
issue-tracking.html
2007-04-25T09:21:16Z
2007-04-25T09:21:16Z
<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2007-04-25T09:21:16Z
j2ee.html
2007-04-25T09:21:16Z
2007-04-25T09:21:16Z
<br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
2007-04-25T09:21:16Z