import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import org.opendaylight.mdsal.binding.javav2.generator.context.ModuleContext;
import org.opendaylight.mdsal.binding.javav2.model.api.BaseTypeWithRestrictions;
import org.opendaylight.mdsal.binding.javav2.model.api.ConcreteType;
import org.opendaylight.mdsal.binding.javav2.model.api.ParameterizedType;
import org.opendaylight.mdsal.binding.javav2.model.api.WildcardType;
import org.opendaylight.mdsal.binding.javav2.spec.structural.Augmentable;
import org.opendaylight.mdsal.binding.javav2.spec.structural.Augmentation;
-import org.opendaylight.mdsal.binding.javav2.spec.base.RpcCallback;
import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
import org.opendaylight.yangtools.yang.model.util.BaseConstraints;
+import org.w3c.dom.Document;
@Beta
public final class Types {
new CacheLoader<Class<?>, ConcreteType>() {
@Override
- public ConcreteType load(Class<?> key) throws Exception {
+ public ConcreteType load(@Nonnull final Class<?> key) throws Exception {
return new ConcreteTypeImpl(key.getPackage().getName(), key.getSimpleName(), null);
}
};
CacheBuilder.newBuilder().weakKeys().build(TYPE_LOADER);
public static final ConcreteType BOOLEAN = typeForClass(Boolean.class);
- public static final ConcreteType RPC_CALLBACK = typeForClass(RpcCallback.class);
+ public static final ConcreteType CLASS = typeForClass(Class.class);
public static final ConcreteType STRING = typeForClass(String.class);
public static final ConcreteType VOID = typeForClass(Void.class);
+ public static final ConcreteType DOCUMENT = typeForClass(Document.class);
+
public static final ConcreteType BYTE_ARRAY = primitiveType("byte[]", null);
public static final ConcreteType CHAR_ARRAY = primitiveType("char[]", null);
}
}
+ public static ConcreteType typeForClass(final Class<?> cls, final Restrictions restrictions,
+ final ModuleContext moduleContext) {
+ if (restrictions != null) {
+ if (restrictions instanceof DefaultRestrictions) {
+ return new ConcreteTypeImpl(cls.getPackage().getName(), cls.getSimpleName(), restrictions);
+ } else {
+ return new BaseTypeWithRestrictionsImpl(cls.getPackage().getName(), cls.getSimpleName(), restrictions,
+ moduleContext);
+ }
+ } else {
+ return typeForClass(cls);
+ }
+ }
+
/**
* Returns an instance of {@link ParameterizedType} describing the typed
* {@link Map}<K,V>
return new WildcardTypeImpl(packageName, typeName);
}
+ /**
+ * Creates instance of type
+ * {@link WildcardType
+ * WildcardType}
+ *
+ * @param packageName
+ * string with the package name
+ * @param typeName
+ * string with the type name
+ * @param isPkNameNormalized
+ * if the package name has been normalized
+ * @param isTypeNormalized
+ * if the type name has been normalized
+ * @return <code>WildcardType</code> representation of
+ * <code>packageName</code> and <code>typeName</code>
+ */
+ public static WildcardType wildcardTypeFor(final String packageName, final String typeName,
+ final boolean isPkNameNormalized, final boolean isTypeNormalized, ModuleContext context) {
+ return new WildcardTypeImpl(packageName, typeName, isPkNameNormalized, isTypeNormalized, context);
+ }
+
/**
* Creates instance of
* {@link ParameterizedType
@Nullable
public static String getOuterClassName(final Type valueType) {
final String pkgName = valueType.getPackageName();
- if(CharMatcher.JAVA_UPPER_CASE.indexIn(pkgName) >= 0) {
+ final int index = CharMatcher.JAVA_UPPER_CASE.indexIn(pkgName);
+ if (index >= 0) {
// It is inner class.
- return Iterables.getLast(DOT_SPLITTER.split(pkgName));
+ return Iterables.getFirst(DOT_SPLITTER.split(pkgName.substring(index)), null);
}
return null;
}
+ @Nullable
+ public static String getOuterClassPackageName(final Type valueType) {
+ final String pkgName = valueType.getPackageName();
+ final int index = CharMatcher.JAVA_UPPER_CASE.indexIn(pkgName);
+ if (index >= 1) {
+ return pkgName.substring(0, index - 1);
+ }
+ return pkgName;
+ }
+
/**
*
* Represents concrete JAVA type.
* string with the name of the type
*/
private ConcreteTypeImpl(final String pkName, final String name, final Restrictions restrictions) {
- super(pkName, name);
+ super(pkName, name, true,null);
this.restrictions = restrictions;
}
@Override
public Restrictions getRestrictions() {
- return restrictions;
+ return this.restrictions;
}
}
* string with the name of the type
*/
private BaseTypeWithRestrictionsImpl(final String pkName, final String name, final Restrictions restrictions) {
- super(pkName, name);
+ super(pkName, name, null);
+ this.restrictions = Preconditions.checkNotNull(restrictions);
+ }
+
+ private BaseTypeWithRestrictionsImpl(final String pkName, final String name, final Restrictions restrictions,
+ final ModuleContext moduleContext) {
+ super(pkName, name, moduleContext);
this.restrictions = Preconditions.checkNotNull(restrictions);
}
@Override
public Restrictions getRestrictions() {
- return restrictions;
+ return this.restrictions;
}
}
* array of actual parameters
*/
public ParameterizedTypeImpl(final Type rawType, final Type[] actTypes) {
- super(rawType.getPackageName(), rawType.getName());
+ super(rawType.getPackageName(), rawType.getName(), true, null);
this.rawType = rawType;
this.actualTypes = actTypes.clone();
}
@Override
public Type[] getActualTypeArguments() {
- return actualTypes;
+ return this.actualTypes;
}
@Override
public Type getRawType() {
- return rawType;
+ return this.rawType;
}
}
* @param typeName
* string with the name of type
*/
+ //FIXME: doesn't seem to be called at all
public WildcardTypeImpl(final String packageName, final String typeName) {
- super(packageName, typeName);
+ super(packageName, typeName, null);
+ }
+
+ /**
+ * Creates instance of this class with concrete package and type name.
+ *
+ * @param packageName
+ * string with the package name
+ * @param typeName
+ * string with the name of type
+ * @param isPkNameNormalized
+ * if the package name has been normalized
+ * @param isTypeNormalized
+ * if the type name has been normalized
+ */
+ public WildcardTypeImpl(final String packageName, final String typeName, final boolean isPkNameNormalized,
+ final boolean isTypeNormalized, ModuleContext context) {
+ super(packageName, typeName, isPkNameNormalized, isTypeNormalized, context);
}
}
@Override
public List<RangeConstraint> getRangeConstraints() {
- return rangeConstraints;
+ return this.rangeConstraints;
}
@Override