public void saveNamespace(String name, Map<String, List> desc) throws Exception {
   StoreDesc sdesc = StoreDesc.getGlobalData();
   m_gitService.putContent(
       sdesc.getRepository(),
       format(NAMESPACE_PATH, name),
       NAMESPACE_TYPE,
       m_js.deepSerialize(desc));
 }
 private List<Map> getEntities(StoreDesc sdesc) throws Exception {
   String pack = sdesc.getPack();
   boolean withInternal = false;
   if (!StoreDesc.isAidPack(pack)) {
     withInternal = true;
   }
   List entities = m_entityService.getEntities(sdesc, false, null);
   // List entTypes = m_entityService.getEntitytypes(sdesc.getStoreId());
   // System.out.println("entities:"+entities);
   // System.out.println("entTypes:"+entTypes);
   return entities;
 }
 public Map generateSource(StoreDesc sdesc, List<Map> entities) throws Exception {
   String namespace = sdesc.getNamespace();
   String pack = sdesc.getPack();
   if (entities == null) {
     entities = getEntities(sdesc);
   }
   printList("\n----> generateSource.entities(" + namespace + "," + pack + "):", entities);
   File outDir = new File(sdesc.getBaseDir(), "/src");
   List<String> srcFiles = m_sourceGenService.generate(sdesc, entities, outDir.toString());
   Map retMap = new HashMap();
   retMap.put(SOURCES, srcFiles);
   retMap.put(ENTITIES, entities);
   return retMap;
 }
 private Map enhance(StoreDesc sdesc, List<Map> entities, List<String> classNames)
     throws Exception {
   File outDir1 = new File(sdesc.getBaseDir(), "classes");
   if (!outDir1.exists()) {
     outDir1.mkdirs();
   }
   File[] locations = new File[1];
   locations[0] = outDir1;
   System.out.println("Enhancer.enhance:" + sdesc);
   FileSystemClassLoader fscl =
       new FileSystemClassLoader(this.getClass().getClassLoader(), locations);
   JDOEnhancer enhancer = m_nucleusService.getEnhancer(sdesc);
   enhancer.setClassLoader(fscl);
   if (enhancer != null) {
     for (String className : classNames) {
       File file = new File(outDir1, className.replace(".", "/"));
       if (jdoStore(entities, className)) {
         System.out.println("DomainObjectsServiceImpl.enhancer.add:" + file);
         enhancer.addClasses(file.toString() + ".class");
       }
     }
     enhancer.enhance();
   }
   try {
     System.out.println("Enhancer.close:" + sdesc);
     m_nucleusService.close(sdesc);
   } catch (Exception e) {
     System.out.println("Nucleus.close.ex:" + e);
   }
   return new HashMap();
 }
 public void createClasses(StoreDesc sdesc) throws Exception {
   String namespace = sdesc.getNamespace();
   String pack = sdesc.getPack();
   List<Map> entities = getEntities(sdesc);
   File outDir = new File(sdesc.getBaseDir(), "classes");
   ClassLoader clParent = Thread.currentThread().getContextClassLoader();
   List<String> classFiles = null;
   try {
     // BundleDelegatingClassLoader bdc = new BundleDelegatingClassLoader(m_bc.getBundle(),
     // clParent);
     // Thread.currentThread().setContextClassLoader(bdc);
     classFiles = m_classGenService.generate(sdesc, entities, outDir.toString());
   } finally {
     Thread.currentThread().setContextClassLoader(clParent);
   }
   enhance(sdesc, entities, classFiles);
 }
 public List<Map> getNamespaces() throws Exception {
   StoreDesc sdesc = StoreDesc.getGlobalData();
   List<String> types = new ArrayList();
   types.add(NAMESPACE_TYPE);
   Map map =
       m_gitService.getWorkingTree(
           sdesc.getRepository(), NAMESPACES_PATH, 100, types, null, null, null);
   List<Map> childList = (List) map.get("children");
   for (Map child : childList) {
     String name = (String) child.get("name");
     Map m = new HashMap();
     m.put("name", name);
     child.putAll(m);
     child.remove("children");
     child.remove("path");
   }
   return childList;
 }
 public void generateSource(@PName(StoreDesc.STORE_ID) String storeId) throws RpcException {
   try {
     StoreDesc sdesc = StoreDesc.get(storeId);
     generateSource(sdesc, null);
   } catch (Exception e) {
     throw new RpcException(
         ERROR_FROM_METHOD, INTERNAL_SERVER_ERROR, "DomainObjectsServiceImpl.generateClasses:", e);
   }
 }
 public void createClasses(@PName(StoreDesc.STORE_ID) String storeId) throws RpcException {
   try {
     StoreDesc sdesc = StoreDesc.get(storeId);
     createClasses(sdesc);
   } catch (Exception e) {
     e.printStackTrace();
     throw new RpcException(
         ERROR_FROM_METHOD, INTERNAL_SERVER_ERROR, "DomainObjectsServiceImpl.createClasses:", e);
   }
 }
 public Map compile(StoreDesc sdesc, List<Map> entities, List<String> srcFiles) throws Exception {
   File outDir1 = new File(sdesc.getBaseDir(), "classes");
   if (!outDir1.exists()) {
     outDir1.mkdirs();
   }
   File[] locations = new File[1];
   locations[0] = outDir1;
   FileSystemClassLoader fscl =
       new FileSystemClassLoader(this.getClass().getClassLoader(), locations);
   JDOEnhancer enhancer = m_nucleusService.getEnhancer(sdesc);
   enhancer.setClassLoader(fscl);
   final Options options = new Options();
   options.put(Options.KEY_SOURCE_VERSION, Options.VERSION_1_6);
   options.put(Options.KEY_TARGET_VERSION, Options.VERSION_1_6);
   options.put(Options.KEY_CLASS_LOADER_WRITER, createClassWriter(outDir1));
   options.put(Options.KEY_CLASS_LOADER, fscl);
   CompilationUnit[] cus = new CompilationUnit[srcFiles.size()];
   int i = 0;
   for (String src : srcFiles) {
     cus[i++] = createCompileUnit(src);
   }
   CompilationResult result = m_javaCompiler.compile(cus, options);
   System.out.println("result:" + result);
   if (result != null && result.getErrors() != null) {
     List<String> errorList = new ArrayList();
     for (CompilerMessage msg : result.getErrors()) {
       String ms = msg.getFile() + ":" + msg.getLine() + "=>" + msg.getMessage();
       errorList.add(ms);
     }
     Map retMap = new HashMap();
     System.out.println("result:" + errorList);
     retMap.put("errors", errorList);
     return retMap;
   } else {
     if (enhancer != null) {
       for (int c = 0; c < cus.length; c++) {
         String className = cus[c].getMainClassName();
         File file = new File(outDir1, className.replace(".", "/"));
         if (jdoStore(entities, className)) {
           System.out.println("DomainObjectsServiceImpl.enhancer.add:" + file);
           enhancer.addClasses(file.toString() + ".class");
         }
       }
       enhancer.enhance();
     }
     try {
       m_nucleusService.close(sdesc);
     } catch (Exception e) {
       System.out.println("CLOSE:" + e);
     }
     return new HashMap();
   }
 }
 public void handleEvent(Event event) {
   System.out.println("DomainObjectsServiceImpl.Event: " + event);
   try {
     String ns = (String) event.getProperty("namespace");
     StoreDesc sdesc = StoreDesc.getNamespaceData(ns);
     m_permissionService.loginInternal(ns);
     ThreadContext.loadThreadContext(ns, "admin");
     createClasses(sdesc);
     System.out.println(
         ">>>> End handleEvent:"
             + ThreadContext.getThreadContext().get(ThreadContext.SESSION_MANAGER));
     ThreadContext.getThreadContext().finalize(null);
     System.out.println(">>>> End handleEvent");
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
   }
 }
 public Map<String, List> getNamespace(String name) throws Exception {
   StoreDesc sdesc = StoreDesc.getGlobalData();
   String ret = m_gitService.getContent(sdesc.getRepository(), format(NAMESPACE_PATH, name));
   return (Map) m_ds.deserialize(ret);
 }
 public void saveBranding(Map<String, String> desc) throws Exception {
   StoreDesc sdesc = StoreDesc.getGlobalData();
   m_gitService.putContent(
       sdesc.getRepository(), BRANDING_PATH, "sw.setting", m_js.deepSerialize(desc));
 }
 public void deleteNamespace(String name) throws Exception {
   StoreDesc sdesc = StoreDesc.getGlobalData();
   m_gitService.deleteObject(sdesc.getRepository(), format(NAMESPACE_PATH, name));
 }