org.wso2.carbon.registry.core.Resource.addProperty()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(16.2k)|赞(0)|评价(0)|浏览(102)

本文整理了Java中org.wso2.carbon.registry.core.Resource.addProperty方法的一些代码示例,展示了Resource.addProperty的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Resource.addProperty方法的具体详情如下:
包路径:org.wso2.carbon.registry.core.Resource
类名称:Resource
方法名:addProperty

Resource.addProperty介绍

暂无

代码示例

代码示例来源:origin: org.wso2.carbon.governance/org.wso2.carbon.governance.api

private boolean addDefaultAttributeIfNotExists(final GovernanceArtifact artifact, Resource resource, final String artifactName) throws GovernanceException {
  GovernanceArtifact[] governanceArtifacts = searchArtifactsByGroupingAttribute(artifact, mediaType, artifactName);
  if(governanceArtifacts != null && governanceArtifacts.length == 0) {
    resource.addProperty("default", "true");
    return true;
  }
  return false;
}

代码示例来源:origin: org.wso2.carbon.governance/org.wso2.carbon.mashup.javascript.hostobjects.registry

public static void jsFunction_addProperty(Context cx, Scriptable thisObj, Object[] arguments,
                     Function funObj) throws CarbonException {
  ResourceHostObject resourceHostObject = (ResourceHostObject) thisObj;
  if (arguments.length == 2) {
    if (arguments[0] instanceof String && arguments[1] instanceof String) {
      resourceHostObject.resource.addProperty((String) arguments[0], (String) arguments[1]);
    } else {
      throw new CarbonException("Invalid argument types for addProperty() method");
    }
  } else {
    throw new CarbonException("Invalid no. of arguments for addProperty() method");
  }
}

代码示例来源:origin: org.wso2.carbon.registry/org.wso2.carbon.registry.extensions

/**
   * This will validate the given schema against the w3c.XMLSchema.
   *
   * @param xsdContent : Input stream representing XSD content
   *
   * @throws org.wso2.carbon.registry.core.exceptions.RegistryException
   *          : If there is a problem in the XSD then that will throw as the exception
   */
  public void validate(InputStream xsdContent, Resource resource) throws RegistryException {
    try {
      XMLReader reader = XMLReaderFactory.createXMLReader();
      InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(XMLSCHEMA_XSD_LOCATION);
      Source scoure = new SAXSource(reader, new InputSource(in));
      // create a SchemaFactory capable of understanding WXS schemas
      SchemaFactory factory = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);
      // load a WXS schema, represented by a Schema instance
      Source schemaFile = new StreamSource(xsdContent);
      Schema schema = factory.newSchema(schemaFile);
      // create a Validator instance, which can be used to validate an instance document
      Validator validator = schema.newValidator();
      // validate the DOM tree
      validator.validate(scoure);
      resource.setProperty(XSD_STATUS, XSD_VALID);
    } catch (Exception e) {
      resource.setProperty(XSD_STATUS, XSD_IN_VALID);
      resource.addProperty(XSD_VALIDATION_ERROR, e.getMessage());
      throw new RegistryException(e.getMessage());
    }
  }
}

代码示例来源:origin: org.wso2.carbon.identity.governance/org.wso2.carbon.identity.recovery

/**
 * Create registry resource from a challenge question model object.
 *
 * @param question
 * @return
 * @throws RegistryException
 */
private Resource createRegistryResource(ChallengeQuestion question) throws RegistryException, UnsupportedEncodingException {
  byte[] questionText = question.getQuestion().getBytes("UTF-8");
  String questionSetId = question.getQuestionSetId();
  String questionId = question.getQuestionId();
  String locale = question.getLocale();
  Resource resource = new ResourceImpl();
  resource.setContent(questionText);
  resource.addProperty(IdentityRecoveryConstants.Questions.CHALLENGE_QUESTION_SET_ID, questionSetId);
  resource.addProperty(IdentityRecoveryConstants.Questions.CHALLENGE_QUESTION_ID, questionId);
  resource.addProperty(IdentityRecoveryConstants.Questions.CHALLENGE_QUESTION_LOCALE, locale); // added locale
  resource.setMediaType(RegistryConstants.TAG_MEDIA_TYPE);
  return resource;
}

代码示例来源:origin: org.wso2.carbon.identity/org.wso2.carbon.security.mgt

