oltu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1481727 - in /oltu/whiteboard/simonetripodi/oltu-commons: pom.xml src/main/mdo/AccessTokenRequest.xml src/main/mdo/AccessTokenResponse.xml src/main/stylesheet/commons.xsl
Date Mon, 13 May 2013 08:06:54 GMT
Author: simonetripodi
Date: Mon May 13 08:06:53 2013
New Revision: 1481727

URL: http://svn.apache.org/r1481727
Log:
started defining the JSON serialization

Modified:
    oltu/whiteboard/simonetripodi/oltu-commons/pom.xml
    oltu/whiteboard/simonetripodi/oltu-commons/src/main/mdo/AccessTokenRequest.xml
    oltu/whiteboard/simonetripodi/oltu-commons/src/main/mdo/AccessTokenResponse.xml
    oltu/whiteboard/simonetripodi/oltu-commons/src/main/stylesheet/commons.xsl

Modified: oltu/whiteboard/simonetripodi/oltu-commons/pom.xml
URL: http://svn.apache.org/viewvc/oltu/whiteboard/simonetripodi/oltu-commons/pom.xml?rev=1481727&r1=1481726&r2=1481727&view=diff
==============================================================================
--- oltu/whiteboard/simonetripodi/oltu-commons/pom.xml (original)
+++ oltu/whiteboard/simonetripodi/oltu-commons/pom.xml Mon May 13 08:06:53 2013
@@ -27,6 +27,14 @@
   <artifactId>org.apache.oltu.commons</artifactId>
   <version>1.0.0-SNAPSHOT</version>
 
+  <dependencies>
+    <dependency>
+      <groupId>org.codehaus.jettison</groupId>
+      <artifactId>jettison</artifactId>
+      <version>1.3.3</version>
+    </dependency>
+  </dependencies>
+
   <build>
     <plugins>
       <plugin>

Modified: oltu/whiteboard/simonetripodi/oltu-commons/src/main/mdo/AccessTokenRequest.xml
URL: http://svn.apache.org/viewvc/oltu/whiteboard/simonetripodi/oltu-commons/src/main/mdo/AccessTokenRequest.xml?rev=1481727&r1=1481726&r2=1481727&view=diff
==============================================================================
--- oltu/whiteboard/simonetripodi/oltu-commons/src/main/mdo/AccessTokenRequest.xml (original)
+++ oltu/whiteboard/simonetripodi/oltu-commons/src/main/mdo/AccessTokenRequest.xml Mon May
13 08:06:53 2013
@@ -19,6 +19,6 @@
   <description><![CDATA[Represents the Access Token Request as described in section
<a href="http://tools.ietf.org/html/rfc6749#section-4.3.2">4.3.2</a>.]]></description>
   <parameter field="grantType" type="String" name="grant_type" required="true" />
   <parameter field="username" type="String" name="username" required="true" />
-  <parameter field="password" type="long" name="password" required="false" />
+  <parameter field="password" type="String" name="password" required="false" />
   <parameter field="scope" type="String" name="scope" required="false" />
 </class>

Modified: oltu/whiteboard/simonetripodi/oltu-commons/src/main/mdo/AccessTokenResponse.xml
URL: http://svn.apache.org/viewvc/oltu/whiteboard/simonetripodi/oltu-commons/src/main/mdo/AccessTokenResponse.xml?rev=1481727&r1=1481726&r2=1481727&view=diff
==============================================================================
--- oltu/whiteboard/simonetripodi/oltu-commons/src/main/mdo/AccessTokenResponse.xml (original)
+++ oltu/whiteboard/simonetripodi/oltu-commons/src/main/mdo/AccessTokenResponse.xml Mon May
13 08:06:53 2013
@@ -19,7 +19,7 @@
   <description><![CDATA[Represents the Access Token Response as described in section
<a href="http://tools.ietf.org/html/rfc6749#section-4.3.3">4.3.3</a>.]]></description>
   <parameter field="accessToken" type="String" name="access_token" required="true" />
   <parameter field="tokenType" type="String" name="token_type" required="true" />
-  <parameter field="expiresIn" type="long" name="expires_in" required="false" />
+  <parameter field="expiresIn" type="Long" name="expires_in" required="false" />
   <parameter field="scope" type="String" name="scope" required="false" />
   <parameter field="state" type="String" name="state" required="false" />
 </class>

