Skip to content

Commit

Permalink
eclipse-archived#190 In progress TqCL-syntax and library services
Browse files Browse the repository at this point in the history
  • Loading branch information
rtotaro committed Dec 31, 2016
1 parent 991f6f9 commit 44277cc
Show file tree
Hide file tree
Showing 50 changed files with 4,382 additions and 3,513 deletions.
5 changes: 5 additions & 0 deletions org.eclipse.triquetrum.commands.api/.project
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ds.core.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
Expand Down
6 changes: 5 additions & 1 deletion org.eclipse.triquetrum.commands.api/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Bundle-SymbolicName: org.eclipse.triquetrum.commands.api
Bundle-Version: 0.1.0.qualifier
Bundle-Activator: org.eclipse.triquetrum.commands.api.TqCLServices
Bundle-Vendor: Eclipse Triquetrum
Require-Bundle: org.eclipse.core.runtime
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.osgi.services;bundle-version="3.5.100"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.triquetrum.commands.api,
org.eclipse.triquetrum.commands.api.services
Service-Component: OSGI-INF/librariesProvider.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.triquetrum.commands.api">
<implementation class="org.eclipse.triquetrum.commands.api.services.impl.TcQLLibraryProviderProxy"/>
<reference bind="addLibraryProvider" cardinality="1..n" interface="org.eclipse.triquetrum.commands.api.services.TqCLLibraryProvider" name="TqCLLibraryProvider" policy="dynamic"/>
<service>
<provide interface="org.eclipse.triquetrum.commands.api.services.impl.TcQLLibraryProviderProxy"/>
</service>
</scr:component>
5 changes: 3 additions & 2 deletions org.eclipse.triquetrum.commands.api/build.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
source.. = src/main/java/
output.. = target/classes/
bin.includes = META-INF/,\
.
.,\
OSGI-INF/librariesProvider.xml
source.. = src/main/java/
Original file line number Diff line number Diff line change
@@ -1,30 +1,86 @@
/*******************************************************************************
* Copyright (c) 2016 Totaro Rodolfo
* 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:
* Rodolfo Totaro - initial API and implementation and/or initial documentation
*******************************************************************************/
package org.eclipse.triquetrum.commands.api;

import java.util.Collection;

import org.eclipse.triquetrum.commands.api.services.ModelBuilderService;
import org.eclipse.triquetrum.commands.api.services.TqCLLibraryProvider;
import org.eclipse.triquetrum.commands.api.services.impl.TcQLLibraryProviderProxy;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;

public class TqCLServices implements BundleActivator {

private static BundleContext context;

private static TqCLServices instance;

static BundleContext getContext() {
return context;
}

/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.
* BundleContext)
*/
public void start(BundleContext bundleContext) throws Exception {
TqCLServices.context = bundleContext;
instance=this;
}

/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*
* @see
* org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext bundleContext) throws Exception {
TqCLServices.context = null;
instance=null;
}

public static TqCLServices getInstance() {
return instance;
}

