use of org.wso2.ballerinalang.compiler.packaging.converters.Converter in project ballerina by ballerina-lang.
the class PullCommand method execute.
@Override
public void execute() {
if (helpFlag) {
String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(parentCmdParser, "pull");
outStream.println(commandUsageInfo);
return;
}
if (argList == null || argList.size() == 0) {
throw new BLangCompilerException("no package given");
}
if (argList.size() > 1) {
throw new BLangCompilerException("too many arguments");
}
// Enable remote debugging
if (null != debugPort) {
System.setProperty(SYSTEM_PROP_BAL_DEBUG, debugPort);
}
String resourceName = argList.get(0);
String orgName;
String packageName;
String version;
// Get org-name
int orgNameIndex = resourceName.indexOf("/");
if (orgNameIndex != -1) {
orgName = resourceName.substring(0, orgNameIndex);
} else {
throw new BLangCompilerException("no package-name provided");
}
// Get package name
int packageNameIndex = resourceName.indexOf(":");
if (packageNameIndex != -1) {
// version is provided
packageName = resourceName.substring(orgNameIndex + 1, packageNameIndex);
version = resourceName.substring(packageNameIndex + 1, resourceName.length());
} else {
packageName = resourceName.substring(orgNameIndex + 1, resourceName.length());
version = "*";
}
URI baseURI = URI.create("https://staging.central.ballerina.io:9090/");
Repo remoteRepo = new RemoteRepo(baseURI);
PackageID packageID = new PackageID(new Name(orgName), new Name(packageName), new Name(version));
Patten patten = remoteRepo.calculate(packageID);
if (patten != Patten.NULL) {
Converter converter = remoteRepo.getConverterInstance();
patten.convertToSources(converter, packageID).collect(Collectors.toList());
} else {
outStream.println("couldn't find package " + patten);
}
Runtime.getRuntime().exit(0);
}
use of org.wso2.ballerinalang.compiler.packaging.converters.Converter in project ballerina by ballerina-lang.
the class RepoHierarchy method resolve.
public Resolution resolve(PackageID pkg) {
log1(pkg);
for (int i = 0; i < repos.length; i++) {
Repo repo = repos[i];
Patten patten = repo.calculate(pkg);
if (patten != Patten.NULL) {
Converter converter = repo.getConverterInstance();
List<PackageSourceEntry> paths = patten.convertToSources(converter, pkg).collect(Collectors.toList());
log2(repo, patten, paths);
if (!paths.isEmpty()) {
return new Resolution(getChildHierarchyForRepo(i), paths);
}
} else {
log3(repo);
}
}
log4();
return Resolution.NOT_FOUND;
}
use of org.wso2.ballerinalang.compiler.packaging.converters.Converter in project carbon-business-process by wso2.
the class RestResponseFactory method getVariableValue.
public Object getVariableValue(QueryVariable restVariable) {
Object value;
if (restVariable.getType() != null) {
// Try locating a converter if the type has been specified
RestVariableConverter converter = null;
for (RestVariableConverter conv : variableConverters) {
if (conv.getRestTypeName().equals(restVariable.getType())) {
converter = conv;
break;
}
}
if (converter == null) {
throw new ActivitiIllegalArgumentException("Variable '" + restVariable.getName() + "' has unsupported type: '" + restVariable.getType() + "'.");
}
RestVariable temp = new RestVariable();
temp.setValue(restVariable.getValue());
temp.setType(restVariable.getType());
temp.setName(restVariable.getName());
value = converter.getVariableValue(temp);
} else {
// Revert to type determined by REST-to-Java mapping when no explicit type has been provided
value = restVariable.getValue();
}
return value;
}
use of org.wso2.ballerinalang.compiler.packaging.converters.Converter in project siddhi by wso2.
the class EventTestCase method testStreamEventConverter.
@Test
public void testStreamEventConverter() {
Attribute price = new Attribute("price", Attribute.Type.DOUBLE);
Attribute volume = new Attribute("volume", Attribute.Type.INT);
Attribute symbol = new Attribute("symbol", Attribute.Type.STRING);
MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
metaStreamEvent.addData(volume);
metaStreamEvent.initializeAfterWindowData();
metaStreamEvent.addData(price);
metaStreamEvent.addOutputData(symbol);
// complex attribute
metaStreamEvent.addOutputData(null);
StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.DOUBLE).attribute("volume", Attribute.Type.INT);
Event event = new Event(System.currentTimeMillis(), new Object[] { "WSO2", 200, 50 });
metaStreamEvent.addInputDefinition(streamDefinition);
StreamEventConverter converter = StreamEventConverterFactory.constructEventConverter(metaStreamEvent);
StreamEventPool eventPool = new StreamEventPool(metaStreamEvent, 5);
StreamEvent borrowedEvent = eventPool.borrowEvent();
converter.convertEvent(event, borrowedEvent);
AssertJUnit.assertTrue(converter instanceof SelectiveStreamEventConverter);
// volume
AssertJUnit.assertEquals(1, borrowedEvent.getBeforeWindowData().length);
// price
AssertJUnit.assertEquals(1, borrowedEvent.getOnAfterWindowData().length);
// symbol and avgPrice
AssertJUnit.assertEquals(2, borrowedEvent.getOutputData().length);
AssertJUnit.assertEquals(50, borrowedEvent.getBeforeWindowData()[0]);
AssertJUnit.assertEquals(200, borrowedEvent.getOnAfterWindowData()[0]);
AssertJUnit.assertEquals("WSO2", borrowedEvent.getOutputData()[0]);
}
use of org.wso2.ballerinalang.compiler.packaging.converters.Converter in project siddhi by wso2.
the class EventTestCase method testPassThroughStreamEventConverter.
@Test
public void testPassThroughStreamEventConverter() {
Attribute symbol = new Attribute("symbol", Attribute.Type.STRING);
Attribute price = new Attribute("price", Attribute.Type.DOUBLE);
Attribute volume = new Attribute("volume", Attribute.Type.INT);
MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
metaStreamEvent.addOutputDataAllowingDuplicate(symbol);
metaStreamEvent.addOutputDataAllowingDuplicate(price);
metaStreamEvent.addOutputDataAllowingDuplicate(volume);
StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.DOUBLE).attribute("volume", Attribute.Type.INT);
Event event = new Event(System.currentTimeMillis(), new Object[] { "WSO2", 200.0, 50 });
metaStreamEvent.addInputDefinition(streamDefinition);
StreamEventConverter converter = StreamEventConverterFactory.constructEventConverter(metaStreamEvent);
StreamEventPool eventPool = new StreamEventPool(metaStreamEvent, 5);
StreamEvent borrowedEvent = eventPool.borrowEvent();
converter.convertEvent(event, borrowedEvent);
AssertJUnit.assertTrue(converter instanceof ZeroStreamEventConverter);
AssertJUnit.assertEquals(3, borrowedEvent.getOutputData().length);
AssertJUnit.assertEquals("WSO2", borrowedEvent.getOutputData()[0]);
AssertJUnit.assertEquals(200.0, borrowedEvent.getOutputData()[1]);
AssertJUnit.assertEquals(50, borrowedEvent.getOutputData()[2]);
}
Aggregations