public void addTrustStore(byte[] content, String filename, String password, String provider, String type) throws SecurityConfigException {
  if (filename == null) {
    throw new SecurityConfigException("Key Store name can't be null");
  }
  try {
    if (KeyStoreUtil.isPrimaryStore(filename)) {
      throw new SecurityConfigException("Key store " + filename + " already available");
    }
    String path = SecurityConstants.KEY_STORES + "/" + filename;
    if (registry.resourceExists(path)) {
      throw new SecurityConfigException("Key store " + filename + " already available");
    }
    KeyStore keyStore = KeyStore.getInstance(type);
    keyStore.load(new ByteArrayInputStream(content), password.toCharArray());
    CryptoUtil cryptoUtil = CryptoUtil.getDefaultCryptoUtil();
    Resource resource = registry.newResource();
    resource.addProperty(SecurityConstants.PROP_PASSWORD, cryptoUtil
        .encryptAndBase64Encode(password.getBytes()));
    resource.addProperty(SecurityConstants.PROP_PROVIDER, provider);
    resource.addProperty(SecurityConstants.PROP_TYPE, type);
    resource.setContent(content);
    registry.put(path, resource);
  } catch (SecurityConfigException e) {
    throw e;
  } catch (Exception e) {
    String msg = "Error when adding a trustStore";
    log.error(msg, e);
    throw new SecurityConfigException(msg, e);
  }
}

代码示例来源:origin: wso2/carbon-identity-framework

resource.removeProperty(IdentityRegistryResources.OPENID_PATTERN);
resource.addProperty(IdentityRegistryResources.SUB_DOMAIN, opAdmin.getSubDomain());
resource.addProperty(IdentityRegistryResources.OPENID_PATTERN, opAdmin
    .getTenantOpenIDPattern());
registry.put(path, resource);

代码示例来源:origin: org.wso2.carbon.governance/org.wso2.carbon.governance.api

private void addDefaultAttributeToAssociations(final GovernanceArtifact artifact) throws GovernanceException {
  try {
    if(mediaType.equals("application/vnd.wso2-soap-service+xml")) {
      Association[] associations = registry.getAllAssociations(artifact.getPath());
      for(Association association : associations) {
        String destinationPath = association.getDestinationPath();
        if(destinationPath.contains("wsdl")) {
          String[] subPaths = destinationPath.split("/");
          final String artifactName = subPaths[subPaths.length - 1];
          GovernanceArtifact[] governanceArtifacts = searchArtifactsByGroupingAttribute(artifact, CommonConstants.WSDL_MEDIA_TYPE, artifactName);
          if(governanceArtifacts != null && governanceArtifacts.length == 0) {
            Resource wsdlResource = registry.get(destinationPath);
            wsdlResource.addProperty("default", "true");
            registry.put(destinationPath, wsdlResource);
          }
        }
      }
    }
  } catch(RegistryException ex) {
    log.error("An error occurred while retrieving association of the resource " + artifact.getPath(), ex);
  }
}

代码示例来源:origin: org.wso2.carbon.registry/org.wso2.carbon.registry.indexing

private void defineQueries(String queryPath, String queryContent) throws RegistryException {
  UserRegistry registry =
      (UserRegistry) Utils.getRegistry();
  Resource q1 = registry.newResource();
  q1.setContent(queryContent);
  q1.setMediaType(RegistryConstants.SQL_QUERY_MEDIA_TYPE);
  q1.addProperty(RegistryConstants.RESULT_TYPE_PROPERTY_NAME,
      RegistryConstants.RESOURCES_RESULT_TYPE);
  registry.put(queryPath, q1);
}

代码示例来源:origin: org.wso2.carbon.appmgt/org.wso2.carbon.appmgt.impl

/**
 * Persist WebApp Status into a property of WebApp Registry resource
 *
 * @param artifactId WebApp artifact ID
 * @param apiStatus Current status of the WebApp
 * @throws org.wso2.carbon.appmgt.api.AppManagementException on error
 */
private void saveAPIStatus(String artifactId, String apiStatus) throws AppManagementException {
  try{
    Resource resource = registry.get(artifactId);
    if (resource != null) {
      String propValue = resource.getProperty(AppMConstants.API_STATUS);
      if (propValue == null) {
        resource.addProperty(AppMConstants.API_STATUS, apiStatus);
      } else {
        resource.setProperty(AppMConstants.API_STATUS, apiStatus);
      }
      registry.put(artifactId,resource);
    }
  }catch (RegistryException e) {
    handleException("Error while adding WebApp", e);
  }
}

代码示例来源:origin: org.wso2.carbon.registry/org.wso2.carbon.registry.properties

/**
 * Method to add a property, if there already exist a property with the same name, this
 * will add the value to the existing property name. (So please remove the old property with
 * the same name before calling this method).
 *
 * @param path path of the resource.
 * @param name property name.
 * @param value property value.
 *
 * @throws RegistryException throws if there is an error.
 */
