use of org.bimserver.shared.meta.SService in project BIMserver by opensourceBIM.
the class MetaServiceImpl method convertServiceInterface.
private SServiceInterface convertServiceInterface(String name) {
SServiceInterface sServiceInterface = new SServiceInterface();
SService byName = getBimServer().getServicesMap().getByName(name);
sServiceInterface.setName(name);
sServiceInterface.setNameSpace(byName.getNameSpace());
sServiceInterface.setSimpleName(byName.getSimpleName());
return sServiceInterface;
}
use of org.bimserver.shared.meta.SService in project BIMserver by opensourceBIM.
the class MetaServiceImpl method getServiceMethods.
@Override
public List<SServiceMethod> getServiceMethods(String serviceInterfaceName) throws ServerException, UserException {
List<SServiceMethod> sServiceMethods = new ArrayList<SServiceMethod>();
SService sService = getBimServer().getServicesMap().getByName(serviceInterfaceName);
if (sService == null) {
throw new UserException("Service \"" + serviceInterfaceName + "\" not found");
}
for (SMethod sMethod : sService.getMethods()) {
SServiceMethod sServiceMethod = convertMethod(sMethod);
sServiceMethods.add(sServiceMethod);
}
return sServiceMethods;
}
use of org.bimserver.shared.meta.SService in project BIMserver by opensourceBIM.
the class MetaServiceImpl method getServiceMethodParameters.
@Override
public List<SServiceParameter> getServiceMethodParameters(String serviceInterfaceName, String serviceMethodName) throws ServerException, UserException {
List<SServiceParameter> sServiceParameters = new ArrayList<SServiceParameter>();
SService serviceInterface = getBimServer().getServicesMap().getByName(serviceInterfaceName);
if (serviceInterface == null) {
throw new UserException("Service \"" + serviceInterfaceName + "\" not found");
}
SMethod sMethod = serviceInterface.getSMethod(serviceMethodName);
if (sMethod == null) {
throw new UserException("Method \"" + serviceMethodName + "\" not found in \"" + serviceInterfaceName + "\"");
}
for (SParameter sParameter : sMethod.getParameters()) {
SServiceParameter sServiceParameter = new SServiceParameter();
sServiceParameter.setName(sParameter.getName());
sServiceParameter.setDoc(sParameter.getDoc());
sServiceParameter.setType(createSServiceType(sParameter.getType(), false));
sServiceParameter.setGenericType(createSServiceType(sParameter.getGenericType(), false));
sServiceParameters.add(sServiceParameter);
}
return sServiceParameters;
}
use of org.bimserver.shared.meta.SService in project BIMserver by opensourceBIM.
the class RealtimeReflectorFactoryBuilder method createCreateReflectorMethod1.
private void createCreateReflectorMethod1(String newClassPrefix, CtClass reflectorFactoryImpl) throws NotFoundException, CannotCompileException {
CtClass[] parameters = new CtClass[2];
parameters[0] = pool.get(Class.class.getName());
parameters[1] = pool.get(Reflector.class.getName());
CtMethod method = new CtMethod(pool.get(PublicInterface.class.getName()), "createReflector", parameters, reflectorFactoryImpl);
StringBuilder methodBuilder = new StringBuilder();
methodBuilder.append("{");
methodBuilder.append("if (1==0) {");
for (String name : servicesMap.keySetName()) {
SService sService = servicesMap.getByName(name);
methodBuilder.append("} else if ($1.getSimpleName().equals(\"" + sService.getSimpleName() + "\")) {");
methodBuilder.append("return new " + GENERATED_CLASSES_PACKAGE + "." + sService.getSimpleName() + "Impl" + newClassPrefix + "($2);");
}
methodBuilder.append("}");
methodBuilder.append("return null;");
methodBuilder.append("}");
method.setBody(methodBuilder.toString());
reflectorFactoryImpl.addMethod(method);
}
use of org.bimserver.shared.meta.SService in project BIMserver by opensourceBIM.
the class NotificationsManager method handleIncoming.
public void handleIncoming(JsonObject request) throws UserException, ConvertException, IOException {
// TODO copied code from JsonHandler
String interfaceName = request.get("interface").getAsString();
String methodName = request.get("method").getAsString();
SService sService = servicesMap.getByName(interfaceName);
if (sService == null) {
sService = servicesMap.getBySimpleName(interfaceName);
}
if (sService == null) {
throw new UserException("No service found with name " + interfaceName);
}
SMethod method = sService.getSMethod(methodName);
if (method == null) {
SMethod alternative = servicesMap.findMethod(methodName);
if (alternative == null) {
throw new UserException("Method " + methodName + " not found on " + interfaceName);
} else {
throw new UserException("Method " + methodName + " not found on " + interfaceName + " (suggestion: " + alternative.getService().getSimpleName() + ")");
}
}
KeyValuePair[] parameters = new KeyValuePair[method.getParameters().size()];
if (request.has("parameters")) {
JsonObject parametersJson = request.getAsJsonObject("parameters");
for (int i = 0; i < method.getParameters().size(); i++) {
SParameter parameter = method.getParameter(i);
if (parametersJson.has(parameter.getName())) {
parameters[i] = new KeyValuePair(parameter.getName(), converter.fromJson(parameter.getType(), parameter.getGenericType(), parametersJson.get(parameter.getName())));
} else {
LOGGER.error("Missing parameters: " + method.getName() + " -> " + parameter.getName());
}
}
} else {
throw new UserException("Missing 'parameters' field");
}
try {
method.invoke(sService.getInterfaceClass(), service, parameters);
} catch (ServiceException e) {
LOGGER.error("", e);
} catch (ReflectorException e) {
LOGGER.error("", e);
}
}
Aggregations