| #* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| *# |
| package ${package}; |
| |
| import org.apache.archiva.redback.components.registry.Registry; |
| |
| // Util imports |
| import java.util.*; |
| |
| // Model class imports |
| #foreach ( $class in $classes ) |
| #if ( ${class.packageName} != ${package} ) |
| import ${class.packageName}.${class.name}; |
| #end |
| #end |
| |
| ## TODO! make it possible to change property name via metadata |
| ## TODO! handle other types |
| |
| #macro ( handlePrimitive $localVar $registryVar $name $type $getter ) |
| #if ( $type == "boolean" ) |
| $type $localVar = ${registryVar}.getBoolean( prefix + "${name}", $getter ); |
| #elseif ( $type == "char" ) |
| $javaTool.fail( "Type not yet handled: $type" ) |
| #elseif ( $type == "double" ) |
| $javaTool.fail( "Type not yet handled: $type" ) |
| #elseif ( $type == "float" ) |
| $javaTool.fail( "Type not yet handled: $type" ) |
| #elseif ( $type == "int" ) |
| $type $localVar = ${registryVar}.getInt( prefix + "${name}", $getter ); |
| #elseif ( $type == "long" ) |
| $javaTool.fail( "Type not yet handled: $type" ) |
| #elseif ( $type == "short" ) |
| $javaTool.fail( "Type not yet handled: $type" ) |
| #elseif ( $type == "String" ) |
| //$type $localVar = ${registryVar}.getString( prefix + "${name}", $getter ); |
| |
| List<String> ${localVar}List = registry.getList( prefix + "${name}" ); |
| String ${name} = $getter; |
| if (${localVar}List != null && !${localVar}List.isEmpty() ) |
| { |
| StringBuilder sb = new StringBuilder( ); |
| for (int i = 0,size = ${localVar}List.size();i<size;i++) |
| { |
| sb.append( ${localVar}List.get( i ) ); |
| if (i<size - 1) |
| { |
| sb.append( ',' ); |
| } |
| } |
| ${name} = sb.toString(); |
| } |
| |
| #elseif ( $type == "Boolean" ) |
| $javaTool.fail( "Type not yet handled: $type" ) |
| #elseif ( $type == "Date" ) |
| $javaTool.fail( "Type not yet handled: $type" ) |
| #elseif ( $type == "DOM" ) |
| $javaTool.fail( "Type not yet handled: $type" ) |
| #else |
| $javaTool.fail( "Unknown type: $type" ) |
| #end |
| #end |
| |
| #macro ( fillCollection $uncapFieldName $to ) |
| #set ( $singularFieldName = $javaTool.singular($uncapFieldName) ) |
| #if ( $model.hasClass( $to, $version ) ) |
| ## TODO! make it possible to have unwrapped lists via metadata |
| List ${uncapFieldName}Subsets = registry.getSubsetList( prefix + "${uncapFieldName}.${singularFieldName}" ); |
| for ( Iterator i = ${uncapFieldName}Subsets.iterator(); i.hasNext(); ) |
| { |
| $to v = read${to}( "", (Registry) i.next() ); |
| ${uncapFieldName}.add( v ); |
| } |
| #else |
| ${uncapFieldName}.addAll( registry.getList( prefix + "${uncapFieldName}.${singularFieldName}" ) ); |
| #end |
| #end |
| |
| /** |
| * Generate Redback Registry input mechanism for model '${model.name}'. |
| */ |
| public class ${model.name}RegistryReader |
| { |
| public ${model.name} read( Registry registry ) |
| { |
| #set ( $root = $model.getClass( $model.getRoot( $version ), $version ) ) |
| return read${root.name}( "", registry ); |
| } |
| |
| #foreach ( $class in $classes ) |
| private ${class.name} read${class.name}( String prefix, Registry registry ) |
| { |
| ${class.name} value = new ${class.name}(); |
| |
| #foreach ( $field in $class.getAllFields( $version, true ) ) |
| ## TODO: handle aliases |
| ## TODO: handle required (and optional for those that cry when the registry item is not found) |
| #set ( $uncapFieldName = $javaTool.uncapitalise($field.name) ) |
| #if ( $field.primitive ) |
| #handlePrimitive( $uncapFieldName "registry" $field.name $field.type "value.${javaTool.makeGetter( $field )}()" ) |
| #else |
| #set ( $assoc = $field ) |
| #if ( $assoc.multiplicity == "1" ) |
| $assoc.to $uncapFieldName = read${assoc.to}( prefix + "${uncapFieldName}.", registry ); |
| #else |
| #if ( $assoc.type == "java.util.List" || $assoc.type == "java.util.Set" ) |
| $assoc.type $uncapFieldName = $assoc.defaultValue; |
| #fillCollection( $uncapFieldName $assoc.to ) |
| #elseif ( $assoc.type == "java.util.Map" || $assoc.type == "java.util.Properties" ) |
| ## TODO! make it possible to have exploded maps in xml via metadata |
| $assoc.type $uncapFieldName = registry.getProperties( prefix + "${uncapFieldName}" ); |
| #else |
| $javaTool.fail( "Unknown collection type: $assoc.type" ) |
| #end |
| #end |
| #end |
| value.${javaTool.makeSetter( $field )}( $uncapFieldName ); |
| #end |
| |
| return value; |
| } |
| |
| #end |
| } |