001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Emil Ong
028: */
029:
030: package com.caucho.remote.client;
031:
032: import com.caucho.config.*;
033: import com.caucho.config.types.*;
034: import com.caucho.util.*;
035: import com.caucho.webbeans.cfg.*;
036: import com.caucho.webbeans.component.*;
037: import com.caucho.webbeans.manager.*;
038:
039: import java.util.ArrayList;
040: import java.util.Hashtable;
041: import java.util.logging.Logger;
042:
043: import javax.annotation.PostConstruct;
044: import javax.webbeans.*;
045:
046: /**
047: * Configuration class for a remote client
048: */
049: public class RemoteClient extends BeanConfig {
050: private static final Logger log = Logger
051: .getLogger(RemoteClient.class.getName());
052: private static final L10N L = new L10N(RemoteClient.class);
053:
054: private Class _interface;
055:
056: /**
057: * Creates a new protocol configuration object.
058: */
059: public RemoteClient() {
060: setBeanConfigClass(ProtocolProxyFactory.class);
061: }
062:
063: /**
064: * Sets the proxy interface class.
065: */
066: public void setInterface(Class type) {
067: _interface = type;
068:
069: if (!type.isInterface())
070: throw new ConfigException(
071: L
072: .l(
073: "remote-client interface '{0}' must be an interface",
074: type.getName()));
075: }
076:
077: protected void deploy() {
078: ProtocolProxyFactory factory = (ProtocolProxyFactory) getObject();
079:
080: Object proxy = factory.createProxy(_interface);
081:
082: WebBeansContainer webBeans = WebBeansContainer.create();
083:
084: ClassComponent comp = new SingletonComponent(webBeans, proxy);
085:
086: if (getName() != null) {
087: comp.setName(getName());
088:
089: addOptionalStringProperty("name", getName());
090: }
091:
092: comp.setBindingList(getBindingList());
093:
094: if (getType() != null)
095: comp.setType(getType());
096: else
097: comp.setType(webBeans.createComponentType(Component.class));
098:
099: comp.init();
100:
101: webBeans.addComponent(comp);
102: }
103: }
|