blob: 1a74136096b13ccacb0ff4034f354861b5ae897f [file]
<%#
* 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 <%= polygene.packageName %>.rest;
import org.apache.polygene.library.restlet.PolygeneRestApplication;
import org.restlet.Context;
import org.restlet.routing.Router;
import org.restlet.security.Enroler;
import org.restlet.security.Verifier;
<%
for( var moduleName in polygene.modules) {
var module = polygene.modules[moduleName];
for( var idx2 in module.cruds ) {
var crud = module.cruds[idx2];
%>import <%= polygene.packageName %>.model.<%= moduleName %>.<%= crud.name %>;
<%
}
}%>
<% if( hasFeature('security') ) { %>
import <%= polygene.packageName %>.rest.security.DefaultEnroler;
import <%= polygene.packageName %>.rest.security.DefaultVerifier;
<% } else { %>
import <%= polygene.packageName %>.rest.security.NullEnroler;
import <%= polygene.packageName %>.rest.security.NullVerifier;
<% } %>
public class <%= polygene.name %>RestApplication extends PolygeneRestApplication
{
private static final String BASEPATH = "/<%= polygene.name.toLowerCase() %>/";
public <%= polygene.name %>RestApplication( Context context )
{
super( context );
}
@Override
protected void addRoutes( Router router )
{
<%
for( var moduleName in polygene.modules) {
var module = polygene.modules[moduleName];
for( var idx2 in module.cruds ) {
var crud = module.cruds[idx2];
%> addResourcePath( "<%= crud.name.toLowerCase() %>", <%= crud.name %>.class, BASEPATH );
<%
}
}
%> System.out.println( "REST API defined;" );
printRoutes( System.out );
}
protected Verifier createVerifier()
{
<% if( hasFeature('security') ) {
%> return objectFactory.newObject(DefaultVerifier.class, this);
<% } else {
%> return objectFactory.newObject(NullVerifier.class, this);
<% }
%> }
protected Enroler createEnroler()
{
<% if( hasFeature('security') ) {
%> return objectFactory.newObject(DefaultEnroler.class, this);
<% } else {
%> return objectFactory.newObject(NullEnroler.class, this);
<% }
%> }
}