Skip to main content
summaryrefslogblamecommitdiffstats
blob: 533bebbcaf6f403be3e91f6a72690349c569ce55 (plain) (tree)























































































































                                                                                                                               



                                                                                            




































                                                                                                                                                           
[comment encoding = UTF-8 /]
[comment
/*******************************************************************************
 * Copyright (c) 2014 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 code generator (https://bugs.eclipse.org/bugs/show_bug.cgi?id=422448)
 *     
 *******************************************************************************/
/]

[module services('http://org.eclipse.lyo/oslc4j/adaptorInterface')/]

[query public javaClassBaseNamespace(anAdaptorInterface : AdaptorInterface) : String = 
anAdaptorInterface.javaClassBaseNamespace
/]

[query public javaFilesBasePath(anAdaptorInterface : AdaptorInterface) : String = 
anAdaptorInterface.javaFilesBasePath
/]

[query public jspFilesBasePath(anAdaptorInterface : AdaptorInterface) : String = 
anAdaptorInterface.jspFilesBasePath
/]

[query public javascriptFilesBasePath(anAdaptorInterface : AdaptorInterface) : String = 
anAdaptorInterface.javascriptFilesBasePath
/]


[query public jspFilesWebappPath(anAdaptorInterface : AdaptorInterface) : String = 
'/'.concat(javaClassBaseNamespace(anAdaptorInterface)).substituteAll('.', '/')
/]

[query public methodSignature(parameters: Sequence(String), forJAXRSMethod : Boolean) : String =  
concatenate(
	parameters->collect(aParameter: String |
					    (if (forJAXRSMethod) then 
					        '@PathParam("'.concat(aParameter).concat('") final String ').concat(aParameter)
					    else 
					        'final String '.concat(aParameter)
					    endif)
	)->sep(', ').oclAsType(String))
/]

[query public methodParameterList(parameters: Sequence(String)) : String =  
concatenate(parameters->sep(', ').oclAsType(String))
/]

[query public JAXRSPathAnnotation(pathAnnotation : String) : String = 
    (if (pathAnnotation.size() >= 1) then 
        '@Path("'.concat(pathAnnotation).concat('")')
    else 
        ''
    endif)
/]

[query public JAXRSPathParameters(uriSegment : String) : Sequence(String) = 
uriSegment.tokenize('}')
    ->select(token : String | token.index('{') <> -1)
    ->collect(token : String | token.substring(token.index('{')+1))
/]

[query private stripURISegmentEnd(URISegment : String) : String = 
(if (URISegment.size() = 0) then 
     URISegment
else 
    (if (URISegment.size() = 1) then 
         (if (URISegment.endsWith('/')) then '' else URISegment endif)
    else 
        URISegment.substring(1, URISegment.size()-(if (URISegment.endsWith('/')) then 1 else 0 endif))
    endif)
endif)
/]

[query private stripURISegmentStart(URISegment : String) : String = 
(if (URISegment.size() = 0) then 
     URISegment
else 
    (if (URISegment.size() = 1) then 
         (if (URISegment.startsWith('/')) then '' else URISegment endif)
    else 
        URISegment.substring((if (URISegment.startsWith('/')) then 2 else 1 endif), URISegment.size())
    endif)
endif)
/]

[query public JAXRSConcatURISegments(leftURISegment : String, rightURISegment : String) : String = 
	concatenatePaths(leftURISegment, rightURISegment) 
/]

[query public concatenatePaths (leftSegment : String, rightSegment : String) : String = 
(if (stripURISegmentEnd(leftSegment).size() = 0) then 
    stripURISegmentStart(rightSegment) 
else 
    (if (stripURISegmentStart(rightSegment).size() = 0) then 
        stripURISegmentEnd(leftSegment) 
    else 
        stripURISegmentEnd(leftSegment).concat('/').concat(stripURISegmentStart(rightSegment)) 
    endif)
endif)
/]

[query public commaSeparate(commaSeparatedString : String, prependIfNotEmpty : Boolean, appendIfNotEmpty : Boolean) : String = 
(if prependIfNotEmpty._and(commaSeparatedString.size() > 0) then ', ' else ''endif)
.concat(commaSeparatedString)
.concat(
(if appendIfNotEmpty._and(commaSeparatedString.size() > 0) then ' ,' else ''endif)
)
/]

[query public javaSimpleStringFromUri(uriString: String, toUpperFirst : Boolean) : String = 
javaString(uriString.tokenize('/\\#')->last(), toUpperFirst)
/]

[query public javaConstantString (aString : String) : String = 
concatenate(
	aString.replaceAll('\\W+', '_').tokenize('_')->sep('_').oclAsType(String)
).toUpperCase()
/]

[query public javaString (aString : String) : String = 
concatenate(
	aString.replaceAll('\\W+', ' ').tokenize(' ')->collect(s : String  | s.toUpperFirst())
)
/]

[query public javaString (aString : String, toUpperFirst : Boolean) : String = 
if (toUpperFirst) then javaString(aString).toUpperFirst() else javaString(aString).toLowerFirst() endif
/]

[query public concatenate (aStringSequence : Sequence(String)) : String = 
(if (aStringSequence->size() = 0) then 
    '' 
else 
    (if (aStringSequence->size() = 1) then 
		aStringSequence->at(1)
    else 
	    (if (aStringSequence->size() = 2) then 
			aStringSequence->at(1).concat(aStringSequence->at(2))
	    else 
			aStringSequence->at(1).concat(aStringSequence->at(2)).concat(concatenate(aStringSequence->subSequence(3, aStringSequence->size())))
	    endif)
    endif)
endif)
/]

[query public concatenate (aStringSequence : Sequence(String), separatorString : String) : String = 
	concatenate(aStringSequence->sep(separatorString).oclAsType(String))
/]


Back to the top