Example usage for java.lang TypeNotPresentException TypeNotPresentException

List of usage examples for java.lang TypeNotPresentException TypeNotPresentException

Introduction

In this page you can find the example usage for java.lang TypeNotPresentException TypeNotPresentException.

Prototype

public TypeNotPresentException(String typeName, Throwable cause) 

Source Link

Document

Constructs a TypeNotPresentException for the named type with the specified cause.

Usage

From source file:com.ca.mas.cordova.storage.StorageDataMarshaller.java

public static DataMarshaller findMarshaller(Object type) {
    for (DataMarshaller current : marshallers) {
        if (current.getType().isAssignableFrom(type.getClass())) {
            return current;
        }// w  ww. j  a v a2s .c  o m
    }
    throw new TypeNotPresentException(type.getClass().getName(), null);
}

From source file:org.adminmap.core.rpc.Request.java

/**
 * Determines the class property that is encoded is our param array at the specified index
 * //from w w  w  .j a va  2  s  .  c  om
 * @param index
 * @return the class property
 * 
 */
private Class<?> getParameterClassProperty(final int index) {

    final JSONObject jsonObject = params.getJSONObject(index);
    final String className = JSONObject.getNames(jsonObject)[0]; // The key is the class name
    Class<?> encodedClassProperty = null;
    try {
        encodedClassProperty = Class.forName(className);
    } catch (ClassNotFoundException e) {
        throw new TypeNotPresentException(className, e);
    }

    return encodedClassProperty;
}

From source file:io.github.jeddict.jpa.spec.extend.SingleRelationAttribute.java

@Override
@Deprecated/*from   w w  w . j a v a  2  s.  c o  m*/
public void loadAttribute(EntityMappings entityMappings, Element element, VariableElement variableElement,
        ExecutableElement getterElement, AnnotationMirror annotationMirror) {
    super.loadAttribute(entityMappings, element, variableElement, getterElement, annotationMirror);
    if (JavaSourceParserUtil.isAnnotatedWith(element, ID_FQN)) {
        this.setPrimaryKey(Boolean.TRUE);
    }

    AnnotationMirror joinColumnsAnnotationMirror = JavaSourceParserUtil.findAnnotation(element,
            JOIN_COLUMNS_FQN);
    if (joinColumnsAnnotationMirror != null) {
        List joinColumnsAnnot = (List) JavaSourceParserUtil.findAnnotationValue(joinColumnsAnnotationMirror,
                "value");
        if (joinColumnsAnnot != null) {
            for (Object joinColumnObj : joinColumnsAnnot) {
                this.getJoinColumn().add(new JoinColumn().load(element, (AnnotationMirror) joinColumnObj));
            }
        }
    } else {
        AnnotationMirror joinColumnAnnotationMirror = JavaSourceParserUtil.findAnnotation(element,
                JOIN_COLUMN_FQN);
        if (joinColumnAnnotationMirror != null) {
            this.getJoinColumn().add(new JoinColumn().load(element, joinColumnAnnotationMirror));
        }
    }

    this.optional = (Boolean) JavaSourceParserUtil.findAnnotationValue(annotationMirror, "optional");

    AnnotationMirror mapsIdAnnotationMirror = JavaSourceParserUtil.findAnnotation(element, MAPS_ID_FQN);
    AnnotationMirror idAnnotationMirror = JavaSourceParserUtil.findAnnotation(element, ID_FQN);

    this.primaryKey = mapsIdAnnotationMirror != null || idAnnotationMirror != null;
    if (mapsIdAnnotationMirror != null) {
        this.mapsId = (String) JavaSourceParserUtil.findAnnotationValue(mapsIdAnnotationMirror, "value");
    }

    AnnotationMirror foreignKeyValue = (AnnotationMirror) JavaSourceParserUtil
            .findAnnotationValue(annotationMirror, "foreignKey");
    if (foreignKeyValue != null) {
        this.foreignKey = ForeignKey.load(element, foreignKeyValue);
    }

    DeclaredType declaredType = (DeclaredType) JavaSourceParserUtil.findAnnotationValue(annotationMirror,
            "targetEntity");
    if (declaredType == null) {
        if (variableElement.asType() instanceof ErrorType) { //variable => "<any>"
            throw new TypeNotPresentException(this.name + " type not found", null);
        }
        String fqn = variableElement.asType().toString();
        this.targetEntityPackage = getPackageName(fqn);
        this.targetEntity = getSimpleClassName(fqn);
    } else {
        String fqn = declaredType.asElement().asType().toString();
        this.targetEntityPackage = getPackageName(fqn);
        this.targetEntity = getSimpleClassName(fqn);
    }

}