public void setProperty(String path, String name, String value) throws RegistryException {
  if(name != null && name.startsWith("registry.")) {
    throw new RegistryException("Property cannot start with the \"registry.\" prefix. " +
        "Property name " + name + ". Resource path = " + path);
  }
  UserRegistry registry = (UserRegistry) getRootRegistry();
  if (RegistryUtils.isRegistryReadOnly(registry.getRegistryContext())) {
    return;
  }
  Resource resource = registry.get(path);
  if(resource.getProperties().keySet().contains(name)) {
    throw new RegistryException("Cannot duplicate property name. Please choose a different name. " +
        "Property name " + name + ". Resource path = " + path);
  }
  resource.addProperty(name, value);
  registry.put(resource.getPath(), resource);
  resource.discard();
}

代码示例来源:origin: org.wso2.carbon.identity/org.wso2.carbon.identity.core

/**
 * @param parameterDO
 * @throws IdentityException
 */
public void createOrUpdateParameter(ParameterDO parameterDO) throws IdentityException {
  String path = null;
  Resource resource = null;
  if (log.isDebugEnabled()) {
    log.debug("Creating or updating parameter");
  }
  try {
    path = IdentityRegistryResources.CARD_ISSUER;
    if (registry.resourceExists(path)) {
      resource = registry.get(path);
    } else {
      resource = registry.newResource();
    }
    if (resource.getProperty(parameterDO.getName()) != null) {
      resource.removeProperty(parameterDO.getName());
    }
    resource.addProperty(parameterDO.getName(), parameterDO.getValue());
    registry.put(path, resource);
  } catch (RegistryException e) {
    log.error("Error while creating or updating parameter", e);
    throw IdentityException.error("Error while creating or updating parameter", e);
  }
}

代码示例来源:origin: org.wso2.carbon.identity.framework/org.wso2.carbon.identity.core

/**
 * @param parameterDO
 * @throws IdentityException
 */
public void createOrUpdateParameter(ParameterDO parameterDO) throws IdentityException {
  String path = null;
  Resource resource = null;
  if (log.isDebugEnabled()) {
    log.debug("Creating or updating parameter");
  }
  try {
    path = IdentityRegistryResources.CARD_ISSUER;
    if (registry.resourceExists(path)) {
      resource = registry.get(path);
    } else {
      resource = registry.newResource();
    }
    if (resource.getProperty(parameterDO.getName()) != null) {
      resource.removeProperty(parameterDO.getName());
    }
    resource.addProperty(parameterDO.getName(), parameterDO.getValue());
    registry.put(path, resource);
  } catch (RegistryException e) {
    log.error("Error while creating or updating parameter", e);
    throw IdentityException.error("Error while creating or updating parameter", e);
  }
}

代码示例来源:origin: wso2/carbon-identity-framework

/**
 * @param parameterDO
 * @throws IdentityException
 */
public void createOrUpdateParameter(ParameterDO parameterDO) throws IdentityException {
  String path = null;
  Resource resource = null;
  if (log.isDebugEnabled()) {
    log.debug("Creating or updating parameter");
  }
  try {
    path = IdentityRegistryResources.CARD_ISSUER;
    if (registry.resourceExists(path)) {
      resource = registry.get(path);
    } else {
      resource = registry.newResource();
    }
    if (resource.getProperty(parameterDO.getName()) != null) {
      resource.removeProperty(parameterDO.getName());
    }
    resource.addProperty(parameterDO.getName(), parameterDO.getValue());
    registry.put(path, resource);
  } catch (RegistryException e) {
    log.error("Error while creating or updating parameter", e);
    throw IdentityException.error("Error while creating or updating parameter", e);
  }
}

代码示例来源:origin: org.wso2.carbon.identity/org.wso2.carbon.identity.mgt

