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 */
017package org.apache.camel.component.extension.verifier;
018
019import org.apache.camel.component.extension.ComponentVerifierExtension;
020import org.apache.camel.component.extension.ComponentVerifierExtension.VerificationError.Attribute;
021import org.apache.camel.component.extension.ComponentVerifierExtension.VerificationError.Code;
022import org.apache.camel.component.extension.ComponentVerifierExtension.VerificationError.ExceptionAttribute;
023import org.apache.camel.component.extension.ComponentVerifierExtension.VerificationError.GroupAttribute;
024import org.apache.camel.component.extension.ComponentVerifierExtension.VerificationError.HttpAttribute;
025import org.apache.camel.component.extension.ComponentVerifierExtension.VerificationError.StandardCode;
026
027/**
028 * Package visible helper class holding implementation classes for
029 * constant like error code and attributes in {@link  ComponentVerifierExtension.VerificationError}
030 */
031public final class ComponentVerifierExtensionHelper {
032
033    /**
034     * Custom class for error codes
035     */
036    public static class ErrorCode implements Code {
037
038        private final String name;
039
040        public ErrorCode(String name) {
041            if (name == null) {
042                throw new IllegalArgumentException("Name of an error code must not be null");
043            }
044            this.name = name;
045        }
046
047        @Override
048        public String name() {
049            return name;
050        }
051
052        @Override
053        public boolean equals(Object o) {
054            if (this == o) {
055                return true;
056            }
057            if (!(o instanceof Code)) {
058                return false;
059            }
060
061            Code errorCode = (Code) o;
062
063            return name.equals(errorCode.name());
064        }
065
066        @Override
067        public int hashCode() {
068            return name.hashCode();
069        }
070
071        @Override
072        public String toString() {
073            return name();
074        }
075    }
076
077    public static class ErrorAttribute implements Attribute {
078
079        private final String name;
080
081        public ErrorAttribute(String name) {
082            if (name == null) {
083                throw new IllegalArgumentException("Name of an error attribute must not be null");
084            }
085            this.name = name;
086        }
087
088        @Override
089        public String name() {
090            return name;
091        }
092
093
094        @Override
095        public boolean equals(Object o) {
096            if (this == o) {
097                return true;
098            }
099            if (!(o instanceof Attribute)) {
100                return false;
101            }
102
103            Attribute that = (Attribute) o;
104
105            return name.equals(that.name());
106        }
107
108        @Override
109        public int hashCode() {
110            return name.hashCode();
111        }
112
113        @Override
114        public String toString() {
115            return name();
116        }
117    }
118
119    // ===========================================================================================================
120    // Helper classes for implementing the constants in ComponentVerifier:
121
122    public static class StandardErrorCode extends ErrorCode implements StandardCode {
123        public StandardErrorCode(String name) {
124            super(name);
125        }
126    }
127
128    public static class ExceptionErrorAttribute extends ErrorAttribute implements ExceptionAttribute {
129        public ExceptionErrorAttribute(String name) {
130            super(name);
131        }
132    }
133
134    public static class HttpErrorAttribute extends ErrorAttribute implements HttpAttribute {
135        public HttpErrorAttribute(String name) {
136            super(name);
137        }
138    }
139
140    public static class GroupErrorAttribute extends ErrorAttribute implements GroupAttribute {
141        public GroupErrorAttribute(String name) {
142            super(name);
143        }
144    }
145}