Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<artifactId>hamcrest-core</artifactId>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
Expand Down
2 changes: 1 addition & 1 deletion rwx-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class JiraServerInfoConverter implements Converter<AbstractJiraServerInfo
@Override
public AbstractJiraServerInfo parse( Object object )
{
Map<String, Object> map = (Map<String, Object>) object;
Map<?, ?> map = (Map<?, ?>) object;
String version = (String) map.get( "version" );
String baseUrl = (String) map.get( "baseUrl" );
String buildDate = (String) map.get( "buildDate" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,15 @@ private void assertMultiCallResponse( MultiCallResponse response )
assertEquals( "org.dashbuilder-dashbuilder-parent-metadata", kojiBuildInfo.getPackageName() );

// if we do not know the type, access Map directly
Map<String, Object> data1Map = (Map<String, Object>) data1;
Map<?, ?> data1Map = (Map<?, ?>) data1;
assertEquals( 48475, data1Map.get( "package_id" ) );
assertEquals( 513598, data1Map.get( "build_id" ) );
assertEquals( "org.dashbuilder-dashbuilder-parent-metadata", data1Map.get( "package_name" ) );


// b. verify response from listTags call

List<Object> data2List = (List<Object>) data2;
List<?> data2List = (List<?>) data2;
assertEquals( 4, data2List.size() );

// if we know the type (KojiTagInfo) in the list, parse the element to it
Expand All @@ -185,7 +185,7 @@ private void assertMultiCallResponse( MultiCallResponse response )
// if we do not know the type, access List directly
Object data2_1 = data2List.get( 0 );
assertTrue( data2_1 instanceof Map );
Map<String, Object> data2_1Map = (Map<String, Object>) data2_1;
Map<?, ?> data2_1Map = (Map<?, ?>) data2_1;
assertEquals( "jb-bxms-6.3-candidate", data2_1Map.get( "name" ) );
assertEquals( 8829, data2_1Map.get( "id" ) );
}
Expand Down
3 changes: 2 additions & 1 deletion rwx/src/main/java/org/commonjava/rwx/core/Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public <T> T parseAs( Object o, Class<T> type )

public Object renderTo( Object obj )
{
Renderer renderer = rendererMap.get( obj.getClass() );
@SuppressWarnings( "unchecked" )
Renderer<Object> renderer = (Renderer<Object>) rendererMap.get( obj.getClass() );
if ( renderer == null )
{
throw new IllegalArgumentException( "Renderer not found for " + obj.getClass() );
Expand Down
9 changes: 8 additions & 1 deletion rwx/src/main/java/org/commonjava/rwx/util/ParseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ public static Object upgradeCast( Class<?> clazz, Object value )

private static <T> Class<T> wrap( Class<T> c )
{
return c.isPrimitive() ? (Class<T>) PRIMITIVES_TO_WRAPPERS.get( c ) : c;
if ( !c.isPrimitive() )
{
return c;
}

@SuppressWarnings( "unchecked" )
Class<T> wrapped = (Class<T>) PRIMITIVES_TO_WRAPPERS.get( c );
return wrapped;
}

private static final Map<Class<?>, Class<?>> PRIMITIVES_TO_WRAPPERS = new HashMap<>();
Expand Down
20 changes: 10 additions & 10 deletions rwx/src/main/java/org/commonjava/rwx/util/RenderUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ else if ( rpcObject instanceof MethodResponse )
}
else if ( rpcObject instanceof Map<?, ?> )
{
return toStructPartXMLString( (Map<String, Object>) rpcObject );
return toStructPartXMLString( (Map<?, ?>) rpcObject );
}
else if ( rpcObject instanceof List )
{
return toArrayPartXMLString( (List<Object>) rpcObject );
return toArrayPartXMLString( (List<?>) rpcObject );
}
else
{
throw new XmlRpcException( "Not supported, " + rpcObject.getClass() );
}
}

private static String toStructPartXMLString( Map<String, Object> rpcObject ) throws XmlRpcException
private static String toStructPartXMLString( Map<?, ?> rpcObject ) throws XmlRpcException
{
StringWriter result = new StringWriter();
try
Expand All @@ -90,7 +90,7 @@ private static String toStructPartXMLString( Map<String, Object> rpcObject ) thr
return result.toString();
}

private static String toArrayPartXMLString( List<Object> rpcObject ) throws XmlRpcException
private static String toArrayPartXMLString( List<?> rpcObject ) throws XmlRpcException
{
StringWriter result = new StringWriter();
try
Expand Down Expand Up @@ -174,11 +174,11 @@ private static void writeValue( XMLStreamWriter w, Object object ) throws XMLStr

if ( object instanceof List )
{
writeArray( w, (List<Object>) object );
writeArray( w, (List<?>) object );
}
else if ( object instanceof Map<?, ?> )
{
writeStruct( w, (Map<String, Object>) object );
writeStruct( w, (Map<?, ?>) object );
}
else
{
Expand All @@ -188,7 +188,7 @@ else if ( object instanceof Map<?, ?> )
w.writeEndElement();
}

private static void writeArray( XMLStreamWriter w, List<Object> objects )
private static void writeArray( XMLStreamWriter w, List<?> objects )
throws XMLStreamException, CoercionException
{
w.writeStartElement( ARRAY );
Expand All @@ -201,15 +201,15 @@ private static void writeArray( XMLStreamWriter w, List<Object> objects )
w.writeEndElement();
}

private static void writeStruct( XMLStreamWriter w, Map<String, Object> map )
private static void writeStruct( XMLStreamWriter w, Map<?, ?> map )
throws XMLStreamException, CoercionException
{
w.writeStartElement( STRUCT );
for ( Map.Entry<String, Object> entry : map.entrySet() )
for ( Map.Entry<?, ?> entry : map.entrySet() )
{
w.writeStartElement( MEMBER );
w.writeStartElement( NAME );
w.writeCharacters( entry.getKey() );
w.writeCharacters( (String) entry.getKey() );
w.writeEndElement();
writeValue( w, entry.getValue() );
w.writeEndElement();
Expand Down
64 changes: 23 additions & 41 deletions rwx/src/main/resources/groovy/Parser.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,65 +18,47 @@ import java.util.Map;
public class ${simpleClassName}_Parser implements Parser<${simpleClassName}>
{
@Override
@SuppressWarnings( "unchecked" )
public ${simpleClassName} parse( Object object )
{
${simpleClassName} ret = new ${simpleClassName}();
Object val;

<% if (structPart == true) { %>
Map<String, Object> map = (Map) object;
<% params.each { %>
<% if (structPart == true) { %>
Map<?, ?> map = (Map<?, ?>) object;
<% params.each { %>
val = map.get( "${it.key}" );
if ( val != null )
{
{
val = nullifyNil( val );
<% if (it.converter != null) { %>
ret.${it.methodName}( new ${it.converter}().parse( val ) );
<% } else if (it.actionClass == null) { %>
<% if (it.isPrimitive) { %>if ( val != null ) <% } %>ret.${it.methodName}( (${it.type}) <% if (it.isUpgradeCast) { %>upgradeCast( ${it.type}.class, val )<% } else { %>val<% } %> );
<% } else { %>
<% if (it.contains) { %>
List<${it.elementClass}> ${it.localListVariableName} = new ArrayList<>();
for ( Object obj : ( List<Object> ) val )
<% if (it.converter != null) { %> ret.${it.methodName}( new ${it.converter}().parse( val ) );
<% } else if (it.actionClass == null) { %> <% if (it.isPrimitive) { %>if ( val != null ) <% } %>ret.${it.methodName}( <% if (it.type != 'java.lang.Object') { %>(${it.type}) <% } %><% if (it.isUpgradeCast) { %>upgradeCast( ${it.type}.class, val )<% } else { %>val<% } %> );
<% } else if (it.contains) { %> List<${it.elementClass}> ${it.localListVariableName} = new ArrayList<>();
for ( Object obj : (List<?>) val )
{
${it.localListVariableName}.add( new ${it.actionClass}().parse( obj ) );
}
ret.${it.methodName}( ${it.localListVariableName} );
<% } else { %>
ret.${it.methodName}( new ${it.actionClass}().parse( val ) );
<% } %>
<% } %>
}
<% } %>
<% } else { %>
<% if (arrayPart == true) { %>
List<Object> list = (List)object;
<% } else { %>
List<Object> list = ((RpcObject) object).getParams();
<% } %>
<% params.eachWithIndex { it, idx -> %>
<% } else { %> ret.${it.methodName}( new ${it.actionClass}().parse( val ) );
<% } %> }
<% } %><% } else { %><% if (arrayPart == true) { %>
List<?> list = (List<?>) object;
<% } else { %>
List<?> list = ((RpcObject) object).getParams();
<% } %><% params.eachWithIndex { it, idx -> %>
val = list.get( ${idx} );
if ( val != null && !isNil( val ) )
{
<% if (it.converter != null) { %>
ret.${it.methodName}( new ${it.converter}().parse( val ) );
<% } else if (it.actionClass == null) { %>
ret.${it.methodName}( (${it.type}) <% if (it.isUpgradeCast) { %>upgradeCast( ${it.type}.class, val )<% } else { %>val<% } %> );
<% } else { %>
<% if (it.contains) { %>
List<${it.elementClass}> ${it.localListVariableName} = new ArrayList<>();
for ( Object obj : ( List<Object> ) val )
<% if (it.converter != null) { %> ret.${it.methodName}( new ${it.converter}().parse( val ) );
<% } else if (it.actionClass == null) { %> ret.${it.methodName}( <% if (it.type != 'java.lang.Object') { %>(${it.type}) <% } %><% if (it.isUpgradeCast) { %>upgradeCast( ${it.type}.class, val )<% } else { %>val<% } %> );
<% } else if (it.contains) { %> List<${it.elementClass}> ${it.localListVariableName} = new ArrayList<>();
for ( Object obj : (List<?>) val )
{
${it.localListVariableName}.add( new ${it.actionClass}().parse( obj ) );
}
ret.${it.methodName}( ${it.localListVariableName} );
<% } else { %>
ret.${it.methodName}( new ${it.actionClass}().parse( val ) );
<% } %>
<% } %>
}
<% } %>
<% } %>
<% } else { %> ret.${it.methodName}( new ${it.actionClass}().parse( val ) );
<% } %> }
<% } %><% } %>
return ret;
}
}
15 changes: 5 additions & 10 deletions rwx/src/main/resources/groovy/Registry.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@ package ${packageName};

import org.commonjava.rwx.core.Registry;

<% imports.each { %>
import ${it};<% } %>

<% imports.each { %>import ${it};
<% } %>
/**
* Created by RWX AnnoProcessor.
*/
public class ${registrySimpleClassName}
public final class ${registrySimpleClassName}
extends Registry
{

public ${registrySimpleClassName}()
{
<% classes.each { %>
setRenderer( ${it}.class, new ${it}_Renderer() );
<% classes.each { %> setRenderer( ${it}.class, new ${it}_Renderer() );
setParser( ${it}.class, new ${it}_Parser() );
<% } %>
}

<% } %> }
}
74 changes: 23 additions & 51 deletions rwx/src/main/resources/groovy/Renderer.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,76 +19,48 @@ public class ${simpleClassName}_Renderer implements Renderer<${simpleClassName}>
@Override
public Object render( ${simpleClassName} object )
{
<% if (request == true) { %>
MethodCall methodCall = new MethodCall();
<% if (request == true) { %> MethodCall methodCall = new MethodCall();
methodCall.setMethodName( "${methodName}" );
<% } else if (response == true) { %>
MethodResponse methodResponse = new MethodResponse();
<% } %>

<% if (structPart == true) { %>
Map<String, Object> map = new HashMap<>();
<% params.each { %>
<% if (it.converter != null) { %>
map.put( "${it.key}", new ${it.converter}().render( object.${it.methodName}() ) );
<% } else if (it.actionClass == null) { %>
map.put( "${it.key}", object.${it.methodName}() );
<% } else { %>
if ( object.${it.methodName}() != null )
<% } else if (response == true) { %> MethodResponse methodResponse = new MethodResponse();

<% } %><% if (structPart == true) { %> Map<String, Object> map = new HashMap<>();
<% params.each { %><% if (it.converter != null) { %> map.put( "${it.key}", new ${it.converter}().render( object.${it.methodName}() ) );
<% } else if (it.actionClass == null) { %> map.put( "${it.key}", object.${it.methodName}() );
<% } else { %> if ( object.${it.methodName}() != null )
{
<% if (it.contains) { %>
List<Object> ${it.localListVariableName} = new ArrayList<>( );
<% if (it.contains) { %> List<Object> ${it.localListVariableName} = new ArrayList<>();
for ( ${it.elementClass} obj : object.${it.methodName}() )
{
${it.localListVariableName}.add( new ${it.actionClass}().render( obj ) );
}
map.put( "${it.key}", ${it.localListVariableName} );
<% } else { %>
map.put( "${it.key}", new ${it.actionClass}().render( object.${it.methodName}() ) );
<% } %>
}
<% } %>
<% } %>
<% } else { %>
List<Object> list = new ArrayList<>();
<% params.each { %>
<% if (it.converter != null) { %>
list.add( new ${it.converter}().render( object.${it.methodName}() ) );
<% } else if (it.actionClass == null) { %>
list.add( object.${it.methodName}() );
<% } else { %>
if ( object.${it.methodName}() != null )
<% } else { %> map.put( "${it.key}", new ${it.actionClass}().render( object.${it.methodName}() ) );
<% } %> }
<% } %><% } %><% } else { %> List<Object> list = new ArrayList<>();
<% params.each { %><% if (it.converter != null) { %> list.add( new ${it.converter}().render( object.${it.methodName}() ) );
<% } else if (it.actionClass == null) { %> list.add( object.${it.methodName}() );
<% } else { %> if ( object.${it.methodName}() != null )
{
<% if (it.contains) { %>
List<Object> ${it.localListVariableName} = new ArrayList<>( );
<% if (it.contains) { %> List<Object> ${it.localListVariableName} = new ArrayList<>();
for ( ${it.elementClass} obj : object.${it.methodName}() )
{
${it.localListVariableName}.add( new ${it.actionClass}().render( obj ) );
}
list.add( ${it.localListVariableName} );
<% } else { %>
list.add( new ${it.actionClass}().render( object.${it.methodName}() ) );
<% } %>
}
<% } else { %> list.add( new ${it.actionClass}().render( object.${it.methodName}() ) );
<% } %> }
else
{
list.add( null );
}
<% } %>
<% } %>
<% } %>

<% if (request == true) { %>
methodCall.setParams( list );
<% } %><% } %><% } %>
<% if (request == true) { %> methodCall.setParams( list );
return methodCall;
<% } else if (response == true) { %>
methodResponse.setParams( list );
<% } else if (response == true) { %> methodResponse.setParams( list );
return methodResponse;
<% } else if (arrayPart == true) { %>
return list;
<% } else { %>
map.values().removeAll( java.util.Collections.singleton( null ) );
<% } else if (arrayPart == true) { %> return list;
<% } else { %> map.values().removeAll( java.util.Collections.singleton( null ) );
return map;
<% } %>
}
<% } %> }
}
Loading
Loading