Package org.osgi.service.cm

Examples of org.osgi.service.cm.ConfigurationException


     * types). if the validation fails an Exception MUST BE thrown.<p>
     * @throws ConfigurationException if the validation fails
     */
    protected void validateConfiguration() throws ConfigurationException {
        if(getId() == null || getId().isEmpty()){
            throw new ConfigurationException(ID, "The id of a ReferencedSite configuration MUST NOT be NULL nor empty!");
        }
        //check if the prefixes can be converted to an String[]
        try {
            setEntityPrefixes(getEntityPrefixes());
        } catch (IllegalArgumentException e) {
            throw new ConfigurationException(ENTITY_PREFIX, e.getMessage(),e);
        }
        //check the configured licenses and create the License array
        setLicenses(getLicenses());
        //check if the fieldMappings can be converted to an String[]
        try {
            setFieldMappings(getFieldMappings());
        } catch (IllegalArgumentException e) {
            throw new ConfigurationException(SITE_FIELD_MAPPINGS, e.getMessage(),e);
        }
        try {
            setDefaultMappedEntityState(getDefaultMappedEntityState());
        } catch (IllegalArgumentException e) {
            throw new ConfigurationException(DEFAULT_MAPPING_STATE,
                String.format("Unknown default MappingState (%s=%s) for Site %s! Valid values are %s ",
                    DEFAULT_MAPPING_STATE,config.get(DEFAULT_MAPPING_STATE),getId(),
                        Arrays.toString(MappingState.values())),e);
        }
        try {
            setDefaultManagedEntityState(getDefaultManagedEntityState());
        } catch (IllegalArgumentException e) {
            throw new ConfigurationException(DEFAULT_SYMBOL_STATE,
                String.format("Unknown default SymbolState (%s=%s) for Site %s! Valid values are %s ",
                    DEFAULT_SYMBOL_STATE,config.get(DEFAULT_SYMBOL_STATE),getId(),
                        Arrays.toString(ManagedEntityState.values()),e));
        }
        //check if the default expire duration is a number
        try {
            setDefaultExpireDuration(getDefaultExpireDuration());
        } catch (NumberFormatException e) {
            throw new ConfigurationException(DEFAULT_EXPIRE_DURATION,
                String.format("Unable to parse Number for %s=%s. Will return -1 (no expire duration)",
                    DEFAULT_EXPIRE_DURATION,config.get(DEFAULT_EXPIRE_DURATION)),e);
        }
    }
View Full Code Here


        log.info("activating Entityhub with configuration "+context.getProperties());
        this.context = context;
        //First check the entityhub ID and
        log.info(" ... init Basic Properties");
        if(config.getID() == null || config.getID().isEmpty()){
            throw new ConfigurationException(EntityhubConfiguration.ID, "The Entityhub Configuration does not define a ID for the Entityhub");
        } else {
            log.info("   + id: "+config.getID());
        }
        if(config.getName() == null || config.getName().isEmpty()){
            throw new ConfigurationException(EntityhubConfiguration.NAME, "The Entityhub Configuration does not define a name for the Entityhub");
        } else {
            log.info("   + id: "+config.getName());
        }
        if(config.getDescription() != null){
            log.info("   + id: "+config.getDescription());
        }
        if(config.getEntityhubPrefix() == null){
            throw new ConfigurationException(EntityhubConfiguration.PREFIX, "The Entityhub Configuration does not define a Prefix for the Entityhub");
        }
        try {
            new URI(config.getEntityhubPrefix());
            log.info("   + prefix: "+config.getEntityhubPrefix());
        } catch (URISyntaxException e1) {
            throw new ConfigurationException(EntityhubConfiguration.PREFIX, "The Prefix configured for the Entityhub is not an valied URI (prefix="+config.getEntityhubPrefix()+")");
        }
        //next get the reference to the configured EntityhubYard
        if(config.getEntityhubPrefix() == null){
            throw new ConfigurationException(EntityhubConfiguration.ENTITYHUB_YARD_ID, "The ID of the Yard used by the Entityhub MUST NOT be NULL");
        }
        if(config.getEntityhubYardId().isEmpty()){
            throw new ConfigurationException(EntityhubConfiguration.ENTITYHUB_YARD_ID, "The ID of the Yard used by the Entityhub MUST NOT be empty");
        }
        String entityhubYardFilterString = String.format("(&(%s=%s)(%s=%s))",
            Constants.OBJECTCLASS,Yard.class.getName(),
            Yard.ID,config.getEntityhubYardId());
        log.info(" ... tracking EntityhubYard by Filter:"+entityhubYardFilterString);