From source file:org.apache.camel.component.file.GenericFileEndpoint.java

/**
 * A strategy method to lazily create the file strategy
 *///  w  ww  .j  a v a  2  s  .co m
@SuppressWarnings("unchecked")
protected GenericFileProcessStrategy<T> createGenericFileStrategy() {
    Class<?> factory = null;
    try {
        FactoryFinder finder = getCamelContext()
                .getFactoryFinder("META-INF/services/org/apache/camel/component/");
        factory = finder.findClass(getScheme(), "strategy.factory.");
    } catch (ClassNotFoundException e) {
        if (log.isTraceEnabled()) {
            log.trace("'strategy.factory.class' not found", e);
        }
    } catch (IOException e) {
        if (log.isTraceEnabled()) {
            log.trace("No strategy factory defined in 'META-INF/services/org/apache/camel/component/'", e);
        }
    }

    if (factory == null) {
        // use default
        factory = this.getCamelContext().getClassResolver().resolveClass(DEFAULT_STRATEGYFACTORY_CLASS);
        if (factory == null) {
            throw new TypeNotPresentException(DEFAULT_STRATEGYFACTORY_CLASS + " class not found", null);
        }
    }

    try {
        Method factoryMethod = factory.getMethod("createGenericFileProcessStrategy", CamelContext.class,
                Map.class);
        return (GenericFileProcessStrategy<T>) ObjectHelper.invokeMethod(factoryMethod, null, getCamelContext(),
                getParamsAsMap());
    } catch (NoSuchMethodException e) {
        throw new TypeNotPresentException(
                factory.getSimpleName() + ".createGenericFileProcessStrategy method not found", e);
    }
}

From source file:org.netbeans.jpa.modeler.spec.extend.MultiRelationAttribute.java

