blob: e188755c1fbe48311299430137456240df6813d3 [file] [log] [blame]
<%#
* 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;
<%
}
%>
public class <%= polygene.name %>RestApplication extends PolygeneRestApplication
{
public <%= polygene.name %>RestApplication()
{
super( "/<%= polygene.name.toLowerCase() %>/", createContext() );
}
@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 );
<%
}
}
%> }
@Override
public synchronized void start()
throws Exception
{
super.start();
System.out.println( "REST API defined;" );
printRoutes( System.out );
}
protected Verifier createVerifier()
{
<% if( hasFeature('security') ) {
%> return objectFactory.newObject(DefaultVerifier.class, this);
<% } else {
%> // Security was not specified during generation, and Verifier is not needed.
return null;
<% }
%> }
protected Enroler createEnroler()
{
<% if( hasFeature('security') ) {
%> return objectFactory.newObject(DefaultEnroler.class, this);
<% } else {
%> // Security was not specified during generation, and Enroler is not needed.
return null;
<% }
%> }
private static Context createContext()
{
return new Context("<%= polygene.packageName %>.rest");
}
}