/*
* 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.wink.common.internal.type;
public abstract class TypeBase extends JavaType {
/**
* Lazily initialized external representation of the type
*/
volatile String _canonicalName;
protected TypeBase(Class<?> raw, int hash) {
super(raw, hash);
}
@Override
public String toCanonical() {
String str = _canonicalName;
if (str == null) {
str = buildCanonicalName();
}
return str;
}
protected abstract String buildCanonicalName();
protected final JavaType copyHandlers(JavaType fromType) {
_valueHandler = fromType.getValueHandler();
_typeHandler = fromType.getTypeHandler();
return this;
}
@Override
public abstract StringBuilder getGenericSignature(StringBuilder sb);
@Override
public abstract StringBuilder getErasedSignature(StringBuilder sb);
/*
/**********************************************************
/* Methods for sub-classes to use
/**********************************************************
*/
/**
* @param trailingSemicolon Whether to add trailing semicolon for non-primitive
* (reference) types or not
*/
protected static StringBuilder _classSignature(Class<?> cls, StringBuilder sb, boolean trailingSemicolon) {
if (cls.isPrimitive()) {
if (cls == Boolean.TYPE) {
sb.append('Z');
} else if (cls == Byte.TYPE) {
sb.append('B');
} else if (cls == Short.TYPE) {
sb.append('S');
} else if (cls == Character.TYPE) {
sb.append('C');
} else if (cls == Integer.TYPE) {
sb.append('I');
} else if (cls == Long.TYPE) {
sb.append('J');
} else if (cls == Float.TYPE) {
sb.append('F');
} else if (cls == Double.TYPE) {
sb.append('D');
} else if (cls == Void.TYPE) {
sb.append('V');
} else {
throw new IllegalStateException("Unrecognized primitive type: " + cls.getName());
}
} else {
sb.append('L');
String name = cls.getName();
for (int i = 0, len = name.length(); i < len; ++i) {
char c = name.charAt(i);
if (c == '.')
c = '/';
sb.append(c);
}
if (trailingSemicolon) {
sb.append(';');
}
}
return sb;
}
}