01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.servicemix.common.xbean;
18:
19: import java.util.Arrays;
20:
21: import org.apache.servicemix.common.Endpoint;
22: import org.apache.servicemix.common.ServiceMixComponent;
23:
24: import javax.jbi.management.DeploymentException;
25:
26: /**
27: * A useful XBean deployer which check that the endpoints inherit one of
28: * the given allowed endpoint classes.
29: *
30: * @author gnodet
31: */
32: public class BaseXBeanDeployer extends AbstractXBeanDeployer {
33:
34: private final Class[] endpointClasses;
35:
36: public BaseXBeanDeployer(ServiceMixComponent component) {
37: this (component, new Class[0]);
38: }
39:
40: public BaseXBeanDeployer(ServiceMixComponent component,
41: Class endpointClass) {
42: this (component, new Class[] { endpointClass });
43: }
44:
45: public BaseXBeanDeployer(ServiceMixComponent component,
46: Class[] endpointClasses) {
47: super (component);
48: if (endpointClasses == null) {
49: throw new NullPointerException(
50: "endpointClasses must be non null");
51: }
52: this .endpointClasses = endpointClasses;
53: }
54:
55: protected void validate(Endpoint endpoint)
56: throws DeploymentException {
57: for (int i = 0; i < endpointClasses.length; i++) {
58: if (endpointClasses[i].isInstance(endpoint)) {
59: super .validate(endpoint);
60: return;
61: }
62: }
63: throw new DeploymentException("Endpoint is not of type: "
64: + Arrays.asList(endpointClasses) + " but is of type: "
65: + endpoint.getClass());
66: }
67:
68: }
|