@Override
public void loadAttribute(EntityMappings entityMappings, Element element, VariableElement variableElement,
        AnnotationMirror relationAnnotationMirror) {
    super.loadAttribute(entityMappings, element, variableElement, relationAnnotationMirror);

    AnnotationMirror orderByMirror = JavaSourceParserUtil.findAnnotation(element, "javax.persistence.OrderBy");
    if (orderByMirror != null) {
        Object value = JavaSourceParserUtil.findAnnotationValue(orderByMirror, "value");
        this.orderBy = value == null ? StringUtils.EMPTY : value.toString();
    }//from  w  w w  .j  av a 2 s.c o m

    this.mappedBy = (String) JavaSourceParserUtil.findAnnotationValue(relationAnnotationMirror, "mappedBy");
    this.collectionType = ((DeclaredType) variableElement.asType()).asElement().toString();
    Class collectionTypeClass = null;
    try {
        collectionTypeClass = Class.forName(this.collectionType);
    } catch (ClassNotFoundException ex) {
    }
    boolean mapKeyExist = collectionTypeClass != null && Map.class.isAssignableFrom(collectionTypeClass);

    DeclaredType declaredType = (DeclaredType) JavaSourceParserUtil
            .findAnnotationValue(relationAnnotationMirror, "targetEntity");
    if (declaredType == null) {
        if (variableElement.asType() instanceof ErrorType) { //variable => "<any>"
            throw new TypeNotPresentException(this.name + " type not found", null);
        }
        declaredType = (DeclaredType) ((DeclaredType) variableElement.asType()).getTypeArguments()
                .get(mapKeyExist ? 1 : 0);
    }
    this.targetEntity = declaredType.asElement().getSimpleName().toString();

    if (mapKeyExist) {
        this.mapKey = new MapKey().load(element, null);
        this.mapKeyType = this.mapKey != null ? MapKeyType.EXT : MapKeyType.NEW;

        DeclaredType keyDeclaredType = MapKeyClass.getDeclaredType(element);
        if (keyDeclaredType == null) {
            keyDeclaredType = (DeclaredType) ((DeclaredType) variableElement.asType()).getTypeArguments()
                    .get(0);
        }
        if (isEmbeddableClass(keyDeclaredType.asElement())) {
            loadEmbeddableClass(entityMappings, element, variableElement, keyDeclaredType);
            this.mapKeyAttributeType = getSimpleClassName(keyDeclaredType.toString());
        } else if (isEntityClass(keyDeclaredType.asElement())) {
            loadEntityClass(entityMappings, element, variableElement, keyDeclaredType);
            this.mapKeyAttributeType = getSimpleClassName(keyDeclaredType.toString());
        } else {
            this.mapKeyAttributeType = keyDeclaredType.toString();
        }

        this.mapKeyColumn = new Column().load(element,
                JavaSourceParserUtil.findAnnotation(element, MAP_KEY_COLUMN_FQN));
        this.mapKeyTemporal = TemporalType.load(element,
                JavaSourceParserUtil.findAnnotation(element, MAP_KEY_TEMPORAL_FQN));
        this.mapKeyEnumerated = EnumType.load(element,
                JavaSourceParserUtil.findAnnotation(element, MAP_KEY_ENUMERATED_FQN));

        AnnotationMirror joinColumnsAnnotationMirror = JavaSourceParserUtil.findAnnotation(element,
                "javax.persistence.MapKeyJoinColumns");
        if (joinColumnsAnnotationMirror != null) {
            List joinColumnsAnnot = (List) JavaSourceParserUtil.findAnnotationValue(joinColumnsAnnotationMirror,
                    "value");
            if (joinColumnsAnnot != null) {
                for (Object joinColumnObj : joinColumnsAnnot) {
                    this.getMapKeyJoinColumn()
                            .add(new JoinColumn().load(element, (AnnotationMirror) joinColumnObj));
                }
            }
        } else {
            AnnotationMirror joinColumnAnnotationMirror = JavaSourceParserUtil.findAnnotation(element,
                    "javax.persistence.MapKeyJoinColumn");
            if (joinColumnAnnotationMirror != null) {
                this.getMapKeyJoinColumn().add(new JoinColumn().load(element, joinColumnAnnotationMirror));
            }
        }

        this.mapKeyForeignKey = ForeignKey.load(element, null);
        this.getMapKeyAttributeOverride().addAll(AttributeOverride.load(element));

    }
}

From source file:org.adminmap.core.rpc.Request.java

/**
 *  Prints a method prototype in the following format:
 *  <p>//from w w  w.ja va 2s  . c  om
 *  methodName(Type, Type, ...)
 */
public void printPrototype() {

    if (method == null || method.trim().isEmpty()) {
        System.out.println("No method name specified in the request");
        return;
    }

    if (params == null || params.length() == 0) {
        System.out.println(method + "()");
        return;
    }

    System.out.print(method + "(");

    for (int i = 0; i < params.length(); i++) {

        final JSONObject parameters = params.getJSONObject(i);
        for (String className : JSONObject.getNames(parameters)) {

            Class<?> classProperty = null;
            try {
                classProperty = Class.forName(className);
            } catch (ClassNotFoundException e) {
                throw new TypeNotPresentException(className, e);
            }

            System.out.print(classProperty.getSimpleName());
            if (i < params.length() - 1)
                System.out.print(", ");
        }
    } // end of for()

    System.out.println(")");

}

From source file:io.github.jeddict.jpa.spec.extend.MultiRelationAttribute.java

