001: /*
002: * JacORB - a free Java ORB
003: *
004: * Copyright (C) 1999-2004 Gerald Brose
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Library General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Library General Public License for more details.
015: *
016: * You should have received a copy of the GNU Library General Public
017: * License along with this library; if not, write to the Free
018: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
019: *
020: */
021: package org.jacorb.orb.etf;
022:
023: import org.apache.avalon.framework.configuration.*;
024:
025: import org.omg.ETF.*;
026: import org.omg.IOP.*;
027: import org.omg.RTCORBA.ProtocolProperties;
028:
029: /**
030: * @author Andre Spiegel
031: * @version $Id: FactoriesBase.java,v 1.4 2006/06/26 08:09:30 alphonse.bendt Exp $
032: */
033: public abstract class FactoriesBase extends
034: org.omg.ETF._FactoriesLocalBase implements Configurable {
035: protected org.jacorb.config.Configuration configuration;
036:
037: protected static Class connectionClz;
038:
039: protected static Class listenerClz;
040:
041: protected static Class profileClz;
042:
043: protected static Class addressClz;
044:
045: public void configure(Configuration configuration)
046: throws ConfigurationException {
047: if (configuration == null) {
048: throw new IllegalArgumentException();
049: }
050: this .configuration = (org.jacorb.config.Configuration) configuration;
051: }
052:
053: /**
054: * ETF defined operation to create a connection.
055: */
056: public Connection create_connection(ProtocolProperties props) {
057: return (Connection) newInstance(connectionClz,
058: "ETF::Connection");
059: }
060:
061: /**
062: * ETF defined operation to create a connection.
063: */
064: public Listener create_listener(ProtocolProperties props,
065: int stacksize, short base_priority) {
066: return (Listener) newInstance(listenerClz, "ETF::Listener");
067: }
068:
069: public Profile demarshal_profile(
070: TaggedProfileHolder tagged_profile,
071: TaggedComponentSeqHolder components) {
072: final ProfileBase profile = (ProfileBase) newInstance(
073: profileClz, "ETF::Profile");
074: profile.demarshal(tagged_profile, components);
075: return profile;
076: }
077:
078: // Although not part of the ETF IDL for a Factory object, this is the best
079: // place to add a new method for creating protocol address instances
080: public ProtocolAddressBase create_protocol_address(String addr) {
081: final ProtocolAddressBase address = (ProtocolAddressBase) newInstance(
082: addressClz, "ETF::ProtocolAddressBase");
083: final int address_start = this .match_tag(addr);
084: if (address_start >= 0) {
085: // general form is "prot://address"
086: if (!address.fromString(addr.substring(address_start + 2))) {
087: throw new org.omg.CORBA.INTERNAL(
088: "Invalid protocol address string: " + address);
089: }
090: }
091: return address;
092: }
093:
094: public int match_tag(String address) {
095: return -1;
096: }
097:
098: public abstract Profile decode_corbaloc(String corbaloc);
099:
100: private Object newInstance(final Class clazz,
101: final String description) {
102: Object connection = null;
103: try {
104: connection = clazz.newInstance();
105: } catch (Exception e) {
106: throw new org.omg.CORBA.INTERNAL("Cannot instantiate "
107: + description + " class: " + e.toString());
108: }
109:
110: if (connection instanceof Configurable) {
111: try {
112: ((Configurable) connection).configure(configuration);
113: } catch (ConfigurationException e) {
114: throw new org.omg.CORBA.INTERNAL(
115: "ConfigurationException: " + e.toString());
116: }
117: }
118: return connection;
119: }
120: }
|