View Full Code Here

            weight = ((Number)value).intValue();
        } else if(value != null){
            try {
                weight = new BigDecimal(value.toString()).intValueExact();
            } catch (RuntimeException e) {
                throw new ConfigurationException(WEIGHT, "Unable to parse integer weight!", e);
            }
        } else { //weight not defined
            weight = 0;
        }
        value = config.get(SYNC_INTERVAL);
        if(value instanceof Number){
            syncInterval = Math.max(((Number)value).intValue(),MIN_SYNC_INTERVAL);
        } else if(value != null){
            try {
                syncInterval = Math.max(new BigDecimal(value.toString()).intValueExact(),MIN_SYNC_INTERVAL);
            } catch (RuntimeException e) {
                throw new ConfigurationException(SYNC_INTERVAL, "Unable to parse integer weight!", e);
            }
        } else { //weight not defined
            syncInterval = DEFAULT_SYNC_INTERVAL;
        }
        value = config.get(TDB_DIR);
        File dataDir;
        if(value != null && !value.toString().isEmpty()){
            dataDir = new File(substituteProperty(value.toString(),bc)).getAbsoluteFile();
        } else {
            value = config.get(Constants.SERVICE_PID);
            if(value == null){
                throw new ConfigurationException(TDB_DIR, "No Data Directory for "
                    + "the Jena TDB store parsed. Also unable to use the "
                    + "'service.pid' property as default because this property "
                    + "is not present in the parsed configuration.");
            }
            dataDir = bc.getDataFile("singleTdb"+File.separatorChar+value.toString());
            log.info("No TDB directory parsed - use default '{}'",dataDir);
        }
        //parse the default graph name
        value = config.get(DEFAULT_GRAPH_NAME);
        if(value != null && !value.toString().isEmpty()){
            try {
                new URI(value.toString());
                defaultGraphName = new UriRef(value.toString());
            } catch (URISyntaxException e) {
                throw new ConfigurationException(DEFAULT_GRAPH_NAME, "The parsed name '"
                        + value + "'for the default graph (union over all "
                        + "named graphs managed by this Jena TDB dataset) MUST BE "
                        + "an valid URI or NULL do deactivate this feature!",e);
            }
        } else {
            defaultGraphName = null; //deactivate the default graph name
        }
       
        //validate the parsed directory!
        if(!dataDir.exists()){
            if(dataDir.mkdirs()){
                log.info("Created Jena TDB data directory {}",dataDir);
            } else {
                throw new ConfigurationException(TDB_DIR, "Unable to create Jena TDB data directory '"+dataDir+"'!");
            }
        } else if(!dataDir.isDirectory()){
            throw new ConfigurationException("tdb.dir", "Configured jena TDB data directory '"
                    + dataDir+"' already exists, but is not a Directory!");
        } //else exists and is a directory ... nothing to do
        TDB.getContext().set(TDB.symUnionDefaultGraph, true);
        setDataset(TDBFactory.createDataset(dataDir.getAbsolutePath()));
        //init the read/write lock
       
        //init the graph config (stores the graph and mgraph names in a config file)
        initGraphConfigs(dataDir,config);
       
        //finally ensure the the defaultGraphName is not also used as a graph/mgraph name
        if(graphNames.contains(defaultGraphName)){
            throw new ConfigurationException(DEFAULT_GRAPH_NAME, "The configured default graph name '"
                +defaultGraphName+"' is also used as a Graph name!");
        }
        if(mGraphNames.contains(defaultGraphName)){
            throw new ConfigurationException(DEFAULT_GRAPH_NAME, "The configured default graph name '"
                +defaultGraphName+"' is also used as a MGraph name!");
        }
       
        syncThread = new SyncThread();
        syncThread.setDaemon(true);