@Override
@Deprecated//from ww w. j  a va2s.c om
public void loadAttribute(EntityMappings entityMappings, Element element, VariableElement variableElement,
        ExecutableElement getterElement, AnnotationMirror relationAnnotationMirror) {
    super.loadAttribute(entityMappings, element, variableElement, getterElement, relationAnnotationMirror);

    this.mappedBy = (String) JavaSourceParserUtil.findAnnotationValue(relationAnnotationMirror, "mappedBy");
    this.orderBy = OrderBy.load(element, variableElement);
    this.orderColumn = OrderColumn.load(element, variableElement);
    this.collectionType = ((DeclaredType) variableElement.asType()).asElement().toString();
    Class collectionTypeClass = null;
    try {
        collectionTypeClass = Class.forName(this.collectionType);
    } catch (ClassNotFoundException ex) {
    }
    boolean mapKeyExist = collectionTypeClass != null && Map.class.isAssignableFrom(collectionTypeClass);

    DeclaredType declaredType = (DeclaredType) JavaSourceParserUtil
            .findAnnotationValue(relationAnnotationMirror, "targetEntity");
    if (declaredType == null) {
        if (variableElement.asType() instanceof ErrorType) { //variable => "<any>"
            throw new TypeNotPresentException(this.name + " type not found", null);
        }
        declaredType = (DeclaredType) ((DeclaredType) variableElement.asType()).getTypeArguments()
                .get(mapKeyExist ? 1 : 0);
    }
    String fqn = declaredType.asElement().asType().toString();
    this.targetEntityPackage = getPackageName(fqn);
    this.targetEntity = getSimpleClassName(fqn);

    if (mapKeyExist) {
        this.mapKeyConvert = Convert.load(element, mapKeyExist, true);
        this.mapKey = new MapKey().load(element, null);
        this.mapKeyType = this.mapKey != null ? MapKeyType.EXT : MapKeyType.NEW;

        DeclaredType keyDeclaredType = MapKeyClass.getDeclaredType(element);
        if (keyDeclaredType == null) {
            keyDeclaredType = (DeclaredType) ((DeclaredType) variableElement.asType()).getTypeArguments()
                    .get(0);
        }
        if (isEmbeddable(keyDeclaredType.asElement())) {
            loadEmbeddableClass(entityMappings, element, variableElement, keyDeclaredType);
            this.mapKeyAttributeType = getSimpleClassName(keyDeclaredType.toString());
        } else if (isEntity(keyDeclaredType.asElement())) {
            loadEntity(entityMappings, element, variableElement, keyDeclaredType);
            this.mapKeyAttributeType = getSimpleClassName(keyDeclaredType.toString());
        } else {
            this.mapKeyAttributeType = keyDeclaredType.toString();
        }

        this.mapKeyColumn = new Column().load(element,
                JavaSourceParserUtil.findAnnotation(element, MAP_KEY_COLUMN_FQN));
        this.mapKeyTemporal = TemporalType.load(element,
                JavaSourceParserUtil.findAnnotation(element, MAP_KEY_TEMPORAL_FQN));
        this.mapKeyEnumerated = EnumType.load(element,
                JavaSourceParserUtil.findAnnotation(element, MAP_KEY_ENUMERATED_FQN));

        AnnotationMirror joinColumnsAnnotationMirror = JavaSourceParserUtil.findAnnotation(element,
                MAP_KEY_JOIN_COLUMNS_FQN);
        if (joinColumnsAnnotationMirror != null) {
            List joinColumnsAnnot = (List) JavaSourceParserUtil.findAnnotationValue(joinColumnsAnnotationMirror,
                    "value");
            if (joinColumnsAnnot != null) {
                for (Object joinColumnObj : joinColumnsAnnot) {
                    this.getMapKeyJoinColumn()
                            .add(new JoinColumn().load(element, (AnnotationMirror) joinColumnObj));
                }
            }
        } else {
            AnnotationMirror joinColumnAnnotationMirror = JavaSourceParserUtil.findAnnotation(element,
                    MAP_KEY_JOIN_COLUMN_FQN);
            if (joinColumnAnnotationMirror != null) {
                this.getMapKeyJoinColumn().add(new JoinColumn().load(element, joinColumnAnnotationMirror));
            }
        }

        this.mapKeyForeignKey = ForeignKey.load(element, null);
        this.getMapKeyAttributeOverride().addAll(AttributeOverride.load(element));

    }
}