resource.addProperty("question", questionDTOs[i].getQuestion());
resource.addProperty("isPromoteQuestion", String.valueOf(questionDTOs[i].isPromoteQuestion()));
resource.addProperty("questionSetId", questionDTOs[i].getQuestionSetId());
registry.put(IdentityMgtConstants.IDENTITY_MANAGEMENT_QUESTIONS +
    RegistryConstants.PATH_SEPARATOR + "question" + i +

代码示例来源:origin: org.apache.stratos/org.apache.stratos.adc.mgt

/**
*
*/
public void addDomainMappingToRegistry(String hostName, String actualHost)
    throws ADCException, RegistryException, DomainMappingExistsException {
  try {
    registry.beginTransaction();
    Resource hostResource = registry.newResource();
    hostResource.addProperty(CartridgeConstants.DomainMappingInfo.ACTUAL_HOST, actualHost);
    if (!registry.resourceExists(CartridgeConstants.DomainMappingInfo.HOSTINFO +
                      hostName)) {
      registry.put(CartridgeConstants.DomainMappingInfo.HOSTINFO + hostName,
                hostResource);
    } else {
      registry.rollbackTransaction();
      String msg = "Requested domain is already taken!";
      log.error(msg);
      throw new DomainMappingExistsException(msg, hostName);
    }
    registry.commitTransaction();
  } catch (RegistryException e) {
    registry.rollbackTransaction();
    throw e; 
  }
}

代码示例来源:origin: org.wso2.carbon.identity/org.wso2.carbon.security.mgt

private void persistTrustedService(String groupName, String serviceName, String trustedService,
                  String certAlias) throws SecurityConfigException {
  Registry registry;
  String resourcePath;
  Resource resource;
  try {
    resourcePath = RegistryResources.SERVICE_GROUPS + groupName
        + RegistryResources.SERVICES + serviceName + "/trustedServices";
    registry = getConfigSystemRegistry(); //TODO: Multitenancy
    if (registry != null) {
      if (registry.resourceExists(resourcePath)) {
        resource = registry.get(resourcePath);
      } else {
        resource = registry.newResource();
      }
      if (resource.getProperty(trustedService) != null) {
        resource.removeProperty(trustedService);
      }
      resource.addProperty(trustedService, certAlias);
      registry.put(resourcePath, resource);
    }
  } catch (Exception e) {
    log.error("Error occured while adding trusted service for STS", e);
    throw new SecurityConfigException("Error occured while adding trusted service for STS",
        e);
  }
}

代码示例来源:origin: org.wso2.carbon.identity.framework/org.wso2.carbon.security.mgt

private void persistTrustedService(String groupName, String serviceName, String trustedService,
                  String certAlias) throws SecurityConfigException {
  Registry registry;
  String resourcePath;
  Resource resource;
  try {
    resourcePath = RegistryResources.SERVICE_GROUPS + groupName
        + RegistryResources.SERVICES + serviceName + "/trustedServices";
    registry = getConfigSystemRegistry(); //TODO: Multitenancy
    if (registry != null) {
      if (registry.resourceExists(resourcePath)) {
        resource = registry.get(resourcePath);
      } else {
        resource = registry.newResource();
      }
      if (resource.getProperty(trustedService) != null) {
        resource.removeProperty(trustedService);
      }
      resource.addProperty(trustedService, certAlias);
      registry.put(resourcePath, resource);
    }
  } catch (Exception e) {
    log.error("Error occured while adding trusted service for STS", e);
    throw new SecurityConfigException("Error occured while adding trusted service for STS",
        e);
  }
}

代码示例来源:origin: wso2/carbon-identity-framework

private void persistTrustedService(String groupName, String serviceName, String trustedService,
                  String certAlias) throws SecurityConfigException {
  Registry registry;
  String resourcePath;
  Resource resource;
  try {
    resourcePath = RegistryResources.SERVICE_GROUPS + groupName
        + RegistryResources.SERVICES + serviceName + "/trustedServices";
    registry = getConfigSystemRegistry(); //TODO: Multitenancy
    if (registry != null) {
      if (registry.resourceExists(resourcePath)) {
        resource = registry.get(resourcePath);
      } else {
        resource = registry.newResource();
      }
      if (resource.getProperty(trustedService) != null) {
        resource.removeProperty(trustedService);
      }
      resource.addProperty(trustedService, certAlias);
      registry.put(resourcePath, resource);
    }
  } catch (Exception e) {
    log.error("Error occured while adding trusted service for STS", e);
    throw new SecurityConfigException("Error occured while adding trusted service for STS",
        e);
  }
}

代码示例来源:origin: org.wso2.carbon.registry/org.wso2.carbon.registry.extensions

@Override
public void createLink(RequestContext requestContext) throws RegistryException {
  String symlinkPath = requestContext.getResourcePath().getPath();
  String targetResourcePath = requestContext.getTargetPath();
  if (requestContext.getRegistry().resourceExists(targetResourcePath)) {
    Resource r = requestContext.getRegistry().get(targetResourcePath);
    r.addProperty("registry.resource.symlink.path", symlinkPath);
    requestContext.getRegistry().put(targetResourcePath, r);
  }
}

代码示例来源:origin: org.wso2.carbon/org.wso2.carbon.eventing.impl

/**
 * Update the topic index by holding the thread
 *
 * @param mode  Insert | Delete
 * @param id    subscription id
 * @param topic topic name
 * @throws Exception RegistryException
 */
private synchronized void updateTopicIndex(boolean mode, String id, String topic)
    throws RegistryException {
  if (mode) {
    resTopicIndex = registry.get(getTopicIndexPath());
    resTopicIndex.addProperty(id, topic + "/" + SUBSCRIPTION_COLLECTION_NAME);
    registry.put(getTopicIndexPath(), resTopicIndex);
  } else {
    resTopicIndex = registry.get(getTopicIndexPath());
    resTopicIndex.removeProperty(id);
    registry.put(getTopicIndexPath(), resTopicIndex);
  }
}

相关文章