本文整理汇总了Java中org.alfresco.service.cmr.dictionary.ConstraintException类的典型用法代码示例。如果您正苦于以下问题:Java ConstraintException类的具体用法?Java ConstraintException怎么用?Java ConstraintException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConstraintException类属于org.alfresco.service.cmr.dictionary包,在下文中一共展示了ConstraintException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: evaluateSingleValue
import org.alfresco.service.cmr.dictionary.ConstraintException; //导入依赖的package包/类
@Override
protected void evaluateSingleValue(Object value)
{
// ensure that the value can be converted to a String
String checkValue = null;
try
{
checkValue = DefaultTypeConverter.INSTANCE.convert(String.class, value);
}
catch (TypeConversionException e)
{
throw new ConstraintException(ERR_NON_STRING, value);
}
AuthorityType type = AuthorityType.getAuthorityType(checkValue);
if((type != AuthorityType.GROUP) && (type != AuthorityType.ROLE))
{
throw new ConstraintException(ERR_INVALID_AUTHORITY_NAME, value, type);
}
}
示例2: evaluateSingleValue
import org.alfresco.service.cmr.dictionary.ConstraintException; //导入依赖的package包/类
@Override
protected void evaluateSingleValue(Object value)
{
// ensure that the value can be converted to a String
String checkValue = null;
try
{
checkValue = DefaultTypeConverter.INSTANCE.convert(String.class, value);
}
catch (TypeConversionException e)
{
throw new ConstraintException(ERR_NON_STRING, value);
}
AuthorityType type = AuthorityType.getAuthorityType(checkValue);
if((type != AuthorityType.USER) && (type != AuthorityType.GUEST))
{
throw new ConstraintException(ERR_INVALID_USERNAME, value, type);
}
}
示例3: getRawAllowedValues
import org.alfresco.service.cmr.dictionary.ConstraintException; //导入依赖的package包/类
@Override
public List<String> getRawAllowedValues()
{
List<String> result = null;
try
{
result = loadClasspathTemplates(templatesParentClasspath,
"json");
}
catch (IOException e)
{
throw new ConstraintException("ListTemplateTypesConstraints",
e);
}
List<String> repositoryTemplates = loadRepositoryTemplates(templatesParentRepositoryPath);
result.addAll(repositoryTemplates);
if (result.size() == 0)
{
result.add(NULL_SYSTEM_TEMPLATE);
}
super.setAllowedValues(result);
return result;
}
示例4: evaluateSingleValue
import org.alfresco.service.cmr.dictionary.ConstraintException; //导入依赖的package包/类
protected void evaluateSingleValue(Object value)
{
// ensure that the value can be converted to a String
String checkValue = null;
try
{
checkValue = DefaultTypeConverter.INSTANCE.convert(String.class, value);
}
catch (TypeConversionException e)
{
throw new ConstraintException(ERR_NON_STRING, value);
}
// Check that the value length
int length = checkValue.length();
if (length > maxLength || length < minLength)
{
if (length > 20)
{
checkValue = checkValue.substring(0, 17) + "...";
}
throw new ConstraintException(ERR_INVALID_LENGTH, checkValue, minLength, maxLength);
}
}
示例5: evaluateSingleValue
import org.alfresco.service.cmr.dictionary.ConstraintException; //导入依赖的package包/类
protected void evaluateSingleValue(Object value)
{
// ensure that the value can be converted to a double
double checkValue = Double.NaN;
try
{
checkValue = DefaultTypeConverter.INSTANCE.doubleValue(value);
}
catch (NumberFormatException e)
{
throw new ConstraintException(ERR_NON_NUMERIC, value);
}
// Infinity and NaN cannot match
if (Double.isInfinite(checkValue) || Double.isNaN(checkValue))
{
throw new ConstraintException(ERR_OUT_OF_RANGE, checkValue, minValue, maxValue);
}
// Check that the value is in range
if (checkValue > maxValue || checkValue < minValue)
{
throw new ConstraintException(ERR_OUT_OF_RANGE, checkValue, minValue, maxValue);
}
}
示例6: evaluateSingleValue
import org.alfresco.service.cmr.dictionary.ConstraintException; //导入依赖的package包/类
protected void evaluateSingleValue(Object value)
{
// convert the value to a String
String valueStr = DefaultTypeConverter.INSTANCE.convert(String.class, value);
Matcher matcher = patternMatcher.matcher(valueStr);
boolean matches = matcher.matches();
if (matches != requiresMatch)
{
// Look for a message corresponding to this constraint name
String messageId = CONSTRAINT_REGEX_MSG_PREFIX + getShortName();
if (I18NUtil.getMessage(messageId, value) != null)
{
throw new ConstraintException(messageId, value);
}
// Otherwise, fall back to a generic (but unfriendly) message
else if (requiresMatch)
{
throw new ConstraintException(RegexConstraint.CONSTRAINT_REGEX_NO_MATCH, value, expression);
}
else
{
throw new ConstraintException(RegexConstraint.CONSTRAINT_REGEX_MATCH, value, expression);
}
}
}
示例7: evaluateSingleValue
import org.alfresco.service.cmr.dictionary.ConstraintException; //导入依赖的package包/类
/**
* Fails on everything but String values, which pass.
* Null values cause runtime exceptions and all other failures are by
* DictionaryException.
*/
@Override
protected void evaluateSingleValue(Object value)
{
if (value == null)
{
throw new NullPointerException("Null value in dummy test");
}
else if (value instanceof String)
{
tested.add(value);
}
else
{
throw new ConstraintException("Non-String value");
}
}
示例8: evaluateSingleValue
import org.alfresco.service.cmr.dictionary.ConstraintException; //导入依赖的package包/类
/**
* @see org.alfresco.repo.dictionary.constraint.AbstractConstraint#evaluateSingleValue(java.lang.Object)
*/
@Override
protected void evaluateSingleValue(Object value)
{
// convert the value to a String
String valueStr = null;
try
{
valueStr = DefaultTypeConverter.INSTANCE.convert(String.class, value);
}
catch (TypeConversionException e)
{
throw new ConstraintException(ERR_NON_STRING, value);
}
// check that the value is in the set of allowed values
if (caseSensitive)
{
if (!allowedValuesSet.contains(valueStr))
{
throw new ConstraintException(ERR_INVALID_VALUE, value);
}
}
else
{
if (!allowedValuesUpperSet.contains(valueStr.toUpperCase()))
{
throw new ConstraintException(ERR_INVALID_VALUE, value);
}
}
}
示例9: testCollections
import org.alfresco.service.cmr.dictionary.ConstraintException; //导入依赖的package包/类
/**
* ensure that the default handling of checks on collections will work
*/
public void testCollections() throws Exception
{
DummyConstraint constraint = new DummyConstraint();
constraint.initialize();
assertEquals("DummyConstraint type should be 'org.alfresco.repo.dictionary.constraint.ConstraintsTest$DummyConstraint'",
"org.alfresco.repo.dictionary.constraint.ConstraintsTest$DummyConstraint",
constraint.getType());
assertNotNull("DummyConstraint should not have empty parameters", constraint.getParameters());
assertEquals("DummyConstraint should not have empty parameters", 0, constraint.getParameters().size());
List<Object> dummyObjects = new ArrayList<Object>(3);
dummyObjects.add("ABC"); // correct
dummyObjects.add("DEF"); // correct
dummyObjects.add(this); // NO
try
{
constraint.evaluate(dummyObjects);
fail("Failed to detected constraint violation in collection");
}
catch (ConstraintException e)
{
// expected
checkI18NofExceptionMessage(e);
}
// check that the two strings were properly dealt with
assertEquals("String values not checked", 2, constraint.tested.size());
}
示例10: evaluate
import org.alfresco.service.cmr.dictionary.ConstraintException; //导入依赖的package包/类
private void evaluate(Constraint constraint, Object value, boolean expectFailure) throws Exception
{
try
{
constraint.evaluate(value);
if (expectFailure)
{
// it should have failed
fail("Failure did not occur: \n" +
" constraint: " + constraint + "\n" +
" value: " + value);
}
}
catch (ConstraintException e)
{
// check if we expect an error
if (expectFailure)
{
// expected - check message I18N
checkI18NofExceptionMessage(e);
}
else
{
// didn't expect it
throw e;
}
}
}
示例11: evaluateSingleValue
import org.alfresco.service.cmr.dictionary.ConstraintException; //导入依赖的package包/类
@Override
protected void evaluateSingleValue(Object value)
{
String checkValue = DefaultTypeConverter.INSTANCE.convert(String.class, value);
if (checkValue.contains("#"))
{
throw new ConstraintException("The value must not contain '#'");
}
}
示例12: evaluateSingleValue
import org.alfresco.service.cmr.dictionary.ConstraintException; //导入依赖的package包/类
@Override
protected void evaluateSingleValue(Object value)
{
// convert the value to a String
String valueStr = null;
try
{
valueStr = DefaultTypeConverter.INSTANCE.convert(String.class, value);
}
catch (TypeConversionException e)
{
throw new ConstraintException(RMConstraintMessageKeys.ERR_NON_STRING, value, e);
}
// check that the value is in the set of allowed values
if (isCaseSensitive())
{
if (!getAllowedValues().contains(valueStr))
{
throw new ConstraintException(RMConstraintMessageKeys.ERR_INVALID_VALUE, value);
}
}
else
{
if (!getAllowedValuesUpper().contains(valueStr.toUpperCase()))
{
throw new ConstraintException(RMConstraintMessageKeys.ERR_INVALID_VALUE, value);
}
}
}
示例13: getDocument
import org.alfresco.service.cmr.dictionary.ConstraintException; //导入依赖的package包/类
public void getDocument(NodeRef nodeRef)
throws GoogleDocsAuthenticationException,
GoogleDocsServiceException,
GoogleDocsRefreshTokenException,
IOException,
ConstraintException
{
// TODO Wrap with try for null
String resourceID = nodeService.getProperty(nodeRef, GoogleDocsModel.PROP_RESOURCE_ID).toString();
getDocument(nodeRef, resourceID);
}
示例14: getSpreadSheet
import org.alfresco.service.cmr.dictionary.ConstraintException; //导入依赖的package包/类
public void getSpreadSheet(NodeRef nodeRef)
throws GoogleDocsAuthenticationException,
GoogleDocsServiceException,
GoogleDocsRefreshTokenException,
IOException,
ConstraintException
{
// TODO Wrap with try for null
String resourceID = nodeService.getProperty(nodeRef, GoogleDocsModel.PROP_RESOURCE_ID).toString();
getSpreadSheet(nodeRef, resourceID);
}
示例15: getPresentation
import org.alfresco.service.cmr.dictionary.ConstraintException; //导入依赖的package包/类
public void getPresentation(NodeRef nodeRef)
throws GoogleDocsAuthenticationException,
GoogleDocsServiceException,
GoogleDocsRefreshTokenException,
IOException,
ConstraintException
{
// TODO Wrap with try for null
String resourceID = nodeService.getProperty(nodeRef, GoogleDocsModel.PROP_RESOURCE_ID).toString();
getPresentation(nodeRef, resourceID);
}