Exemplo n.º 1
0
 /**
  * Creates the service corresponding to the given class.
  *
  * @param javaClass is the java class which is an Acceleo service
  * @param root is the root element of the model
  * @return the new service
  */
 private static Service createService(Class<?> javaClass, ResourceSet root) {
   Service service = CoreFactory.eINSTANCE.createService();
   root.getResources().add(service);
   service.setName(javaClass.getName());
   Method[] javaMethods = javaClass.getDeclaredMethods();
   for (int i = 0; i < javaMethods.length; i++) {
     Method javaMethod = javaMethods[i];
     org.eclipse.acceleo.compatibility.model.mt.core.Method method =
         CoreFactory.eINSTANCE.createMethod();
     service.getMethods().add(method);
     method.setName(javaMethod.getName());
     if (javaMethod.getReturnType() != null) {
       method.setReturn(javaMethod.getReturnType().getName());
     } else {
       method.setReturn("void"); // $NON-NLS-1$
     }
     Class<?>[] javaParameters = javaMethod.getParameterTypes();
     for (int j = 0; j < javaParameters.length; j++) {
       Class<?> javaParameter = javaParameters[j];
       org.eclipse.acceleo.compatibility.model.mt.core.Parameter parameter =
           CoreFactory.eINSTANCE.createParameter();
       method.getParameters().add(parameter);
       if (javaParameter != null) {
         parameter.setType(javaParameter.getName());
       } else {
         parameter.setType("void"); // $NON-NLS-1$
       }
     }
   }
   return service;
 }
Exemplo n.º 2
0
 /**
  * Gets or creates the service that matches the given qualified name in the resource set.
  *
  * @param qualifiedName is the qualified name of the class to load
  * @param root is the root element of the model
  * @return the new service, or null if the qualified name is not a java service
  */
 private static Service getOrCreateService(String qualifiedName, ResourceSet root) {
   Iterator<Resource> resources = root.getResources().iterator();
   while (resources.hasNext()) {
     Resource resource = resources.next();
     if (resource instanceof Service
         && resource.getName() != null
         && resource.getName().equals(qualifiedName)) {
       return (Service) resource;
     }
   }
   final Class<?> javaClass = AcceleoWorkspaceUtil.INSTANCE.getClass(qualifiedName, false);
   Service result;
   if (javaClass != null) {
     result = createService(javaClass, root);
   } else {
     result = null;
   }
   return result;
 }