001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.config;
017:
018: import java.util.List;
019: import java.util.ArrayList;
020:
021: /**
022: * @version $Rev: 602704 $ $Date: 2007-12-09 09:58:22 -0800 $
023: */
024: public class ValidationContext implements ValidationResults {
025: private final List<ValidationFailure> failures = new ArrayList<ValidationFailure>();
026: private final List<ValidationWarning> warnings = new ArrayList<ValidationWarning>();
027: private final List<ValidationError> errors = new ArrayList<ValidationError>();
028:
029: private final String jarPath;
030: private final String moduleType;
031:
032: public ValidationContext(
033: Class<? extends DeploymentModule> moduleType, String jarPath) {
034: this .moduleType = moduleType.getSimpleName();
035: this .jarPath = jarPath;
036: }
037:
038: public void fail(String component, String key, Object... details) {
039: ValidationFailure failure = new ValidationFailure(key);
040: failure.setDetails(details);
041: failure.setComponentName(component);
042:
043: addFailure(failure);
044: }
045:
046: public void warn(String component, String key, Object... details) {
047: ValidationWarning warning = new ValidationWarning(key);
048: warning.setDetails(details);
049: warning.setComponentName(component);
050:
051: addWarning(warning);
052: }
053:
054: public void error(String component, String key, Object... details) {
055: ValidationError error = new ValidationError(key);
056: error.setDetails(details);
057: error.setComponentName(component);
058:
059: addError(error);
060: }
061:
062: public void addWarning(ValidationWarning warning) {
063: warnings.add(warning);
064: }
065:
066: public void addFailure(ValidationFailure failure) {
067: failures.add(failure);
068: }
069:
070: public void addError(ValidationError error) {
071: errors.add(error);
072: }
073:
074: public ValidationFailure[] getFailures() {
075: return failures.toArray(new ValidationFailure[failures.size()]);
076: }
077:
078: public ValidationWarning[] getWarnings() {
079: return warnings.toArray(new ValidationWarning[warnings.size()]);
080: }
081:
082: public ValidationError[] getErrors() {
083: return errors.toArray(new ValidationError[errors.size()]);
084: }
085:
086: public boolean hasWarnings() {
087: return warnings.size() > 0;
088: }
089:
090: public boolean hasFailures() {
091: return failures.size() > 0;
092: }
093:
094: public boolean hasErrors() {
095: return errors.size() > 0;
096: }
097:
098: public String getJarPath() {
099: return jarPath;
100: }
101:
102: public String getModuleType() {
103: return moduleType;
104: }
105:
106: }
|