Skip to content

Commit

Permalink
Clean up.
Browse files Browse the repository at this point in the history
Refactoring to add a base class to:
- reduce duplication in the getFactoryClassName() method
- reduce duplication in the toString()method where present
- provide each type of Ref with a consistent toString() implementation

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1771226 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Nov 24, 2016
1 parent 5a9ec92 commit 871efbf
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 336 deletions.
87 changes: 87 additions & 0 deletions java/org/apache/naming/AbstractRef.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* 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.naming;

import java.util.Enumeration;

import javax.naming.Context;
import javax.naming.RefAddr;
import javax.naming.Reference;

public abstract class AbstractRef extends Reference {

private static final long serialVersionUID = 1L;


public AbstractRef(String className) {
super(className);
}


public AbstractRef(String className, String factory, String factoryLocation) {
super(className, factory, factoryLocation);
}


/**
* Retrieves the class name of the factory of the object to which this
* reference refers.
*/
@Override
public final String getFactoryClassName() {
String factory = super.getFactoryClassName();
if (factory != null) {
return factory;
} else {
factory = System.getProperty(Context.OBJECT_FACTORIES);
if (factory != null) {
return null;
} else {
return getDefaultFactoryClassName();
}
}
}


protected abstract String getDefaultFactoryClassName();


/**
* Return a String rendering of this object.
*/
@Override
public final String toString() {
StringBuilder sb = new StringBuilder(this.getClass().getSimpleName());
sb.append("[className=");
sb.append(getClassName());
sb.append(",factoryClassLocation=");
sb.append(getFactoryClassLocation());
sb.append(",factoryClassName=");
sb.append(getFactoryClassName());
Enumeration<RefAddr> refAddrs = getAll();
while (refAddrs.hasMoreElements()) {
RefAddr refAddr = refAddrs.nextElement();
sb.append(",{type=");
sb.append(refAddr.getType());
sb.append(",content=");
sb.append(refAddr.getContent());
sb.append("}");
}
sb.append("]");
return sb.toString();
}
}
46 changes: 5 additions & 41 deletions java/org/apache/naming/EjbRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/


package org.apache.naming;

import javax.naming.Context;
import javax.naming.Reference;
import javax.naming.StringRefAddr;

