forked from eclipse-archived/triquetrum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eclipse-archived#190 In progress TqCL-syntax and library services
- Loading branch information
Showing
50 changed files
with
4,382 additions
and
3,513 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
org.eclipse.triquetrum.commands.api/OSGI-INF/librariesProvider.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
60 changes: 58 additions & 2 deletions
60
...iquetrum.commands.api/src/main/java/org/eclipse/triquetrum/commands/api/TqCLServices.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...s.api/src/main/java/org/eclipse/triquetrum/commands/api/services/ModelBuilderService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...ommands.api/src/main/java/org/eclipse/triquetrum/commands/api/services/TcQLException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
....api/src/main/java/org/eclipse/triquetrum/commands/api/services/TqCLLibraryException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...s.api/src/main/java/org/eclipse/triquetrum/commands/api/services/TqCLLibraryProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
111 changes: 111 additions & 0 deletions
111
...main/java/org/eclipse/triquetrum/commands/api/services/impl/TcQLLibraryProviderProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.