Package org.jconfig

Examples of org.jconfig.ConfigurationManagerException


     * @throws ConfigurationManagerException
     */
    public Configuration load(String configurationName) throws ConfigurationManagerException {   
        InitialDirContext ctx = getContext();
        if ( ctx == null ) {
            throw new ConfigurationManagerException("There is no connection to the LDAP server");
        }
        Configuration config = new DefaultConfiguration(null);
        getCategories(ctx,config);
        getAllProperties(ctx,config);
        return config;
View Full Code Here


    public void store(Configuration configuration) throws ConfigurationManagerException {
      throw new RuntimeException("not yet implemented");
    }
 
  public Configuration load(String configurationName, ConfigurationParser parser) throws ConfigurationManagerException {
    throw new ConfigurationManagerException("Using a specific parser with this handler is not supported");
  }
View Full Code Here

            java.net.URLConnection con = jcfURL.openConnection();
            is = con.getInputStream();
        }
        catch ( Exception e ) {
          ErrorReporter.getErrorHandler().reportError("Problem with URL handling/connection/validating",e);
            throw new ConfigurationManagerException( "Problem with URL handling/connection/validating: "
            + e.getMessage() );
        }
       
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setValidating(validate);
        DocumentBuilder db = null;
        try {
            db = dbf.newDocumentBuilder();
        } catch (ParserConfigurationException pce) {
          ErrorReporter.getErrorHandler().reportError("The parser cannot create a new document builder",pce);
            throw new ConfigurationManagerException("The parser cannot create a new document builder: " + pce.getMessage());
        }
        // if we have to validate then we need to define an error handler here
        if (validate) {
            try {
                // Set an ErrorHandler before parsing
                OutputStreamWriter errorWriter =
                new OutputStreamWriter(System.err, "UTF-8");
                db.setErrorHandler(
                new ConfigErrorHandler(new PrintWriter(errorWriter, true)));
            } catch (Exception e) {
              ErrorReporter.getErrorHandler().reportError("The parser cannot set up the error handler",e);
                throw new ConfigurationManagerException("The parser cannot set up the error handler");
            }
        }
        Document doc = null;
        try {
            doc = db.parse(is);
        } catch (SAXException se) {
          ErrorReporter.getErrorHandler().reportError("The parser cannot parse the XML",se);
            throw new ConfigurationManagerException("The parser cannot parse the XML: " + se.getMessage());
        } catch (IOException ioe) {
          ErrorReporter.getErrorHandler().reportError("The parser cannot open the file",ioe);
            throw new ConfigurationManagerException("The parser cannot open the file: " + ioe.getMessage());
        }
        Configuration config = parser.parse(doc, configName);       
        config.resetCreated();
        return config;
    }
View Full Code Here

                    braces--;
                }
            }
            if ( braces != 0 ) {
              ErrorReporter.getErrorHandler().reportError("Unmatched brackets in script file");
                throw new ConfigurationManagerException("Unmatched brackets in script file");
            }
            Configuration cfg = new ExtensibleConfiguration(configurationName);
            boolean process = false;
            String currentCategoryName = null;
            for ( int i = 0; i < content.size();i++) {
                String tmp = (String)content.get(i);
                tmp = tmp.trim();
                if ( process ) {
                    if ( tmp.startsWith("}") ) {
                        process = false;                    
                    }
                    else {                                               
                        String left = tmp.substring(0,tmp.indexOf("=")-1);
                        left = left.trim();
                        String right = tmp.substring(tmp.indexOf("=")+1);
                        right = right.trim();                                               
                        cfg.setProperty(left,right,currentCategoryName);                       
                    }
                }
                if ( tmp.startsWith("category") && tmp.indexOf("{") != -1 ) {
                    process = true;
                    String name = tmp.substring(9);
                    name = name.substring(0,name.indexOf("{"));
                    name = name.trim();                   
                    String extend = null;
                    if ( tmp.indexOf(" extends ") != -1 ) {
                        extend = name.substring(name.indexOf(" extends ")+9);
                        extend = extend.trim();
                        name = name.substring(0,name.indexOf(" extends "));                           
                    }
                    Category ec = new DefaultCategory(name);
                    if ( extend != null ) {
                        ec.setExtendsCategory(extend);
                    }
                    cfg.setCategory(ec);
                    currentCategoryName = name;
                }
            }
            return cfg;
        }
        catch (IOException e) {
          ErrorReporter.getErrorHandler().reportError("Error while trying to read file",e);
            throw new ConfigurationManagerException("Error while trying to read file");
        }       
    }
View Full Code Here

    public void store(Configuration configuration) throws ConfigurationManagerException {
        throw new RuntimeException("not yet implemented");
    }
   
  public Configuration load(String configurationName, ConfigurationParser parser) throws ConfigurationManagerException {
    throw new ConfigurationManagerException("Using a specific parser with this handler is not supported");
  }
View Full Code Here

            fw.write(config.getXMLAsString());
            // close the file because we are done
            fw.close();
        } catch (Exception e) {
          ErrorReporter.getErrorHandler().reportError("The file cannot be saved",e);
            throw new ConfigurationManagerException("The file cannot be saved:"+e.getMessage());
        }
    }
