Example usage for org.apache.commons.lang3 ClassUtils getShortClassName

List of usage examples for org.apache.commons.lang3 ClassUtils getShortClassName

Introduction

In this page you can find the example usage for org.apache.commons.lang3 ClassUtils getShortClassName.

Prototype

public static String getShortClassName(String className) 

Source Link

Document

Gets the class name minus the package name from a String.

The string passed in is assumed to be a class name - it is not checked.

Note that this method differs from Class.getSimpleName() in that this will return "Map.Entry" whilst the java.lang.Class variant will simply return "Entry" .

Usage

From source file:com.genologics.ri.stepconfiguration.GenericTypeLink.java

@Override
public String toString() {
    StringBuilder sb = new StringBuilder(32);
    sb.append(ClassUtils.getShortClassName(getClass()));
    if (value != null) {
        sb.append(':').append(value);
    }//ww  w.  ja  v a2 s.c o m
    return sb.toString();
}

From source file:controllers.factories.tests.ViewModelFactoryTest.java

@Test
public void testCreateWithModelWorksWhenOwnViewExists() {
    OpinionDocument model = (OpinionDocument) new OpinionDocument().setPolarity(-0.9)
            .setContent("some content");
    ViewModelFactory factory = new ViewModelFactory();
    ViewModel viewModel = factory.setModel(model).create();

    assertThat(viewModel).isNotNull();/*w  w  w .  java2  s  .  c  o m*/
    assertThat(viewModel).isInstanceOf(OpinionDocumentModel.class);

    OpinionDocumentModel typedViewModel = (OpinionDocumentModel) viewModel;
    assertThat(typedViewModel.type).isEqualTo(ClassUtils.getShortClassName(model.getClass()));
    assertThat(typedViewModel.content).isEqualTo(model.getContent());
    assertThat(typedViewModel.polarity).isEqualTo(model.getPolarity());
}

From source file:com.genologics.ri.processtype.Field.java

@Override
public String toString() {
    StringBuilder sb = new StringBuilder(32);
    sb.append(ClassUtils.getShortClassName(getClass()));
    if (name != null) {
        sb.append(':').append(name);
    }//from  www. ja  v  a 2s .c o m
    return sb.toString();
}

From source file:com.datatorrent.lib.io.SimpleSinglePortInputOperator.java

@Override
public final void activate(OperatorContext ctx) {
    isActive = true;//from ww w. j  a v  a2  s  . c  om
    if (this instanceof Runnable) {
        ioThread = new Thread((Runnable) this, "io-" + ClassUtils.getShortClassName(this.getClass()));
        ioThread.start();
    }
}

From source file:com.xylocore.copybook.generator.CopybookClassGenerator.java

/**
 * FILLIN/*from   w  w w.j  av  a 2s  .c  om*/
 */
public void generate() {
    validateEnvironment();

    try {
        processCopybook();

        Metadata myMetadata = environment.getMetadata();
        String myPackageName = ClassUtils.getPackageName(myMetadata.getClassName());
        String myClassName = ClassUtils.getShortClassName(myMetadata.getClassName());
        File myGenerationRootDirectory = new File(environment.getGenerationRootDirectory());

        File myOutputDirectory = StringUtils.isNotEmpty(myPackageName)
                ? new File(myGenerationRootDirectory, myPackageName.replace('.', File.separatorChar))
                : myGenerationRootDirectory;
        myOutputDirectory.mkdirs();

        File myOutputFile = new File(myOutputDirectory, myClassName + ".java");

        try (FileWriter myWriter = new FileWriter(myOutputFile)) {
            selectElementsOfInterest();

            copybookClassEmitter.generate(environment, copybook, elementsOfInterest, myWriter);
        } catch (IOException myIOException) {
            // TODO: throw an appropriate exception
        }
    } catch (Exception myException) {
        // TODO: throw an appropriate exception
        throw new RuntimeException(myException.getMessage(), myException);
    }
}

From source file:net.danizen.norconex.committer.kafka.KafkaCommitterTest.java

@Test
public void testValidation() throws IOException {
    CountingConsoleAppender appender = new CountingConsoleAppender();
    appender.startCountingFor(XMLConfigurationUtil.class, Level.WARN);
    try (Reader r = new InputStreamReader(
            getClass().getResourceAsStream(ClassUtils.getShortClassName(getClass()) + ".xml"))) {
        XMLConfigurationUtil.newInstance(r);
    } finally {/*from w  ww  .  j a v  a  2s  .c  o  m*/
        appender.stopCountingFor(XMLConfigurationUtil.class);
    }
    Assert.assertEquals("Validation warnings/errors were found.", 0, appender.getCount());
}

From source file:controllers.factories.ViewModelFactory.java

