Monday, April 25, 2011

The difference between the include element and the import element is that the import element allows references to schema components from schema documents with different target namespaces and the include element adds the schema components from other schema documents that have the same target namespace (or no specified target namespace) to the containing schema. In short, the import element allows you to use schema components from any schema; the include element allows you to add all the components of an included schema to the containing schema.

Well let's start with the any. Ok, let's say you want to write a schema for sending messages but you want to make it flexible. You want to define the message envelope but the structure of the message payload is unknown to the system. Here's how you'd do it.

This means the message must have a Date, a Sender and any content.

Here's an example message:

The any tag can be further customised with attributes such as minOccurs and maxOccurs.

Validation is only available during marshalling in JAXB 1.0. Validation is also available during unmarshalling in JAXB 2.0.

Termination occurs in JAXB 1.0 when a validation error occurs. In JAXB 2.0 custom ValidationEventHandlers can be used to deal with validation errors.

JAXB 2.0 uses annotations and supports bi-directional mapping.

JAXB 2.0 generates less code.

JAXB 1.0 does not support key XML Schema components like anyAttribute, key, keyref, and unique. It also does not support attributes like complexType.abstract, element.abstract, element.substitutionGroup, xsi:type, complexType.block, complexType.final, element.block, element.final, schema.blockDefault, and schema.finalDefault. In version 2.0, support has been added for all of these schema constructs.

XPath 1.0 became a W3C recommendation in November 1999 . XPath 2.0 became a W3C recommendation in January 2007. In XPath 2.0 every value has become a sequence. XPath 2.0 has a richer type set.

An example please?

No problem. Let's start with some XML.

The XML represents some books in a library. Suppose you wish to query this XML to see the names of the books that Brian Smith has wrote. Now you don't want the hassle of converting the XML to book objects and filtering through them yourself just to get the names. So you decide to use XPath. Here's how you'd do it.

Every so often an understanding of mathematical probability is needed when programming. Let's cover some basics.Factorials

How many possible ways are there to arrange the 26 letters of the alphabet?Well, there are 26 possible ways to arrange the first letter, 25 possible ways to arrange the second letter, ... 1 possible ways to arrange the last letter letter.

This is equal to 26 * 25 * 24 * ... * 1. This mathematical sequence is called a factorial. And can be written as 26! The answer to 26! is 403291461126605635584000000 -- wow.

Selections

We are often concerned with particular selections of objects rather than all objects. For example, suppose we have three letters: A, B, C. It is possible to select two letters 6 different ways: AB, BA, AC, CA, BC, CB. When order matters it the selection is a permutation. When order does not matter it is said to be a combination. Hence, for the same three letters (A, B, C) there may be 6 permutations but only 3 combinations: AB, AC, BC.

CombinationsIn general, the number of combinations of r objects from n objects is given by:

Sunday, April 17, 2011

Simple Mail Transfer Protocol (SMTP) is text based protocol for sending emails across the Internet. It grew for the need for different systems needing to communicate with each other.

A SMTP transactions consists of three command / reply sequences. They are:

MAIL command. Establishes return address.

RCPT command. Establishes recipient of message.

DATA content of the message.

(Note: SMTP commands usually consist of four characters others are HELO and EHLO).

The Server responds to these commands uses status codes. The responses are positive (2xx reply codes) or negative. Negative replies can be permanent (5xx codes) or transient (4xx codes)

What is the difference between SMTP and POP and IMAP?

SMTP is really for sending messages. It cannot pull messages from a remote server on demand. You wanna read those messages sent to you that are on your email server. You need to use either the Post Office Protocol (POP) or Internet Message Access Protocol (IMAP).

So you wanna try it?

Ok, so you're sick of using email tools such as outlook for sending email messages. You wanna send your own messages?

Open a command prompt.

Type "telnet 25".

Talk to the server using SMTP.

SMTP and Web Services

It is possible to have Web Services over SMTP instead of HTTP. But it's more complex. Why? Because SMTP does not provide much flexibility to responses for requests. With HTTP a SOAP request message can be put into the HTTP message body. Similar a SOAP message can be put in the HTTP message body for a response. SMTP allows a SOAP message to be easily attached to the request. But not the response. A separate SMTP is required for the response.

So why why why would you ever want to use SMTP for sending SOAP messages? It might be:

Saturday, April 16, 2011

Ok, so you're embarrassed about your lack of knowledge of WEB 2.0 and in particular Rich Clients and that little place in the Netherlands called... AJAX. Well have no fear! You will now learn the basics of AJAX.

Let's start with a requirement. You are required to update part of your web page and (only part of your web page) asynchronously. When? Well when a button called 'Update with AJAX' is clicked!
And what are you required to update it to? The contents of a file that reside on your server.

Ok let's look at the solution.

Simple Ajax / Javascript Example

Very simple Javascript / Ajax Example

This page shows some very simple JavaScript / Ajax in action!

This will text be updated!

Now let's look at the salient points here:

The HTML is pretty simple. There is a paragraph with the "id".
This is the paragraph that will be updated when the Ajax Updatebutton is pressed.

The Javascript function loadDoc() is defined in the HTML header.

The loadDoc() function creates a XMLHttpRequest object (or an ActiveXObject for
those annoying browsers!)

The XMLHttpRequest is pretty cool. This is what facilitates the AJAX request.
It has a event property onreadystatechange. When this property an anonymous
function will execute.

The anonymous function, checks a property readyState. When this property is 4 it means that the server has finished the request and the response is ready.

When the response is ready, the function checks another property responseTextwhich contains the response from the server. It updates the paragraph with the response.

So what actually sends the request?

The open API sets up the request. It states what type a request (Get, parameter 1), the URL / URI (ajax_info.txt, parameter 2) and that the request should be
asynchronous (false, parameter 3).

The send API sends the request. In this case, no parameter is included.
This means the the client sends no request to the Server. It can if it wants to. It would simply include a parameter in the send() API which is the data the client will
send to the server.

Now to get this working all you need is this file and a file named ajax_info.txt on the same Server! Enjoy!

Friday, April 15, 2011

Ok, so no matter how much disk space you have, you will inevitably run out. Time to see what files you can delete. Well it's not always so easy to figure out where the largest files that are gobbling up your disk are. Why? Because Windows Explorer does not show the size of folders.

You could have a Virtual Disk tucked away in a folder within a folder from a training course two years ago but it's not always so easy to find!
Now, you could go old skool open up a cmd box and type > dir /s. This will list every single folder and the total file size.

However, unless you have very folders (unlikely) and very few files (more unlikely) this is difficult to read.

Even, dir /s /p won't get you that far!

What you need is what Windows Explorer should give you but doesn't. You need to be able to see all your folders visually and see who's hogging the juice.

There are many tools out on the web that will help out here. I recommend WinDirStat. It's free, simple to use and presents everything you need to know after quickly scanning your disk.

Monday, April 4, 2011

Would you like a very simple example of Javascript in action? No problem. Let's say you have a page and when you click a button, you'd like to execute a Javascript function to update some text in the page to display the current date / time. Now first let's see that in action!

Just press the button...

This will be updated with the date and current time!

Now the source code...

This will be updated with the current date and time!

Now here are the salient points:

The Javascript function is called displayDate() and this is defined in the head.

The paragraph in the html page is given the id=demo.

The Javascript function gets a handle on the demo paragraph using the DOM APIs

About Me

Alex Staveley is a software professional passionate about software
engineering and technical architecture. He blogs about architectural
approaches, Java topics, web solutions and various technical bits and
pieces.