Package org.wso2.carbon.registry.core

Examples of org.wso2.carbon.registry.core.Resource


            sql1 = getConvertedRegQuery(statement);
        }


        Resource q1 = null;
        Set nodes = new HashSet();

        try {
//this modifications are done so that the queries are not stored in the registry.
//            q1 = registry.newResource();

//            q1.setContent(sql1);

//            q1.setMediaType(RegistryConstants.SQL_QUERY_MEDIA_TYPE);

//            q1.addProperty(RegistryConstants.RESULT_TYPE_PROPERTY_NAME,

//                    RegistryConstants.RESOURCES_RESULT_TYPE);

//            registry.put(RegistryConstants.CONFIG_REGISTRY_BASE_PATH + RegistryConstants.QUERIES_COLLECTION_PATH + "/custom-queries", q1);
            Map parameters = new HashMap();
            parameters.put("query",sql1);
//            Resource result = registry.executeQuery(RegistryConstants.CONFIG_REGISTRY_BASE_PATH + RegistryConstants.QUERIES_COLLECTION_PATH + "/custom-queries", parameters);
            Resource result = registry.executeQuery(null, parameters);

            String[] paths = (String[]) result.getContent();

            for (String path : paths) {

                nodes.add(session.getNode(path));
            }
View Full Code Here


    if (loggerCollection != null) {
      String[] loggerResourcePaths = loggerCollection.getChildren();
      for (String loggerResourcePath : loggerResourcePaths) {
        String loggerName = loggerResourcePath.substring(LoggingConstants.LOGGERS.length());
        Logger logger = LogManager.getLogger(loggerName);
        Resource loggerResource = registryManager.getLogger(loggerName);
        if (loggerResource != null && logger != null) {
          logger.setLevel(Level.toLevel(loggerResource
              .getProperty(LoggingConstants.LoggerProperties.LOG_LEVEL)));
          logger.setAdditivity(Boolean.parseBoolean(loggerResource
              .getProperty(LoggingConstants.LoggerProperties.ADDITIVITY)));
        }
      }
    }

    // update the appender data according to data stored in database
    Collection appenderCollection = registryManager.getAppenders();
    if (appenderCollection != null) {
      String[] appenderResourcePaths = appenderCollection.getChildren();
      for (String appenderResourcePath : appenderResourcePaths) {
        String appenderName = appenderResourcePath.substring(LoggingConstants.APPENDERS
            .length());
        Appender appender = getAppenderFromSet(appenderSet, appenderName);
        Resource appenderResource = registryManager.getAppender(appenderName);
        if (appenderResource != null && appender != null) {
          if ((appender.getLayout() != null)
              && (appender.getLayout() instanceof PatternLayout)) {
            ((PatternLayout) appender.getLayout())
                .setConversionPattern(appenderResource
                    .getProperty(LoggingConstants.AppenderProperties.PATTERN));
          }
          if (appender instanceof FileAppender) {
            FileAppender fileAppender = ((FileAppender) appender);
            fileAppender.setFile(appenderResource
                .getProperty(LoggingConstants.AppenderProperties.LOG_FILE_NAME));
            fileAppender.activateOptions();
          }

          if (appender instanceof MemoryAppender) {
            MemoryAppender memoryAppender = (MemoryAppender) appender;
            memoryAppender.setCircularBuffer(new CircularBuffer(200));
            memoryAppender.activateOptions();
          }

          if (appender instanceof SyslogAppender) {
            SyslogAppender syslogAppender = (SyslogAppender) appender;
            syslogAppender.setSyslogHost(appenderResource
                .getProperty(LoggingConstants.AppenderProperties.SYS_LOG_HOST));
            syslogAppender.setFacility(appenderResource
                .getProperty(LoggingConstants.AppenderProperties.FACILITY));
          }

          if (appender instanceof AppenderSkeleton) {
            AppenderSkeleton appenderSkeleton = (AppenderSkeleton) appender;
            appenderSkeleton.setThreshold(Level.toLevel(appenderResource
                .getProperty(LoggingConstants.AppenderProperties.THRESHOLD)));
            appenderSkeleton.activateOptions();
          }
        }
      }
View Full Code Here

            for (String id : msgIds) {
                String messageResourcePath = SocialImplConstants.USER_REGISTRY_ROOT + userId +
                                             SocialImplConstants.MESSAGES_PATH +
                                             SocialImplConstants.SEPARATOR + msgCollectionId +
                                             SocialImplConstants.SEPARATOR + id;
                Resource messageResource;
                if (registry.resourceExists(messageResourcePath)) {
                    messageResource = registry.get(messageResourcePath);
                    //TODO: FilterOptions
                    messagesList.add(getPropertiesAddedMessageOjb(messageResource, fields));
View Full Code Here

                                       MessageCollection messageCollection, boolean isUpdate)
            throws RegistryException {
        String msgCollectionResourcePath = SocialImplConstants.USER_REGISTRY_ROOT + userId +
                                           SocialImplConstants.MESSAGES_PATH +
                                           SocialImplConstants.SEPARATOR + collectionId;
        Resource msgCollectionResource;

        registry = getRegistry();
        if (registry.resourceExists(msgCollectionResourcePath)) {
            msgCollectionResource = registry.get(msgCollectionResourcePath);
        } else {
View Full Code Here

            /*   /users/{userId}/messages/{msgCollectionId}/{messageId}  */
            messagePath = SocialImplConstants.USER_REGISTRY_ROOT + userId +
                          SocialImplConstants.MESSAGES_PATH + SocialImplConstants.SEPARATOR +
                          msgCollectionId + SocialImplConstants.SEPARATOR + messageId;
        }
        Resource messageResource;

        registry = getRegistry();
        if (registry.resourceExists(messagePath)) {
            messageResource = registry.get(messagePath);
        } else {
View Full Code Here

        }
    }

    public static WSDLValidationInfo[] validate(RequestContext requestContext,
                                              Definition wsdlDefinition) throws Exception {
        Resource resource = requestContext.getResource();
        Object resourceContent = resource.getContent();
        String sourceURL = requestContext.getSourceURL();
        InputStream inputStream = null;
        try {
            if (resourceContent instanceof byte[]) {
View Full Code Here

                log.error(msg);
                response.setStatus(400);
                return;
            }

            Resource resource = null;
            try {
                resource = registry.get(path);
            } catch (RegistryException e) {
                String msg = "Error retrieving the resource " + path + ". " + e.getMessage();
                log.error(msg, e);
                throw e;
            }

            if (resource instanceof Collection) {
                String msg = "Could not get the resource content. Path " + path + " refers to a collection.";
                log.error(msg);
                response.setStatus(501);
                return;
            }

            response.setDateHeader("Last-Modified", resource.getLastModified().getTime());

            if (resource.getMediaType() != null && resource.getMediaType().length() > 0) {
                response.setContentType(resource.getMediaType());
            } else {
                response.setHeader(
                        "Content-Disposition", "attachment; filename=" + RegistryUtils.getResourceName(path));
                response.setContentType("application/download");
            }

            InputStream contentStream = resource.getContentStream();
            if (contentStream != null) {

                try {
                    ServletOutputStream servletOutputStream = response.getOutputStream();
                    byte[] contentChunk = new byte[1024];
                    int byteCount;
                    while ((byteCount = contentStream.read(contentChunk)) != -1) {
                        servletOutputStream.write(contentChunk, 0, byteCount);
                    }

                    response.flushBuffer();
                    servletOutputStream.flush();

                } finally {
                    contentStream.close();
                }

            } else {
                Object content = resource.getContent();
                if (content != null) {

                    if (content instanceof byte[]) {
                        ServletOutputStream servletOutputStream = response.getOutputStream();
                        servletOutputStream.write((byte[])content);
                        response.flushBuffer();
                        servletOutputStream.flush();
                    } else {
                        PrintWriter writer = response.getWriter();
                        writer.write(content.toString());
                        writer.flush();
                    }
                }
            }

            resource.discard();

        } catch (RegistryException e) {
            String msg = "Failed to get resource content. " + e.getMessage();
            log.error(msg, e);
            response.setStatus(500);
View Full Code Here

    public static void saveTemplatePoliciesToRegistry(Registry registry) throws RegistryException,
                                                                                IOException {

        BundleContext bundleContext = ThrottleServiceComponent.getBundleContext();
        Resource serviceTemplate = registry.newResource();
        serviceTemplate.setContentStream(bundleContext
                .getBundle().getResource("template-service-policy.xml").openStream());
        registry.put(ThrottleComponentConstants.TEMPLATE_URI +
                     ThrottleComponentConstants.SERVICE_LEVEL, serviceTemplate);

        Resource moduleTemplate = registry.newResource();
        moduleTemplate.setContentStream(bundleContext
                .getBundle().getResource("template-module-policy.xml").openStream());
        registry.put(ThrottleComponentConstants.TEMPLATE_URI +
                     ThrottleComponentConstants.GLOBAL_LEVEL, moduleTemplate);

        Resource operationTemplate = registry.newResource();
        operationTemplate.setContentStream(bundleContext
                .getBundle().getResource("template-operation-policy.xml").openStream());
        registry.put(ThrottleComponentConstants.TEMPLATE_URI +
                     ThrottleComponentConstants.OPERATION_LEVEL, operationTemplate);

        Resource mediatorTemplate = registry.newResource();
        mediatorTemplate.setContentStream(bundleContext
                .getBundle().getResource("template-mediator-policy.xml").openStream());
        registry.put(ThrottleComponentConstants.TEMPLATE_URI +
                     ThrottleComponentConstants.MEDIATION_LEVEL, mediatorTemplate);
    }
View Full Code Here

                RemoteRegistry remoteConfigurationRegisitry = new RemoteRegistry(new URL(aspectConfigurationRegistryURL),
                    aspectConfigurationRegistryUsername,
                    aspectConfigurationRegistryPassword);

                Resource configurationResource = remoteConfigurationRegisitry.get(aspectConfigurationLocation);
                String xmlContent = new String((byte[])configurationResource.getContent());  
                OMElement checklistConfiguration = AXIOMUtil.stringToOM(xmlContent);
                Iterator stateElements = checklistConfiguration.getChildElements();
                                                          /*
                <lifecycle-configuration>
                    <state name="Created">
View Full Code Here

        resource.setProperty(stateProperty, states.get(0));
    }

    public void invoke(RequestContext context, String action) throws RegistryException {
        Resource resource = context.getResource();
        String currentState = resource.getProperty(stateProperty);
        int stateIndex = states.indexOf(currentState);
        if (stateIndex == -1) {
            throw new RegistryException("State '" + currentState + "' is not valid!");
        }

        String newState;
        if (PROMOTE.equals(action)) {
            if (stateIndex == states.size() - 1) {
                throw new RegistryException("Can't promote beyond end of configured lifecycle!");
            }

            // Make sure all conditions are met
            List<Condition> conditions = transitions.get(currentState);
            if (conditions != null) {
                for (Condition condition : conditions) {
                    if (!condition.isTrue(resource)) {
                        throw new RegistryException(
                                "Condition failed - " + condition.getDescription());
                    }
                }
            }
            newState = states.get(stateIndex + 1);
        } else if (DEMOTE.equals(action)) {
            if (stateIndex == 0) {
                throw new RegistryException("Can't demote beyond start of configured lifecycle!");
            }
            newState = states.get(stateIndex - 1);
        } else {
            throw new RegistryException("Invalid action '" + action + "'");
        }

        resource.setProperty(stateProperty, newState);
        context.getRepository().put(resource.getPath(), resource);
    }
View Full Code Here

TOP

Related Classes of org.wso2.carbon.registry.core.Resource

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.