Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010 JBoss Inc
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.drools.io;
 
 import java.io.File;
 import java.io.Reader;
 import java.net.URL;
 

Convenience Factory to provide Resource implementations for the desired IO resource.

 KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
 kbuilder.add( ResourceFactory.newUrlResource( "htp://www.domain.org/myProcess.bpmn2" ),
               ResourceType.BPMN2 );
 
 KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
 kbuilder.add( ResourceFactory.newClassPathResource( "htp://www.domain.org/myrules.drl", getClass() ),
               ResourceType.DRL );
 
 
 public class ResourceFactory {
     private static ResourceFactoryService factoryService;

    
A Service that can be started, to provide notifications of changed Resources.

Returns:
 
     }

    
As service, that scans the disk for changes, this acts as a Monitor for the Notifer service.

Returns:
 
     }
 
     public static Resource newUrlResource(URL url) {
         return getFactoryService().newUrlResourceurl );
     }
 
     public static Resource newUrlResource(String path) {
         return getFactoryService().newUrlResourcepath );
     }
 
     public static Resource newFileResource(File file) {
         return getFactoryService().newFileSystemResourcefile );
     }
 
     public static Resource newFileResource(String fileName) {
         return getFactoryService().newFileSystemResourcefileName );
     }
 
     public static Resource newByteArrayResource(byte[] bytes) {
         return getFactoryService().newByteArrayResourcebytes );
     }
 
     public static Resource newInputStreamResource(InputStream stream) {
         return getFactoryService().newInputStreamResourcestream );
     }
 
     public static Resource newInputStreamResource(InputStream stream,
                                                   String encoding) {
         return getFactoryService().newInputStreamResourcestream,
                                                            encoding );
     }
 
     public static Resource newReaderResource(Reader reader) {
         return getFactoryService().newReaderResourcereader );
     }
 
     public static Resource newReaderResource(Reader reader,
                                             String encoding) {
        return getFactoryService().newReaderResourcereader,
                                                        encoding );
    }
    public static Resource newClassPathResource(String path) {
        return getFactoryService().newClassPathResourcepath );
    }
    public static Resource newClassPathResource(String path,
                                                Class clazz) {
        return getFactoryService().newClassPathResourcepath,
                                                           clazz );
    }
    public static Resource newClassPathResource(String path,
                                                ClassLoader classLoader) {
        return getFactoryService().newClassPathResourcepath,
                                                           classLoader );
    }
    public static Resource newClassPathResource(String path,
                                                String encoding) {
        return getFactoryService().newClassPathResourcepath,
                                                         encoding );
    }
    public static Resource newClassPathResource(String path,
                                                String encoding,
                                                Class clazz) {
        return getFactoryService().newClassPathResourcepath,
                                                         encoding,
                                                         clazz );
    }
    public static Resource newClassPathResource(String path,
                                                String encoding,
                                                ClassLoader classLoader) {
        return getFactoryService().newClassPathResourcepath,
                                                         encoding,
                                                         classLoader );
    }
    
    public static Resource newDescrResourceKnowledgeDescr descr ) {
        return getFactoryService().newDescrResourcedescr );
    }
    
    private static synchronized void setFactoryService(ResourceFactoryService factoryService) {
        . = factoryService;
    }
    private static synchronized ResourceFactoryService getFactoryService() {
        if (  == null ) {
            loadFactoryService();
        }
        return ;
    }
    private static void loadFactoryService() {
        setFactoryService( ServiceRegistryImpl.getInstance().getResourceFactoryService.class ) );
    }
New to GrepCode? Check out our FAQ X