Search in sources :

Example 6 with InternalResource

use of org.drools.core.io.internal.InternalResource in project drools by kiegroup.

the class KieRepositoryImpl method getKieModule.

public KieModule getKieModule(Resource resource) {
    InternalResource res = (InternalResource) resource;
    try {
        KieModule kModule;
        // find kmodule.xml
        if (res.hasURL()) {
            String urlPath = res.getURL().toExternalForm();
            if (res.isDirectory()) {
                if (!urlPath.endsWith("/")) {
                    urlPath = urlPath + "/";
                }
                urlPath = urlPath + KieModuleModelImpl.KMODULE_JAR_PATH;
            } else {
                urlPath = "jar:" + urlPath + "!/" + KieModuleModelImpl.KMODULE_JAR_PATH;
            }
            kModule = ClasspathKieProject.fetchKModule(new URL(urlPath));
            log.debug("Fetched KieModule from resource: " + resource);
        } else {
            // might be a byte[] resource
            MemoryFileSystem mfs = MemoryFileSystem.readFromJar(res.getInputStream());
            byte[] bytes = mfs.getBytes(KieModuleModelImpl.KMODULE_JAR_PATH);
            KieModuleModel kieProject = KieModuleModelImpl.fromXML(new ByteArrayInputStream(bytes));
            setDefaultsforEmptyKieModule(kieProject);
            String pomProperties = mfs.findPomProperties();
            ReleaseId releaseId = ReleaseIdImpl.fromPropertiesString(pomProperties);
            kModule = new MemoryKieModule(releaseId, kieProject, mfs);
        }
        return kModule;
    } catch (Exception e) {
        throw new RuntimeException("Unable to fetch module from resource: " + res, e);
    }
}
Also used : InternalResource(org.drools.core.io.internal.InternalResource) MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) ByteArrayInputStream(java.io.ByteArrayInputStream) KieModuleModel(org.kie.api.builder.model.KieModuleModel) ReleaseId(org.kie.api.builder.ReleaseId) KieModule(org.kie.api.builder.KieModule) KieBuilderImpl.setDefaultsforEmptyKieModule(org.drools.compiler.kie.builder.impl.KieBuilderImpl.setDefaultsforEmptyKieModule) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 7 with InternalResource

use of org.drools.core.io.internal.InternalResource in project drools by kiegroup.

the class DecisionTableConfigurationHandler method end.

public Object end(String uri, String localName, ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    final InternalResource resource = (InternalResource) parser.getParent();
    ResourceConfiguration dtConf = (ResourceConfiguration) parser.getCurrent();
    resource.setConfiguration(dtConf);
    return dtConf;
}
Also used : InternalResource(org.drools.core.io.internal.InternalResource) Element(org.w3c.dom.Element) ResourceConfiguration(org.kie.api.io.ResourceConfiguration)

Example 8 with InternalResource

use of org.drools.core.io.internal.InternalResource in project drools by kiegroup.

the class ResourceHandler method start.

public Object start(String uri, String localName, Attributes attrs, ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    final Collection collection = (Collection) parser.getParent();
    String src = attrs.getValue("source");
    String type = attrs.getValue("type");
    String basicAuthentication = attrs.getValue("basicAuthentication");
    String username = attrs.getValue("username");
    String password = attrs.getValue("password");
    String name = attrs.getValue("name");
    String description = attrs.getValue("description");
    String categories = attrs.getValue("categories");
    emptyAttributeCheck(localName, "source", src, parser);
    emptyAttributeCheck(localName, "type", type, parser);
    InternalResource resource = null;
    if (src.trim().startsWith("classpath:")) {
        resource = new ClassPathResource(src.substring(src.indexOf(':') + 1), parser.getClassLoader());
    } else {
        resource = new UrlResource(src);
        ((UrlResource) resource).setBasicAuthentication(basicAuthentication);
        ((UrlResource) resource).setUsername(username);
        ((UrlResource) resource).setPassword(password);
    }
    resource.setResourceType(ResourceType.getResourceType(type));
    resource.setSourcePath(name);
    resource.setDescription(description);
    resource.setCategories(categories);
    return resource;
}
Also used : InternalResource(org.drools.core.io.internal.InternalResource) UrlResource(org.drools.core.io.impl.UrlResource) Collection(java.util.Collection) ClassPathResource(org.drools.core.io.impl.ClassPathResource)

Aggregations

InternalResource (org.drools.core.io.internal.InternalResource)8 IOException (java.io.IOException)3 ClassPathResource (org.drools.core.io.impl.ClassPathResource)3 Resource (org.kie.api.io.Resource)3 ChangeSet (org.kie.internal.ChangeSet)3 PMMLResource (org.drools.compiler.compiler.PMMLResource)2 BaseResource (org.drools.core.io.impl.BaseResource)2 DescrResource (org.drools.core.io.impl.DescrResource)2 ReaderResource (org.drools.core.io.impl.ReaderResource)2 XStream (com.thoughtworks.xstream.XStream)1 DomDriver (com.thoughtworks.xstream.io.xml.DomDriver)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 ExecutionException (java.util.concurrent.ExecutionException)1