A little bit more...

Tuesday, January 30, 2007

AspectJ Syntax Notes and More…

Note: Some of the following items, especially items in red, are based on my experience with aspectj 1.5.3.200611221118 (AJDT 1.4.1.200611230655) , JVM 1.5.0-b64, and JDT 3.2.0.v20060609m-F7snq1fxia-Z4XP.

  • [Nested/Inner Aspect] Nested aspects must be static. An inner aspect has to be static, in order to get rid of the implicit “&& this()” which you get on a perthis-Aspect.
  • [Aspect Extension] aspects may only extend abstract aspects. It is an error for a concrete aspect to extend another concrete aspect.
  • [Aspect Instantiation] Because advice only runs in the context of an aspect instance, aspect instantiation indirectly controls when advice runs.
  • [Aspect Instantiation] The criteria used to determine how an aspect is instantiated is inherited from its parent aspect. If the aspect has no parent aspect, then by default the aspect is a singleton aspect.
  • [Aspect Instantiation] Static initialization occurs when the type is loaded (i.e., the Java VM
    loads the resulting class file for Lolo). At that point, the implementation of the before calls the static method aspectOf to access the singleton instance of Lolo.
  • [Aspect Instantiation] You can get a NoAspectBoundException when there is a cycle in aspect initialization or static initialization (within one aspect, or between a chain of several aspects), most commonly when an aspect advises its own initializer.
  • [Aspect Instantiation] During the constructor of an aspect, calling aspectOf() on that aspect would fail. Because at that moment, no aspect instance has been bound. It is the same reason why in an after() :(execution(AspectA.new())) advice, calling AspectA.aspectOf() would fail. In this case, instead, target can be used to expose the instance of AspectA.
  • [Aspect Instantiation] ! Do not advise join points in cflowbelow(execution(AspectA.new())), there are bugs or flaws with aspectj which your advice may reproduce, especially when dynamically determined variable are involved in your advice body. Or don’t define your own aspect constructor, but just use the default aspect constructor, which would make your aspectj code more robust.
  • [Advice Execution] ! Exception or Error thrown in advice “before(String[] args) : execution(public static void *.main(String[]))” can’t be captured!
  • [Declaration] ! How to declare an error if some join points that are supposed to be captured are actually not captured?
  • [PCD] A named pointcut may be defined in either a class or aspect, and is treated as a member of the class or aspect where it is found. As a member, it may have an access modifier such as public or private. Abstract pointcuts may only be declared within abstract aspects. For completeness, a pointcut with a declaration may be declared final. Though named pointcut declarations appear somewhat like method declarations, and can be overridden in subaspects, they cannot be overloaded.
  • [PCD] call(Foo.new(..)) can’t be used together with target(*).
  • [PCD] Rather than cflow, use lexical-structure based pointcuts, within or withincode, preferablely. It will make the cross-reference view of the AJDT more accurate and less time consuming.

to be continued…

Resources:

  1. aspectj doc
  2. aspectj-user-request mailing list

Saturday, January 20, 2007

DOM Level 3 Load and Save

1. Introduction

Defined by w3 consortium, just as its name indicates, it serves as interfaces to objects that dealing with loading and saving DOM objects.

It’s noteworthy that various specific implementations doesn’t always fully support.

With java, it is well supported, though, some optional specifications are not supported (at least not always workabe from my experience). However, for web developers, there’s a quote from a book for you:

Now that XMLHttpRequest is being standardized, it seems likely that LSParser will never be supported by most browsers.

In addition, with java, you can also selectively use javax.xml.transform to deal with loading and saving DOM objects.

2. Breakdown

Cite from org.w3c.dom.ls:

DOMImplementationLS
DOMImplementationLS contains the factory methods for creating Load and Save objects.

LSInput
This interface represents an input source for data.

LSLoadEvent
This interface represents a load event object that signals the completion of a document load.

LSOutput
This interface represents an output destination for data.

LSParser
An interface to an object that is able to build, or augment, a DOM tree from various input sources.

LSParserFilter
LSParserFilters provide applications the ability to examine nodes as they are being constructed while parsing.

