XML schema


A structure of an XML document can be defined as follows:
  • Document Type Definition (DTDs)
  • XML Schema Definition (XSD)
  • XML Data Reduced (XDR) -proprietary to Microsoft Technology

Outlook new message system tray icon not showing

Tools->Options->Email Options->Advanced Email Options...->Show an envelope icon in the notification area




HP Envelop Paper Mismatch problem


Change as showed above before printing envelope.

Networking

It has been 2 months...
I recently moved, and I need set up my network. Got a problem. Verizon FIOS has its own router with wireless, and I get an ethernet cable from there to my office, in my office, I got several computers, and I got an additional router. So what I do?

I tried to set up additional router, and it doesn't work. It turned out that you could not just add an router on top of anther router, but you could use the router as a switch, which means you don't use WAN port, instead LAN point, in this way, your router is essentially a switch, and it works.

Flex to Java Notes (1)
















The red-circled parts, aka, Java Remoting Service are what I am going to talk about.

  • BlazeDS server is contained in a J2EE web application. That's why we need web server to host it.
  • A Flex client makes a request over a channel and the request is routed to an endpoint on the BlazeDS server. From the endpoint, the request is routed through a chain of Java objects that includes the MessageBroker object, a service object, a destination object, and finally an adapter object. The adapter fulfills the request either locally, or by contacting a backend system or a remote server such as Java Message Service (JMS) server.
  • Channels are client-side objects that encapsulate the connection behavior between Flex components and the BlazeDS server. Channels communicate with corresponding endpoints on the BlazeDS server. You configure the properties of a channel and its corresponding endpoint in the services-config.xml file. 
  • <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
  •     <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
  • </channel-definition>
  • How exactly Flex components know how to connect to BlazeDS, using which channel?
  • Answer: you can use automatic way or manual way.
  • Automatic way: compile Flex component using -service option, check your "Flex Compiler", you should find something like -services "C:/flex_workspace/EZQ5Browser/WebContent/WEB-INF/flex/services-config.xml" -locale en_US
  • Manual way: 
  • <RemoteObject id="ro" destination="Dest">
  •     <mx:channelSet>
  •         <mx:ChannelSet>
  •             <mx:channels>
  •                 <mx:AMFChannel id="myAmf"
  •                     uri="http://myserver:2000/myapp/messagebroker/amf"/>
  •             </mx:channels>
  •         </mx:ChannelSet>
  •     </mx:channelSet>
  • </RemoteObject>
  • Destination to channels


Mercurial Notes (2)

This is from my colleague Esteban:

When you are working with Mercurial, it may help you understand that the work you are doing in your local repository is being done on your own personal branch (an unnamed branch).

In the meantime, other people continue making changes to the original branch on the master repository.

When you try to synchronize your repository with the master you discover that your branch has diverged from the main branch (as it happens if somebody pushes changes before you).

The best strategy to get back in sync with the master repository is to move all your work in your personal branch, to the top of the history (the top of the current history in the master repository).

Mercurial and the Eclipse plugin let you do this with a command called "rebase".

Steps to synchronize your committed changes with the master repository:
  1. pull and update to the latest version
  2. rebase
  • select the first change you committed in your personal branch
  • select the current tip of the branch you are working with
  • resolve any conflicts
  • commit
     3. push your changes to the server

Why do you get two heads after pulling from the master repository?






















Rebasing:



Mercurial Notes

This is an Email from my colleague Gareth:


Ian explained this a little last night.  Since this is going to come up a lot, I wanted to explain what the dialog options are.

