Package org.osgi.service.deploymentadmin.spi

Examples of org.osgi.service.deploymentadmin.spi.ResourceProcessorException


        checkMethodRuntimeFailure("cancel");
    }
   
    private void checkMethodFailure(int code, String methodName) throws ResourceProcessorException {
        if (shouldFail(methodName)) {
            throw new ResourceProcessorException(code, methodName + " fails forcedly!");
        }
    }
View Full Code Here


                validate(input);
                input.close();
            }
            catch (Exception e) {
                resourceFile.delete();
                throw new ResourceProcessorException(ResourceProcessorException.CODE_OTHER_ERROR, "Error validating resource.", e);
            }

            m_resources.put(name, deploymentPackageName);
        }
    }
View Full Code Here

    public void process(String name, InputStream stream) throws ResourceProcessorException {
        ensureSession();
        String originalDeploymentPackage = m_resourceStore.getDeploymentPackage(name);
        if ((originalDeploymentPackage != null) && !m_deploymentPackageName.equals(originalDeploymentPackage)) {
            throw new ResourceProcessorException(ResourceProcessorException.CODE_RESOURCE_SHARING_VIOLATION, "Resource " + name + " does not belong to deployment package " + m_deploymentPackageName + ", but to " + originalDeploymentPackage);
        }

        try {
            m_resourceStore.addResource(m_deploymentPackageName, name, stream);
        }
        catch (IOException e) {
            throw new ResourceProcessorException(ResourceProcessorException.CODE_OTHER_ERROR, "Error storing resource.", e);
        }

        m_toInstall.add(name);
    }
View Full Code Here

                validate(input);
                input.close();
            }
            catch (Exception e) {
                resourceFile.delete();
                throw new ResourceProcessorException(ResourceProcessorException.CODE_OTHER_ERROR, "Error validating resource.", e);
            }

            m_resources.put(name, deploymentPackageName);
        }
    }
View Full Code Here

    public void process(String name, InputStream stream) throws ResourceProcessorException {
        ensureSession();
        String originalDeploymentPackage = m_resourceStore.getDeploymentPackage(name);
        if ((originalDeploymentPackage != null) && !m_deploymentPackageName.equals(originalDeploymentPackage)) {
            throw new ResourceProcessorException(ResourceProcessorException.CODE_RESOURCE_SHARING_VIOLATION, "Resource " + name + " does not belong to deployment package " + m_deploymentPackageName + ", but to " + originalDeploymentPackage);
        }

        try {
            m_resourceStore.addResource(m_deploymentPackageName, name, stream);
        }
        catch (IOException e) {
            throw new ResourceProcessorException(ResourceProcessorException.CODE_OTHER_ERROR, "Error storing resource.", e);
        }

        m_toInstall.add(name);
    }
