You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2014/01/15 10:58:42 UTC

svn commit: r1558330 - /incubator/olingo/site/trunk/content/doc/tutorials/AnnotationProcessorExtension.mdtext

Author: mibo
Date: Wed Jan 15 09:58:42 2014
New Revision: 1558330

URL: http://svn.apache.org/r1558330
Log:
Fixed code inline

Modified:
    incubator/olingo/site/trunk/content/doc/tutorials/AnnotationProcessorExtension.mdtext

Modified: incubator/olingo/site/trunk/content/doc/tutorials/AnnotationProcessorExtension.mdtext
URL: http://svn.apache.org/viewvc/incubator/olingo/site/trunk/content/doc/tutorials/AnnotationProcessorExtension.mdtext?rev=1558330&r1=1558329&r2=1558330&view=diff
==============================================================================
--- incubator/olingo/site/trunk/content/doc/tutorials/AnnotationProcessorExtension.mdtext (original)
+++ incubator/olingo/site/trunk/content/doc/tutorials/AnnotationProcessorExtension.mdtext Wed Jan 15 09:58:42 2014
@@ -45,6 +45,7 @@ In addition we need the dependency to al
 
 The resulting `pom.xml` then looks like:
 
+    :::xml
     <?xml version="1.0" encoding="UTF-8"?>
     <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
@@ -130,6 +131,7 @@ The _Car_ consists of an `Id`, `Model`, 
 #### Create Java Beans for Entities
 For each of both entities first a java bean (_POJO_) is created in the package `org.apache.olingo.sample.annotation.model` which looks like:
 
+    :::java
     package org.apache.olingo.sample.annotation.model;
 
     /** Imports*/
@@ -141,10 +143,11 @@ For each of both entities first a java b
       private List<Car> cars = new ArrayList<Car>();
   
       /** getter and setter */
+    }
 
+and:
 
-
-
+    :::java
     package org.apache.olingo.sample.annotation.model;
     
     /** Imports*/
@@ -157,102 +160,102 @@ For each of both entities first a java b
       private Manufacturer manufacturer;
       
       /** getter and setter */
-
+    }
 
 #### Annotated created Java Beans
 Now those beans have to be annotated with the annotations of the _Annotation Processor Extension_.
 
 Both beans needs at first the `@EdmEntityType` and `@EdmEntitySet` annotation to define that they represent an OData Entity. These annotation must be added at the bean class which as example for the _Manufacturer_ then look like:
 
-```
-@EdmEntityType
-@EdmEntitySet
-public class Manufacturer { /** more code */ }
-```
+    :::java
+    @EdmEntityType
+    @EdmEntitySet
+    public class Manufacturer { /** more code */ }
 
 Then all simple properties of the Entity must be annotated with `@EdmProperty`, the _Key_ for the Entity additional must be annotated with `@EdmKey` which is in this sample the `Id` field of the entities.
 
 For the _Manufacturer_ it then look like:
 
-```
-@EdmEntityType
-@EdmEntitySet
-public class Manufacturer {
-  @EdmKey
-  @EdmProperty
-  private String id;
-  @EdmProperty
-  private String name;
-  @EdmProperty
-  private Calendar founded;
-
- /** more code */ }
-```
+    :::java
+    @EdmEntityType
+    @EdmEntitySet
+    public class Manufacturer {
+      @EdmKey
+      @EdmProperty
+      private String id;
+      @EdmProperty
+      private String name;
+      @EdmProperty
+      private Calendar founded;
+    
+     /** more code */ 
+    }
 
 A relation to another Entity must be annotated with `@EdmNavigationProperty`. In this sample this are the bi-directional relation between a _Manufacturer_ and its _Cars_.  
 
 For the _Manufacturer_ the added annotation look like:
 