@SuppressWarnings("rawtypes")
public ModelBuilderService getModelBuilderService(Class<?> modelClass) {
try {
Collection<ServiceReference<ModelBuilderService>> serviceReferences = getContext()
.getServiceReferences(ModelBuilderService.class, null);
for (ServiceReference<ModelBuilderService> serviceReference : serviceReferences) {
ModelBuilderService service = getContext().getService(serviceReference);
if (service.getSupportedModelClass() == modelClass) {
return service;
}
}
} catch (InvalidSyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return null;
}

public TqCLLibraryProvider getTcqlLibraryProvider()
{
ServiceReference<TcQLLibraryProviderProxy> serviceReference = getContext().getServiceReference(TcQLLibraryProviderProxy.class);
TcQLLibraryProviderProxy service = getContext().getService(serviceReference);
return service;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2016 Totaro Rodolfo
* 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:
* Rodolfo Totaro - initial API and implementation and/or initial documentation
*******************************************************************************/
package org.eclipse.triquetrum.commands.api.services;

public interface ModelBuilderService<CompositeActor,Actor,Port,Parameter,Director> {

public Class<?> getSupportedModelClass();

public Actor insertActor(CompositeActor parent,String actorclass) throws TcQLException;

public Director insertDirector(CompositeActor actor,String directorClass) throws TcQLException;

public Port insertPort(Actor actor, String portClass) throws TcQLException;

public Port insertParameter(Actor actor, String parameterClass) throws TcQLException;



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*******************************************************************************
* Copyright (c) 2016 Totaro Rodolfo
* 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:
* Rodolfo Totaro - initial API and implementation and/or initial documentation
*******************************************************************************/
package org.eclipse.triquetrum.commands.api.services;

public class TcQLException extends Exception {

/**
*
*/
private static final long serialVersionUID = 8072711939052951422L;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*******************************************************************************
* Copyright (c) 2016 Totaro Rodolfo
* 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:
* Rodolfo Totaro - initial API and implementation and/or initial documentation
*******************************************************************************/
package org.eclipse.triquetrum.commands.api.services;

public class TqCLLibraryException extends Exception {

/**
*
*/
private static final long serialVersionUID = -3068348640374298798L;

public TqCLLibraryException(String message, Throwable cause, boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
// TODO Auto-generated constructor stub
}

public TqCLLibraryException(String message, Throwable cause) {
super(message, cause);
// TODO Auto-generated constructor stub
}

public TqCLLibraryException(String message) {
super(message);
// TODO Auto-generated constructor stub
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
/*******************************************************************************
* Copyright (c) 2016 Totaro Rodolfo
* 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:
* Rodolfo Totaro - initial API and implementation and/or initial documentation
*******************************************************************************/
package org.eclipse.triquetrum.commands.api.services;

import java.util.List;
import java.util.Set;

public interface TqCLLibraryProvider {

public List<String> getActors(String library) throws TqCLLibraryException;

public List<String> getDirectors(String library) throws TqCLLibraryException;

public List<String> getParameterTypes(String library) throws TqCLLibraryException;

public List<String> getPortTypes(String library) throws TqCLLibraryException;

public List<String> getActorPorts(String actor) throws TqCLLibraryException;

public List<String> getActorParameters(String actor) throws TqCLLibraryException;

public Set<String> getLibraryNames();

public boolean hasElement(String element);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*******************************************************************************
* Copyright (c) 2016 Totaro Rodolfo
* 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:
* Rodolfo Totaro - initial API and implementation and/or initial documentation
*******************************************************************************/
package org.eclipse.triquetrum.commands.api.services.impl;

import java.text.MessageFormat;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.eclipse.triquetrum.commands.api.services.TqCLLibraryException;
import org.eclipse.triquetrum.commands.api.services.TqCLLibraryProvider;

public class TcQLLibraryProviderProxy implements TqCLLibraryProvider {

private Map<String, TqCLLibraryProvider> libraryProviders = new HashMap<>();


@Override
public List<String> getActors(String library) throws TqCLLibraryException {
checkLibrary(library);
return libraryProviders.get(library).getActors(library);
}

private void checkLibrary(String library) throws TqCLLibraryException {
if (!libraryProviders.containsKey(library)) {
String message = MessageFormat.format("Library {0} not found", library);
throw new TqCLLibraryException(message);
}
}

@Override
public List<String> getDirectors(String library) throws TqCLLibraryException {
checkLibrary(library);
return libraryProviders.get(library).getDirectors(library);
}

@Override
public List<String> getParameterTypes(String library) throws TqCLLibraryException {
checkLibrary(library);
return libraryProviders.get(library).getParameterTypes(library);
}

@Override
public List<String> getPortTypes(String library) throws TqCLLibraryException {
checkLibrary(library);
return libraryProviders.get(library).getPortTypes(library);
}

@Override
public List<String> getActorPorts(String actor) throws TqCLLibraryException {
for (TqCLLibraryProvider provider : libraryProviders.values()) {
boolean hasElement = provider.hasElement(actor);
if (hasElement) {
return provider.getActorPorts(actor);
}
}
String message = MessageFormat.format("Actor {0} not found", actor);
throw new TqCLLibraryException(message);
}

@Override
public List<String> getActorParameters(String actor) throws TqCLLibraryException {
for (TqCLLibraryProvider provider : libraryProviders.values()) {
boolean hasElement = provider.hasElement(actor);
if (hasElement) {
return provider.getActorParameters(actor);
}
}
String message = MessageFormat.format("Actor {0} not found", actor);
throw new TqCLLibraryException(message);
}

@Override
public Set<String> getLibraryNames() {
return libraryProviders.keySet();
}

@Override
public boolean hasElement(String element) {
for (TqCLLibraryProvider libraryProvider : libraryProviders.values()) {
if (libraryProvider.hasElement(element)) {
return true;
}
}
return false;
}

public void setLibraryProviders(Collection<TqCLLibraryProvider> libraryProviders) {
for (TqCLLibraryProvider tqCLLibraryProvider : libraryProviders) {
addLibraryProvider(tqCLLibraryProvider);
}
}

public void addLibraryProvider(TqCLLibraryProvider tqCLLibraryProvider) {
Set<String> libraryNames = tqCLLibraryProvider.getLibraryNames();
for (String library : libraryNames) {
this.libraryProviders.put(library, tqCLLibraryProvider);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ protected String getRuleName(AbstractElement element) {
private static final long serialVersionUID = 1L;
{
put(grammarAccess.getCommandAccess().getAlternatives_0(), "rule__Command__Alternatives_0");
put(grammarAccess.getCategoryAccess().getAlternatives(), "rule__Category__Alternatives");
put(grammarAccess.getNamedObjAccess().getAlternatives(), "rule__NamedObj__Alternatives");
put(grammarAccess.getJvmTypeReferenceAccess().getAlternatives(), "rule__JvmTypeReference__Alternatives");
put(grammarAccess.getJvmArgumentTypeReferenceAccess().getAlternatives(), "rule__JvmArgumentTypeReference__Alternatives");
put(grammarAccess.getJvmWildcardTypeReferenceAccess().getAlternatives_2(), "rule__JvmWildcardTypeReference__Alternatives_2");
put(grammarAccess.getXImportDeclarationAccess().getAlternatives_1(), "rule__XImportDeclaration__Alternatives_1");
put(grammarAccess.getXImportDeclarationAccess().getAlternatives_1_0_3(), "rule__XImportDeclaration__Alternatives_1_0_3");
put(grammarAccess.getCategoryAccess().getAlternatives(), "rule__Category__Alternatives");
put(grammarAccess.getTriquetrumScriptAccess().getGroup(), "rule__TriquetrumScript__Group__0");
put(grammarAccess.getCommandAccess().getGroup(), "rule__Command__Group__0");
put(grammarAccess.getImportAccess().getGroup(), "rule__Import__Group__0");
put(grammarAccess.getIncludeAccess().getGroup(), "rule__Include__Group__0");
put(grammarAccess.getLibraryAccess().getGroup(), "rule__Library__Group__0");
put(grammarAccess.getInsertAccess().getGroup(), "rule__Insert__Group__0");
put(grammarAccess.getInsertAccess().getGroup_5(), "rule__Insert__Group_5__0");
Expand Down Expand Up @@ -100,7 +100,7 @@ protected String getRuleName(AbstractElement element) {
put(grammarAccess.getQualifiedNameInStaticImportAccess().getGroup(), "rule__QualifiedNameInStaticImport__Group__0");
put(grammarAccess.getTriquetrumScriptAccess().getLibrariesAssignment_0(), "rule__TriquetrumScript__LibrariesAssignment_0");
put(grammarAccess.getTriquetrumScriptAccess().getCommandsAssignment_1(), "rule__TriquetrumScript__CommandsAssignment_1");
put(grammarAccess.getImportAccess().getFilenameAssignment_1(), "rule__Import__FilenameAssignment_1");
put(grammarAccess.getIncludeAccess().getFilenameAssignment_1(), "rule__Include__FilenameAssignment_1");
put(grammarAccess.getLibraryAccess().getNameAssignment_1(), "rule__Library__NameAssignment_1");
put(grammarAccess.getInsertAccess().getCategoryAssignment_1(), "rule__Insert__CategoryAssignment_1");
put(grammarAccess.getInsertAccess().getObjAssignment_2(), "rule__Insert__ObjAssignment_2");
Expand Down
Loading

0 comments on commit 44277cc

Please sign in to comment.