blob: 202dc252e8c159d83eafaba3ac7a91da6e4dfda5 [file] [log] [blame]
[comment encoding = UTF-8 /]
[module generateOCLstdlib('http://www.eclipse.org/ocl/3.1.0/Pivot','http://www.eclipse.org/emf/2002/Ecore')/]
[import generateOclCommon/]
[template public generate(pkg : Package, javaPackage : String, javaClass : String, sourceFile : String, uri : String) ? (pkg.eContainer() = null)]
[comment @main /]
[file (javaClass + '.java', false, 'UTF-8')]
/**
* <copyright>
*
* Copyright (c) 2010,2012 E.D.Willink and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* E.D.Willink - initial API and implementation
*
* </copyright>
*
* This code is auto-generated
* from: [sourceFile/]
* by: org.eclipse.ocl.examples.build.acceleo.GenerateOCLstdlib
* defined by: org.eclipse.ocl.examples.build.acceleo.generateOCLstdlib.mtl
* invoked by: org.eclipse.ocl.examples.build.utilities.OCLstdlibCodeGenerator
* from: org.eclipse.ocl.examples.build.GenerateOCLstdlibModel.mwe2
*
* Do not edit it.
*/
package [javaPackage/];
import java.util.List;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.ocl.examples.pivot.*;
import org.eclipse.ocl.examples.pivot.Class;
import org.eclipse.ocl.examples.pivot.Library;
import org.eclipse.ocl.examples.pivot.Package;
import org.eclipse.ocl.examples.pivot.library.StandardLibraryContribution;
import org.eclipse.uml2.common.util.SubsetSupersetEObjectEList;
/**
* This is the [uri/] Standard Library
* auto-generated from [sourceFile/].
* It facilitates efficient library loading without the overheads of model reading.
* <p>
* This Standard Library may be registered as the definition of a Standard Library for
* the OCL evaluation framework by invoking {@link #install}.
* <p>
* The Standard Library is normally activated when the MetaModelManager attempts
* to locate a library type when its default Standard Library URI is the same
* as this Standard Library.
*/
@SuppressWarnings("nls")
public class [javaClass/] extends AbstractPivotModel
{
/**
* The static package-of-types pivot model of the Standard Library.
*/
private static [javaClass/] INSTANCE = null;
/**
* The URI of this Standard Library.
*/
public static final String STDLIB_URI = "[uri/]";
[pkg.defineConstants()/]
/**
* Return the default OCL standard Library.
* This static definition auto-generated from [sourceFile/]
* is used as the default when no overriding copy is registered.
*/
public static OCLstdlib getDefault() {
if (INSTANCE == null) {
Library library = create("[pkg.name/]", "[pkg.nsPrefix/]", "[pkg.nsURI/]");
INSTANCE = new OCLstdlib(STDLIB_URI, library);
}
return INSTANCE;
}
/**
* Install this library in the {@link StandardLibraryContribution#REGISTRY}.
* This method may be invoked by standalone applications to replicate
* the registration that should appear as a standard_library plugin
* extension when running within Eclipse.
*/
public static void install() {
StandardLibraryContribution.REGISTRY.put(STDLIB_URI, new Loader());
}
/**
* Unnstall this library from the {@link StandardLibraryContribution#REGISTRY}.
* This method may be invoked by standalone applications to release the library
* resources for garbage collection and memory leakage detection.
*/
public static void uninstall() {
StandardLibraryContribution.REGISTRY.remove(STDLIB_URI);
INSTANCE = null;
}
/**
* The Loader shares the Standard Library instance whenever this default library
* is loaded from the registry of Standard Libraries populated by the standard_library
* extension point.
*/
public static class Loader implements StandardLibraryContribution
{
public StandardLibraryContribution getContribution() {
return this;
}
public Resource getResource() {
return getDefault();
}
}
/**
* Construct an OCL Standard Library with specified resource URI and library content.
*/
public [javaClass/](String uri, Library library) {
super(URI.createURI(uri));
getContents().add(library);
}
/**
* Construct a copy of the OCL Standard Library with specified resource URI,
* and package name, prefix and namespace URI.
*/
public static [javaClass/] create(String uri, String name, String nsPrefix, String nsURI) {
@SuppressWarnings("serial")
EcoreUtil.Copier copier = new EcoreUtil.Copier(true, false)
{
@Override
protected void copyReference(EReference eReference, EObject eObject, EObject copyEObject) {
Object eGet = eObject.eGet(eReference);
if (eGet instanceof SubsetSupersetEObjectEList) {
if (eReference == PivotPackage.Literals.TEMPLATE_SIGNATURE__PARAMETER) {
return; // Avoid doubling up on TEMPLATE_SIGNATURE__OWNED_PARAMETER
}
System.out.println(eReference.getContainerClass().getName() + "::" + eReference.getName());
}
super.copyReference(eReference, eObject, copyEObject);
}
};
Library library = (Library) copier.copy(getDefault().getContents().get(0));
copier.copyReferences();
library.setName(name);
library.setNsPrefix(nsPrefix);
library.setNsURI(nsURI);
return new [javaClass/](uri, library);
}
private static Library create(String name, String nsPrefix, String nsURI)
{
Library [pkg.getPrefixedSymbolName('library')/] = createLibrary("[pkg.name/]", nsPrefix, nsURI);
List<Precedence> ownedPrecedences = library.getOwnedPrecedences();
[for (precedence : Precedence | pkg.ownedPrecedence)]
[emitPrecedence(precedence)/]
[/for]
[for (ownedType : Type | pkg.ownedType->sortedBy(getMoniker()))]
[emitType(ownedType)/]
[/for]
[for (nestedPackage : Package | pkg.nestedPackage->sortedBy(name))]
[emitPackage(nestedPackage)/]
[/for]
return [pkg.getSymbolName()/];
}
}
[/file]
[/template]