Modified: oltu/whiteboard/simonetripodi/oltu-commons/src/main/stylesheet/commons.xsl
URL: http://svn.apache.org/viewvc/oltu/whiteboard/simonetripodi/oltu-commons/src/main/stylesheet/commons.xsl?rev=1481727&r1=1481726&r2=1481727&view=diff
==============================================================================
--- oltu/whiteboard/simonetripodi/oltu-commons/src/main/stylesheet/commons.xsl (original)
+++ oltu/whiteboard/simonetripodi/oltu-commons/src/main/stylesheet/commons.xsl Mon May 13
08:06:53 2013
@@ -50,8 +50,12 @@ package org.apache.oltu.commons;
 public final class <xsl:value-of select="@name" />
     extends BaseMessage
 {
-    <xsl:apply-templates select="parameter" mode="staticField" />
     <xsl:apply-templates select="parameter" mode="field" />
+    /**
+     * Hidden constructor, this class can not be instantiated directly.
+     *
+     * @see Builder
+     */
     private <xsl:value-of select="@name" />(<xsl:apply-templates select="parameter"
mode="ctorArg" />)
     {<xsl:apply-templates select="parameter" mode="ctorArgSetting" />
     }
@@ -73,14 +77,58 @@ public final class <xsl:value-of select=
 
     }
 
-}
-</xsl:template>
+    public static final class Utils
+    {
+        <xsl:apply-templates select="parameter" mode="staticField" />
 
-  <xsl:template match="parameter" mode="staticField">
-    /**
-     * The {@code <xsl:value-of select="@name" />} constant.
-     */
-    private static final String <xsl:value-of select="translate(@name, $lcletters, $ucletters)"
/> = "<xsl:value-of select="@name" />";
+        /**
+         * Hidden constructor, this class must not be instantiated.
+         */
+        private Utils()
+        {
+            // do nothing
+        }
+
+        public static String toJsonString(<xsl:value-of select="@name" /> reference)
+        {
+            java.io.StringWriter target = new java.io.StringWriter();
+            toJson( reference, target );
+            return target.toString();
+        }
+
+        public static void toJson(<xsl:value-of select="@name" /> reference, java.io.Writer
target)
+        {
+            org.codehaus.jettison.mapped.MappedNamespaceConvention convention = new org.codehaus.jettison.mapped.MappedNamespaceConvention();
+            org.codehaus.jettison.AbstractXMLStreamWriter writer = new org.codehaus.jettison.mapped.MappedXMLStreamWriter(convention,
target);
+
+            try
+            {
+                writer.writeStartDocument();
+                <xsl:apply-templates select="parameter" mode="jsonWriter" />
+                writer.writeEndDocument();
+            }
+            catch ( Throwable t )
+            {
+                throw new RuntimeException( "An error occurred while transforming <xsl:value-of
select="@name" /> reference to JSON: " + t.getMessage(), t );
+            }
+            finally
+            {
+                if ( target != null )
+                {
+                    try
+                    {
+                        target.close();
+                    }
+                    catch ( java.io.IOException ioe )
+                    {
+                        // swallow it
+                    }
+                }
+            }
+        }
+
+    }
+}
 </xsl:template>
 
   <xsl:template match="parameter" mode="field">
@@ -130,6 +178,23 @@ public final class <xsl:value-of select=
     <xsl:if test="position() &gt; 1">, </xsl:if><xsl:value-of select="@field"
/>
   </xsl:template>
 
+  <xsl:template match="parameter" mode="staticField">
+        /**
+         * The {@code <xsl:value-of select="@name" />} constant.
+         */
+        private static final String <xsl:value-of select="translate(@name, $lcletters,
$ucletters)" /> = "<xsl:value-of select="@name" />";
+</xsl:template>
+
+  <xsl:template match="parameter" mode="jsonWriter">
+        <xsl:value-of select="@type" /> <xsl:text> </xsl:text><xsl:value-of
select="@field" /> = reference.get<xsl:call-template name="toCamelCase"><xsl:with-param
name="fieldName" select="@field" /></xsl:call-template>();
+                if ( <xsl:value-of select="@field" /> != null )
+                {
+                    writer.writeStartElement( <xsl:value-of select="translate(@name, $lcletters,
$ucletters)" /> );
+                    writer.writeCharacters( String.valueOf( <xsl:value-of select="@field"
/> ) );
+                    writer.writeEndElement();
+                }
+                </xsl:template>
+
   <xsl:template name="toCamelCase">
     <xsl:param name="fieldName" />
     <xsl:variable name="f" select="substring($fieldName, 1, 1)" />



Mime
View raw message