You'll get this dialog if you've made changes to a repository at the same time as someone else.  (You committed changes to your local repository, then went to push them.  Someone else had sneaked in and pushed changes ahead of you that you don't have.)  You'll get this dialog.

If you imagine your repository, this is what it looked like after you committed your changes "L1" and "L2":

But some other developer (probably with a few extra cups of coffee in them because boy they did it awfully fast) made changes "R1" and "R2" at the same time and pushed them to the main repository ahead of you.  The dialog is saying you've got a situation like this:


There are three ways to handle it.  One is to force your changes anyway and split into two heads.  NEVER DO THIS.  It's not what we want.

The easiest thing to do is "Rebase", and it's always the first thing you should try. What "Rebase" does is looks at the files involved.  If you've both worked on completely different files, it will just update your repository to take the "R1" and "R2" changes, then stick your changes on top:

Now you can push your changes with no problem.   In the graph of the branch, this simply adds your changes as a new node after  that "coffee'd up" developer.  Since most of the time we'll all be working on different files, this is the most common scenario, and how we should try to handle it.

OK, but what if Mr/Mrs coffee worked on the SAME files as you did.  What a jerk!  Rebase doesn't work.  You get an error that a merge is required.  OK, no biggie.  Now you have to do a merge.  I'm not sure how the dialogs work and will update this when I find out, but you want to get to that second option "Merge two heads".

If you've changed different parts of the same file, the merge can be done automatically.  If not, you've got to handle the conflicts in the UI just like we did all the time in IDEA and CVS.  Once we're done and happy with the merge, we commit the updated files and push our changes.  The graph now looks like this, with "M1" being the combined streams of work.

Hope that helps.  Please let me know if there's problems with the explanation, or your experience differ with what I've described above.  Happy "Rebasing".

Thanks,

Gareth

Read a file in Classpath

new BufferedReader(new InputStreamReader(Q5Service.class.getResourceAsStream("/Extents.csv")));

Make a link folder in windows


C:\spring-flex-testdrive-1.0.3-v1\projects\java\spring-flex-testdrive-java>mklink /D builds.out C:\spring-flex-testdrive-1.0.3-v1\tomcat
ps\spring-flex-testdrive\WEB-INF\classes
symbolic link created for builds.out <<===>> C:\spring-flex-testdrive-1.0.3-v1\tomcat\webapps\spring-flex-testdrive\WEB-INF\classes

Another example:
do it in cmd line with administrator privilege.
The following is to create a link folder "Banking Documents" under current directory.
C:\Users\hliu\Documents>mklink /D "Banking Documents" "E:\backup\Banking Documents"

Eclipse 64 bits + Java 32bits

Failed to load the JNI shared library "C:\Program Files (x86)\Java\jdk1.6.0_20\bin..\jre\bin\client\jvm.dll".

-vm
C:\Program Files\Java\jre6\bin\javaw.exe


How to print String Array

import java.util.Arrays;

Arrays.toString(arr);

Get All Time Zones in Java

isEmpty vs isBlank

You can see isBlank() is more thorough than isEmpty().

2 Eclipse Plugins that I couldn't live without

  • AnyEdit: 
    • http://andrei.gmxhome.de/eclipse/
    • Convert Tabs <-> Spaces
    • Compare/Replace with external file or open editor
  • StartExplorer
    • http://startexplorer.sourceforge.net/update/
    • Open file in Windows Explorer
    • Copy full path

How To Move Off-Screen Windows Back To Your Desktop

My home PC only has one monitor, but my workstation has 2 monitors. So when I remote to my workstation, and I will only be able to see only screen. Here is the trick:

Select the window that only shows in the other screen, click Move, now press ->.
If the window doesn't show "Move", you could use 'ALT+SPACE+M' to activate Move option.

Default Windows 7 Login Screen

C:\Windows\System32\oobe\Info\Backgrounds\backgroundDefault.jpg

File Size could be more than 256KB

Error starting modern compiler

This error is caused by eclipse using a different java VM than the one JAVA_HOME is pointing to.

Eclipse Debugging - show static variable values

I just noticed that when I do debugging in Eclipse, when I moved the mouse over some static variables, the values are not showed up. Here is the fix:


How to drop database (schema) in Oracle


//List all schema:

SELECT username FROM all_users ORDER BY username; 

//Drop table test_db

drop user test_db cascade;

Steve Jobs and Technology

I am a developer, and my passion is to use the best possible technology to write useful and beautiful applications for my customers, and I hope my applications are good enough that my customers would love to pay for them.

I recently watched some video about Steve Jobs. One of them is he is promoting iPod Nano, the other is he is promoting iPhone. As I watched, I could not help thinking what a great salesman Mr. Jobs are. He has an almost unmatched ability to sell stuff to millions of people, of course, the stuff that he is selling is really good stuff.

Jeff Bozos said his company (Amazon) is customer obsessed.

To understand, technology is the tool, not the goal, customer is the goal.

That's the difference between Steve/Jeff and geeks. That's the mindset shift that we geeks should make.

The question we should ask is, what I could do to help customers? what values I could bring to customers? how much time that I could save for customers? what convenience that I could give to customers? If your customers are happy and satisfied, trust me on this, you will be happy at the end.

Python Notes

  • difference between raw_input and input: raw_input takes everything as string, while input treat everything as non-string or expression.
  • str() or `` or repr(): convert other types into string
  • import math, math.sqrt(81)
  • family=['mom','dad','brother'] family[-1]='brother'
  • 'abcd'[-1] = 'd'

Microsoft DOS Command

dir /?
or any command + /?
cd /d J:/test: this will change Drive too, could not do it by cd J:/test
using del or erase to delete a folder, it will only delete the files under this folder, but the folder will remain. To delete folder, you need rmdir.
use rmdir /s or rd/s will delete the whole dir (including sub)

To create a file from CMD, echo "test" > test.txt
To display a file: type test.txt
CTRL + Break: stop execution
ren: rename
move:move file
pushd .
cd /
popd
---this will help you remember where you were.

even better
pushd /
popd

Pushd: Stores the name of the current directory for use by the popd command before changing the current directory to the specified directory.
pushd + <the path you want to go>

Popd: change back to dir that Pushd stores.

type help, will display all dos commands.

Install Eclipse Plugins

Sometimes, you just could not be able to install Eclipse Plugin through Help->Install New Software, then type in the URL, for example, StartExplorer plugin.

This is one of my favorite plugins. The way to do this is simply download the jar file, and drop it into C:\Program Files\eclipse\eclipse3.6.1\plugins folder, then restart Eclipse. That's it.

Sometimes, you need check "Available Softwares sites", make sure the site is not disabled.

Convert Java project to Maven project

Installing m2eclipse
(Just so you know, STS comes with this plugin already, whew!)
Select Java project, right click, maven->Enable Dependency Management.

Or you could New->Maven->Maven POM File

To create a new Maven project

New->Maven->Maven Project
You could choose which archetype you want to generate, there a lot of them!!!!

You could also run maven command in Eclipse, by using Run as, Maven Build, you could specify your goal.

Maven Archetype Plugin

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

mvn archetype:create-from-project

Maven Lifecycle References

http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference

Maven in 5 minutes

http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

Create maven-driven project in one command:

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

All plugins in Maven 2.0 look much like a dependency - and in some ways they are. This plugin will be automatically downloaded and used - including a specific version if you request it (the default is to use the latest available).

Take a look at STS's "Effective POM" view, you can understand what plugin, phase, and goal.

You must specify a valid lifecycle phase, or a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal

mvn test-compile
mvn:compiler:testCompile
mvn org.apache.maven.plugins:maven-compiler-plugin:2.3.2:testCompile

Spring Roo with MySQL (DB Reverse Engineering)

  • Be Noted: all the tables in the given schema, their primary key need to be auto_increment.
  • create project weddingMySQLRE 
  • persistence setup --provider HIBERNATE --database MYSQL --databaseName guestdb --userName root --password secret
  • change <property name="hibernate.hbm2ddl.auto" value="create"/> to <property name="hibernate.hbm2ddl.auto" value="update"/> in /src/main/resources/META-INF/persistence.xml
  • database introspect --schema guestdb 
  1. Located add-on that may offer this JDBC driver 
  2. 1 found, sorted by rank; T = trusted developer; R = Roo 1.1 compatible 
  • addon install id --searchResultId 01
  • database introspect --schema guestdb
  • database reverse engineer --schema guestdb --package ~.domain
  • controller all --package ~.web
  • add weddingMySQLRE project into server, and start server
  • http://localhost:8080/weddingMySQLRE
Thoughts: It's a little bit difficult to do DBRE on oracle, that's because Spring Roo does not provide OSGi drivers for Oracle and DB2. So we have to either obtain an OSGi-enabled driver or wrap the 
driver using Roo's wrapping facility. See the following links to see how to do it:

http://saber.b2b2000.com/display/BLUE/2011/01/26/Roo+reverse+engineering+on+Oracle

Spring Roo with MySQL

  • create project weddingMySQL 
  • persistence setup --provider HIBERNATE --database MYSQL --databaseName guestdb --userName root --password secret
  • change <property name="hibernate.hbm2ddl.auto" value="create"/> to <property name="hibernate.hbm2ddl.auto" value="update"/> in /src/main/resources/META-INF/persistence.xml
  • entity --class ~.domain.Rsvp
  • field string code --notNull --sizeMin 1 --sizeMax 30
  • field string email --sizeMax 30
  • field number attending --type java.lang.Integer
  • field string specialRequests --sizeMax 100
  • field date confirmed --type java.util.Date
  • entity --class ~.domain.MyTable --identifierField cid --identifierColumn CID --table testtable (could not use domain.testXXX)
  • field string company --sizeMax 40
  • controller scaffold ~.web.RsvpController
  • controller scaffold ~.web.MyTableController
  • add wedding2 project into server, and start server
  • http://localhost:8080/weddingMySQL

MySQL Installation and Configuration

1. download mysql (mysql-5.5.13-win32.zip).
2. unzip it into C:\mysql-5.5.13-win32\
3.put c:\mysql-5.5.13-win32\bin in PATH
4. in cmd, mysqld.exe  (this will start mysql server)
5. mysql -u root -p   (this will login you in as root, the password is blank)
6. create database guestdb;   (this will create a database named as "gestdb")

You can change root password by using
UPDATE mysql.user SET Password=PASSWORD('') WHERE User='root'; 
FLUSH PRIVILEGES;
Now we have mysql good to go.

Spring Roo Using Real Existing Oracle Database

I have this table Candidate (CID, Name, COL3), be noted, I don't have ID and Version there.
  • create new Root project: Project name: wedding4Real; Top Level: com.wedding
  • open roo shell
  • persistence setup --provider HIBERNATE --database ORACLE --databaseName XE --userName practice_db --password secret 
  • change <property name="hibernate.hbm2ddl.auto" value="create"/> to <property name="hibernate.hbm2ddl.auto" value="update"/> in /src/main/resources/META-INF/persistence.xml
  • entity --class ~.domain.Candidate --identifierField cid --identifierColumn CID --table Candidate
  • add versionField ="", like @RooEntity(identifierField = "cid", identifierColumn = "CID", versionField = "", table = "Candidate") in /wedding4Real/src/main/java/com/wedding/domain/Candidate.java
  • field string Name
  • field string COL3
  • controller scaffold ~.web.RsvpController 
  1. NullPointerException at org.springframework.roo.addon.web.mvc.controller.WebScaffoldMetadata.getDatePatterns(WebScaffoldMetadata.java:1231)
  2. This seems a known defect found in 1.1.1 version.
  3. Switch to Spring Roo 1.1.4 version, and retry
  4. Confirmed: this is working after 1.1.1 version
  • add wedding project into server, and start server
  • http://localhost:8080/wedding4Real
Thoughts: look like this will not work in Spring Flex, since the most recent Spring Flex Addon is only compatible up to 1.1.1 version. So we'll have to wait for Spring Flex Addon to work with the real existing table (which means no version\ID columns).

Spring Roo Flex Using Existing Oracle Database

  • create new Root project: Project name: weddingFlex; Top Level: com.wedding
  • open roo shell
  • persistence setup --provider HIBERNATE --database ORACLE --databaseName XE --userName practice_db --password secret 
  • change <property name="hibernate.hbm2ddl.auto" value="create"/> to <property name="hibernate.hbm2ddl.auto" value="update"/> in /src/main/resources/META-INF/persistence.xml
  • flex setup
  • entity --class ~.domain.Rsvp
  • field string code --notNull --sizeMin 1 --sizeMax 30
  • field string email --sizeMax 30
  • field number attending --type java.lang.Integer
  • field string specialRequests --sizeMax 100
  • field date confirmed --type java.util.Date
  • flex remoting all --package ~.service
  • add weddingFlex project into server, and start server
  • http://localhost:8080/weddingFlex/weddingFlex_scaffold.html

Spring Roo Using Existing Oracle Database

I have tested this in both Spring Roo 1.1.1 and 1.1.4.
  • create new Root project: Project name: wedding2; Top Level: com.wedding
  • open roo shell
  • persistence setup --provider HIBERNATE --database ORACLE --databaseName XE --userName practice_db --password secret 
  • change <property name="hibernate.hbm2ddl.auto" value="create"/> to <property name="hibernate.hbm2ddl.auto" value="update"/> in /src/main/resources/META-INF/persistence.xml
  • entity --class ~.domain.Rsvp
  • field string code --notNull --sizeMin 1 --sizeMax 30
  • field string email --sizeMax 30
  • field number attending --type java.lang.Integer
  • field string specialRequests --sizeMax 100
  • field date confirmed --type java.util.Date
  • controller scaffold ~.web.RsvpController
  • add wedding2 project into server, and start server
  • http://localhost:8080/wedding2

Spring Roo Notes without Flex

We are going do this from STS based on this
This is the most simple version:
  • create new Root project: Project name: wedding; Top Level: com.wedding
  • open roo shell
  • persistence setup --provider HIBERNATE --database ORACLE --databaseName XE --userName practice_db --password secret 
  • entity --class ~.domain.Rsvp
  • field string code --notNull --sizeMin 1 --sizeMax 30
  • field string email --sizeMax 30
  • field number attending --type java.lang.Integer
  • field string specialRequests --sizeMax 100
  • field date confirmed --type java.util.Date
  • controller scaffold ~.web.RsvpController
  • add wedding project into server, and start server
  • http://localhost:8080/wedding

Spring-Flex-Addon: using existing database

Here is a good link
  1. persistence setup --provider HIBERNATE --database ORACLE --databaseName XE --userName practice_db --password secret 
  2. comment out <property name="hibernate.hbm2ddl.auto" value="create"/> in /TestRoo/src/main/resources/META-INF/persistence.xml 
  3. flex setup 
  4. entity --class ~.domain.Toy --identifierField id --identifierColumn ID --table Toy 
  5. field string DESCRIPTION --notNull 
  6. field string MANUFACTER 
  7. field number version --type java.lang.Integer 
  8. flex remoting all --package ~.service
problem is flex remoting all --package ~.service, at this step, Toy.as is not created.

The workaround is:
shutdown roo at this point, and manually create Toy.as.

Well, still not work, first, wipe all the existing data, second, could not add new entry from GUI.

The complete notes to use Spring-Flex Addon (4)

If there is any problem.

You might need add the following into pom.xml

The complete notes to use Spring-Flex Addon (3)

Use STS sts-2.6.0.SR1 + Flash Builder 4.5

Be Noted: STS has to be 32 bit.

  • Install Flash Builder 4.5 (there is no plugin version now.)
  • Run C:\Program Files (x86)\Adobe\Adobe Flash Builder 4.5\utilities\Adobe Flash Builder 4.5 Plug-in Utility.exe
  • Choose C:\springsource\sts-2.6.0.SR1 as Eclipse folder
Now open STS, now you should have Flash View.
  • Make sure 1.6 Java SDK as the default JRE
  • Make sure using Roo 1.1.1.RELEASE
  • New->Spring Roo project
  • Project name: election 2012, Top level package name: com.hempire
  • Maven support: Dependency management only
  • Click Finish
  • Open Roo Shell
  • persistence setup --provider HIBERNATE --database ORACLE --databaseName XE --userName practice_db --password secret
  • flex setup
  • entity --class ~.domain.Candidate --testAutomatically
  • field string name --notNull
  • flex remoting all --package ~.service
Open servers View, select SpringSource tc Server, right click, Add and Remove, add election2012 project.
start the server.
Select election2012 project, right click, Run As, Web Application. Application will open.

The complete notes to use Spring-Flex Addon (2)

From command line
  • mkdir eclection2012
  • cd eclection 2012
  • roo
  • project --topLevelPackage com.hempire --projectName election2012
  • persistence setup --provider HIBERNATE --database ORACLE --databaseName XE --userName practice_db --password secret
  • flex setup
  • entity --class ~.domain.Candidate --testAutomatically
  • field string name --notNull
  • flex remoting all --package ~.service
  • exit
  • mvn compile
  • mvn tomcat:run
  • http://localhost:8080/election2012/election2012_scaffold.html

The complete notes to use Spring-Flex Addon (1)

Prerequisites:
1. Java JDK 1.6 (I suppose 1.5 is OK too).
2. Maven 2.09 or above.
3. Install ojdbc jars
mvn install:install-file -Dfile=C:\bea\weblogic92\server\lib\ojdbc14.jar -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.2 -Dpackaging=jar -DgeneratePom=true

mvn install:install-file -Dfile=C:\bea\wlserver_10.3\server\lib\ojdbc6.jar -Dpackaging=jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.1.0

4. Set up spring-roo with spring-flex-addonWe have 2 options here.
a. Spring Roo 1.1.0.M1 + Spring-Flex-Addon-1.0.0.M1
  • put org.springframework.flex.roo.addon-1.0.0.M1.jar under C:\springsource\spring-roo-1.1.0.M1\bundle
  • C:\springsource\spring-roo-1.1.0.M1\bin in PATH
b. Spring Roo 1.1.1.RELEASE + Spring-Flex-Addon-1.0.0.BUILD
  • put org.springframework.flex.roo.addon-1.0.0.BUILD-20110219.075648-225.jar under C:\springsource\spring-roo-1.1.1.RELEASE\bundle
  • C:\springsource\spring-roo-1.1.1.RELEASE\bin in PATH
We will use option b, since the new versions of STS are only compatible with Spring Roo 1.1.1.RELEASE.

5. Setup database
  • SQL> connect
  • Enter user-name: system
  • Enter password:
  • Connected.
  • SQL> create user practice_db identified by secret;
  • User created.
  • SQL> grant dba to practice_db;
  • Grant succeeded.

Flex Addon Tutorial

Link 

The tutorial is good, but there are a couple of problems for pom.xml

1. change SNAPSHOT to M1. That's because SNAPSHOT repository is not available now.

     spring-flex-core
     1.5.0.BUILD-SNAPSHOT
need to be changed to 1.5.0.M1

           org.springframework.flex.roo.annotations
           1.0.0.BUILD-SNAPSHOT
need to be changed to 1.0.0.M1     

2. add plugin-repository

<pluginRepository>
   <id>flex-mojos-repository2</id>
   <url>http://repository.sonatype.org/content/groups/flexgroup</url>
</pluginRepository>

The url is
http://localhost:8080/flex2spring/flex2spring_scaffold.html

<project name>_scaffold.html

Spring Roo and Spring Flex Addon

According to link, there are 2 combinations that are working so far.

a. Spring-flex-1.5.0.M1 release (org.springframework.flex.roo.addon-1.0.0.M1.jar) is only compatible with spring-roo-1.1.0.M1 and STS 2.3.3.M1.
b. There is a patch (org.springframework.flex.roo.addon-1.0.0.BUILD-20110219.075648-225.jar), which will work with Spring-roo-1.1.1.Release.

Spring-flex-1.5.0.M1 release is the only release so far which contains Spring Flex Addon.
The good thing is the latest STS (Version: 2.6.0.RELEASE) is compatible with Spring-roo-1.1.1.Release, this will give us all the three featrues:
a. the most updated STS
b. Spring Roo
c. Flex Addon for Spring Roo

Be noted, if you want to option b, which probably most of us will do, you need manually add the following lines to pom.xml
Introducint Flex Addon for Spring Roo
Flex Spring Forum
STS with Flash Builder Plugin
Getting Started With Spring Roo

Mecurial

1. install TortoiseHg
2. If you type hg in cmd, it's not working, make sure C:\Program Files\TortoiseHg in path.
2. use command
In C:\Users\hliu\mercurial.ini,
add something like

[ui]
username = hliu <haiboliu@dovetailsystems.com>

Otherwise, when you type hg commit, it will have an error

"abort: no username supplied (see "hg help config")"

3. create a repository at your local for your own use
go to top level of your coeds
hg init
hg add
hg commit

http://hginit.com/

EJB Transaction


Bean Type
Container-Managed
Bean-Managed
JTA
JDBC
EntityYNN
SessionYYY
Message-drivenYYY

Callback

In computer programming, a callback is a reference to executable code, or a piece of executable code, that is passed as an argument to other code. 

JMS in Spring

If you used JMS before, you knew the drill. Before we could send/receive a message, we need create get a connection factory, then create a connection, start a connection, create a session, create a queue or topic, create a producer/consumer....and after that, we need clean up the connection and session.

Now enter Spring

All we need is inject a JmsTemplate and Destination to producer/consumer bean.

Here is how to send a message in producer bean.
jmsTemplate.send(destination,
    new MessageCreator()
    {
     public Message createMessage(Session session) throws JMSException
     {
      TextMessage message = session.createTextMessage("Hello, World!");
      return message;
     }
    });

Here is how to receive a message in consumer bean.
Message message = (Message) jmsTemplate.receive(destination);
Here is the configuration for JmsTemplate and Destination
<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
     <property name="brokerURL" value="tcp://localhost:61616"/>
</bean>

<bean id="queue_destination" class="org.apache.activemq.command.ActiveMQQueue">
     <constructor-arg index="0" value="BolunQueue"/>
</bean>
You are welcome!

Regular Expression Example

^[0-9]+:

This will look for at the start of each line something like 1:

It's very useful to reformat some java codes which were posted with line number.

What's wrong with ActiveMQ version apache-activemq-5.5.0-bin.zip

I am trying to play with the most updated ActiveMQ: apache-activemq-5.5.0-bin.zip.

I thought it should be fairly easy. Download the zip file, unzip it, put lib\ and activemq-all-5.5.0.jar in classpath, and make sure java in PATH, I got everything covered.

But when I try to start activemq, I got an error:

Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file

Dear God, this drives me crazy, I could not figure it out anything that I did wrong to cause this, tried all the options that I could think of, finally I gave up, I told myself, what about try some other version, let's say, apache-activemq-5.4.2-bin.zip. 

Guess what, it is working!

Find + Grep

find . -name "*Extent.java" -exec echo "{}," \; -exec grep " CLASSNAME" '{}' > output.xml \;

This is search all the files ends with "Extent.java", print the name, then grep the line which contains "ClASSNAME", then put everything into output.xml

snippet of output.xml

/advising/src/com/dovetailsys/advising/Q5CNPBankRestrictionExtent.java,
    public static final String CLASSNAME = "CNPBankRestriction";

JEE Transaction

2 types of transactions:
a. Container-managed transactions
b. Bean-managed transactions

Table 14-1 Transaction Attributes and Scope 
Transaction Attribute Client's Transaction Business Method's Transaction
Required None T2
T1 T1
RequiresNew None T2
T1 T2
Mandatory None error
T1 T1
NotSupported None None
T1 None
Supports None None
T1 T1
Never None None
T1 Error

Mandatory vs Never
NotSupported vs Supports
@TransactionAttribute(NOT_SUPPORTED)
@Stateful
public class TransactionBean implements Transaction {
...
    @TransactionAttribute(REQUIRES_NEW)
    public void firstMethod() {...}
 
    @TransactionAttribute(REQUIRED)
    public void secondMethod() {...}
 
    public void thirdMethod() {...}
 
    public void fourthMethod() {...}
}

Maven Setting Up

1. download the zip, unzip it into some folder, let's say C:\Applications\apache-maven-3.0.3
2. setting up variables
M2_HOME=C:\Applications\apache-maven-3.0.3
put %M2_HOME% into PATH
M2_REPO=C:\Users\Paul\.m2\repository
3. mvn -v   should work now.
4. to make sure a project maven compatible, use mvn eclipse:eclipse
5. in Eclipse, you need setup M2_REPO variable
select Window > Preferences. Select the Java > Build Path > Classpath Variables page.

Inject Non-Spring Bean

Additional Jar files:

org.springframework.aspects-3.1.0.M1.jar
c:\aspectj-1.6.11\lib\aspectjweaver.jar

Also need make sure JVM AspectJ-enabled.

put -javaagent:C:/aspectj-1.6.11/lib/aspectjweaver.jar
into VM Argument section

The above are just setting environments.

Why/when we want to inject stuff into a non-spring bean?
There are many scenarios that a bean is not instantiated by Spring, but we still want to inject value/references into this bean.

In config:

xmlns:aop="http://www.springframework.org/schema/aop"
...
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
...

<aop:spring-configured/>

<bean id='noSpringBean' class="packageA.NoSpringBean" abstract="true">
<property name="beanName" value="Bolun"/>
<property name="height" value="187"/>
</bean>

NoSpringBean.java

@Configurable("noSpringBean")
public class NoSpringBean
{
...
}

When you test it, you will see a lot of Waving stuff before our codes are really executed, performance wise, this could be really bad.

Adding org.springframework.transaction-3.1.0.M1.jar into path, removed a lot of complains.

Spring Example: Wired Together


package packageA;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class HelloApp2 
{
   public static void main(String[] args) 
   {
     ApplicationContext ctx = new ClassPathXmlApplicationContext("config.xml");
     GreetingService greetingService = (GreetingService) ctx.getBean("greetingService");
     greetingService.sayALotOfGreeting();
     greetingService.theWinnderOfOscar();
     greetingService.sayGreeting();

     Lime iLime = (Lime) ctx.getBean("lime");
     iLime.drink();
   }
}

Spring Example: Groovy File


class Lime implements packageA.Lime 
{
    void drink() 
    {
      print "Groovy not in line!"
    }
}

Spring Example: Injected Method Implementation


package packageA;

import java.lang.reflect.Method;
import org.springframework.beans.factory.support.MethodReplacer;

public class WinnerInEnvelop implements MethodReplacer
{
   public Object reimplement(Object arg0, Method arg1, Object[] arg2) throws Throwable 
   {
      System.out.println("Samuel Bolun Liu");
      return null;
   }
}

Spring Example: Config file

Groovy in Spring

Now I could inject Groovy class into Spring, but the problem is Groovy class has to implement a Java interface, in this way, I could get the bean from application context.

I am wondering is it possible that I could get Groovy class without using interface?

Groovy in Spring

--------------------for DI---------------------
org.springframework.asm-3.1.0.M1.jar
org.springframework.beans-3.1.0.M1.jar
org.springframework.context-3.1.0.M1.jar
org.springframework.core-3.1.0.M1.jar
org.springframework.expression-3.1.0.M1
c:\springsource\spring-framework-3.1.0.M1\dist\dependencies\commons-logging-1.1.1.jar
--------------------for method injection---------------------
c:\springsource\spring-framework-3.1.0.M1\dist\dependencies\cglib-nodep-2.2.jar
--------------------for Groovy integration------------------
c:\springsource\spring-framework-3.1.0.M1\dist\dependencies\aopalliance.jar
org.springframework.aop-3.1.0.M1.jar
c:\groovy-1.7.2\lib\antlr-2.7.7.jar
c:\groovy-1.7.2\lib\asm-3.2.jar
c:\groovy-1.7.2\lib\groovy-1.7.2.jar

Groovy, Grails, Ruby, Rails

The combination of Groovy and Grails offers productivity benefits rivaling Ruby on Rails, but on the proven, scalable, and seamlessly integrated Java platform.

Ruby and Groovy are languages.

Rails and Grails are frameworks.

Python is a language.

Django is a framework.

tulpe vs list

A tuple is a sequence of immutable Python objects. Tuples are sequences, just like lists. The only difference is that tuples can't be changed ie. tuples are immutable and tuples use parentheses and lists use square brackets.

JMS

JNDI Context (jndi.properties)
QueueConnectionFactory
QueueConnection
QueueSession
QueueSender
QueueSender could send message

Don't you hate this? To send a message, we have go through all these....

Spring continue (2)

I tried to implement some method injection. Easy, right?

But I keep getting some weird errors, it turns out that I missed a jar called cglib, I just don't understand why Spring doesn't include this jar? or did I miss the boat?

I also found I actually need cglib-nodep-2.2.jar (see "nodep" part? means no dependency), if you just use cglib-2.2.jar, you'll get other compilation error, because this jar need other jars as dependencies.

Aghh....

check this out

ls -1

ls -1: Print one entry per line of output.

Spring continue

You can configure both simple property values (using the value attribute) and properties with references to other beans (using the ref attribute). But value and ref are only useful when your bean’s properties are singular.

What if a property is a collection of values?

list
set
map
props

Spring 3.1.0.M1

Here are the contents of \spring-framework-3.1.0.M1\dist\

org.springframework.aop-3.1.0.M1.jar
org.springframework.asm-3.1.0.M1.jar
org.springframework.aspects-3.1.0.M1.jar
org.springframework.beans-3.1.0.M1.jar
org.springframework.context.support-3.1.0.M1.jar
org.springframework.context-3.1.0.M1.jar
org.springframework.core-3.1.0.M1.jar
org.springframework.expression-3.1.0.M1.jar
org.springframework.instrument.tomcat-3.1.0.M1.jar
org.springframework.instrument-3.1.0.M1.jar
org.springframework.jdbc-3.1.0.M1.jar
org.springframework.jms-3.1.0.M1.jar
org.springframework.orm-3.1.0.M1.jar
org.springframework.oxm-3.1.0.M1.jar
org.springframework.test-3.1.0.M1.jar
org.springframework.transaction-3.1.0.M1.jar
org.springframework.web.portlet-3.1.0.M1.jar
org.springframework.web.servlet-3.1.0.M1.jar
org.springframework.web.struts-3.1.0.M1.jar
org.springframework.web-3.1.0.M1.jar

I tried an really easy example, try to use ApplicationContext and ClassPathXmlApplicationContext, guess what, it's not that easy to make a simple program to work!

First, you have to add commons-logging-1.1.1.jar into classpath, I guess Spring is using this jar, but they don't put it into one of their package???
Second, I have to import all the following jars:

org.springframework.asm-3.1.0.M1.jar
org.springframework.beans-3.1.0.M1.jar
org.springframework.context-3.1.0.M1.jar
org.springframework.core-3.1.0.M1.jar
org.springframework.expression-3.1.0.M1.jar

although in the code, I don't see anywhere I am explicitly using asm.jar and expression.jar, just weird. 

One usage of Python

Image you have something like
data1=value1,data2=value2,....

And you want to format them into 'data1':value1, 'data2':value2,...

You could do this quickly using python

def foramtConversion(**items):
     print items

then put your values into this foramtConversion() function as parameters, boom, you get what you want, simple like that.