/**
* Represents a reference address to an EJB.
*
* @author Remy Maucherat
*/
public class EjbRef extends Reference {
public class EjbRef extends AbstractRef {

private static final long serialVersionUID = 1L;


// -------------------------------------------------------------- Constants
/**
* Default factory for this reference.
*/
public static final String DEFAULT_FACTORY =
org.apache.naming.factory.Constants.DEFAULT_EJB_FACTORY;
org.apache.naming.factory.Constants.DEFAULT_EJB_FACTORY;


/**
Expand All @@ -58,9 +53,6 @@ public class EjbRef extends Reference {
public static final String LINK = "link";


// ----------------------------------------------------------- Constructors


/**
* EJB Reference.
*
Expand All @@ -86,7 +78,7 @@ public EjbRef(String ejbType, String home, String remote, String link) {
* the factory (e.g. URL)
*/
public EjbRef(String ejbType, String home, String remote, String link,
String factory, String factoryLocation) {
String factory, String factoryLocation) {
super(home, factory, factoryLocation);
StringRefAddr refAddr = null;
if (ejbType != null) {
Expand All @@ -104,36 +96,8 @@ public EjbRef(String ejbType, String home, String remote, String link,
}


// ----------------------------------------------------- Instance Variables


// -------------------------------------------------------- RefAddr Methods


// ------------------------------------------------------ Reference Methods


/**
* Retrieves the class name of the factory of the object to which this
* reference refers.
*/
@Override
public String getFactoryClassName() {
String factory = super.getFactoryClassName();
if (factory != null) {
return factory;
} else {
factory = System.getProperty(Context.OBJECT_FACTORIES);
if (factory != null) {
return null;
} else {
return DEFAULT_FACTORY;
}
}
protected String getDefaultFactoryClassName() {
return DEFAULT_FACTORY;
}


// ------------------------------------------------------------- Properties


}
76 changes: 4 additions & 72 deletions java/org/apache/naming/HandlerRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/


package org.apache.naming;

import java.util.Enumeration;

import javax.naming.Context;
import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.StringRefAddr;

/**
* Represents a reference handler for a web service.
*
* @author Fabien Carrion
*/

public class HandlerRef extends Reference {
public class HandlerRef extends AbstractRef {

private static final long serialVersionUID = 1L;


// -------------------------------------------------------------- Constants
/**
* Default factory for this reference.
*/
public static final String DEFAULT_FACTORY =
org.apache.naming.factory.Constants.DEFAULT_HANDLER_FACTORY;
org.apache.naming.factory.Constants.DEFAULT_HANDLER_FACTORY;


/**
Expand Down Expand Up @@ -92,9 +83,6 @@ public class HandlerRef extends Reference {
public static final String HANDLER_PORTNAME = "handlerportname";


// ----------------------------------------------------------- Constructors


public HandlerRef(String refname, String handlerClass) {
this(refname, handlerClass, null, null);
}
Expand All @@ -115,64 +103,8 @@ public HandlerRef(String refname, String handlerClass,
}


// ----------------------------------------------------- Instance Variables


// ------------------------------------------------------ Reference Methods


/**
* Retrieves the class name of the factory of the object to which this
* reference refers.
*/
@Override
public String getFactoryClassName() {
String factory = super.getFactoryClassName();
if (factory != null) {
return factory;
} else {
factory = System.getProperty(Context.OBJECT_FACTORIES);
if (factory != null) {
return null;
} else {
return DEFAULT_FACTORY;
}
}
protected String getDefaultFactoryClassName() {
return DEFAULT_FACTORY;
}


// --------------------------------------------------------- Public Methods


/**
* Return a String rendering of this object.
*/
@Override
public String toString() {

StringBuilder sb = new StringBuilder("HandlerRef[");
sb.append("className=");
sb.append(getClassName());
sb.append(",factoryClassLocation=");
sb.append(getFactoryClassLocation());
sb.append(",factoryClassName=");
sb.append(getFactoryClassName());
Enumeration<RefAddr> refAddrs = getAll();
while (refAddrs.hasMoreElements()) {
RefAddr refAddr = refAddrs.nextElement();
sb.append(",{type=");
sb.append(refAddr.getType());
sb.append(",content=");
sb.append(refAddr.getContent());
sb.append("}");
}
sb.append("]");
return (sb.toString());

}


// ------------------------------------------------------------- Properties


}
25 changes: 4 additions & 21 deletions java/org/apache/naming/ResourceEnvRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@
*/
package org.apache.naming;

import javax.naming.Context;
import javax.naming.Reference;

/**
* Represents a reference address to a resource environment.
*
* @author Remy Maucherat
*/
public class ResourceEnvRef extends Reference {
public class ResourceEnvRef extends AbstractRef {

private static final long serialVersionUID = 1L;

Expand All @@ -33,7 +30,7 @@ public class ResourceEnvRef extends Reference {
* Default factory for this reference.
*/
public static final String DEFAULT_FACTORY =
org.apache.naming.factory.Constants.DEFAULT_RESOURCE_ENV_FACTORY;
org.apache.naming.factory.Constants.DEFAULT_RESOURCE_ENV_FACTORY;


/**
Expand All @@ -46,22 +43,8 @@ public ResourceEnvRef(String resourceType) {
}


/**
* Retrieves the class name of the factory of the object to which this
* reference refers.
*/
@Override
public String getFactoryClassName() {
String factory = super.getFactoryClassName();
if (factory != null) {
return factory;
} else {
factory = System.getProperty(Context.OBJECT_FACTORIES);
if (factory != null) {
return null;
} else {
return DEFAULT_FACTORY;
}
}
protected String getDefaultFactoryClassName() {
return DEFAULT_FACTORY;
}
}
Loading

0 comments on commit 871efbf

Please sign in to comment.