/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.yoko.bindings.corba;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.ExchangeImpl;
import org.apache.cxf.message.MessageImpl;
import org.apache.cxf.transport.MessageObserver;
import org.apache.schemas.yoko.bindings.corba.BindingType;
import org.omg.CORBA.ORB;
import org.omg.CORBA.ServerRequest;
import org.omg.PortableServer.DynamicImplementation;
import org.omg.PortableServer.POA;
public class CorbaDSIServant extends DynamicImplementation {
private static final Logger LOG = LogUtils.getL7dLogger(CorbaDSIServant.class);
private ORB orb;
private POA servantPOA;
private List<String> interfaces;
private MessageObserver incomingObserver;
private CorbaDestination destination;
public CorbaDSIServant() {
//Complete
}
public void init(ORB theOrb,
POA poa,
CorbaDestination dest,
MessageObserver observer) {
orb = theOrb;
servantPOA = poa;
destination = dest;
incomingObserver = observer;
// Get the list of interfaces that this servant will support
try {
BindingType bindType = destination.getBindingInfo().getExtensor(BindingType.class);
if (bindType == null) {
throw new CorbaBindingException("Unable to determine corba binding information");
}
List<String> bases = bindType.getBases();
interfaces = new ArrayList<String>();
interfaces.add(bindType.getRepositoryID());
for (Iterator<String> iter = bases.iterator(); iter.hasNext();) {
interfaces.add(iter.next());
}
} catch (java.lang.Exception ex) {
LOG.log(Level.SEVERE, "Couldn't initialize the corba DSI servant");
throw new CorbaBindingException(ex);
}
}
protected MessageObserver getObserver() {
return incomingObserver;
}
protected void setObserver(MessageObserver observer) {
incomingObserver = observer;
}
protected ORB getOrb() {
return orb;
}
public CorbaDestination getDestination() {
return destination;
}
public void invoke(ServerRequest request) throws CorbaBindingException {
MessageImpl msgImpl = new MessageImpl();
msgImpl.setDestination(getDestination());
Exchange exg = new ExchangeImpl();
exg.put(String.class, request.operation());
exg.put(ORB.class, getOrb());
exg.put(ServerRequest.class, request);
msgImpl.setExchange(exg);
// invokes the interceptors
getObserver().onMessage(msgImpl);
}
public String[] _all_interfaces(POA poa, byte[] objectId) {
return interfaces.toArray(new String[interfaces.size()]);
}
public POA _default_POA() {
return servantPOA;
}
}