View Full Code Here

    public void process(String name, InputStream stream) throws ResourceProcessorException {
        m_log.log(LogService.LOG_DEBUG, "processing " + name);
        // initial validation
        synchronized (LOCK) {
            if (m_session == null) {
                throw new ResourceProcessorException(ResourceProcessorException.CODE_OTHER_ERROR, "Can not process resource without a Deployment Session");
            }
        }
        MetaDataReader reader = new MetaDataReader();
        MetaData data = null;
        try {
            data = reader.parse(stream);
        }
        catch (IOException e) {
            throw new ResourceProcessorException(ResourceProcessorException.CODE_OTHER_ERROR, "Unable to process resource.", e);
        }
        if (data == null) {
            throw new ResourceProcessorException(ResourceProcessorException.CODE_OTHER_ERROR, "Supplied configuration is not conform the metatype xml specification.");
        }
        // process resources
        String filter = null;
        Map optionalAttributes = data.getOptionalAttributes();
        if (optionalAttributes != null) {
            filter = (String) optionalAttributes.get(AutoConfResourceProcessor.CONFIGURATION_ADMIN_FILTER_ATTRIBUTE);
        }
        // add to session data
        if (!m_toBeInstalled.containsKey(name)) {
            m_toBeInstalled.put(name, new ArrayList());
        }
        Map designates = data.getDesignates();
        if (designates == null) {
            // if there are no designates, there's nothing to process
            m_log.log(LogService.LOG_INFO, "No designates found in the resource, so there's nothing to process.");
            return;
        }
        Map localOcds = data.getObjectClassDefinitions();
        if (localOcds == null) {
            localOcds = Collections.EMPTY_MAP;
        }
        Iterator i = designates.keySet().iterator();
        while (i.hasNext()) {
            Designate designate = (Designate) designates.get(i.next());
           
            // check object
            if (designate.getObject() == null) {
                throw new ResourceProcessorException(ResourceProcessorException.CODE_OTHER_ERROR, "Designate Object child missing or invalid");
            }
           
            // check attributes
            if (designate.getObject().getAttributes() == null || designate.getObject().getAttributes().size() == 0) {
                throw new ResourceProcessorException(ResourceProcessorException.CODE_OTHER_ERROR, "Object Attributes child missing or invalid");
            }
           
            // check ocdRef
            String ocdRef = designate.getObject().getOcdRef();
            if (ocdRef == null || "".equals(ocdRef)) {
                throw new ResourceProcessorException(ResourceProcessorException.CODE_OTHER_ERROR, "Object ocdRef attribute missing or invalid");
            }

            // determine OCD
            ObjectClassDefinition ocd = null;
            OCD localOcd = (OCD) localOcds.get(ocdRef);
            // ask meta type service for matching OCD if no local OCD has been defined
            ocd = (localOcd != null) ? new ObjectClassDefinitionImpl(localOcd) : getMetaTypeOCD(data, designate);
            if (ocd == null) {
                throw new ResourceProcessorException(ResourceProcessorException.CODE_OTHER_ERROR, "No Object Class Definition found with id=" + ocdRef);
            }
            // determine configuration data based on the values and their type definition
            Dictionary dict = getProperties(designate, ocd);
            if (dict == null) {
                // designate does not match it's definition, but was marked optional, ignore it
View Full Code Here

    public void dropped(String name) throws ResourceProcessorException {
        m_log.log(LogService.LOG_DEBUG, "dropped " + name);
        synchronized (LOCK) {
          if (m_session == null) {
            throw new ResourceProcessorException(ResourceProcessorException.CODE_OTHER_ERROR, "Can not process resource without a Deployment Session");
          }
        }
      try {
        List resources = m_persistencyManager.load(name);
        if (!m_toBeDeleted.containsKey(name)) {
          m_toBeDeleted.put(name, new ArrayList());
        }
        ((List) m_toBeDeleted.get(name)).addAll(resources);
      }
      catch (IOException ioe) {
        throw new ResourceProcessorException(ResourceProcessorException.CODE_OTHER_ERROR, "Unable to drop resource: " + name, ioe);
      }
        m_log.log(LogService.LOG_DEBUG, "dropped " + name + " done");
    }
View Full Code Here

    public void dropAllResources() throws ResourceProcessorException {
        m_log.log(LogService.LOG_DEBUG, "drop all resources");
        synchronized (LOCK) {
          if (m_session == null) {
            throw new ResourceProcessorException(ResourceProcessorException.CODE_OTHER_ERROR, "Can not drop all resources without a Deployment Session");
          }
        }

      File basedir = m_bc.getDataFile("");
      if (basedir != null && basedir.isDirectory()) {
        String[] files = basedir.list();
        for (int i = 0; i < files.length; i++) {
          dropped(files[i]);
        }
      }
      else {
        throw new ResourceProcessorException(ResourceProcessorException.CODE_OTHER_ERROR, "Unable to drop resources, data area is not accessible");
      }
        m_log.log(LogService.LOG_DEBUG, "drop all resources done");
    }
View Full Code Here

    public void prepare() throws ResourceProcessorException {
        m_log.log(LogService.LOG_DEBUG, "prepare");
        synchronized (LOCK) {
          if (m_session == null) {
            throw new ResourceProcessorException(ResourceProcessorException.CODE_OTHER_ERROR, "Can not process resource without a Deployment Session");
          }
        }
      try {
            m_log.log(LogService.LOG_DEBUG, "prepare delete");
        // delete dropped resources
        for (Iterator i = m_toBeDeleted.keySet().iterator(); i.hasNext();) {
          String name = (String) i.next();
          List resources = (List) m_toBeDeleted.get(name);
          for (Iterator j = resources.iterator(); j.hasNext();) {
            AutoConfResource resource = (AutoConfResource) j.next();
            m_configurationAdminTasks.add(new DropResourceTask(resource));
          }
          m_postCommitTasks.add(new DeleteResourceTask(name));
        }

            m_log.log(LogService.LOG_DEBUG, "prepare install/update");
        // install new/updated resources
        for (Iterator j = m_toBeInstalled.keySet().iterator(); j.hasNext();) {
          String name = (String) j.next();
          List existingResources = null;
          try {
            existingResources = m_persistencyManager.load(name);
          }
          catch (IOException ioe) {
            throw new ResourceProcessorException(ResourceProcessorException.CODE_PREPARE, "Unable to read existing resources for resource " + name, ioe);
          }
          List resources = (List) m_toBeInstalled.get(name);
          for (Iterator iterator = resources.iterator(); iterator.hasNext();) {
            AutoConfResource resource = (AutoConfResource) iterator.next();
            m_configurationAdminTasks.add(new InstallOrUpdateResourceTask(resource));
          }
          // remove existing configurations that were not in the new version of the resource
          for (Iterator i = existingResources.iterator(); i.hasNext();) {
            AutoConfResource existingResource = (AutoConfResource) i.next();
            Configuration configuration = null;
            if (existingResource.isFactoryConfig()) {
              configuration = m_configAdmin.getConfiguration(existingResource.getGeneratedPid(), existingResource.getBundleLocation());
            } else {
              configuration = m_configAdmin.getConfiguration(existingResource.getPid(), existingResource.getBundleLocation());
            }
            configuration.delete();
          }
          m_postCommitTasks.add(new StoreResourceTask(name, resources));
        }
      }
      catch (IOException ioe) {
        m_toBeInstalled.clear();
        throw new ResourceProcessorException(ResourceProcessorException.CODE_PREPARE, "Unable to prepare for commit for resource", ioe);
      }
        m_log.log(LogService.LOG_DEBUG, "prepare done");
    }
View Full Code Here

              if (designate.isOptional()) {
                properties = null;
                break;
              }
              else {
                throw new ResourceProcessorException(ResourceProcessorException.CODE_OTHER_ERROR, "Could not match attribute to it's definition: adref=" + adRef);
              }
            }
            properties.put(adRef, value);
            found = true;
            break;
          }
        }
        if (!found) {
          if (designate.isOptional()) {
            properties = null;
            break;
          } else {
            throw new ResourceProcessorException(ResourceProcessorException.CODE_OTHER_ERROR, "Could not find attribute definition: adref=" + adRef);
          }
        }
      }

      return properties;
View Full Code Here

TOP

Related Classes of org.osgi.service.deploymentadmin.spi.ResourceProcessorException

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.