View Full Code Here

            weight = ((Number)value).intValue();
        } else if(value != null){
            try {
                weight = new BigDecimal(value.toString()).intValueExact();
            } catch (RuntimeException e) {
                throw new ConfigurationException(WEIGHT, "Unable to parse integer weight!", e);
            }
        } else { //weight not defined
            weight = 0;
        }
        value = config.get(SYNC_INTERVAL);
        if(value instanceof Number){
            syncInterval = Math.max(((Number)value).intValue(),MIN_SYNC_INTERVAL);
        } else if(value != null){
            try {
                syncInterval = Math.max(new BigDecimal(value.toString()).intValueExact(),MIN_SYNC_INTERVAL);
            } catch (RuntimeException e) {
                throw new ConfigurationException(SYNC_INTERVAL, "Unable to parse integer weight!", e);
            }
        } else { //sync interval not defined
            syncInterval = DEFAULT_SYNC_INTERVAL;
        }
        value = config.get(TDB_DIR);
        File dataDir;
        if(value != null && !value.toString().isEmpty()){
            dataDir = new File(substituteProperty(value.toString(),bc)).getAbsoluteFile();
        } else {
            value = config.get(Constants.SERVICE_PID);
            if(value == null){
                throw new ConfigurationException(TDB_DIR, "No Data Directory for "
                    + "the Jena TDB store parsed. Also unable to use the "
                    + "'service.pid' property as default because this property "
                    + "is not present in the parsed configuration.");
            }
            dataDir = bc.getDataFile("singleTdb"+File.separatorChar+value.toString());
            log.info("No TDB directory parsed - use default '{}'",dataDir);
        }
        //parse the default graph name
        value = config.get(DEFAULT_GRAPH_NAME);
        if(value != null && !value.toString().isEmpty()){
            try {
                new URI(value.toString());
                defaultGraphName = new UriRef(value.toString());
            } catch (URISyntaxException e) {
                throw new ConfigurationException(DEFAULT_GRAPH_NAME, "The parsed name '"
                        + value + "'for the default graph (union over all "
                    + "named graphs managed by this Jena TDB dataset) MUST BE "
                        + "an valid URI or NULL do deactivate this feature!",e);
            }
        } else {
            defaultGraphName = null; //deactivate the default graph name
        }
       
        //validate the parsed directory!
        if(!dataDir.exists()){
            if(dataDir.mkdirs()){
                log.info("Created Jena TDB data directory {}",dataDir);
            } else {
                throw new ConfigurationException(TDB_DIR, "Unable to create Jena TDB data directory '"+dataDir+"'!");
            }
        } else if(!dataDir.isDirectory()){
            throw new ConfigurationException("tdb.dir", "Configured jena TDB data directory '"
                    + dataDir+"' already exists, but is not a Directory!");
        } //else exists and is a directory ... nothing to do
        TDB.getContext().set(TDB.symUnionDefaultGraph, true);
        setDataset( TDBFactory.createDataset(dataDir.getAbsolutePath()) );
        graphNameIndex = new ModelGraph(datasetLock, getDataset().getDefaultModel(),true);

        // Remove existing default graph names from the index (if might have changed
        // in the mean time).
        removeDefaultGraphFromIndex();

        //finally ensure the the defaultGraphName is not also used as a graph/mgraph name
        if (defaultGraphName != null) {
          if (isExistingGraphName(defaultGraphName)) {
            throw new ConfigurationException(DEFAULT_GRAPH_NAME, "The configured default graph name '"
                +defaultGraphName+"' is already used as a Graph or MGraph name!");
          } else {
            addToIndex( defaultGraphName, Symbols.Default );
            addToIndex( defaultGraphName, Symbols.Graph );
          }
View Full Code Here

                    }
                    catch ( Exception e )
                    {
                        // IOException from getting/updated config
                        // IllegalStateException from hashing password
                        throw new ConfigurationException( OsgiManager.PROP_PASSWORD, "Cannot update password property",
                            e );
                    }
                    finally
                    {
                        bc.ungetService( ref );
View Full Code Here

    }

    public synchronized void updated(String pid, Dictionary dict) throws ConfigurationException {
        String name = (String) dict.get(LOG_NAME);
        if ((name == null) || "".equals(name)) {
            throw new ConfigurationException(LOG_NAME, "Log name has to be specified.");
        }

        Component service = (Component) m_logInstances.get(pid);
        if (service == null) {
            // publish log service
View Full Code Here

                // ensure unique configuration of the log writer
                SlingLoggerWriter existingWriter = writerByFileName.get(logFileName);
                if (existingWriter != null
                    && existingWriter.getConfigurationPID().equals(pid)) {
                    // this file is already configured by another LOG_PID
                    throw new ConfigurationException(LogManager.LOG_FILE,
                        "LogFile " + logFileName
                            + " already configured by configuration "
                            + existingWriter.getConfigurationPID());
                }
            }

            // get number of files and ensure minimum and default
            Object fileNumProp = configuration.get(LogManager.LOG_FILE_NUMBER);
            int fileNum = -1;
            if (fileNumProp instanceof Number) {
                fileNum = ((Number) fileNumProp).intValue();
            } else if (fileNumProp != null) {
                try {
                    fileNum = Integer.parseInt(fileNumProp.toString());
                } catch (NumberFormatException nfe) {
                    // don't care
                }
            }
            if (fileNum <= 0) {
                fileNum = LogManager.LOG_FILE_NUMBER_DEFAULT;
            }

            // get the log file size
            Object fileSizeProp = configuration.get(LogManager.LOG_FILE_SIZE);
            String fileSize = null;
            if (fileSizeProp != null) {
                fileSize = fileSizeProp.toString();
            }
            if (fileSize == null || fileSize.length() == 0) {
                fileSize = LogManager.LOG_FILE_SIZE_DEFAULT;
            }

            try {
                if (slw == null) {
                    slw = new SlingLoggerWriter(pid);
                    slw.configure(logFileName, fileNum, fileSize);
                    writerByPid.put(pid, slw);

                    if (logFileName != null) {
                        writerByFileName.put(logFileName, slw);
                    }
                } else {
                    slw.configure(logFileName, fileNum, fileSize);
                }
            } catch (IOException ioe) {
                internalFailure("Cannot create log file " + logFileName, ioe);
                internalFailure("Logging to the console", null);
                throw new ConfigurationException(LogManager.LOG_FILE,
                    "Cannot create writer for log file " + logFileName);
            }

        } else {
View Full Code Here

            String file = (String) configuration.get(LogManager.LOG_FILE);
            Set<String> categories = toCategoryList(configuration.get(LogManager.LOG_LOGGERS));

            // verify categories
            if (categories == null) {
                throw new ConfigurationException(LogManager.LOG_LOGGERS,
                    "Missing categories in configuration " + pid);
            }

            // verify no other configuration has any of the categories
            for (String cat : categories) {
                SlingLoggerConfig cfg = configByCategory.get(cat);
                if (cfg != null && !pid.equals(cfg.getConfigPid())) {
                    throw new ConfigurationException(LogManager.LOG_LOGGERS,
                        "Category " + cat
                            + " already defined by configuration " + pid);
                }
            }

            // verify writer
            SlingLoggerWriter writer;
            if (file != null && file.length() > 0) {
                writer = writerByPid.get(file);
                if (writer == null) {
                    writer = writerByFileName.get(file);
                    if (writer == null) {
                        file = getAbsoluteLogFile(file);
                        writer = writerByFileName.get(file);
                        if (writer == null) {
                            writer = defaultWriter;
                        }
                    }
                }
            } else {
                writer = defaultWriter;
            }

            // verify log level
            if (level == null) {
                throw new ConfigurationException(LogManager.LOG_LEVEL,
                    "Value required");
            }
            SlingLoggerLevel logLevel = SlingLoggerLevel.valueOf(level.toUpperCase());

            // verify pattern
View Full Code Here

      catch (NoSuchMethodException e) {
        try {
          update = bean.getClass().getMethod(updateMethod, new Class[] { String.class, Dictionary.class });
        }
        catch (NoSuchMethodException e1) {
          throw new ConfigurationException(instancePid, "Invalid or missing update method for bean "
              + reference + "; requires signature " + updateMethod
              + "(java.util.String, java.util.Dictionary) or " + updateMethod + "(java.util.Map)", e);
        }
      }

      try {
        update.invoke(bean, new Object[] { instancePid, props });
      }
      catch (IllegalAccessException e) {
        throw new ConfigurationException(instancePid, "Insufficient permission to invoke update method", e);
      }
      catch (InvocationTargetException e) {
        throw new ConfigurationException(instancePid, "Error updating", e.getTargetException());
      }
    }
View Full Code Here

      catch (NoSuchMethodException e) {
        try {
          update = bean.getClass().getMethod(updateMethod, new Class[] { Dictionary.class });
        }
        catch (NoSuchMethodException e1) {
          throw new ConfigurationException(servicePid, "Invalid or missing update method for bean "
              + reference + "; requires signature " + updateMethod + "(java.util.Dictionary) or "
              + updateMethod + "(java.util.Map)", e);
        }
      }

      try {
        update.invoke(bean, new Object[] { props });
      }
      catch (IllegalAccessException e) {
        throw new ConfigurationException(servicePid, "Insufficient permission to invoke update method", e);
      }
      catch (InvocationTargetException e) {
        throw new ConfigurationException(servicePid, "Error updating", e.getTargetException());
      }
    }
View Full Code Here

TOP

Related Classes of org.osgi.service.cm.ConfigurationException

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.