Jason B Herald x = sin x

19Sep/090

Domain Lookup

Here is some code to do domain lookup in java (nslookup style):

Hashtable env = new Hashtable();
env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
DirContext ictx = new InitialDirContext(env);
Attributes attrs = ictx.getAttributes("gmail.com", new String[]{"MX"});
Attribute attr = attrs.get("MX");

Filed under: Java No Comments
3Sep/090

JBoss Seam

So I took up the task of learning to use the JBoss Application server and while the server itself is really nice the real power seems to be in a concept called the Seam.
There are 2 Terms to consider when trying to figure out exactly what a seam is:

Bijection :
allows objects to be in-jected or out-jected to/from assigned variables using the @In and @Out annotations

Contexts :
Stateless context
Event (or request) context
Page context
Conversation context
Session context
Business process context
Application context

Most of these contexts are similar to other technologies but the 2 new ones are: conversation context, and business process context.
The documentation says they are:

3.1.6. Business process context
The business process context holds state associated with the long running business process. This state is managed and made persistent by the BPM engine (JBoss jBPM). The business process spans multiple interactions with multiple users, so this state is shared between multiple users, but in a well-defined manner. The current task determines the current business process instance, and the lifecycle of the business process is defined externally using a process definition language, so there are no special annotations for business process demarcation.

3.1.4. Conversation context
The conversation context is a truly central concept in Seam. A conversation is a unit of work from the point of view of the user. It might span several interactions with the user, several requests, and several database transactions. But to the user, a conversation solves a single problem. For example, "book hotel", "approve contract", "create order" are all conversations. You might like to think of a conversation implementing a single "use case" or "user story", but the relationship is not necessarily quite exact.

A conversation holds state associated with "what the user is doing now, in this window". A single user may have multiple conversations in progress at any point in time, usually in multiple windows. The conversation context allows us to ensure that state from the different conversations does not collide and cause bugs.

It might take you some time to get used to thinking of applications in terms of conversations. But once you get used to it, we think you'll love the notion, and never be able to not think in terms of conversations again!

Some conversations last for just a single request. Conversations that span multiple requests must be demarcated using annotations provided by Seam.

Some conversations are also tasks. A task is a conversation that is significant in terms of a long-running business process, and has the potential to trigger a business process state transition when it is successfully completed. Seam provides a special set of annotations for task demarcation.

Conversations may be nested, with one conversation taking place "inside" a wider conversation. This is an advanced feature.

Usually, conversation state is actually held by Seam in the servlet session between requests. Seam implements configurable conversation timeout, automatically destroying inactive conversations, and thus ensuring that the state held by a single user login session does not grow without bound if the user abandons conversations.

Seam serializes processing of concurrent requests that take place in the same long-running conversation context, in the same process.

Alternatively, Seam may be configured to keep conversational state in the client browser.

Filed under: JBoss, Java No Comments
5Feb/090

Struts 2 validator types

<validator name="required" class="com.opensymphony.xwork2.validator.validators.RequiredFieldValidator"/>
<validator name="requiredstring" class="com.opensymphony.xwork2.validator.validators.RequiredStringValidator"/>
<validator name="int" class="com.opensymphony.xwork2.validator.validators.IntRangeFieldValidator"/>
<validator name="long" class="com.opensymphony.xwork2.validator.validators.LongRangeFieldValidator"/>
<validator name="short" class="com.opensymphony.xwork2.validator.validators.ShortRangeFieldValidator"/>
<validator name="double" class="com.opensymphony.xwork2.validator.validators.DoubleRangeFieldValidator"/>
<validator name="date" class="com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator"/>
<validator name="expression" class="com.opensymphony.xwork2.validator.validators.ExpressionValidator"/>
<validator name="fieldexpression" class="com.opensymphony.xwork2.validator.validators.FieldExpressionValidator"/>
<validator name="email" class="com.opensymphony.xwork2.validator.validators.EmailValidator"/>
<validator name="url" class="com.opensymphony.xwork2.validator.validators.URLValidator"/>
<validator name="visitor" class="com.opensymphony.xwork2.validator.validators.VisitorFieldValidator"/>
<validator name="conversion" class="com.opensymphony.xwork2.validator.validators.ConversionErrorFieldValidator"/>
<validator name="stringlength" class="com.opensymphony.xwork2.validator.validators.StringLengthFieldValidator"/>
<validator name="regex" class="com.opensymphony.xwork2.validator.validators.RegexFieldValidator"/>
<validator name="conditionalvisitor" class="com.opensymphony.xwork2.validator.validators.ConditionalVisitorFieldValidator"/>
Link to Ref
Filed under: Java, Struts 2 No Comments
5Feb/090

Struts 2 Zip Code Validator

<field name="ah.address.zip">

<field-validator type="required">
<param name="trim">true</param>
<message>Zip Code is required</message>
</field-validator>

<field-validator type="regex">
<param name="expression"><![CDATA[^\d{5}$]]></param>
<message>Zip Code must be 5 characters</message>
</field-validator>

</field>

Filed under: Java, Struts 2 No Comments
27Sep/080

Aop

K so I was going to have an entire AOP example finished tonight but the family ended up stopping by to see the new baby <excuses, excuses> which means the example will have to come tomorrow.  However here is a great synopsis on aspectj to tide you over till then (I want my AOP!):

Filed under: AOP, Code, Java No Comments

 

September 2010
M T W T F S S
« Aug    
 12345
6789101112
13141516171819
20212223242526
27282930  

Categories

Pages