| [comment encoding = UTF-8 /] |
| [comment |
| /******************************************************************************* |
| * Copyright (c) 2017 Jad El-khoury. |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * and Eclipse Distribution License v. 1.0 which accompanies this distribution. |
| * |
| * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html |
| * and the Eclipse Distribution License is available at |
| * http://www.eclipse.org/org/documents/edl-v10.php. |
| * |
| * Contributors: |
| * |
| * Jad El-khoury - initial implementation of main class for client-only adaptor |
| * |
| *******************************************************************************/ |
| /] |
| |
| [module generateClientOnlyMainApplication('http://org.eclipse.lyo/oslc4j/adaptorInterface')] |
| |
| [import org::eclipse::lyo::oslc4j::codegenerator::services::services/] |
| [import org::eclipse::lyo::oslc4j::codegenerator::services::resourceServices/] |
| [import org::eclipse::lyo::oslc4j::codegenerator::services::requiredAdaptorServices/] |
| [import org::eclipse::lyo::oslc4j::codegenerator::services::adaptorInterfaceServices/] |
| [import org::eclipse::lyo::oslc4j::codegenerator::services::serviceServices/] |
| [import org::eclipse::lyo::oslc4j::codegenerator::services::serviceProviderServices/] |
| [import org::eclipse::lyo::oslc4j::codegenerator::services::serviceProviderCatalogServices/] |
| |
| [template public generateClientOnlyMainApplication(anAdaptorInterface : AdaptorInterface)] |
| [file (javaClassFullFileNameForClientOnlyMainApplication(anAdaptorInterface), false, 'UTF-8')] |
| /******************************************************************************* |
| * Copyright (c) 2017 Jad El-khoury. |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * and Eclipse Distribution License v. 1.0 which accompanies this distribution. |
| * |
| * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html |
| * and the Eclipse Distribution License is available at |
| * http://www.eclipse.org/org/documents/edl-v10.php. |
| * |
| * Contributors: |
| * |
| * Jad El-khoury - initial implementation of main class for client-only adaptor |
| * |
| * This file is generated by org.eclipse.lyo.oslc4j.codegenerator |
| *******************************************************************************/ |
| |
| package [javaClassPackageNameForClientOnlyMainApplication(anAdaptorInterface) /]; |
| |
| import java.io.File; |
| import java.io.FileOutputStream; |
| import java.util.ArrayList; |
| import java.util.List; |
| import java.util.NoSuchElementException; |
| import java.util.logging.Level; |
| import java.util.logging.Logger; |
| import java.net.MalformedURLException; |
| |
| import org.eclipse.lyo.oslc4j.core.OSLC4JUtils; |
| import org.eclipse.lyo.oslc4j.core.model.ResourceShape; |
| import org.eclipse.lyo.oslc4j.core.model.ResourceShapeFactory; |
| import org.eclipse.lyo.oslc4j.core.model.ServiceProviderCatalog; |
| import org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper; |
| |
| import com.hp.hpl.jena.rdf.model.Model; |
| |
| [for (aResource: Resource | relevantResources(anAdaptorInterface)->sortedBy(name)) separator(lineSeparator())]import [javaClassFullName(aResource, anAdaptorInterface, null) /];[/for] |
| [for (aRequiredAdaptor: RequiredAdaptor | anAdaptorInterface.requiredAdaptors) separator(lineSeparator())]import [javaClassFullNameForClient(aRequiredAdaptor, anAdaptorInterface) /];[/for] |
| |
| // [protected ('imports')] |
| // [/protected] |
| |
| // [protected ('pre_class_code')] |
| // [/protected] |
| |
| public class [javaClassNameForClientOnlyMainApplication(anAdaptorInterface)/] { |
| |
| private static String baseUrl = "http://localhost:8080"; |
| private static String servletUrlPattern = "services/"; |
| private static final Logger logger = Logger.getLogger([javaClassNameForClientOnlyMainApplication(anAdaptorInterface) /].class.getName()); |
| |
| // [protected ('class_attributes')] |
| // [/protected] |
| |
| // [protected ('class_methods')] |
| // [/protected] |
| |
| public static void main(String['[]'/] args) throws Exception |
| { |
| // [protected ('main')] |
| //TODO: Replace/adjust this default main function as necessary. |
| //All manual changes in this "protected" user code area will NOT be overwritten upon subsequent code generations. |
| //To revert to the default generated content, delete all content in this file, and then re-generate. |
| try { |
| OSLC4JUtils.setPublicURI(baseUrl); |
| OSLC4JUtils.setServletPath(servletUrlPattern); |
| } catch (MalformedURLException e) { |
| logger.log(Level.SEVERE, "Application encountered MalformedURLException.", e); |
| } catch (IllegalArgumentException e) { |
| logger.log(Level.SEVERE, "Application encountered IllegalArgumentException.", e); |
| } |
| |
| [for (aRequiredAdaptor: RequiredAdaptor | anAdaptorInterface.requiredAdaptors)] |
| ServiceProviderCatalog [javaClassNameForClient(aRequiredAdaptor).toLowerFirst().concat('Catalog')/] = [javaClassNameForClient(aRequiredAdaptor)/].getServiceProviderCatalog(); |
| [/for] |
| |
| List<ResourceShape> shapes = new ArrayList<ResourceShape>(); |
| [for (aResource: Resource | relevantResources(anAdaptorInterface)->sortedBy(name))] |
| shapes.add([javaClassName(aResource)/].createResourceShape()); |
| [/for] |
| Model model = JenaModelHelper.createJenaModel(shapes.toArray()); |
| String fileName = "resourceShapes.ttl"; |
| FileOutputStream output = new FileOutputStream(new File(fileName)); |
| model.write(output, "TURTLE" ); |
| } |
| // [/protected] |
| } |
| [/file] |
| [/template] |