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:
022: import javax.naming.Context;
023: import javax.naming.RefAddr;
024: import javax.naming.Reference;
025: import javax.naming.StringRefAddr;
026:
027: /**
028: * Represents a reference handler for a web service.
029: *
030: * @author Fabien Carrion
031: */
032:
033: public class HandlerRef extends Reference {
034:
035: // -------------------------------------------------------------- Constants
036:
037: /**
038: * Default factory for this reference.
039: */
040: public static final String DEFAULT_FACTORY = org.apache.naming.factory.Constants.DEFAULT_HANDLER_FACTORY;
041:
042: /**
043: * HandlerName address type.
044: */
045: public static final String HANDLER_NAME = "handlername";
046:
047: /**
048: * Handler Classname address type.
049: */
050: public static final String HANDLER_CLASS = "handlerclass";
051:
052: /**
053: * Handler Classname address type.
054: */
055: public static final String HANDLER_LOCALPART = "handlerlocalpart";
056:
057: /**
058: * Handler Classname address type.
059: */
060: public static final String HANDLER_NAMESPACE = "handlernamespace";
061:
062: /**
063: * Handler Classname address type.
064: */
065: public static final String HANDLER_PARAMNAME = "handlerparamname";
066:
067: /**
068: * Handler Classname address type.
069: */
070: public static final String HANDLER_PARAMVALUE = "handlerparamvalue";
071:
072: /**
073: * Handler SoapRole address type.
074: */
075: public static final String HANDLER_SOAPROLE = "handlersoaprole";
076:
077: /**
078: * Handler PortName address type.
079: */
080: public static final String HANDLER_PORTNAME = "handlerportname";
081:
082: // ----------------------------------------------------------- Constructors
083:
084: /**
085: * Service Reference.
086: *
087: * @param serviceClass Service class
088: */
089: public HandlerRef(String refname, String handlerClass) {
090: this (refname, handlerClass, null, null);
091: }
092:
093: /**
094: * Service Reference.
095: *
096: * @param serviceClass Service class
097: */
098: public HandlerRef(String refname, String handlerClass,
099: String factory, String factoryLocation) {
100: super (refname, factory, factoryLocation);
101: StringRefAddr refAddr = null;
102: if (refname != null) {
103: refAddr = new StringRefAddr(HANDLER_NAME, refname);
104: add(refAddr);
105: }
106: if (handlerClass != null) {
107: refAddr = new StringRefAddr(HANDLER_CLASS, handlerClass);
108: add(refAddr);
109: }
110: }
111:
112: // ----------------------------------------------------- Instance Variables
113:
114: // ------------------------------------------------------ Reference Methods
115:
116: /**
117: * Retrieves the class name of the factory of the object to which this
118: * reference refers.
119: */
120: public String getFactoryClassName() {
121: String factory = super .getFactoryClassName();
122: if (factory != null) {
123: return factory;
124: } else {
125: factory = System.getProperty(Context.OBJECT_FACTORIES);
126: if (factory != null) {
127: return null;
128: } else {
129: return DEFAULT_FACTORY;
130: }
131: }
132: }
133:
134: // --------------------------------------------------------- Public Methods
135:
136: /**
137: * Return a String rendering of this object.
138: */
139: public String toString() {
140:
141: StringBuffer sb = new StringBuffer("HandlerRef[");
142: sb.append("className=");
143: sb.append(getClassName());
144: sb.append(",factoryClassLocation=");
145: sb.append(getFactoryClassLocation());
146: sb.append(",factoryClassName=");
147: sb.append(getFactoryClassName());
148: Enumeration refAddrs = getAll();
149: while (refAddrs.hasMoreElements()) {
150: RefAddr refAddr = (RefAddr) refAddrs.nextElement();
151: sb.append(",{type=");
152: sb.append(refAddr.getType());
153: sb.append(",content=");
154: sb.append(refAddr.getContent());
155: sb.append("}");
156: }
157: sb.append("]");
158: return (sb.toString());
159:
160: }
161:
162: // ------------------------------------------------------------- Properties
163:
164: }
|