public void fixResolvedClasses() { for (Concept con : model.getConcepts()) { if (con.getResolvedAs() != Concept.Resolution.NONE) { if (con.getChosenProperties().size() > 0) { // This is very likely an extension/restriction of the original concept, so we need to // redefine it String extPack = model.getDefaultPackage() + "." + con.getPackage(); model.removeConcept(con); Concept original = con.clone(); original.getSubConcepts().clear(); original.getSubConcepts().add(con); con.getSuperConcepts().clear(); con.addSuperConcept(original); con.setChosenSuperConcept(original); con.setPackage(extPack); URI xuri = NameUtils.packageToNamespaceURI(extPack); con.setNamespace(xuri.toASCIIString()); con.setIri(IRI.create(NameUtils.separatingName(xuri.toASCIIString()) + con.getName())); model.addConcept(con); model.addConcept(original); } } } }
public OntoModel buildModel( String name, OWLOntology ontoDescr, Map<InferenceTask, Resource> theory, StatefulKnowledgeSession kSession) { addResource(kSession, theory.get(InferenceTask.COMMON)); OntoModel baseModel = ModelFactory.newModel(name, ModelFactory.CompileTarget.BASE); kSession.fireAllRules(); kSession.insert(ontoDescr); kSession.fireAllRules(); OntoModel latticeModel = buildClassLattice(ontoDescr, kSession, theory, baseModel); latticeModel.sort(); OntoModel propertyModel = buildProperties(ontoDescr, kSession, theory, latticeModel); propertyModel.sort(); reportSessionStatus(kSession); return propertyModel; }
public boolean streamDRLDeclares() throws MojoExecutionException { ModelCompiler compiler = ModelCompilerFactory.newModelCompiler(ModelFactory.CompileTarget.DRL); boolean success; DRLModel drlModel = (DRLModel) compiler.compile(model); try { FileOutputStream fos = new FileOutputStream( getDrlDir().getPath() + File.separator + model.getName() + "_declare.drl"); success = drlModel.stream(fos); fos.flush(); fos.close(); } catch (IOException e) { e.printStackTrace(); return false; } return success; }
public boolean streamJavaInterfaces(boolean includeJar) { ModelCompiler jcompiler = ModelCompilerFactory.newModelCompiler(ModelFactory.CompileTarget.JAR); JarModel jarModel = (JarModel) jcompiler.compile(model); boolean success = jarModel.save(getJavaDir().getPath()); if (includeJar) { try { FileOutputStream fos = new FileOutputStream(getBinDir().getPath() + File.separator + model.getName() + ".jar"); byte[] content = jarModel.buildJar().toByteArray(); fos.write(content, 0, content.length); fos.flush(); fos.close(); } catch (IOException e) { e.printStackTrace(); return false; } } return success; }
public boolean mojo(List<String> args, MOJO_VARIANTS variant) { boolean success = false; try { File pom = new File(folder.getPath() + File.separator + "pom.xml"); if (!pom.exists()) { success = streamMockPOM(pom, model.getName()); } MavenProject mp = new MavenProject(); final Hyperjaxb3Mojo mojo = new Hyperjaxb3Mojo(); mojo.setVerbose(true); mojo.setBindingDirectory(getMetaInfDir()); mojo.setSchemaDirectory(getMetaInfDir()); int j = 0; String[] excludedSchemas = new String[preexistingSchemas.size()]; for (File f : preexistingSchemas) { excludedSchemas[j++] = f.getName(); } mojo.setSchemaExcludes(excludedSchemas); int k = 0; String[] excludedBindings = new String[preesistingBindings.size()]; for (File f : preesistingBindings) { excludedBindings[k++] = f.getName(); } mojo.setBindingExcludes(excludedBindings); mojo.setGenerateDirectory(getXjcDir()); mojo.setExtension(true); mojo.variant = variant.getLabel(); File perx = new File( getBinDir().getPath() + File.separator + "META-INF" + File.separator + "persistence.xml"); if (perx.exists()) { mojo.persistenceXml = perx; try { Document dox = parseXML(perx); XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression expr = xpath.compile("//persistence-unit/@name"); mojo.persistenceUnitName = (String) expr.evaluate(dox, XPathConstants.STRING); } catch (Exception e) { mojo.persistenceXml = new File(getMetaInfDir() + File.separator + "persistence-template-hibernate.xml"); mojo.persistenceUnitName = model.getName(); } } else { mojo.persistenceXml = new File(getMetaInfDir() + File.separator + "persistence-template-hibernate.xml"); mojo.persistenceUnitName = model.getName(); } mojo.generateEquals = false; mojo.generateHashCode = false; mojo.setProject(mp); mojo.setArgs(args); mojo.setForceRegenerate(true); mojo.execute(); success = true; } catch (MojoExecutionException e) { e.printStackTrace(); } return success; }