| [comment encoding = UTF-8 /] |
| [comment |
| /******************************************************************************* |
| * Copyright (c) 2012 IBM Corporation and others. |
| * |
| * 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: |
| * |
| * Russell Boykin - initial API and implementation |
| * Alberto Giammaria - initial API and implementation |
| * Chris Peters - initial API and implementation |
| * Gianluca Bernardini - initial API and implementation |
| * Sam Padgett - initial API and implementation |
| * Michael Fiedler - adapted for OSLC4J |
| * Jad El-khoury - initial implementation of code generator (422448) |
| * Matthieu Helleboid - Support for multiple Service Providers. |
| * Anass Radouani - Support for multiple Service Providers. |
| * Frédéric Loiret - Minor changes for Bootstrap template (519699) |
| *******************************************************************************/ |
| /] |
| |
| [module generateResource('http://org.eclipse.lyo/oslc4j/adaptorInterface')] |
| |
| [import org::eclipse::lyo::oslc4j::codegenerator::services::services/] |
| [import org::eclipse::lyo::oslc4j::codegenerator::services::serviceServices/] |
| [import org::eclipse::lyo::oslc4j::codegenerator::services::serviceProviderServices/] |
| [import org::eclipse::lyo::oslc4j::codegenerator::services::resourceServices/] |
| [import org::eclipse::lyo::oslc4j::codegenerator::services::resourcePropertyServices/] |
| [import org::eclipse::lyo::oslc4j::codegenerator::services::adaptorInterfaceServices/] |
| [import org::eclipse::lyo::oslc4j::codegenerator::services::domainSpecificationServices/] |
| |
| [template public resourcePropertyAsTextInputForCreation(aProperty: ResourceProperty)] |
| "<input name=\"[javaName(aProperty, false)/]\" type=\"text\" style=\"width: 400px\" id=\"[javaName(aProperty, false)/]\" [if (Sequence{'excatlyOne', 'oneOrMany'}->includes(aProperty.occurs.toString()))]required[/if]>" |
| [/template] |
| |
| [template public propertyToHtmlForCreationMethod(aProperty: ResourceProperty, aResource: Resource, aCreationDialog: Dialog, methodSignature: String)] |
| static public String [propertyToHtmlForCreationMethodName(aProperty, aResource, aCreationDialog)/] (final HttpServletRequest httpServletRequest[commaSeparate(methodSignature, true, false)/]) |
| { |
| String s = ""; |
| |
| // [protected ('"Init:'.concat(propertyToHtmlForCreationMethodName(aProperty, aResource, aCreationDialog)).concat('(...'.concat(methodSignature).concat(')"')))] |
| // [/protected] |
| |
| s = s + "<label for=\"[aProperty.name/]\">[aProperty.name/]: </LABEL>"; |
| |
| // [protected ('"Mid:'.concat(propertyToHtmlForCreationMethodName(aProperty, aResource, aCreationDialog)).concat('(...'.concat(methodSignature).concat(')"')))] |
| // [/protected] |
| |
| [let valueType : String = aProperty.valueType.toString()] |
| [if (Sequence{'String', 'XMLLiteral', 'DateTime', 'URI', 'Double', 'Float', 'Integer'}->includes(valueType))] |
| s= s + [resourcePropertyAsTextInputForCreation(aProperty) /]; |
| [elseif(valueType = 'Boolean')] |
| s= s + "<input name=\"[javaName(aProperty, false)/]\" type=\"radio\" value=\"true\">True<input name=\"[javaName(aProperty, false)/]\" type=\"radio\" value=\"false\">False"; |
| [elseif(Sequence{'Resource', 'LocalResource'}->includes(valueType))] |
| [comment TODO: How to deal with properties that are resources? Should then also be created, or should hte user get a list of existing such resources to choose from. |
| Latter sounds most reasonable. For now just ignore such properties./] |
| [/if] |
| [/let] |
| // [protected ('"Finalize:'.concat(propertyToHtmlForCreationMethodName(aProperty, aResource, aCreationDialog)).concat('(...'.concat(methodSignature).concat(')"')))] |
| // [/protected] |
| |
| return s; |
| } |
| [/template] |
| |
| [template public generateClassHeader(aResource : Resource, contextAdaptorInterface : AdaptorInterface)] |
| // [protected ('Copyright')] |
| /******************************************************************************* |
| * Copyright (c) 2012 IBM Corporation and others. |
| * |
| * 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: |
| * |
| * Russell Boykin - initial API and implementation |
| * Alberto Giammaria - initial API and implementation |
| * Chris Peters - initial API and implementation |
| * Gianluca Bernardini - initial API and implementation |
| * Sam Padgett - initial API and implementation |
| * Michael Fiedler - adapted for OSLC4J |
| * Jad El-khoury - initial implementation of code generator (422448) |
| * Matthieu Helleboid - Support for multiple Service Providers. |
| * Anass Radouani - Support for multiple Service Providers. |
| * |
| * This file is generated by org.eclipse.lyo.oslc4j.codegenerator |
| *******************************************************************************/ |
| // [/protected] |
| [/template] |
| |
| [template public generatePackageDeclaration(aResource : Resource, contextAdaptorInterface : AdaptorInterface, defaultJavaClassPackageName : String)] |
| package [javaClassPackageName(aResource, contextAdaptorInterface, defaultJavaClassPackageName) /]; |
| [/template] |
| |
| [template public generateImports(aResource : Resource, contextAdaptorInterface : AdaptorInterface, defaultJavaClassPackageName : String)] |
| import java.net.URI; |
| import java.net.URISyntaxException; |
| import java.util.ArrayList; |
| import java.util.Arrays; |
| import java.util.Date; |
| import java.util.HashMap; |
| import java.util.Map; |
| import java.text.SimpleDateFormat; |
| import java.util.HashSet; |
| import java.util.List; |
| import java.util.Set; |
| import java.util.TreeSet; |
| import java.util.Iterator; |
| import javax.servlet.http.HttpServletRequest; |
| import java.io.UnsupportedEncodingException; |
| import java.net.URLEncoder; |
| import javax.ws.rs.core.UriBuilder; |
| |
| import org.eclipse.lyo.oslc4j.core.OSLC4JUtils; |
| import org.eclipse.lyo.oslc4j.core.exception.OslcCoreApplicationException; |
| import org.eclipse.lyo.oslc4j.core.annotation.OslcAllowedValue; |
| import org.eclipse.lyo.oslc4j.core.annotation.OslcDescription; |
| import org.eclipse.lyo.oslc4j.core.annotation.OslcMemberProperty; |
| import org.eclipse.lyo.oslc4j.core.annotation.OslcName; |
| import org.eclipse.lyo.oslc4j.core.annotation.OslcNamespace; |
| import org.eclipse.lyo.oslc4j.core.annotation.OslcOccurs; |
| import org.eclipse.lyo.oslc4j.core.annotation.OslcPropertyDefinition; |
| import org.eclipse.lyo.oslc4j.core.annotation.OslcRange; |
| import org.eclipse.lyo.oslc4j.core.annotation.OslcReadOnly; |
| import org.eclipse.lyo.oslc4j.core.annotation.OslcRepresentation; |
| import org.eclipse.lyo.oslc4j.core.annotation.OslcResourceShape; |
| import org.eclipse.lyo.oslc4j.core.annotation.OslcTitle; |
| import org.eclipse.lyo.oslc4j.core.annotation.OslcValueType; |
| import org.eclipse.lyo.oslc4j.core.model.AbstractResource; |
| import org.eclipse.lyo.oslc4j.core.model.Link; |
| import org.eclipse.lyo.oslc4j.core.model.Occurs; |
| import org.eclipse.lyo.oslc4j.core.model.OslcConstants; |
| import org.eclipse.lyo.oslc4j.core.model.Representation; |
| import org.eclipse.lyo.oslc4j.core.model.ValueType; |
| import org.eclipse.lyo.oslc4j.core.model.ResourceShape; |
| import org.eclipse.lyo.oslc4j.core.model.ResourceShapeFactory; |
| |
| import [javaInterfaceFullNameForConstants(aResource.definingDomainSpecification(), contextAdaptorInterface, defaultJavaClassPackageName)/]; |
| [for (aDomainSpecification: DomainSpecification | (aResource.resourceProperties->union(aResource.interfaceProperties()->asSet())->collect(p: ResourceProperty | Set{p.definingDomainSpecification()}->union(p.range.definingDomainSpecification()->asSet())))->flatten()->asSet()->sortedBy(name)) separator(lineSeparator())]import [javaInterfaceFullNameForConstants(aDomainSpecification, contextAdaptorInterface, defaultJavaClassPackageName) /];[/for] |
| [for (aProperty: ResourceProperty | allProperties(aResource)->sortedBy(name))] |
| [if(Sequence{'Resource', 'LocalResource'}->includes(aProperty.valueType.toString())) ] |
| [for (r: Resource | aProperty.range)] |
| import [javaClassFullName(r, contextAdaptorInterface, defaultJavaClassPackageName) /]; |
| [/for] |
| [/if] |
| [/for] |
| |
| // [protected ('imports')] |
| // [/protected] |
| [/template] |
| |
| [template public generatePreClassCode(aResource : Resource, contextAdaptorInterface : AdaptorInterface)] |
| // [protected ('preClassCode')] |
| // [/protected] |
| [/template] |
| |
| [template public generateClassAnnotations(aResource : Resource, contextAdaptorInterface : AdaptorInterface)] |
| // [protected ('classAnnotations')] |
| // [/protected] |
| [namespaceAnnotation(aResource)/] |
| [nameAnnotation(aResource)/] |
| [resourceShapeAnnotation(aResource)/] |
| [/template] |
| |
| [template public generateClassDeclaration(aResource : Resource, contextAdaptorInterface : AdaptorInterface)] |
| public class [javaClassName(aResource) /] |
| extends [if (aResource.directParentResource().oclIsUndefined())]AbstractResource[else][javaClassName(aResource.directParentResource()) /][/if] |
| implements [javaInterfaceName(aResource)/][if aResource.interfaceResources()->size() > 0], [for (aResourceToInterface: Resource | aResource.interfaceResources()->sortedBy(name)) separator(', ')][javaInterfaceName(aResourceToInterface) /][/for][/if] |
| [/template] |
| |
| [template public generateInstanceAttributes(aResource : Resource, contextAdaptorInterface : AdaptorInterface)] |
| [for (aProperty: ResourceProperty | ((aResource.resourceProperties->asSequence())->union(interfaceProperties(aResource))))] |
| // [protected ('attributeAnnotation:'.concat(javaAttributeName(aProperty, aResource)))] |
| // [/protected] |
| private [javaAttributeTypeDeclaration(aProperty) /] [javaAttributeName(aProperty, aResource)/][if javaAttributeTypeNeedsConstruction(aProperty)] = new [javaAttributeTypeDeclaration(aProperty)/]()[/if]; |
| [/for] |
| [/template] |
| |
| [template public generateClassAttributes(aResource : Resource, contextAdaptorInterface : AdaptorInterface)] |
| // [protected ('classAttributes')] |
| // [/protected] |
| [/template] |
| |
| [template public generateClassMethods(aResource : Resource, contextAdaptorInterface : AdaptorInterface)] |
| // [protected ('classMethods')] |
| // [/protected] |
| [/template] |
| |
| [template public generateConstructors(aResource : Resource, contextAdaptorInterface : AdaptorInterface)] |
| public [javaClassName(aResource) /]() |
| throws URISyntaxException |
| { |
| super(); |
| |
| // [protected ('constructor1')] |
| // [/protected] |
| } |
| |
| public [javaClassName(aResource) /](final URI about) |
| throws URISyntaxException |
| { |
| super(about); |
| |
| // [protected ('constructor2')] |
| // [/protected] |
| } |
| |
| [for (aBasicCapability: BasicCapability | basicCapabilities(contextAdaptorInterface, aResource))] |
| [let methodSuffix: String = (if (basicCapabilities(contextAdaptorInterface, aResource)->size() = 1) then '' else basicCapabilities(contextAdaptorInterface, aResource)->indexOf(aBasicCapability).toString() endif)] |
| [if (basicCapabilities(contextAdaptorInterface, aResource)->indexOf(aBasicCapability) = 1)] |
| /** |
| * @deprecated Use the methods in class {@link [javaClassFullNameForResourcesFactory(contextAdaptorInterface)/]} instead. |
| */ |
| @Deprecated |
| public [javaClassName(aResource)/]([commaSeparate(aResource.instanceMethodSignature(aBasicCapability, false), false, false)/]) |
| throws URISyntaxException |
| { |
| this (constructURI[methodSuffix/]([commaSeparate(aResource.instanceMethodParameterList(aBasicCapability), false, false)/])); |
| // [protected ('constructor3')] |
| // [/protected] |
| } |
| [/if] |
| |
| /** |
| * @deprecated Use the methods in class {@link [javaClassFullNameForResourcesFactory(contextAdaptorInterface)/]} instead. |
| */ |
| @Deprecated |
| public static URI constructURI[methodSuffix/]([commaSeparate(aResource.instanceMethodSignature(aBasicCapability, false), false, false)/]) |
| { |
| String basePath = OSLC4JUtils.getServletURI(); |
| Map<String, Object> pathParameters = new HashMap<String, Object>(); |
| [for (instanceCompositeID: String | aResource.instanceCompositeID(aBasicCapability))] |
| pathParameters.put("[instanceCompositeID /]", [instanceCompositeID /]); |
| [/for] |
| String instanceURI = "[aResource.instanceURI(aBasicCapability) /]"; |
| |
| final UriBuilder builder = UriBuilder.fromUri(basePath); |
| return builder.path(instanceURI).buildFromMap(pathParameters); |
| } |
| |
| /** |
| * @deprecated Use the methods in class {@link [javaClassFullNameForResourcesFactory(contextAdaptorInterface)/]} instead. |
| */ |
| @Deprecated |
| public static Link constructLink[methodSuffix/]([commaSeparate(aResource.instanceMethodSignature(aBasicCapability, false), false, true)/] final String label) |
| { |
| return new Link(constructURI[methodSuffix/]([commaSeparate(aResource.instanceMethodParameterList(aBasicCapability), false, false)/]), label); |
| } |
| |
| /** |
| * @deprecated Use the methods in class {@link [javaClassFullNameForResourcesFactory(contextAdaptorInterface)/]} instead. |
| */ |
| @Deprecated |
| public static Link constructLink[methodSuffix/]([commaSeparate(aResource.instanceMethodSignature(aBasicCapability, false), false, false)/]) |
| { |
| return new Link(constructURI[methodSuffix/]([commaSeparate(aResource.instanceMethodParameterList(aBasicCapability), false, false)/])); |
| } |
| [/let] |
| [/for] |
| [/template] |
| |
| [template public generateResourceShapeMethods(aResource : Resource, contextAdaptorInterface : AdaptorInterface)] |
| public static ResourceShape createResourceShape() throws OslcCoreApplicationException, URISyntaxException { |
| return ResourceShapeFactory.createResourceShape(OSLC4JUtils.getServletURI(), |
| OslcConstants.PATH_RESOURCE_SHAPES, |
| [javaInterfaceNameForConstants(aResource.definingDomainSpecification())/].[resourcePathConstantName(aResource)/], |
| [javaClassName(aResource) /].class); |
| } |
| |
| |
| [/template] |
| |
| |
| [template public generateToStringMethods(aResource : Resource, contextAdaptorInterface : AdaptorInterface)] |
| public String toString() |
| { |
| return toString(false); |
| } |
| |
| public String toString(boolean asLocalResource) |
| { |
| String result = ""; |
| // [protected ('toString_init')] |
| // [/protected] |
| |
| if (asLocalResource) { |
| result = result + "{a Local [aResource.name.toUpperFirst() /] Resource} - update [aResource.name.toUpperFirst() /].toString() to present resource as desired."; |
| // [protected ('toString_bodyForLocalResource')] |
| // [/protected] |
| } |
| else { |
| result = getAbout().toString(); |
| } |
| |
| // [protected ('toString_finalize')] |
| // [/protected] |
| |
| return result; |
| } |
| |
| public String toHtml() |
| { |
| return toHtml(false); |
| } |
| |
| public String toHtml(boolean asLocalResource) |
| { |
| String result = ""; |
| // [protected ('toHtml_init')] |
| // [/protected] |
| |
| if (asLocalResource) { |
| result = toString(true); |
| // [protected ('toHtml_bodyForLocalResource')] |
| // [/protected] |
| } |
| else { |
| result = "<a href=\"" + getAbout() + "\" class=\"oslc-resource-link\">" + toString() + "</a>"; |
| } |
| |
| // [protected ('toHtml_finalize')] |
| // [/protected] |
| |
| return result; |
| } |
| |
| [/template] |
| |
| [template public generateAddToAttributeMethods(aResource : Resource, contextAdaptorInterface : AdaptorInterface)] |
| [for (aProperty: ResourceProperty | ((aResource.resourceProperties->asSequence())->union(interfaceProperties(aResource))))] |
| [if (Sequence{'zeroOrMany', 'oneOrMany'}->includes(aProperty.occurs.toString()))] |
| public void add[javaAttributeName(aProperty, aResource).toUpperFirst()/](final [javaAttributeBaseType(aProperty) /] [javaName(aProperty, false)/]) |
| { |
| this.[javaAttributeName(aProperty, aResource) /].add([javaName(aProperty, false)/]); |
| } |
| |
| [/if] |
| [/for] |
| [/template] |
| |
| [template public generateGetters(aResource : Resource, contextAdaptorInterface : AdaptorInterface)] |
| [for (aProperty: ResourceProperty | ((aResource.resourceProperties->asSequence())->union(interfaceProperties(aResource))))] |
| // [protected ('getterAnnotation:'.concat(javaAttributeName(aProperty, aResource)))] |
| // [/protected] |
| [if (not (nameAnnotation(aProperty) = ''))] |
| [nameAnnotation(aProperty)/] |
| [/if] |
| [if (not (propertyDefinitionAnnotation(aProperty, aResource, contextAdaptorInterface) = ''))] |
| [propertyDefinitionAnnotation(aProperty, aResource, contextAdaptorInterface)/] |
| [/if] |
| [if (not (descriptionAnnotation(aProperty) = ''))] |
| [descriptionAnnotation(aProperty)/] |
| [/if] |
| [if (not (occursAnnotation(aProperty) = ''))] |
| [occursAnnotation(aProperty)/] |
| [/if] |
| [if (not (valueTypeAnnotation(aProperty) = ''))] |
| [valueTypeAnnotation(aProperty)/] |
| [/if] |
| [if (not (representationAnnotation(aProperty) = ''))] |
| [representationAnnotation(aProperty)/] |
| [/if] |
| [if (not (rangeAnnotation(aProperty, aResource, contextAdaptorInterface)= ''))] |
| [rangeAnnotation(aProperty, aResource, contextAdaptorInterface)/] |
| [/if] |
| [if (not (readOnlyAnnotation(aProperty) = ''))] |
| [readOnlyAnnotation(aProperty)/] |
| [/if] |
| [if (not (titleAnnotation(aProperty)= ''))] |
| [titleAnnotation(aProperty)/] |
| [/if] |
| [if (not (isMemberPropertyAnnotation(aProperty)= ''))] |
| [isMemberPropertyAnnotation(aProperty)/] |
| [/if] |
| [if (not (allowedValueAnnotation(aProperty)= ''))] |
| [allowedValueAnnotation(aProperty)/] |
| [/if] |
| public [javaAttributeTypeDeclaration(aProperty) /] [if (aProperty.valueType.toString() = 'Boolean')]is[else]get[/if][javaAttributeName(aProperty, aResource).toUpperFirst() /]() |
| { |
| // [protected ('getterInit:'.concat(javaAttributeName(aProperty, aResource)))] |
| // [/protected] |
| return [javaAttributeName(aProperty, aResource) /]; |
| } |
| |
| [/for] |
| [/template] |
| |
| [template public generateSetters(aResource : Resource, contextAdaptorInterface : AdaptorInterface)] |
| [for (aProperty: ResourceProperty | ((aResource.resourceProperties->asSequence())->union(interfaceProperties(aResource))))] |
| // [protected ('setterAnnotation:'.concat(javaAttributeName(aProperty, aResource)))] |
| // [/protected] |
| public void set[javaAttributeName(aProperty, aResource).toUpperFirst()/](final [javaAttributeTypeDeclaration(aProperty) /] [javaName(aProperty, false)/] ) |
| { |
| // [protected ('setterInit:'.concat(javaAttributeName(aProperty, aResource)))] |
| // [/protected] |
| [if (Sequence{'zeroOrMany', 'oneOrMany'}->includes(aProperty.occurs.toString()))] |
| this.[javaAttributeName(aProperty, aResource) /].clear(); |
| if ([javaName(aProperty, false)/] != null) |
| { |
| this.[javaAttributeName(aProperty, aResource) /].addAll([javaName(aProperty, false)/]); |
| } |
| [else] |
| this.[javaAttributeName(aProperty, aResource) /] = [javaName(aProperty, false)/]; |
| [/if] |
| |
| // [protected ('setterFinalize:'.concat(javaAttributeName(aProperty, aResource)))] |
| // [/protected] |
| } |
| |
| [/for] |
| [/template] |
| |
| [template public generateAttributeToHtmlMethods(aResource : Resource, contextAdaptorInterface : AdaptorInterface)] |
| [for (aProperty: ResourceProperty | ((aResource.resourceProperties->asSequence())->union(interfaceProperties(aResource))))] |
| [propertyToHtmlForCreationMethod(aProperty, aResource, null, '')/] |
| |
| [for (aCreationDialog: Dialog| contextAdaptorInterface.creationDialogs(aResource))] |
| [propertyToHtmlForCreationMethod(aProperty, aResource, aCreationDialog, dialogMethodSignature(aCreationDialog, false, false))/] |
| [/for] |
| [/for] |
| |
| [comment TODO: This ToHTML is quite complicated. At the moment, I get expections because some of the properties are null. |
| I am getting to many if/else-ses. I think I need to rethink calmely to have a cleaner structure. Good enough for now I hope. /] |
| [for (aProperty: ResourceProperty | ((aResource.resourceProperties->asSequence())->union(interfaceProperties(aResource))))] |
| public String [javaAttributeName(aProperty, aResource) /]ToHtml() |
| { |
| String s = ""; |
| |
| // [protected (javaAttributeName(aProperty, aResource).concat('toHtml_mid'))] |
| // [/protected] |
| |
| try { |
| [comment For these basic valueTypes, one can simply call toString on the attribte /] |
| [if (Sequence{'Boolean', 'String', 'XMLLiteral', 'DateTime', 'URI', 'Double', 'Float', 'Integer'}->includes(aProperty.valueType.toString()))] |
| [if (Sequence{'zeroOrMany', 'oneOrMany'}->includes(aProperty.occurs.toString()))] |
| s = s + "<ul>"; |
| Iterator<[javaAttributeBaseType(aProperty) /]> itr = [javaAttributeName(aProperty, aResource) /].iterator(); |
| while(itr.hasNext()) { |
| s = s + "<li>"; |
| s= s + itr.next().toString(); |
| s = s + "</li>"; |
| } |
| s = s + "</ul>"; |
| [else] |
| if ([javaAttributeName(aProperty, aResource)/] == null) { |
| s = s + "<em>null</em>"; |
| } |
| else { |
| s = s + [javaAttributeName(aProperty, aResource)/].toString(); |
| } |
| [/if] |
| [comment a property with valueType of resource or LocalResource can return either a Class directly referring to a Resource, or Link. |
| If we get a Link, we want to check if we can also work out which kind of resource class this Link refers to. If we can find out, |
| we want to call toHtml on that class. if we cannot, we simply print the Link as a string. /] |
| [elseif(Sequence{'Resource', 'LocalResource'}->includes(aProperty.valueType.toString()))] |
| [if (Sequence{'zeroOrMany', 'oneOrMany'}->includes(aProperty.occurs.toString()))] |
| s = s + "<ul>"; |
| for([javaAttributeBaseType(aProperty) /] next : [javaAttributeName(aProperty, aResource) /]) { |
| s = s + "<li>"; |
| [if (javaAttributeBaseType(aProperty) = 'Link')] |
| [if (aProperty.range->size() = 1)] |
| [comment Even if it is a Link, there are cases where I actually know that the link should point to a particular resource class. |
| (For example, for valueType = Resource, we get a Link irrespective of whether the valueType is set to a specific resource or not. ) /] |
| s = s + (new [javaClassName(aProperty.range->first()) /] (next.getValue())).toHtml([if (aProperty.valueType.toString() = 'LocalResource')]true[else]false[/if]); |
| [else] |
| [comment just print the Link's URI as a String /] |
| if (next.getValue() == null) { |
| s= s + "<em>null</em>"; |
| } |
| else { |
| s = s + "<a href=\"" + next.getValue().toString() + "\">" + next.getValue().toString() + "</a>"; |
| } |
| [/if] |
| [else] |
| [comment itr refers to direct Resource class, and hence can simply call toHtml() on /] |
| s = s + next.toHtml([if (aProperty.valueType.toString() = 'LocalResource')]true[else]false[/if]); |
| [/if] |
| s = s + "</li>"; |
| } |
| s = s + "</ul>"; |
| [else] |
| [if (javaAttributeBaseType(aProperty) = 'Link')] |
| [if (aProperty.range->size() = 1)] |
| [comment Even if it is a Link, there are cases where I actually know that the link should point to a particular resource class. |
| (For example, for valueType = Resource, we get a Link irrespective of whether the valueType is set to a specific resource or not. ) /] |
| if (([javaAttributeName(aProperty, aResource)/] == null) || ([javaAttributeName(aProperty, aResource)/].getValue() == null)) { |
| s = s + "<em>null</em>"; |
| } |
| else { |
| s = s + (new [javaClassName(aProperty.range->first()) /] ([javaAttributeName(aProperty, aResource)/].getValue())).toHtml([if (aProperty.valueType.toString() = 'LocalResource')]true[else]false[/if]); |
| } |
| [else] |
| [comment just print the Link's URI as a String /] |
| if (([javaAttributeName(aProperty, aResource)/] == null) || ([javaAttributeName(aProperty, aResource)/].getValue() == null)) { |
| s = s + "<em>null</em>"; |
| } |
| else { |
| s = s + [javaAttributeName(aProperty, aResource)/].getValue().toString(); |
| } |
| [/if] |
| [else] |
| [comment the attribute refers to direct Resource class, and hence can simply call toHtml() on /] |
| if ([javaAttributeName(aProperty, aResource)/] == null) { |
| s = s + "<em>null</em>"; |
| } |
| else { |
| s = s + [javaAttributeName(aProperty, aResource)/].toHtml([if (aProperty.valueType.toString() = 'LocalResource')]true[else]false[/if]); |
| } |
| [/if] |
| [/if] |
| [/if] |
| } catch (Exception e) { |
| e.printStackTrace(); |
| } |
| |
| // [protected (javaAttributeName(aProperty, aResource).concat('toHtml_finalize'))] |
| // [/protected] |
| |
| return s; |
| } |
| |
| [/for] |
| [/template] |
| |
| [template public generateResource(aResource : Resource, contextAdaptorInterface : AdaptorInterface, defaultJavaFilesPath : String, defaultJavaClassPackageName : String)] |
| [file (javaClassFullFileName(aResource, contextAdaptorInterface, defaultJavaFilesPath, defaultJavaClassPackageName), false, 'UTF-8')] |
| [generateClassHeader(aResource, contextAdaptorInterface)/] |
| |
| [generatePackageDeclaration(aResource, contextAdaptorInterface, defaultJavaClassPackageName)/] |
| |
| [generateImports(aResource, contextAdaptorInterface, defaultJavaClassPackageName)/] |
| |
| [generatePreClassCode(aResource, contextAdaptorInterface)/] |
| |
| [generateClassAnnotations(aResource, contextAdaptorInterface)/] |
| [generateClassDeclaration(aResource, contextAdaptorInterface)/] |
| { |
| [generateInstanceAttributes(aResource, contextAdaptorInterface)/] |
| [generateClassAttributes(aResource, contextAdaptorInterface)/] |
| [generateClassMethods(aResource, contextAdaptorInterface)/] |
| [generateConstructors(aResource, contextAdaptorInterface)/] |
| [generateResourceShapeMethods(aResource, contextAdaptorInterface)/] |
| [generateToStringMethods(aResource, contextAdaptorInterface)/] |
| [generateAddToAttributeMethods(aResource, contextAdaptorInterface)/] |
| [generateGetters(aResource, contextAdaptorInterface)/] |
| [generateSetters(aResource, contextAdaptorInterface)/] |
| [generateAttributeToHtmlMethods(aResource, contextAdaptorInterface)/] |
| } |
| [/file] |
| [/template] |