OPENJPA-2662 remove serp.util.Strings.getPackageName

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1759356 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Struberg 2016-09-05 21:11:01 +00:00
parent 297190a43a
commit 209adb6fc8
19 changed files with 85 additions and 51 deletions

View File

@ -40,9 +40,7 @@ import org.apache.openjpa.lib.conf.Configuration;
import org.apache.openjpa.lib.conf.Configurations;
import org.apache.openjpa.lib.identifier.IdentifierUtil;
import org.apache.openjpa.lib.util.ClassUtil;
import org.apache.openjpa.lib.util.StringUtil;
import org.apache.openjpa.meta.JavaTypes;
import serp.util.Strings;
/**
* Default implementation of {@link MappingDefaults}.

View File

@ -47,7 +47,6 @@ import org.apache.openjpa.lib.util.Localizer.Message;
import org.apache.openjpa.meta.JavaTypes;
import org.apache.openjpa.meta.MetaDataContext;
import org.apache.openjpa.util.MetaDataException;
import serp.util.Strings;
/**
* Base class storing raw mapping information; defines utility methods for

View File

@ -27,7 +27,6 @@ import org.apache.openjpa.jdbc.schema.Table;
import org.apache.openjpa.jdbc.schema.Unique;
import org.apache.openjpa.lib.util.ClassUtil;
import serp.util.Strings;
/**
* No-op mapping defaults.

View File

@ -62,7 +62,6 @@ import org.apache.openjpa.util.UserException;
import serp.bytecode.BCClass;
import serp.bytecode.BCClassLoader;
import serp.bytecode.Project;
import serp.util.Strings;
/**
* Generates a class appropriate for use as an application identity class.
@ -319,7 +318,7 @@ public class ApplicationIdTool {
// collect info on id type
String className = getClassName();
String packageName = Strings.getPackageName(oidClass);
String packageName = ClassUtil.getPackageName(oidClass);
String packageDec = "";
if (packageName.length() > 0)
packageDec = "package " + packageName + ";";
@ -477,7 +476,7 @@ public class ApplicationIdTool {
Set pkgs = getImportPackages();
CodeFormat imports = newCodeFormat();
String base = Strings.getPackageName(_meta.getObjectIdType());
String base = ClassUtil.getPackageName(_meta.getObjectIdType());
String pkg;
for (Iterator itr = pkgs.iterator(); itr.hasNext();) {
pkg = (String) itr.next();
@ -496,13 +495,13 @@ public class ApplicationIdTool {
*/
public Set getImportPackages() {
Set pkgs = new TreeSet();
pkgs.add(Strings.getPackageName(_type));
pkgs.add(ClassUtil.getPackageName(_type));
Class superOidClass = null;
if (_meta != null && _meta.getPCSuperclassMetaData() != null)
superOidClass = _meta.getPCSuperclassMetaData().getObjectIdType();
if (superOidClass != null)
pkgs.add(Strings.getPackageName(superOidClass));
pkgs.add(ClassUtil.getPackageName(superOidClass));
pkgs.add("java.io");
pkgs.add("java.util");
@ -511,7 +510,7 @@ public class ApplicationIdTool {
type = _fields[i].getObjectIdFieldType();
if (type != byte[].class && type != char[].class
&& !type.getName().startsWith("java.sql.")) {
pkgs.add(Strings.getPackageName(type));
pkgs.add(ClassUtil.getPackageName(type));
}
}
return pkgs;
@ -1214,13 +1213,13 @@ public class ApplicationIdTool {
if (_meta == null)
return null;
String packageName = Strings.getPackageName(_meta.getObjectIdType());
String packageName = ClassUtil.getPackageName(_meta.getObjectIdType());
String fileName = ClassUtil.getClassName(_meta.getObjectIdType())
+ ".java";
// if pc class in same package as oid class, try to find pc .java file
File dir = null;
if (_dir == null && Strings.getPackageName(_type).equals(packageName)) {
if (_dir == null && ClassUtil.getPackageName(_type).equals(packageName)) {
dir = Files.getSourceFile(_type);
if (dir != null)
dir = dir.getParentFile();
@ -1424,7 +1423,7 @@ public class ApplicationIdTool {
BCClassLoader bc)
throws ClassNotFoundException {
if (name.indexOf('.') == -1 && context.getName().indexOf('.') != -1)
name = Strings.getPackageName(context) + "." + name;
name = ClassUtil.getPackageName(context) + "." + name;
// first try with regular class loader
ClassLoader loader = AccessController.doPrivileged(

View File

@ -35,7 +35,6 @@ import org.apache.openjpa.lib.util.ParameterTemplate;
import org.apache.openjpa.meta.ClassMetaData;
import org.apache.openjpa.meta.FieldMetaData;
import org.apache.openjpa.meta.JavaTypes;
import serp.util.Strings;
/**
* Generates Java class code from metadata.
@ -128,7 +127,7 @@ public class CodeGenerator {
public void generateCode() {
// setup parameters
String className = ClassUtil.getClassName(_type);
String packageName = Strings.getPackageName(_type);
String packageName = ClassUtil.getPackageName(_type);
String packageDec = "";
if (packageName.length() > 0)
packageDec = "package " + packageName + ";";
@ -192,7 +191,7 @@ public class CodeGenerator {
Set pkgs = getImportPackages();
CodeFormat imports = newCodeFormat();
String base = Strings.getPackageName(_type);
String base = ClassUtil.getPackageName(_type);
String pkg;
for (Iterator itr = pkgs.iterator(); itr.hasNext();) {
pkg = (String) itr.next();
@ -211,15 +210,15 @@ public class CodeGenerator {
*/
public Set getImportPackages() {
Set pkgs = new TreeSet();
pkgs.add(Strings.getPackageName(_type.getSuperclass()));
pkgs.add(ClassUtil.getPackageName(_type.getSuperclass()));
FieldMetaData[] fields = _meta.getDeclaredFields();
for (int i = 0; i < fields.length; i++)
pkgs.add(Strings.getPackageName(fields[i].getDeclaredType()));
pkgs.add(ClassUtil.getPackageName(fields[i].getDeclaredType()));
fields = _meta.getPrimaryKeyFields();
for (int i = 0; i < fields.length; i++)
pkgs.add(Strings.getPackageName(fields[i].getDeclaredType()));
pkgs.add(ClassUtil.getPackageName(fields[i].getDeclaredType()));
return pkgs;
}
@ -504,7 +503,7 @@ public class CodeGenerator {
* Return Java file to write to.
*/
public File getFile() {
String packageName = Strings.getPackageName(_type);
String packageName = ClassUtil.getPackageName(_type);
String fileName = ClassUtil.getClassName(_type) + ".java";
File dir = Files.getPackageFile(_dir, packageName, true);

View File

@ -56,6 +56,7 @@ import org.apache.openjpa.lib.conf.Configurations;
import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.meta.ClassArgParser;
import org.apache.openjpa.lib.util.BytecodeWriter;
import org.apache.openjpa.lib.util.ClassUtil;
import org.apache.openjpa.lib.util.Files;
import org.apache.openjpa.lib.util.J2DoPrivHelper;
import org.apache.openjpa.lib.util.Localizer;
@ -106,7 +107,6 @@ import serp.bytecode.Project;
import serp.bytecode.PutFieldInstruction;
import serp.bytecode.TableSwitchInstruction;
import serp.bytecode.ClassInstruction;
import serp.util.Strings;
/**
* Bytecode enhancer used to enhance persistent classes from metadata. The
@ -319,7 +319,7 @@ public class PCEnhancer {
}
static String toPCSubclassName(Class cls) {
return Strings.getPackageName(PCEnhancer.class) + "."
return ClassUtil.getPackageName(PCEnhancer.class) + "."
+ cls.getName().replace('.', '$') + "$pcsubclass";
}
@ -330,7 +330,7 @@ public class PCEnhancer {
* @since 1.1.0
*/
public static boolean isPCSubclassName(String className) {
return className.startsWith(Strings.getPackageName(PCEnhancer.class))
return className.startsWith(ClassUtil.getPackageName(PCEnhancer.class))
&& className.endsWith("$pcsubclass");
}
@ -344,7 +344,7 @@ public class PCEnhancer {
public static String toManagedTypeName(String className) {
if (isPCSubclassName(className)) {
className = className.substring(
Strings.getPackageName(PCEnhancer.class).length() + 1);
ClassUtil.getPackageName(PCEnhancer.class).length() + 1);
className = className.substring(0, className.lastIndexOf("$"));
// this is not correct for nested PCs
className = className.replace('$', '.');

View File

@ -70,7 +70,6 @@ import org.apache.openjpa.util.OpenJPAException;
import org.apache.openjpa.util.UnsupportedException;
import org.apache.openjpa.util.UserException;
import serp.util.Strings;
/**
* Implementation of the {@link Query} interface.

View File

@ -57,13 +57,13 @@ import org.apache.openjpa.lib.meta.ResourceMetaDataIterator;
import org.apache.openjpa.lib.meta.URLMetaDataIterator;
import org.apache.openjpa.lib.meta.ZipFileMetaDataIterator;
import org.apache.openjpa.lib.meta.ZipStreamMetaDataIterator;
import org.apache.openjpa.lib.util.ClassUtil;
import org.apache.openjpa.lib.util.Files;
import org.apache.openjpa.lib.util.J2DoPrivHelper;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.util.StringUtil;
import org.apache.openjpa.util.GeneralException;
import org.apache.openjpa.util.UserException;
import serp.util.Strings;
/**
* Base class for factory implementations built around XML metadata files
@ -600,15 +600,14 @@ public abstract class AbstractCFMetaDataFactory
String pkg;
for (Iterator itr = clsNames.entrySet().iterator(); itr.hasNext();) {
entry = (Map.Entry) itr.next();
pkg = Strings.getPackageName((String) entry.getKey());
pkg = ClassUtil.getPackageName((String) entry.getKey());
if (pkg.length() == 0)
return (ClassMetaData) entry.getValue();
}
return null;
}
public Set<String> getPersistentTypeNames(boolean devpath,
ClassLoader envLoader) {
public Set<String> getPersistentTypeNames(boolean devpath, ClassLoader envLoader) {
// some configured locations might be implicit in spec, so return
// null if we don't find any classes, rather than if we don't have
// any locations

View File

@ -68,7 +68,6 @@ import org.apache.openjpa.util.UnsupportedException;
import org.apache.openjpa.util.ImplHelper;
import org.apache.openjpa.util.UserException;
import serp.util.Strings;
/**
* Metadata for a managed class field.
@ -1628,7 +1627,7 @@ public class FieldMetaData
// get class name and get package name divide on the last '.', so the
// names don't apply in this case, but the methods do what we want
String methodName = ClassUtil.getClassName(method);
String clsName = Strings.getPackageName(method);
String clsName = ClassUtil.getPackageName(method);
Class<?> cls = null;
Class<?> owner = _owner.getDescribedType();

View File

@ -38,9 +38,9 @@ import java.util.Properties;
import org.apache.openjpa.enhance.PersistenceCapable;
import org.apache.openjpa.lib.meta.CFMetaDataParser;
import org.apache.openjpa.lib.util.ClassUtil;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.util.MetaDataException;
import serp.util.Strings;
/**
* Type constants for managed fields.
@ -261,11 +261,11 @@ public class JavaTypes {
getClassLoader(dec, meta.getEnvClassLoader());
// try the owner's package
String pkg = Strings.getPackageName(dec);
String pkg = ClassUtil.getPackageName(dec);
Class<?> cls = CFMetaDataParser.classForName(name, pkg, runtime, loader);
if (cls == null && vmd != null) {
// try against this value type's package too
pkg = Strings.getPackageName(vmd.getDeclaredType());
pkg = ClassUtil.getPackageName(vmd.getDeclaredType());
cls = CFMetaDataParser.classForName(name, pkg, runtime, loader);
}

View File

@ -46,6 +46,7 @@ import org.apache.openjpa.lib.conf.Configurable;
import org.apache.openjpa.lib.conf.Configuration;
import org.apache.openjpa.lib.conf.Configurations;
import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.util.ClassUtil;
import org.apache.openjpa.lib.util.Closeable;
import org.apache.openjpa.lib.util.J2DoPrivHelper;
import org.apache.openjpa.lib.util.Localizer;
@ -58,7 +59,6 @@ import org.apache.openjpa.util.InternalException;
import org.apache.openjpa.util.MetaDataException;
import org.apache.openjpa.util.OpenJPAId;
import serp.util.Strings;
/**
* Repository of and factory for persistent metadata.
@ -2197,7 +2197,7 @@ public class MetaDataRepository implements PCRegistry.RegisterClassListener, Con
}
// try with qualified name
name = Strings.getPackageName(context.getDescribedType()) + "." + name;
name = ClassUtil.getPackageName(context.getDescribedType()) + "." + name;
try {
return getSequenceMetaData(name, context.getEnvClassLoader(), mustExist);
} catch (MetaDataException mde) {

View File

@ -52,6 +52,7 @@ import java.util.Queue;
import org.apache.commons.lang3.StringUtils;
import org.apache.openjpa.enhance.AsmAdaptor;
import org.apache.openjpa.kernel.OpenJPAStateManager;
import org.apache.openjpa.lib.util.ClassUtil;
import org.apache.openjpa.lib.util.Files;
import org.apache.openjpa.lib.util.J2DoPrivHelper;
import org.apache.openjpa.lib.util.Localizer;
@ -66,7 +67,6 @@ import serp.bytecode.BCMethod;
import serp.bytecode.Code;
import serp.bytecode.JumpInstruction;
import serp.bytecode.Project;
import serp.util.Strings;
/**
* Default implementation of the {@link ProxyManager} interface.
@ -590,7 +590,7 @@ public class ProxyManagerImpl
*/
private static String getProxyClassName(Class type, boolean runtime) {
String id = (runtime) ? "$" + nextProxyId() : "";
return Strings.getPackageName(ProxyManagerImpl.class) + "."
return ClassUtil.getPackageName(ProxyManagerImpl.class) + "."
+ type.getName().replace('.', '$') + id + PROXY_SUFFIX;
}

View File

@ -34,7 +34,6 @@ import java.util.NoSuchElementException;
import org.apache.openjpa.lib.util.ClassUtil;
import org.apache.openjpa.lib.util.J2DoPrivHelper;
import org.apache.openjpa.lib.util.MultiClassLoader;
import serp.util.Strings;
/**
* Iterator over all metadata resources that might contain the
@ -112,7 +111,7 @@ public class ClassMetaDataIterator implements MetaDataIterator {
// <path>/<package-name><suffix> (legacy support)
// <path>/../<package-name><suffix> (legacy support)
// 2. <path>/<class-name><suffix>
String pkg = Strings.getPackageName(cls).replace('.', '/');
String pkg = ClassUtil.getPackageName(cls).replace('.', '/');
if (pkg.length() > 0) {
int idx, start = 0;
String pkgName, path, upPath = "";

View File

@ -133,10 +133,7 @@ public final class ClassUtil {
return fullName;
}
int dims = 0;
while (fullName.charAt(dims) == '[') {
dims++;
}
int dims = getArrayDimensions(fullName);
if (dims > 0) {
if (fullName.length() == dims + 1) {
String classCode = fullName.substring(dims);
@ -170,4 +167,46 @@ public final class ClassUtil {
}
return simpleName;
}
private static int getArrayDimensions(String fullClassName) {
int dims = 0;
while (fullClassName.charAt(dims) == '[') {
dims++;
}
return dims;
}
/**
* Return only the package, or empty string if none.
*/
public static String getPackageName(Class cls) {
return (cls == null) ? null : getPackageName(cls.getName());
}
/**
* Return only the package, or empty string if none.
*/
public static String getPackageName(String fullName) {
if (fullName == null) {
return null;
}
if (fullName.isEmpty()) {
return fullName;
}
int dims = getArrayDimensions(fullName);
if (dims > 0) {
if (fullName.length() == dims + 1) {
// don't care, it's a primitive
return "";
}
else {
fullName = fullName.substring(dims + 1);
}
}
int lastDot = fullName.lastIndexOf('.');
return lastDot > -1 ? fullName.substring(0, lastDot) : "";
}
}

View File

@ -37,7 +37,6 @@ import java.security.AccessController;
import java.security.PrivilegedActionException;
import org.apache.commons.lang3.StringUtils;
import serp.util.Strings;
/**
* Utility operations on files.

View File

@ -100,6 +100,16 @@ public class ClassUtilTest {
System.out.println("took: " + TimeUnit.NANOSECONDS.toMillis(stop - start));
}
@Test
public void testGetPackageName() {
Assert.assertEquals("org.apache.openjpa.lib.util", ClassUtil.getPackageName(ClassUtilTest.class));
Assert.assertEquals("org.apache.openjpa.lib.util", ClassUtil.getPackageName(MyInnerClass.class));
Assert.assertEquals("org.apache.openjpa.lib.util", ClassUtil.getPackageName(MyInnerClass[].class));
Assert.assertEquals("org.apache.openjpa.lib.util", ClassUtil.getPackageName(INSTANCE.getClass()));
Assert.assertEquals("", ClassUtil.getPackageName(long.class));
Assert.assertEquals("", ClassUtil.getPackageName(long[].class));
}
private static abstract class MyInnerClass {
// not needed
}

View File

@ -56,8 +56,6 @@ import java.util.HashMap;
import java.sql.Types;
import java.lang.annotation.Annotation;
import serp.util.Strings;
import javax.persistence.TemporalType;
import javax.persistence.EnumType;
import javax.persistence.InheritanceType;

View File

@ -42,7 +42,6 @@ import org.apache.openjpa.jdbc.sql.JoinSyntaxes;
import org.apache.openjpa.lib.util.ClassUtil;
import org.apache.openjpa.meta.FieldMetaData;
import org.apache.openjpa.meta.JavaTypes;
import serp.util.Strings;
/**
* Supplies default mapping information in accordance with JPA spec.

View File

@ -57,7 +57,6 @@ import org.apache.openjpa.meta.SequenceMetaData;
import org.apache.openjpa.meta.ValueMetaData;
import org.apache.openjpa.util.InternalException;
import org.xml.sax.SAXException;
import serp.util.Strings;
/**
* Serializes persistence metadata back to XML.
@ -531,7 +530,7 @@ public class XMLPersistenceMetaDataSerializer
int type = type(obj);
switch (type) {
case TYPE_META:
return Strings.getPackageName(((ClassMetaData) obj).
return ClassUtil.getPackageName(((ClassMetaData) obj).
getDescribedType());
case TYPE_QUERY:
case TYPE_SEQ:
@ -539,7 +538,7 @@ public class XMLPersistenceMetaDataSerializer
case TYPE_CLASS_SEQS:
SourceTracker st = (SourceTracker) obj;
if (st.getSourceScope() instanceof Class)
return Strings.getPackageName((Class) st.getSourceScope());
return ClassUtil.getPackageName((Class) st.getSourceScope());
return null;
default:
return null;