private ViewModel createSpecific(Object model) {
    Reflections reflections = new Reflections("models",
            Play.application().getWrappedApplication().classloader());
    Set<Class<? extends ViewModel>> viewModelClasses = reflections.getSubTypesOf(ViewModel.class);

    List<Class<?>> modelCandidateClasses = ClassUtils.getAllSuperclasses(model.getClass());
    modelCandidateClasses.add(0, model.getClass());

    Class<?> availableModelClass = null;
    Class<? extends ViewModel> availableViewModelClass = null;
    for (final Class<?> modelSuperclass : modelCandidateClasses) {
        availableViewModelClass = Iterables.find(viewModelClasses, new Predicate<Class<? extends ViewModel>>() {
            @Override/* w w  w  . j a  va 2 s.  co  m*/
            public boolean apply(Class<? extends ViewModel> viewModelClass) {
                return ClassUtils.getShortClassName(viewModelClass)
                        .equals(ClassUtils.getShortClassName(modelSuperclass) + "Model");
            }
        }, null);

        if (availableViewModelClass != null) {
            availableModelClass = modelSuperclass;
            break;
        }
    }

    if (availableModelClass == null) {
        return null;
    }

    try {
        Constructor<? extends ViewModel> constructor = availableViewModelClass
                .getConstructor(availableModelClass);
        return constructor.newInstance(model);
    } catch (Throwable e) {
        return null;
    }
}

From source file:controllers.factories.tests.ViewModelFactoryTest.java

@Test
public void testCreateWithModelWorksWhenOnlySuperclassViewExists() {
    AspectExpression model = (AspectExpression) new AspectExpression().setContent("some content");
    ViewModelFactory factory = new ViewModelFactory();
    ViewModel viewModel = factory.setModel(model).create();

    assertThat(viewModel).isNotNull();/*from  w  w  w  .  ja v  a  2 s . c om*/
    assertThat(viewModel).isInstanceOf(PersistentDocumentModel.class);

    PersistentDocumentModel typedViewModel = (PersistentDocumentModel) viewModel;
    assertThat(typedViewModel.type).isEqualTo(ClassUtils.getShortClassName(model.getClass()));
    assertThat(typedViewModel.content).isEqualTo(model.getContent());
}

From source file:controllers.factories.tests.ViewModelFactoryTest.java

@Test
public void testCreateWithJsonWorksWhenOwnViewExists() {
    JsonNode json = Json.parse("{" + "\"type\": \"OpinionDocument\"," + "\"content\": \"some content\"" + "}");
    ViewModelFactory factory = new ViewModelFactory();
    ViewModel viewModel = factory.setJson(json).create();

    assertThat(viewModel).isNotNull();//w w w  .ja v  a 2s.  c  o m
    assertThat(viewModel).isInstanceOf(OpinionDocumentModel.class);

    PersistentDocumentModel typedViewModel = (PersistentDocumentModel) viewModel;
    assertThat(typedViewModel.type).isEqualTo(ClassUtils.getShortClassName(OpinionDocument.class));
    assertThat(typedViewModel.content).isEqualTo(json.get("content").asText());
}

From source file:controllers.factories.ViewModelFactory.java

@SuppressWarnings("unchecked")
private ViewModel createSpecific(JsonNode json) {
    if (!json.has("type")) {
        return null;
    }//  w  w  w  .  ja  v a 2 s  .c o  m

    String type = json.get("type").asText();
    if (StringUtils.isEmpty(type)) {
        return null;
    }

    if (type.endsWith(MODEL_SUFFIX)) {
        StringUtils.stripEnd(type, MODEL_SUFFIX);
    }

    final String typeName = type;
    Reflections reflections = new Reflections("edu.sabanciuniv.sentilab.sare.models");
    Class<? extends PersistentObject> model = Iterables.find(reflections.getSubTypesOf(PersistentObject.class),
            new Predicate<Class<? extends PersistentObject>>() {
                @Override
                public boolean apply(@Nullable Class<? extends PersistentObject> input) {
                    return typeName.equals(ClassUtils.getShortClassName(input));
                }
            }, null);

    Class<? extends ViewModel> availableViewModelClass = null;
    while (model != null) {
        final String modelName = ClassUtils.getShortClassName(model);
        reflections = new Reflections("models", Play.application().classloader());
        availableViewModelClass = Iterables.find(reflections.getSubTypesOf(ViewModel.class),
                new Predicate<Class<? extends ViewModel>>() {
                    @Override
                    public boolean apply(Class<? extends ViewModel> viewModelClass) {
                        return ClassUtils.getShortClassName(viewModelClass).equals(modelName + MODEL_SUFFIX);
                    }
                }, null);

        if (availableViewModelClass != null) {
            break;
        }

        model = (Class<? extends PersistentObject>) model.getSuperclass();
        if (!PersistentObject.class.isAssignableFrom(model)) {
            break;
        }
    }

    if (availableViewModelClass == null) {
        return null;
    }

    return Json.fromJson(json, availableViewModelClass);
}