001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.naming;
019:
020: import java.util.Enumeration;
021: import java.util.Vector;
022:
023: import javax.naming.Context;
024: import javax.naming.RefAddr;
025: import javax.naming.Reference;
026: import javax.naming.StringRefAddr;
027:
028: /**
029: * Represents a reference web service.
030: *
031: * @author Fabien Carrion
032: */
033:
034: public class ServiceRef extends Reference {
035:
036: // -------------------------------------------------------------- Constants
037:
038: /**
039: * Default factory for this reference.
040: */
041: public static final String DEFAULT_FACTORY = org.apache.naming.factory.Constants.DEFAULT_SERVICE_FACTORY;
042:
043: /**
044: * Service Classname address type.
045: */
046: public static final String SERVICE_INTERFACE = "serviceInterface";
047:
048: /**
049: * ServiceQname address type.
050: */
051: public static final String SERVICE_NAMESPACE = "service namespace";
052: public static final String SERVICE_LOCAL_PART = "service local part";
053:
054: /**
055: * Wsdl Location address type.
056: */
057: public static final String WSDL = "wsdl";
058:
059: /**
060: * Jaxrpcmapping address type.
061: */
062: public static final String JAXRPCMAPPING = "jaxrpcmapping";
063:
064: /**
065: * port-component-ref/port-component-link address type.
066: */
067: public static final String PORTCOMPONENTLINK = "portcomponentlink";
068:
069: /**
070: * port-component-ref/service-endpoint-interface address type.
071: */
072: public static final String SERVICEENDPOINTINTERFACE = "serviceendpointinterface";
073:
074: /**
075: * The vector to save the handler Reference objects, because they can't be saved in the addrs vector.
076: */
077: private Vector<HandlerRef> handlers = new Vector<HandlerRef>();
078:
079: // ----------------------------------------------------------- Constructors
080:
081: /**
082: * Service Reference.
083: *
084: * @param serviceClass Service class
085: */
086: public ServiceRef(String refname, String serviceInterface,
087: String[] serviceQname, String wsdl, String jaxrpcmapping) {
088: this (refname, serviceInterface, serviceQname, wsdl,
089: jaxrpcmapping, null, null);
090: }
091:
092: /**
093: * Service Reference.
094: *
095: * @param serviceClass Service class
096: */
097: public ServiceRef(String refname, String serviceInterface,
098: String[] serviceQname, String wsdl, String jaxrpcmapping,
099: String factory, String factoryLocation) {
100: super (serviceInterface, factory, factoryLocation);
101: StringRefAddr refAddr = null;
102: if (serviceInterface != null) {
103: refAddr = new StringRefAddr(SERVICE_INTERFACE,
104: serviceInterface);
105: add(refAddr);
106: }
107: if (serviceQname[0] != null) {
108: refAddr = new StringRefAddr(SERVICE_NAMESPACE,
109: serviceQname[0]);
110: add(refAddr);
111: }
112: if (serviceQname[1] != null) {
113: refAddr = new StringRefAddr(SERVICE_LOCAL_PART,
114: serviceQname[1]);
115: add(refAddr);
116: }
117: if (wsdl != null) {
118: refAddr = new StringRefAddr(WSDL, wsdl);
119: add(refAddr);
120: }
121: if (jaxrpcmapping != null) {
122: refAddr = new StringRefAddr(JAXRPCMAPPING, jaxrpcmapping);
123: add(refAddr);
124: }
125: }
126:
127: // ----------------------------------------------------- Instance Variables
128:
129: // ------------------------------------------------------ Reference Methods
130:
131: /**
132: * Add and Get Handlers classes.
133: */
134: public HandlerRef getHandler() {
135: return handlers.remove(0);
136: }
137:
138: public int getHandlersSize() {
139: return handlers.size();
140: }
141:
142: public void addHandler(HandlerRef handler) {
143: handlers.add(handler);
144: }
145:
146: /**
147: * Retrieves the class name of the factory of the object to which this
148: * reference refers.
149: */
150: public String getFactoryClassName() {
151: String factory = super .getFactoryClassName();
152: if (factory != null) {
153: return factory;
154: } else {
155: factory = System.getProperty(Context.OBJECT_FACTORIES);
156: if (factory != null) {
157: return null;
158: } else {
159: return DEFAULT_FACTORY;
160: }
161: }
162: }
163:
164: // --------------------------------------------------------- Public Methods
165:
166: /**
167: * Return a String rendering of this object.
168: */
169: public String toString() {
170:
171: StringBuffer sb = new StringBuffer("ServiceRef[");
172: sb.append("className=");
173: sb.append(getClassName());
174: sb.append(",factoryClassLocation=");
175: sb.append(getFactoryClassLocation());
176: sb.append(",factoryClassName=");
177: sb.append(getFactoryClassName());
178: Enumeration refAddrs = getAll();
179: while (refAddrs.hasMoreElements()) {
180: RefAddr refAddr = (RefAddr) refAddrs.nextElement();
181: sb.append(",{type=");
182: sb.append(refAddr.getType());
183: sb.append(",content=");
184: sb.append(refAddr.getContent());
185: sb.append("}");
186: }
187: sb.append("]");
188: return (sb.toString());
189:
190: }
191:
192: // ------------------------------------------------------------- Properties
193:
194: }
|