View Full Code Here

   
    public synchronized Configuration load() throws ConfigurationManagerException {
        String myURL = getURL();
        if ( !myURL.startsWith("jconfig://" ) ) {
          ErrorReporter.getErrorHandler().reportError("Wrong URL. Must start with jconfig://. Syntax: jconfig://server:port/configname");
            throw new ConfigurationManagerException("Wrong URL. Must start with jconfig://. Syntax: jconfig://server:port/configname");
        }
        myURL = myURL.substring(10);
        if ( myURL.indexOf("/") == -1 ) {
          ErrorReporter.getErrorHandler().reportError("Wrong URL. The configname is missing. Syntax: jconfig://server:port/configname");
            throw new ConfigurationManagerException("Wrong URL. The configname is missing. Syntax: jconfig://server:port/configname");
        }
        // TODO: check if this is correct
        int pos = myURL.indexOf("/");
        if ( (pos +1 ) > myURL.length() ) {
          ErrorReporter.getErrorHandler().reportError("Wrong URL. The configname is missing. Syntax: jconfig://server:port/configname");
            throw new ConfigurationManagerException("Wrong URL. The configname is missing. Syntax: jconfig://server:port/configname");
        }
        String name = myURL.substring(pos+1);               
        myURL = "http://"+myURL;       
        return load( myURL,name );       
    }
View Full Code Here

   
    public synchronized Configuration load(String configName) throws ConfigurationManagerException {
        String myURL = getURL();
        if ( !myURL.startsWith("jconfig://" ) ) {
          ErrorReporter.getErrorHandler().reportError("Wrong URL. Must start with jconfig://. Syntax: jconfig://server:port/configname");
            throw new ConfigurationManagerException("Wrong URL. Must start with jconfig://. Syntax: jconfig://server:port/configname");
        }
        myURL = myURL.substring(10);
        if ( myURL.indexOf("/") == -1 ) {
          ErrorReporter.getErrorHandler().reportError("Wrong URL. The configname is missing. Syntax: jconfig://server:port/configname");
            throw new ConfigurationManagerException("Wrong URL. The configname is missing. Syntax: jconfig://server:port/configname");
        }
        // TODO: check if this is correct
        int pos = myURL.indexOf("/");
        if ( (pos +1 ) > myURL.length() ) {
          ErrorReporter.getErrorHandler().reportError("Wrong URL. The configname is missing. Syntax: jconfig://server:port/configname");
            throw new ConfigurationManagerException("Wrong URL. The configname is missing. Syntax: jconfig://server:port/configname");
        }
        String name = myURL.substring(pos+1);               
        myURL = "http://"+myURL;       
        return load( myURL,name );       
    }
View Full Code Here

              ErrorReporter.getErrorHandler().reportError("File not found:"+filename);
                is = new ResourceLocator("config.xml").getInputStream();
            }
        } catch (IOException e) {
          ErrorReporter.getErrorHandler().reportError("Cannot load file:"+filename,e);
            throw new ConfigurationManagerException(e.getLocalizedMessage());
        }
        if ( is != null ) {
          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
          // set the validation flag (true if it should be validated)
          dbf.setValidating(validate);
          DocumentBuilder db = null;
          try {
              db = dbf.newDocumentBuilder();
          } catch (ParserConfigurationException pce) {
            ErrorReporter.getErrorHandler().reportError("The parser cannot create a new document builder",pce);
              throw new ConfigurationManagerException("The parser cannot create a new document builder: " + pce.getMessage());
          }
          // if we have to validate then we need to define an error handler here
          if (validate) {
              try {
                  // Set an ErrorHandler before parsing
                  OutputStreamWriter errorWriter =
                  new OutputStreamWriter(System.err, "UTF-8");
                  db.setErrorHandler(new ConfigErrorHandler(new PrintWriter(errorWriter, true)));
                  //new MyErrorHandler(new PrintWriter(errorWriter, true)));
              } catch (Exception e) {
                ErrorReporter.getErrorHandler().reportError("The parser cannot set up the error handler",e);
                  throw new ConfigurationManagerException("The parser cannot set up the error handler");
              }
          }
          Document doc = null;
          try {
              doc = db.parse(is);
          } catch (SAXException se) {
            ErrorReporter.getErrorHandler().reportError("The parser cannot parse the file",se);
              throw new ConfigurationManagerException("The parser cannot parse the file: " + se.getMessage());
          } catch (IOException ioe) {
            ErrorReporter.getErrorHandler().reportError("The parser cannot open the file",ioe);
              throw new ConfigurationManagerException("The parser cannot open the file: " + ioe.getMessage());
          }    
          Configuration config = parser.parse(doc, configurationName);               
          config.resetCreated();
          return config;
    }
        else {
          ErrorReporter.getErrorHandler().reportError("The file:"+filename+" not found in classpath");
            throw new ConfigurationManagerException("The file could not be found in the classpath");
        }
    }
View Full Code Here

    public void store(Configuration configuration) throws ConfigurationManagerException {
        try {
      store( new ResourceLocator(filename).getFile(),configuration);
    } catch (IOException e) {
      ErrorReporter.getErrorHandler().reportError("File "+filename+" could not be found",e);
      throw new ConfigurationManagerException("File "+filename+" could not be found");
    }
    }
View Full Code Here

TOP

Related Classes of org.jconfig.ConfigurationManagerException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.