Example usage for java.lang Enum getDeclaringClass

List of usage examples for java.lang Enum getDeclaringClass

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public final Class<E> getDeclaringClass() 

Source Link

Document

Returns the Class object corresponding to this enum constant's enum type.

Usage

From source file:sk.lazyman.gizmo.web.PageTemplate.java

public static StringResourceModel createStringResourceStatic(Component component, Enum e) {
    String resourceKey = e.getDeclaringClass().getSimpleName() + "." + e.name();
    return createStringResourceStatic(component, resourceKey);
}

From source file:com.citytechinc.cq.component.touchuidialog.util.TouchUIDialogUtil.java

protected static final com.citytechinc.cq.component.touchuidialog.widget.selection.options.Option buildSelectionOptionForEnum(
        Enum<?> optionEnum, ClassPool classPool, String fieldName)
        throws SecurityException, NoSuchFieldException, NotFoundException, ClassNotFoundException {

    String text = optionEnum.name();
    String value = optionEnum.name();

    CtClass annotatedEnumClass = classPool.getCtClass(optionEnum.getDeclaringClass().getName());
    CtMember annotatedEnumField = annotatedEnumClass.getField(optionEnum.name());
    com.citytechinc.cq.component.annotations.Option optionAnnotation = (com.citytechinc.cq.component.annotations.Option) annotatedEnumField
            .getAnnotation(com.citytechinc.cq.component.annotations.Option.class);

    OptionParameters parameters = new OptionParameters();
    if (optionAnnotation != null) {
        if (StringUtils.isNotEmpty(optionAnnotation.text())) {
            text = optionAnnotation.text();
        }//from w  w w  .  j av a  2  s.  c  om
        if (StringUtils.isNotEmpty(optionAnnotation.value())) {
            value = optionAnnotation.value();
        }
        parameters.setSelected(optionAnnotation.selected());
    }
    parameters.setFieldName(fieldName);
    parameters.setText(text);
    parameters.setValue(value);
    return new com.citytechinc.cq.component.touchuidialog.widget.selection.options.Option(parameters);

}

From source file:com.heliosphere.athena.base.resource.bundle.ResourceBundleManager.java

/**
 * Retrieves a message from a resource bundle from its key.
 * <p>//from   w  w  w .  ja  va 2 s.  c  om
 * @param key Resource key to retrieve.
 * @param parameters Parameters to inject while formatting the message.
 * @return The formatted message.
 */
@SuppressWarnings("nls")
private static final String retrieve(final Enum<? extends IBundle> key, final Object... parameters) {
    if (!isInitialized) {
        initialize();
    }

    final Class<? extends IBundle> bundleClass = key.getDeclaringClass();

    if (BUNDLES.containsKey(bundleClass)) {
        try {
            return MessageFormat.format(BUNDLES.get(bundleClass).getString(((IBundle) key).getKey()),
                    parameters);
        } catch (MissingResourceException e) {
            throw new ResourceBundleException(BundleAthenaBase.ResourceBundleInvalidKey,
                    bundleClass.getSimpleName(), key.name(), bundleClass.getEnumConstants()[0].getKey(),
                    getLocale(), e);
        }
    }

    return "Resource bundle key cannot be found [bundle=" + bundleClass.getName() + ", key=" + key.name() + "]";
}

From source file:com.heliosphere.demeter.base.resource.bundle.ResourceBundleManager.java

/**
 * Retrieves a message from a resource bundle from its key.
 * <p>//ww  w .  j  a  v  a2 s . c  o  m
 * @param key Resource key to retrieve.
 * @param parameters Parameters to inject while formatting the message.
 * @return The formatted message.
 */
