List of usage examples for java.lang Class getSimpleName
public String getSimpleName()
From source file:com.cloud.api.ApiDispatcher.java
public static void plugService(Field field, BaseCmd cmd) { Class<?> fc = field.getType(); Object instance = null;//from ww w. j a v a 2s.c o m if (instance == null) { throw new CloudRuntimeException("Unable to plug service " + fc.getSimpleName() + " in command " + cmd.getClass().getSimpleName()); } try { field.setAccessible(true); field.set(cmd, instance); } catch (IllegalArgumentException e) { s_logger.error("IllegalArgumentException at plugService for command " + cmd.getCommandName() + ", field " + field.getName()); throw new CloudRuntimeException("Internal error at plugService for command " + cmd.getCommandName() + " [Illegal argumet at field " + field.getName() + "]"); } catch (IllegalAccessException e) { s_logger.error("Error at plugService for command " + cmd.getCommandName() + ", field " + field.getName() + " is not accessible."); throw new CloudRuntimeException("Internal error at plugService for command " + cmd.getCommandName() + " [field " + field.getName() + " is not accessible]"); } }
From source file:com.yiji.openapi.sdk.util.Reflections.java
public static Set<String> getFieldNames(Class<?> pojoClass) { Set<String> propertyNames = new HashSet<String>(); Class<?> clazz = pojoClass; do {// w ww. j av a 2 s . c o m Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { if (!Modifier.isStatic(field.getModifiers())) { propertyNames.add(field.getName()); } } clazz = clazz.getSuperclass(); } while (clazz != null && !clazz.getSimpleName().equalsIgnoreCase("Object")); return propertyNames; }
From source file:com.github.gekoh.yagen.util.MappingUtils.java
public static String getJpaEntityName(Class entityClass) { Entity entity = (Entity) entityClass.getAnnotation(Entity.class); if (entity == null) { return null; }/*w ww . j a v a 2 s . c om*/ return StringUtils.isNotEmpty(entity.name()) ? entity.name() : entityClass.getSimpleName(); }
From source file:de.thischwa.pmcms.server.ContextUtil.java
public static String getTypDescriptor(final Class<?> clazz) { if (clazz.equals(Page.class)) return Constants.LINK_TYPE_PAGE; if (clazz.equals(Gallery.class)) return Constants.LINK_TYPE_GALLERY; if (clazz.equals(Image.class)) return Constants.LINK_TYPE_IMAGE; if (clazz.equals(Macro.class)) return Constants.LINK_TYPE_MACRO; if (clazz.equals(Template.class)) return Constants.LINK_TYPE_TEMPLATE; throw new IllegalArgumentException("Unknown pojo class: " + clazz.getSimpleName()); }
From source file:de.fu_berlin.inf.dpp.misc.pico.DotGraphMonitor.java
public static String getColorOld(Class<?> clazz, HashMap<String, String> colors) { String name;/*from ww w . ja v a2 s .c o m*/ Package myPackage = clazz.getPackage(); if (myPackage == null) { name = "misc"; } else { name = myPackage.getName(); } while (name != null && name.length() > 0) { String color = colors.get(name); if (color != null) { return " \"" + clazz.getSimpleName() + "\" [color=" + color + "];\n"; } int index = name.lastIndexOf('.'); if (index == -1) break; name = name.substring(0, index); } return null; }
From source file:labr_client.xml.ObjToXML.java
public static void saveProfile(Component[] comps, String profile) { try {/* w ww .j a va 2s . co m*/ if (comps != null) { JAXBContext context = JAXBContext.newInstance(LabrRequest.class); Marshaller m = context.createMarshaller(); //for pretty-print XML in JAXB m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); LabrRequest request = new LabrRequest(); for (Component comp : comps) { if (comp.getName() != null) { if (comp.getName().equals("name")) { request.patient.name.setValue(((JTextField) comp).getText()); request.patient.name.setX(comp.getX()); request.patient.name.setY(comp.getY()); request.patient.name.setWidth(comp.getWidth()); } else if (comp.getName().equals("firstName")) { request.patient.firstName.setValue(((JTextField) comp).getText()); request.patient.firstName.setX(comp.getX()); request.patient.firstName.setY(comp.getY()); request.patient.firstName.setWidth(comp.getWidth()); } else if (comp.getName().equals("birthDate")) { request.patient.birthDate.setValue(((JFormattedTextField) comp).getText()); request.patient.birthDate.setX(comp.getX()); request.patient.birthDate.setY(comp.getY()); request.patient.birthDate.setWidth(comp.getWidth()); } else if (comp.getName().equals("gender")) { request.patient.gender.setValue((String) (((JComboBox) comp).getSelectedItem())); request.patient.gender.setX(comp.getX()); request.patient.gender.setY(comp.getY()); } else if (comp.getName().equals("straatAndNumber")) { request.patient.straatAndNumber.setValue(((JTextField) comp).getText()); request.patient.straatAndNumber.setX(comp.getX()); request.patient.straatAndNumber.setY(comp.getY()); request.patient.straatAndNumber.setWidth(comp.getWidth()); } else if (comp.getName().equals("zip")) { request.patient.zip.setValue(((JTextField) comp).getText()); request.patient.zip.setX(comp.getX()); request.patient.zip.setY(comp.getY()); request.patient.zip.setWidth(comp.getWidth()); } else if (comp.getName().equals("city")) { request.patient.city.setValue(((JTextField) comp).getText()); request.patient.city.setX(comp.getX()); request.patient.city.setY(comp.getY()); request.patient.city.setWidth(comp.getWidth()); } else if (comp.getName().equals("country")) { request.patient.country.setValue((String) (((JComboBox) comp).getSelectedItem())); request.patient.country.setX(comp.getX()); request.patient.country.setY(comp.getY()); } else if (comp.getName().equals("nationalNumber")) { request.patient.nationalNumber.setValue(((JTextField) comp).getText()); request.patient.nationalNumber.setX(comp.getX()); request.patient.nationalNumber.setY(comp.getY()); request.patient.nationalNumber.setWidth(comp.getWidth()); } else if (comp.getName().equals("Save")) { JButton jbut = (JButton) comp; ImageIcon icon = (ImageIcon) jbut.getIcon(); request.buttons.save.setX(comp.getX()); request.buttons.save.setY(comp.getY()); request.buttons.save.setValue("Save"); if (icon != null) { request.buttons.save.setIcon(icon.getDescription()); } } else if (comp.getName().equals("Search")) { } else if (comp.getName().equals("saveAndSend")) { request.patient.nationalNumber.setValue(((JTextField) comp).getText()); request.patient.nationalNumber.setX(comp.getX()); request.patient.nationalNumber.setY(comp.getY()); request.patient.nationalNumber.setWidth(comp.getWidth()); } else if (comp.getName().equals("print")) { request.patient.nationalNumber.setValue(((JTextField) comp).getText()); request.patient.nationalNumber.setX(comp.getX()); request.patient.nationalNumber.setY(comp.getY()); request.patient.nationalNumber.setWidth(comp.getWidth()); } else { Class<? extends Component> c = comp.getClass(); if (c.getSimpleName().equals("JLabel")) { JLabel lbl = (JLabel) comp; LabrXMLLabel l = new LabrXMLLabel(); l.setColor(String.valueOf(lbl.getForeground().getRGB())); l.setSize(lbl.getFont().getSize()); l.setId(lbl.getName()); l.setValue(lbl.getText()); l.setX(lbl.getX()); l.setY(lbl.getY()); request.labels.getLabel().add(l); } ; if (c.getSimpleName().equals("JCheckBox")) { JCheckBox chbx = (JCheckBox) comp; LabrXMLRequest req = new LabrXMLRequest(); req.setX(chbx.getX()); req.setY(chbx.getY()); req.setLoinc(chbx.getName()); req.setValue(chbx.getText()); req.setSelected(chbx.isSelected()); request.requests.getRequest().add(req); } ; if (c.getSimpleName().equals("JTextBox")) { } ; } } } m.marshal(request, new File(PublicVars.getUserData()[9] + "\\" + profile + ".xml")); } } catch (JAXBException e) { e.printStackTrace(); } }
From source file:labr_client.xml.ObjToXML.java
public static LabrRequest saveLabrRequest(Component[] comps) { try {/*from w w w. j av a2 s . c o m*/ if (comps != null) { JAXBContext context = JAXBContext.newInstance(LabrRequest.class); Marshaller m = context.createMarshaller(); //for pretty-print XML in JAXB m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); LabrRequest request = new LabrRequest(); for (Component comp : comps) { if (comp.getName() != null) { if (comp.getName().equals("name")) { request.patient.name.setValue(((JTextField) comp).getText()); request.patient.name.setX(comp.getX()); request.patient.name.setY(comp.getY()); request.patient.name.setWidth(comp.getWidth()); } else if (comp.getName().equals("firstName")) { request.patient.firstName.setValue(((JTextField) comp).getText()); request.patient.firstName.setX(comp.getX()); request.patient.firstName.setY(comp.getY()); request.patient.firstName.setWidth(comp.getWidth()); } else if (comp.getName().equals("birthDate")) { request.patient.birthDate.setValue(((JFormattedTextField) comp).getText()); request.patient.birthDate.setX(comp.getX()); request.patient.birthDate.setY(comp.getY()); request.patient.birthDate.setWidth(comp.getWidth()); } else if (comp.getName().equals("gender")) { request.patient.gender.setValue((String) (((JComboBox) comp).getSelectedItem())); request.patient.gender.setX(comp.getX()); request.patient.gender.setY(comp.getY()); } else if (comp.getName().equals("straatAndNumber")) { request.patient.straatAndNumber.setValue(((JTextField) comp).getText()); request.patient.straatAndNumber.setX(comp.getX()); request.patient.straatAndNumber.setY(comp.getY()); request.patient.straatAndNumber.setWidth(comp.getWidth()); } else if (comp.getName().equals("zip")) { request.patient.zip.setValue(((JTextField) comp).getText()); request.patient.zip.setX(comp.getX()); request.patient.zip.setY(comp.getY()); request.patient.zip.setWidth(comp.getWidth()); } else if (comp.getName().equals("city")) { request.patient.city.setValue(((JTextField) comp).getText()); request.patient.city.setX(comp.getX()); request.patient.city.setY(comp.getY()); request.patient.city.setWidth(comp.getWidth()); } else if (comp.getName().equals("country")) { request.patient.country.setValue((String) (((JComboBox) comp).getSelectedItem())); request.patient.country.setX(comp.getX()); request.patient.country.setY(comp.getY()); } else if (comp.getName().equals("nationalNumber")) { request.patient.nationalNumber.setValue(((JTextField) comp).getText()); request.patient.nationalNumber.setX(comp.getX()); request.patient.nationalNumber.setY(comp.getY()); request.patient.nationalNumber.setWidth(comp.getWidth()); } else if (comp.getName().equals("Save")) { JButton jbut = (JButton) comp; ImageIcon icon = (ImageIcon) jbut.getIcon(); request.buttons.save.setX(comp.getX()); request.buttons.save.setY(comp.getY()); request.buttons.save.setValue("Save"); if (icon != null) { request.buttons.save.setIcon(icon.getDescription()); } } else if (comp.getName().equals("Search")) { } else if (comp.getName().equals("saveAndSend")) { request.patient.nationalNumber.setValue(((JTextField) comp).getText()); request.patient.nationalNumber.setX(comp.getX()); request.patient.nationalNumber.setY(comp.getY()); request.patient.nationalNumber.setWidth(comp.getWidth()); } else if (comp.getName().equals("print")) { request.patient.nationalNumber.setValue(((JTextField) comp).getText()); request.patient.nationalNumber.setX(comp.getX()); request.patient.nationalNumber.setY(comp.getY()); request.patient.nationalNumber.setWidth(comp.getWidth()); } else { Class<? extends Component> c = comp.getClass(); if (c.getSimpleName().equals("JLabel")) { JLabel lbl = (JLabel) comp; LabrXMLLabel l = new LabrXMLLabel(); l.setColor(String.valueOf(lbl.getForeground().getRGB())); l.setSize(lbl.getFont().getSize()); l.setId(lbl.getName()); l.setValue(lbl.getText()); l.setX(lbl.getX()); l.setY(lbl.getY()); request.labels.getLabel().add(l); } ; if (c.getSimpleName().equals("JCheckBox")) { JCheckBox chbx = (JCheckBox) comp; LabrXMLRequest req = new LabrXMLRequest(); req.setX(chbx.getX()); req.setY(chbx.getY()); req.setLoinc(chbx.getName()); req.setValue(chbx.getText()); req.setSelected(chbx.isSelected()); request.requests.getRequest().add(req); } ; if (c.getSimpleName().equals("JTextBox")) { } ; } } } SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddhhmm"); String date = dateFormat.format(Calendar.getInstance().getTime()); request.attributes.setTitle("LABR-" + PublicVars.getUserData()[5] + "-" + date); return request; } return null; } catch (JAXBException e) { e.printStackTrace(); return null; } }
From source file:com.netflix.spinnaker.halyard.config.model.v1.node.Node.java
/** * @param clazz the class to check against. * @return a NodeMatcher that matches all nodes of given clazz. *//* w ww.j a va 2s . co m*/ static public NodeMatcher thisNodeAcceptor(Class clazz) { return new NodeMatcher() { @Override public boolean matches(Node n) { return clazz.isAssignableFrom(n.getClass()); } @Override public String getName() { return "Match against [" + clazz.getSimpleName() + ":*]"; } }; }
From source file:com.simiacryptus.util.lang.CodeUtil.java
/** * Gets javadoc./*from ww w . j av a2 s . c o m*/ * * @param clazz the clazz * @return the javadoc */ public static String getJavadoc(@Nullable final Class<?> clazz) { try { if (null == clazz) return null; @Nullable final File source = com.simiacryptus.util.lang.CodeUtil.findFile(clazz); if (null == source) return clazz.getName() + " not found"; final List<String> lines = IOUtils.readLines(new FileInputStream(source), Charset.forName("UTF-8")); final int classDeclarationLine = IntStream.range(0, lines.size()) .filter(i -> lines.get(i).contains("class " + clazz.getSimpleName())).findFirst().getAsInt(); final int firstLine = IntStream.rangeClosed(1, classDeclarationLine).map(i -> classDeclarationLine - i) .filter(i -> !lines.get(i).matches("\\s*[/\\*@].*")).findFirst().orElse(-1) + 1; final String javadoc = lines.subList(firstLine, classDeclarationLine).stream() .filter(s -> s.matches("\\s*[/\\*].*")).map(s -> s.replaceFirst("^[ \t]*[/\\*]+", "").trim()) .filter(x -> !x.isEmpty()).reduce((a, b) -> a + "\n" + b).orElse(""); return javadoc.replaceAll("<p>", "\n"); } catch (@javax.annotation.Nonnull final Throwable e) { e.printStackTrace(); return ""; } }
From source file:br.gov.frameworkdemoiselle.ldap.internal.ClazzUtils.java
/** * Verify if a class or yours super classes have annotation, throw * EntryException if annotation is required and wasn't found. * /*from www . jav a 2 s.c om*/ * @param clazz * a class to be verified * @param aclazz * a Annotation class to be searched * @param required * define if should throw a EntryExpcetion when annotation was't * found. * */ public static boolean isAnnotationPresent(Class<?> clazz, Class<? extends Annotation> aclazz, boolean required) { for (Class<?> claz : getSuperClasses(clazz)) if (claz.isAnnotationPresent(aclazz)) return true; if (required) throw new EntryException("Entry " + clazz.getSimpleName() + " doesn't have @" + aclazz.getName()); return false; }