001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.binding.object;
019:
020: import javax.annotation.PostConstruct;
021: import javax.xml.namespace.QName;
022:
023: import org.apache.cxf.Bus;
024: import org.apache.cxf.binding.AbstractBindingFactory;
025: import org.apache.cxf.binding.Binding;
026: import org.apache.cxf.endpoint.ServerLifeCycleManager;
027: import org.apache.cxf.service.model.BindingInfo;
028: import org.apache.cxf.service.model.BindingOperationInfo;
029: import org.apache.cxf.service.model.OperationInfo;
030: import org.apache.cxf.service.model.ServiceInfo;
031:
032: public class ObjectBindingFactory extends AbstractBindingFactory {
033: public static final String BINDING_ID = "http://cxf.apache.org/binding/object";
034: public static final String RUN_NON_LOGICAL = "objectBinding.stopAfterLogical";
035:
036: private boolean autoRegisterLocalEndpoint;
037: private boolean initialized = true;
038: private LocalServerListener listener;
039:
040: @PostConstruct
041: public void initialize() {
042: if (autoRegisterLocalEndpoint) {
043: Bus bus = getBus();
044: ServerLifeCycleManager manager = bus
045: .getExtension(ServerLifeCycleManager.class);
046: if (manager != null) {
047: listener = new LocalServerListener(bus, this );
048: manager.registerListener(listener);
049: }
050: }
051: initialized = true;
052: }
053:
054: public Binding createBinding(BindingInfo bi) {
055: ObjectBinding binding = new ObjectBinding(bi);
056: binding.getOutInterceptors().add(
057: new ObjectDispatchOutInterceptor());
058: binding.getInInterceptors().add(
059: new ObjectDispatchInInterceptor());
060:
061: return binding;
062: }
063:
064: public BindingInfo createBindingInfo(ServiceInfo si,
065: String bindingid, Object config) {
066: BindingInfo info = super .createBindingInfo(si, bindingid,
067: config);
068:
069: if (config instanceof ObjectBindingConfiguration) {
070: ObjectBindingConfiguration c = (ObjectBindingConfiguration) config;
071:
072: info.setProperty(RUN_NON_LOGICAL, c
073: .isNonLogicalPhasesEnabled());
074: }
075:
076: info.setName(new QName(si.getName().getNamespaceURI(), si
077: .getName().getLocalPart()
078: + "ObjectBinding"));
079:
080: for (OperationInfo o : si.getInterface().getOperations()) {
081: BindingOperationInfo bop = info.buildOperation(o.getName(),
082: o.getInputName(), o.getOutputName());
083: info.addOperation(bop);
084: }
085: return info;
086: }
087:
088: public boolean isAutoRegisterLocalEndpoint() {
089: return autoRegisterLocalEndpoint;
090: }
091:
092: public void setAutoRegisterLocalEndpoint(
093: boolean autoRegisterLocalEndpoint) {
094: this .autoRegisterLocalEndpoint = autoRegisterLocalEndpoint;
095:
096: if (initialized && listener == null) {
097: // register the lifecycle listener
098: initialize();
099: }
100: }
101:
102: }
|