private void createCreateReflectorMethod2(CtClass reflectorFactoryImpl) throws NotFoundException, CannotCompileException { CtClass[] parameters = new CtClass[2]; parameters[0] = pool.get(Class.class.getName()); parameters[1] = pool.get(PublicInterface.class.getName()); CtMethod method = new CtMethod(pool.get(Reflector.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() + "Reflector" + implementationCounter + "((" + sService.getInterfaceClass().getName() + ")$2);"); } methodBuilder.append("}"); methodBuilder.append("return null;"); methodBuilder.append("}"); method.setBody(methodBuilder.toString()); reflectorFactoryImpl.addMethod(method); }
private void createCreateReflectorMethod1(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" + implementationCounter + "($2);"); } methodBuilder.append("}"); methodBuilder.append("return null;"); methodBuilder.append("}"); method.setBody(methodBuilder.toString()); reflectorFactoryImpl.addMethod(method); }
@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; }
public ReflectorFactory newReflectorFactory() { implementationCounter++; try { pool = ClassPool.getDefault(); pool.insertClassPath(new ClassClassPath(this.getClass())); for (String name : servicesMap.keySetName()) { SService sService = servicesMap.getByName(name); build1((Class<? extends PublicInterface>) sService.getInterfaceClass(), sService); build2((Class<? extends PublicInterface>) sService.getInterfaceClass(), sService); } CtClass reflectorFactoryImpl = pool.makeClass("org.bimserver.reflector.ReflectorFactoryImpl" + implementationCounter); reflectorFactoryImpl.addInterface(pool.get(ReflectorFactory.class.getName())); createCreateReflectorMethod1(reflectorFactoryImpl); createCreateReflectorMethod2(reflectorFactoryImpl); Class<?> class1 = pool.toClass(reflectorFactoryImpl, getClass().getClassLoader(), getClass().getProtectionDomain()); return (ReflectorFactory) class1.newInstance(); } catch (Exception e) { LOGGER.error("", e); } return null; }
@Override public SServiceMethod getServiceMethod(String serviceInterfaceName, String methodName) throws ServerException, UserException { SService sService = getBimServer().getServicesMap().getByName(serviceInterfaceName); if (sService == null) { throw new UserException("Service \"" + serviceInterfaceName + "\" not found"); } return convertMethod(sService.getMethod(methodName)); }
SService sService = bimServer.getServicesMap().getByName(interfaceName); if (sService == null) { sService = bimServer.getServicesMap().getBySimpleName(interfaceName);
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; }
SService sService = servicesMap.getByName(interfaceName); if (sService == null) { sService = servicesMap.getBySimpleName(interfaceName);
@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; }