LSProgressEvent
This interface represents a progress event object that notifies the application about progress as a document is parsed.

LSResourceResolver
LSResourceResolver provides a way for applications to redirect references to external resources.

LSSerializer
A LSSerializer provides an API for serializing (writing) a DOM document out into XML.

LSSerializerFilter
LSSerializerFilters provide applications the ability to examine nodes as they are being serialized and decide what nodes should be serialized or not.

3. Examples

a. Write an instance of Document to a file with org.w3c.dom.ls:

DOMImplementationLS domImpl = (DOMImplementationLS)doc
.getImplementation();
LSSerializer serializer = domImpl.createLSSerializer();
LSOutput output = domImpl.createLSOutput();
output.setCharacterStream(new PrintWriter(fileName));
serializer.write(doc, output);

b. Write an instance of Document to a file with javax.xml.transform:

StreamResult sr = new StreamResult(new File(fileName));
Transformer t = TransformerFactory.newInstance().newTransformer();
t.transform(new DOMSource(doc), sr);

Note: it seems, from my experience, that example b can’t preserve the print friendly presentation.

Resources:

  1. Document Object Model (DOM) Level 3 Core Specification Version 1.0
  2. Document Object Model (DOM) Level 3 Load and Save Specification Version 1.0
  3. DOM Level 3
  4. Java Impl. Package org.w3c.dom.ls (src, api spec)

Saturday, January 13, 2007

Feed Format — The Programmable Web

Resources:

Spec. Intro.

  1. What Is RSS
  2. Content feeds with RSS 2.0
  3. RSS 2.0 Specification
  4. The Atom Syndication Format
  5. OPML 1.0 Specification
  6. OPML 2.0 draft spec

Feed Reader Impl.

  1. A Java pen source reader: RSSOwl(bin, src)
  2. XML Processing With Java Overview
  3. Three ways of validating a xml document with Java
  4. Comment on W3C DOM and various implmentations in defferent PL
  5. Unicode, UTF等字符编码摘记
  6. Control a Web Browser From Within a Java Programm

Technorati : , , , , ,
Del.icio.us : , , , , ,

Control a Web Browser From Within a Java Programm

Noramlly, more than two way you can use a web browser with your Java programm.

1.Fire commands to invoke a web browser with Java runtime support.

// cmd = ‘rundll32 url.dll,FileProtocolHandler http://…’
cmd = WIN_PATH + ” ” + WIN_FLAG + ” ” + url;
Process p = Runtime.getRuntime().exec(cmd);

See the API Spec of Java for Process, and Java Tip 66 of the Resources section for more information.

2. Use a wrapped browser control

2.1 Use Jacob, the open source COM wrapper. e.g.,

protected void openIExplorer(){
comp = new ActiveXComponent( “InternetExplorer.Application” );
comp.setProperty( “Visible”, new Variant(true) );
comp.invoke( “Navigate”, new Variant[]{ new Variant((String)comboFilename.getSelectedItem()) } );

2.2 Use browser wrapper provided by SWT.

import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.CloseWindowListener;
import org.eclipse.swt.browser.LocationAdapter;
import org.eclipse.swt.browser.LocationEvent;
import org.eclipse.swt.browser.OpenWindowListener;
import org.eclipse.swt.browser.ProgressEvent;
import org.eclipse.swt.browser.ProgressListener;
import org.eclipse.swt.browser.StatusTextEvent;
import org.eclipse.swt.browser.StatusTextListener;
import org.eclipse.swt.browser.VisibilityWindowAdapter;
import org.eclipse.swt.browser.WindowEvent;

3. or any other ways I havn’t figured out…

Resources:

  1. Java Tip 66: Control browsers from your Java application
  2. JavaTM 2 Platform Standard Edition 5.0 API Specification
  3. The JACOB Project: A JAva-COM Bridge
  4. SWT Browser
  5. Package org.eclipse.swt.browser
  6. Developer Forums java to invoke IExplore?

Technorati : , , , , , , ,
Del.icio.us : , , , , , , ,

About Me

My photo
I'm finishing my master degree in Software Engineering, Computer Science. I believe and have been following what Forrest Gump's Mam said: you have to do the best with what god gave you.