@SuppressWarnings("nls")
private static final String retrieve(final Enum<? extends IBundle> key, final Object... parameters) {
    if (!isInitialized) {
        initialize();
    }

    final Class<? extends IBundle> bundleClass = key.getDeclaringClass();

    if (BUNDLES.containsKey(bundleClass)) {
        try {
            return MessageFormat.format(BUNDLES.get(bundleClass).getString(((IBundle) key).getKey()),
                    parameters);
        } catch (MissingResourceException e) {
            throw new ResourceBundleException(BundleDemeterBase.ResourceBundleInvalidKey,
                    bundleClass.getSimpleName(), key.name(), bundleClass.getEnumConstants()[0].getKey(),
                    getLocale(), e);
        }
    }

    return "Resource bundle key cannot be found [bundle=" + bundleClass.getName() + ", key=" + key.name() + "]";
}

From source file:org.agiso.core.i18n.util.I18nUtils.java

public static String getCode(Enum<?> e) {
    try {// w w w . j a v  a  2s  . c  o  m
        return getCode(e.getClass().getField(e.name()));
    } catch (SecurityException ex) {
        // TODO Auto-generated catch block
        ex.printStackTrace();
    } catch (NoSuchFieldException ex) {
        // TODO Auto-generated catch block
        ex.printStackTrace();
    }
    return e.getDeclaringClass().getName() + CODE_SEPARATOR + e.name();
}

From source file:sk.lazyman.gizmo.web.PageTemplate.java

public StringResourceModel createStringResource(Enum e) {
    String resourceKey = e.getDeclaringClass().getSimpleName() + "." + e.name();
    return createStringResource(resourceKey);
}

From source file:com.evolveum.midpoint.gui.api.component.BasePanel.java

public StringResourceModel createStringResource(Enum e, String prefix, String nullKey) {
    StringBuilder sb = new StringBuilder();
    if (StringUtils.isNotEmpty(prefix)) {
        sb.append(prefix).append('.');
    }/*from   w ww . j  ava  2s. c  o m*/

    if (e == null) {
        if (StringUtils.isNotEmpty(nullKey)) {
            sb.append(nullKey);
        } else {
            sb = new StringBuilder();
        }
    } else {
        sb.append(e.getDeclaringClass().getSimpleName()).append('.');
        sb.append(e.name());
    }

    return createStringResource(sb.toString());
}

From source file:com.aliyun.odps.graph.local.TaskContextImpl.java

@Override
public Counter getCounter(Enum<?> name) {
    if (name == null) {
        throw new RuntimeException("ODPS-0730001: Counter name must be not null.");
    }/*from w ww . ja  v a  2  s  .  co  m*/
    return getCounter(name.getDeclaringClass().getName(), name.toString());
}

From source file:net.sourceforge.vulcan.spring.SpringBeanXmlEncoder.java

void encodeEnum(Element propertyNode, Enum<?> e) {
    final Element factory = new Element("bean");

    propertyNode.addContent(factory);/* www  .j  a v a2 s .  c  o m*/

    if (factoryExpert.needsFactory(e)) {
        encodeBeanByFactory(factory, e);
        return;
    }

    factory.setAttribute("class", FieldRetrievingFactoryBean.class.getName());

    final Element targetClass = new Element("property");
    targetClass.setAttribute("name", "targetClass");
    encodeAsValue(targetClass, e.getDeclaringClass().getName());

    final Element targetField = new Element("property");
    targetField.setAttribute("name", "targetField");
    encodeAsValue(targetField, e.name());

    factory.addContent(targetClass);
    factory.addContent(targetField);
}

From source file:com.chinamobile.bcbsp.bspcontroller.Counters.java

/**
 * Find the counter for the given enum. The same enum will always return the
 * same counter.//from   w  w w  .  j ava 2  s .c o  m
 * @param key
 *        the counter key
 * @return the matching counter object
 */
public synchronized Counter findCounter(Enum<?> key) {
    Counter counter = cache.get(key);
    if (counter == null) {
        Group group = getGroup(key.getDeclaringClass().getName());
        counter = group.getCounterForName(key.toString());
        cache.put(key, counter);
    }
    return counter;
}