Search in sources :

Example 6 with SService

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;
}
Also used : SServiceInterface(org.bimserver.interfaces.objects.SServiceInterface) SService(org.bimserver.shared.meta.SService)

Example 7 with SService

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;
}
Also used : SServiceMethod(org.bimserver.interfaces.objects.SServiceMethod) ArrayList(java.util.ArrayList) UserException(org.bimserver.shared.exceptions.UserException) SMethod(org.bimserver.shared.meta.SMethod) SService(org.bimserver.shared.meta.SService)

Example 8 with SService

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;
}
Also used : SParameter(org.bimserver.shared.meta.SParameter) SServiceParameter(org.bimserver.interfaces.objects.SServiceParameter) ArrayList(java.util.ArrayList) UserException(org.bimserver.shared.exceptions.UserException) SMethod(org.bimserver.shared.meta.SMethod) SService(org.bimserver.shared.meta.SService)

Example 9 with SService

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);
}
Also used : CtClass(javassist.CtClass) CtMethod(javassist.CtMethod) SService(org.bimserver.shared.meta.SService)

Example 10 with SService

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);
    }
}
Also used : KeyValuePair(org.bimserver.shared.reflector.KeyValuePair) ServiceException(org.bimserver.shared.exceptions.ServiceException) SParameter(org.bimserver.shared.meta.SParameter) ReflectorException(org.bimserver.shared.reflector.ReflectorException) JsonObject(com.google.gson.JsonObject) UserException(org.bimserver.shared.exceptions.UserException) SMethod(org.bimserver.shared.meta.SMethod) SService(org.bimserver.shared.meta.SService)

Aggregations

SService (org.bimserver.shared.meta.SService)16 SMethod (org.bimserver.shared.meta.SMethod)8 UserException (org.bimserver.shared.exceptions.UserException)7 CtClass (javassist.CtClass)5 SParameter (org.bimserver.shared.meta.SParameter)5 CtMethod (javassist.CtMethod)4 KeyValuePair (org.bimserver.shared.reflector.KeyValuePair)4 PublicInterface (org.bimserver.shared.interfaces.PublicInterface)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 JsonObject (com.google.gson.JsonObject)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ServiceException (org.bimserver.shared.exceptions.ServiceException)2 ReflectorException (org.bimserver.shared.reflector.ReflectorException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 DynamicMessage (com.google.protobuf.DynamicMessage)1 Builder (com.google.protobuf.DynamicMessage.Builder)1 Message (com.google.protobuf.Message)1 EOFException (java.io.EOFException)1 File (java.io.File)1