Posts

Showing posts with the label xml

Eclipse PDE: Everything about Editor

Image
Editors are the most important part of eclipse IDE framework. Editor are the primary framework to create and modify resource like files. Every eclipse plug-in or eclipse based products needs to provide custom editor for editing proprietary resources. I am tried to put important parts of Eclipse Editor Framework in this pos. This is the first post from the series "Everything About Editor" Everything about Editor Document Partition Syntax Highlighting Auto-Edit Strategy Code Completion using Content Assist Eclipse divides the concept of a text editor into two parts: the document and the viewer. While the document holds the actual content of the editor, the viewer is responsible for handling the content display. This nice Model-View-Controller (MVC)-style separation allows you to separate code that manipulates the content of the editor from the part that manipulates its display. The Document represents the "model" part of the text editor framework. It c...

Concurrency in Singleton Designing Pattern

      Please refer previous post for Singleton Designing Pattern . Concurrency is the one of the major issues with singleton designing pattern.       There will be multiple client accessing same singleton resource instance. If this resource is mutable then concurrency need to be taken care . Example from previous post is being used here. 1: package demo.singleton; 2: import java.util.concurrent.locks.ReadWriteLock; 3: import java.util.concurrent.locks.ReentrantReadWriteLock; 4: /** 5: * Singleton Resource Class 6: * @author Yogesh 7: */ 8: public class SingletonResource { 9: private static SingletonResource resorce = null ; 10: int count; 11: private ReadWriteLock writeLock = new ReentrantReadWriteLock(); 12: 13: public static SingletonResource getInstance(){ 14: if (resorce == null ){ 15: synchronized (SingletonResource. class ){ 16: if (res...

XML Oriented vs Annotation oriented programming

What is XML Oriented programming ? – In this approach every application have one or set of documents associated with it. This xml documents contain application configuration information which are defines application’s run time behavior. It is very easy to maintain frequently changing configurations setting using xml document. What is Annotation Oriented Programming ? – Annotation oriented programming language leverage active code generation with the use of declaration tags embedded within the application source code to generate any other kind of source code, configuration files etc. XML vs Annotation 1. XML duplicates a lot of information like class, method name etc. But annotation are part of class it self so no duplication of information. For example web.xml <servlet> <servlet-name> DemoServlet </servlet-name> <servlet-class> demo.servlet.DemoServlet </servlet-class> </servlet> <servlet-map...

RESTful WS using Jersey Part 3 – Java Client

This post is with reference of Restful WS using Jersey Part 2 – Parameterized approach to provide a java client for accessing Restful services The Complete code for Java Client /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package demo.client; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; /** * * @author Yogesh */ public class JavaClient {     public static void main(String[] args) {         String restUrlStr = " http://localhost:17286/HelloWorldRestWSPrj/resources/hello/Yogesh?query=age";         URLConnection conn = null;         try {             URL restUrl = new URL(restUrlStr);   ...

RESTful WS using Jersey Part 2 – Parameterized approach

Image
This post is in sequel  RESTful WS using Jersey Part 1 - Hello World . It shows how to utilize parameterized urls as well as query string. Please refer Part 1 to know developing restful services from scratch. This post utilizes same example. Parameters can be passed as part of path as well as url query string. Jersey provides two annotations @PathParam   and @QueryParam for extracting parameters from path and query respectively. We have modified getText method to accept both kind of parameters as below 1. Complete resource class will be package demo.resorces; import javax.ws.rs.core.Context; import javax.ws.rs.core.UriInfo; import javax.ws.rs.PathParam; import javax.ws.rs.Consumes; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.GET; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; /** * REST Web Service * * @author Yogesh */ @Path("hello/{UserName}") p...

RESTful WS using Jersey Part 1 - Hello World

Image
Here is the simple tutorial for RESTful Web Service using jersey implementation for RESTful Web Services. Java EE 6 has introduced jersey API as implementation for JSR-311 as API for RESTful Web Services. For ease of development,deployment and testing i have used NetBean 6.8 which supports JEE 6. Jersey is an annotation based implementation. Here are the few important annotations used in this tutorial @path(“/path/”) - a relative URI path indicating where the Java class will be hosted @GET - a request method designator and corresponds to HTTP Get method @POST - a request method designator and corresponds to HTTP Post method @Produces("text/plain") - specify the MIME media types of representations a resource can produce @Consumes("text/plain") -specify the MIME media types of representations a resource can consume @PathParam("User_Name") - a type of parameter that you can extract for use in your resource class @QueryPar...

New Features in Java Enterprise Edition 6 (JEE 6)

Latest version of Java Enterprise Edition is focused on eae of development and simplicity. Key goals of this version are Extensibility – supports for additional technologies and frameworks Profiles – support for creating custom profiles based on application scope or requirement. Pruning New Features introduced in this edition are Simplified EJB 3.1 No local business interface – one step further from EJB 3.0 specification, EJB 3.1 specifications removes mandatory business interface Singleton EJB – to share application wide data and support concurrent access. EJB 3.1 can be part of war file directly without creating a separate jar file EAR >>       WAR >>             JSP/Static Pages             WEB_INF >>         ...

Building WebService with Custom Serializer using JDeveloper

Image
      JDeveloper 10g comes with UI based web service assembler. It converts simple java class to web service. You can customize web service assembling using Custom Serializer in case Service class accepts pojo class as parameters or return it. This post explains creating web service from simple java class. It is considered that you have gone through previous posts – JAXB by Jdeveloper and XML Document by Jdeveloper . So you have xml schema , xml document and set of java classes generated by JAXB compilation Here is step by step approach 1.    Code a CustomSerializer , it has to implement SOAPElementSerializer and override deserialize and serialize methods. Sample code is as below package jaxb.serializer; import javax.xml.bind.JAXBException; import oracle.webservices.databinding.SOAPElementSerializer; import javax.xml.soap.SOAPFactory; import javax.xml.soap.SOAPException; import javax.xml.soap.SOAPElement; import ja...

JAXB with JDeveloper

Image
      Jdeveloper 10g comes with JAXB1.0 tool .  This tool makes XML programming just one click away.This tutorial explains using JABX compilation tool of JDeveloper. In previous post we have seen handling of XML schema and XML document . You can refer the same as prerequisite for this post . Here is the step by step approach 1. Compile xml schema 2. Mention package and Test class 3. This will generate set of java classes under mentioned java package.You will notice one interface and implementation for each complex type or node. ItemType.java and ItemTypeIMpl.java get generated for  complex types ItemType. As we had selected Main class for generation, it creates Main class for testing JAXB compilation.           4. Here is the marshalling and un-marshalling code . [ refer this post for JAXB Coding ] package jaxb.test; import java.io.File; import javax.xml.bind.JAXBContext; import javax....

Schema to XML document by JDeveloper

Image
This tutorial explain creating xml schema from scratch and creating xml document from it as well. Jdeveloper 10g has a very easy visual editor for creating xml schema as well as xml document. It is considered that you have basic knowledge of schema. Here are step by step approach 1.Create new project and them create new XML schema   2.By default, a simple schema header tag  and an example element   3. Here we are going to construct schema for an Order xml document like  Order>>Item_list>>Item . A order will have id,description,shipTo address and list of items. To construct such structure we will have three complex type order_type, item_type and order_list_type. So create order_type complex type by drag and drop Complex Type component and edit properties   4. Now drag and drop sequence component to complex component 5.  now drag and drop element components one by one and edit the properties   6. There ...