-```
-@EdmEntityType
-@EdmEntitySet
-public class Manufacturer {
-  /** more code */ 
-
-  @EdmNavigationProperty
-  private List<Car> cars = new ArrayList<Car>();
-
-  /** more code */ 
-}
-```
-
-The complete resulting Entities (POJOs) then look like:
+    :::java
+    @EdmEntityType
+    @EdmEntitySet
+    public class Manufacturer {
+      /** more code */ 
 
-```
-package org.apache.olingo.sample.annotation.model;
+      @EdmNavigationProperty
+      private List<Car> cars = new ArrayList<Car>();
+    
+      /** more code */ 
+    }
 
-/** Imports*/
 
-@EdmEntityType
-@EdmEntitySet
-public class Manufacturer {
-  @EdmKey
-  @EdmProperty
-  private String id;
-  @EdmProperty
-  private String name;
-  @EdmProperty
-  private Calendar founded;
-  @EdmNavigationProperty
-  private List<Car> cars = new ArrayList<Car>();
+The complete resulting Entities (POJOs) then look like:
 
-  /** getter and setter */
-```
+    :::java
+    package org.apache.olingo.sample.annotation.model;
+    
+    /** Imports*/
+    
+    @EdmEntityType
+    @EdmEntitySet
+    public class Manufacturer {
+      @EdmKey
+      @EdmProperty
+      private String id;
+      @EdmProperty
+      private String name;
+      @EdmProperty
+      private Calendar founded;
+      @EdmNavigationProperty
+      private List<Car> cars = new ArrayList<Car>();
+   
+      /** getter and setter */
+    }
 
 and
 
-```
-package org.apache.olingo.sample.annotation.model;
-
-/** Imports */
-
-@EdmEntityType
-@EdmEntitySet
-public class Car {
-  @EdmKey
-  @EdmProperty
-  private String id;
-  @EdmProperty
-  private String model;
-  @EdmProperty
-  private Double price;
-  @EdmProperty
-  private Integer productionYear;
-  @EdmNavigationProperty
-  private Manufacturer manufacturer;
+    :::java
+    package org.apache.olingo.sample.annotation.model;
+    
+    /** Imports*/
+    
+    @EdmEntityType
+    @EdmEntitySet
+    public class Car {
+      @EdmKey
+      @EdmProperty
+      private String id;
+      @EdmProperty
+      private String model;
+      @EdmProperty
+      private Double price;
+      @EdmProperty
+      private Integer productionYear;
+      @EdmNavigationProperty
+      private Manufacturer manufacturer;
+    
+      /** getter and setter */
+    }
 
-  /** getter and setter */
-```
 
 The next step is to create the `ODataService`.
 
@@ -260,18 +263,19 @@ The next step is to create the `ODataSer
 The `ODataService` is created via an `ODataServiceFactory` implementation.
 For the sample a `AnnotationSampleServiceFactory` in the package `org.apache.olingo.sample.annotation.processor` is created which  extends the `ODataServiceFactory`. The resulting code look like:
 
-```
-package org.apache.olingo.sample.annotation.processor;
+    :::java
+    package org.apache.olingo.sample.annotation.processor;
+
+    /** Imports */
+
+    public class AnnotationSampleServiceFactory extends ODataServiceFactory {
+      @Override
+      public ODataService createService(final ODataContext context) throws ODataException {
+        return null;
+      }
+    }
 
-/** Imports */
 
-public class AnnotationSampleServiceFactory extends ODataServiceFactory {
-  @Override
-  public ODataService createService(final ODataContext context) throws ODataException {
-    return null;
-  }
-}
-```   
 In the `createService(...)` method now the `ODataService` needs to be created.
 The _Annotation Processor Extension_ provides therefore the method `createAnnotationService(...)` within the `AnnotationServiceFactory` which can be used. This method require as parameter the _Package_ which contains the _Model_ in form of annotated POJOs (as created in the section _Create the Model_).  
 
@@ -279,33 +283,36 @@ For a persistence between several reques
 
 As result the implementation look like:
 
-```
-public class AnnotationSampleServiceFactory extends ODataServiceFactory {
+    :::java
+    package org.apache.olingo.sample.annotation.processor;
 
-  /**
-   * Instance holder for all annotation relevant instances which should be used as singleton
-   * instances within the ODataApplication (ODataService)
-   */
-  private static class AnnotationInstances {
-    final static String MODEL_PACKAGE = "org.apache.olingo.sample.annotation.model";
-    final static ODataService ANNOTATION_ODATA_SERVICE;
-    
-    static {
-      try {
-        ANNOTATION_ODATA_SERVICE = AnnotationServiceFactory.createAnnotationService(MODEL_PACKAGE);
-      } catch (ODataApplicationException ex) {
-        throw new RuntimeException("Exception during sample data generation.", ex);
-      } catch (ODataException ex) {
-        throw new RuntimeException("Exception during data source initialization generation.", ex);
+    /** Imports */
+
+    public class AnnotationSampleServiceFactory extends ODataServiceFactory {
+
+      /**
+       * Instance holder for all annotation relevant instances which should be used as singleton
+       * instances within the ODataApplication (ODataService)
+       */
+      private static class AnnotationInstances {
+        final static String MODEL_PACKAGE = "org.apache.olingo.sample.annotation.model";
+        final static ODataService ANNOTATION_ODATA_SERVICE;
+        
+        static {
+          try {
+            ANNOTATION_ODATA_SERVICE = AnnotationServiceFactory.createAnnotationService(MODEL_PACKAGE);
+          } catch (ODataApplicationException ex) {
+            throw new RuntimeException("Exception during sample data generation.", ex);
+          } catch (ODataException ex) {
+            throw new RuntimeException("Exception during data source initialization generation.", ex);
+          }
+        }
+      }
+
+      public ODataService createService(final ODataContext context) throws ODataException {
+        return AnnotationInstances.ANNOTATION_ODATA_SERVICE;
       }
-    }
-  }
 
-  public ODataService createService(final ODataContext context) throws ODataException {
-AnnotationsValueAccess
-    return AnnotationInstances.ANNOTATION_ODATA_SERVICE;
-  }
-```
 
 Now the model as well as the service creation is done.
 The next step is to provide the necessary resources to run the application within an application server. 
@@ -317,32 +324,32 @@ For this sample `Apache CXF` is used (se
 
 Therefore the `web.xml` is created in the `src/main/webapp/WEB-INF` folder with following content:
 
-```
-<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
-	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
-	id="WebApp_ID" version="2.5">
-	<display-name>org.apache.olingo.sample.annotation</display-name>
-	<servlet>
-		<servlet-name>ServiceServlet</servlet-name>
-		<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
-		<init-param>
-			<param-name>javax.ws.rs.Application</param-name>
-			<param-value>org.apache.olingo.odata2.core.rest.app.ODataApplication</param-value>
-		</init-param>
-		<init-param>
-			<param-name>org.apache.olingo.odata2.service.factory</param-name>
-			<param-value>org.apache.olingo.sample.annotation.processor.AnnotationSampleServiceFactory</param-value>
-		</init-param>
-		<load-on-startup>1</load-on-startup>
-	</servlet>
-
-	<servlet-mapping>
-		<servlet-name>ServiceServlet</servlet-name>
-		<url-pattern>/AnnotationSample.svc/*</url-pattern>
-	</servlet-mapping>
-</web-app>
-```
+    :::xml
+    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+	    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+        	id="WebApp_ID" version="2.5">
+	    <display-name>org.apache.olingo.sample.annotation</display-name>
+        	<servlet>
+		        <servlet-name>ServiceServlet</servlet-name>
+	        	<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
+        		<init-param>
+			      <param-name>javax.ws.rs.Application</param-name>
+		              <param-value>org.apache.olingo.odata2.core.rest.app.ODataApplication</param-value>
+	        	</init-param>
+        		<init-param>
+		            <param-name>org.apache.olingo.odata2.service.factory</param-name>
+	    		    <param-value>org.apache.olingo.sample.annotation.processor.AnnotationSampleServiceFactory</param-value>
+        		</init-param>
+		    <load-on-startup>1</load-on-startup>
+	    </servlet>
+    
+	    <servlet-mapping>
+    		    <servlet-name>ServiceServlet</servlet-name>
+		    <url-pattern>/AnnotationSample.svc/*</url-pattern>
+	    </servlet-mapping>
+    </web-app>
+
 
 ### Deploy and Run
 Build the project with maven via `mvm clean package` and copy the resulting `WAR-File` from the projects `target` folder in the `deploy` folder of the application server.
@@ -351,4 +358,4 @@ Now just navigate to the URL (e.g. `http
 
 ## More detailed look
 
-A more detailed look into the Annotation Processor Extension can be found in the [wiki](https://wiki.apache.org/Olingo/Documentation/AnnotationProcessor).
+A more detailed look into the Annotation Processor Extension can be found in the [wiki](https://wiki.apache.org/Olingo/Documentation/AnnotationProcessor).
\ No newline at end of file