List of usage examples for java.lang ReflectiveOperationException getMessage
public String getMessage()
From source file:Main.java
private static final Field getFieldOrDie(Class<?> clazz, String fieldName) { try {// www .ja v a 2s .c om Field field = clazz.getDeclaredField(fieldName); field.setAccessible(true); return field; } catch (ReflectiveOperationException e) { throw new LinkageError(e.getMessage()); } }
From source file:edu.usc.goffish.gofs.namenode.NameNodeProvider.java
public static IInternalNameNode loadNameNodeFromConfig(Configuration config, String nameNodeTypeKey, String nameNodeLocationKey) throws ClassNotFoundException, ReflectiveOperationException { // retrieve name node type Class<? extends IInternalNameNode> nameNodeType; {//from ww w .j a v a 2 s . co m String nameNodeTypeString = config.getString(nameNodeTypeKey); if (nameNodeTypeString == null) { throw new ConversionException("Config must contain key " + nameNodeTypeKey); } try { nameNodeType = NameNodeProvider.loadNameNodeType(nameNodeTypeString); } catch (ReflectiveOperationException e) { throw new ConversionException( "Config key " + nameNodeTypeKey + " has invalid format - " + e.getMessage()); } } // retrieve name node location URI nameNodeLocation; { String nameNodeLocationString = config.getString(nameNodeLocationKey); if (nameNodeLocationString == null) { throw new ConversionException("Config must contain key " + nameNodeLocationKey); } try { nameNodeLocation = new URI(nameNodeLocationString); } catch (URISyntaxException e) { throw new ConversionException( "Config key " + nameNodeLocationKey + " has invalid format - " + e.getMessage()); } } return loadNameNode(nameNodeType, nameNodeLocation); }
From source file:jfix.util.Reflections.java
/** * Returns a new instance for given fully qualified classname. *//*from w ww.j a v a2s . c o m*/ public static Object newInstance(String classname) { try { return Class.forName(classname).newInstance(); } catch (ReflectiveOperationException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:de.hska.ld.core.service.annotation.handler.LoggingHandler.java
private LogEntry extractArgs(Args args, Logging logging) { List<Long> idList = new ArrayList<>(); List<Class> referencesList = new ArrayList<>(); int referencesCounter = 0; for (int i = 0; i < args.parameterValues.length; i++) { Object arg = args.parameterValues[i]; if (arg != null && arg.getClass().isAnnotationPresent(Entity.class)) { try { Field field = arg.getClass().getSuperclass().getDeclaredField("id"); field.setAccessible(true); Long id = (Long) field.get(arg); idList.add(id);// www . j a va 2 s .c o m referencesList.add(arg.getClass()); } catch (ReflectiveOperationException e) { LOGGER.error(e.getMessage()); } } else if (arg instanceof Long) { if (referencesCounter >= logging.references().length) { LOGGER.error("The given ID has no annotated referenced class parameter"); } Class reference = logging.references()[referencesCounter]; if (reference != null) { idList.add((Long) arg); referencesList.add(reference); } referencesCounter++; } else if (arg == null && Long.class.equals(args.parameterTypes[i])) { referencesCounter++; } } if (idList.size() > 0 && referencesList.size() == idList.size()) { LogEntry logEntry = new LogEntry(); logEntry.setIds(idList.toArray(new Long[idList.size()])); logEntry.setReferences(referencesList.toArray(new Class[referencesList.size()])); return logEntry; } else { LOGGER.error(""); return null; } }
From source file:io.sqp.core.jackson.JacksonMessageDecoder.java
private SqpMessage decode(MessageType type, DataFormat format, ValueReader reader) throws DecodingException { Class<? extends SqpMessage> msgType = type.getType(); if (!type.hasContent()) { try {/* w w w .ja va 2s . c o m*/ return msgType.newInstance(); } catch (ReflectiveOperationException e) { throw new DecodingException("Couldn't create a message of type " + msgType, e); } } ObjectMapper mapper = JacksonObjectMapperFactory.objectMapper(format); try { return reader.readValue(mapper, msgType); } catch (IOException e) { throw new DecodingException("Error to decoding message of type " + msgType + ": " + e.getMessage(), e); } }
From source file:net.sourceforge.pmd.RuleSetFactory.java
/** * Parse a ruleset node to construct a RuleSet. * * @param ruleSetReferenceId/*from w w w . j ava2s . c o m*/ * The RuleSetReferenceId of the RuleSet being parsed. * @param withDeprecatedRuleReferences * whether rule references that are deprecated should be ignored * or not * @return The new RuleSet. */ private RuleSet parseRuleSetNode(RuleSetReferenceId ruleSetReferenceId, boolean withDeprecatedRuleReferences) throws RuleSetNotFoundException { try (CheckedInputStream inputStream = new CheckedInputStream( ruleSetReferenceId.getInputStream(resourceLoader), new Adler32());) { if (!ruleSetReferenceId.isExternal()) { throw new IllegalArgumentException( "Cannot parse a RuleSet from a non-external reference: <" + ruleSetReferenceId + ">."); } DocumentBuilder builder = createDocumentBuilder(); InputSource inputSource; if (compatibilityFilter != null) { inputSource = new InputSource(compatibilityFilter.filterRuleSetFile(inputStream)); } else { inputSource = new InputSource(inputStream); } Document document = builder.parse(inputSource); Element ruleSetElement = document.getDocumentElement(); RuleSetBuilder ruleSetBuilder = new RuleSetBuilder(inputStream.getChecksum().getValue()) .withFileName(ruleSetReferenceId.getRuleSetFileName()); if (ruleSetElement.hasAttribute("name")) { ruleSetBuilder.withName(ruleSetElement.getAttribute("name")); } else { LOG.warning("RuleSet name is missing. Future versions of PMD will require it."); ruleSetBuilder.withName("Missing RuleSet Name"); } NodeList nodeList = ruleSetElement.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { String nodeName = node.getNodeName(); if (DESCRIPTION.equals(nodeName)) { ruleSetBuilder.withDescription(parseTextNode(node)); } else if ("include-pattern".equals(nodeName)) { ruleSetBuilder.addIncludePattern(parseTextNode(node)); } else if ("exclude-pattern".equals(nodeName)) { ruleSetBuilder.addExcludePattern(parseTextNode(node)); } else if ("rule".equals(nodeName)) { parseRuleNode(ruleSetReferenceId, ruleSetBuilder, node, withDeprecatedRuleReferences); } else { throw new IllegalArgumentException(UNEXPECTED_ELEMENT + node.getNodeName() + "> encountered as child of <ruleset> element."); } } } if (!ruleSetBuilder.hasDescription()) { LOG.warning("RuleSet description is missing. Future versions of PMD will require it."); ruleSetBuilder.withDescription("Missing description"); } ruleSetBuilder.filterRulesByPriority(minimumPriority); return ruleSetBuilder.build(); } catch (ReflectiveOperationException ex) { ex.printStackTrace(); throw new RuntimeException("Couldn't find the class " + ex.getMessage(), ex); } catch (ParserConfigurationException | IOException | SAXException ex) { ex.printStackTrace(); throw new RuntimeException("Couldn't read the ruleset " + ruleSetReferenceId + ": " + ex.getMessage(), ex); } }
From source file:org.nuxeo.ecm.platform.ui.web.component.file.JSFBlobUploaderDescriptor.java
public JSFBlobUploader getJSFBlobUploader() { if (instance != null) { return instance; }/* w w w . ja v a 2s . c om*/ if (klass == null) { return null; } try { Constructor<JSFBlobUploader> ctor = klass.getDeclaredConstructor(String.class); instance = ctor.newInstance(id); return instance; } catch (ReflectiveOperationException e) { throw new RuntimeException("Cannot instantiate class: " + klass, e); } catch (IllegalStateException e) { log.error("Cannot instantiate " + klass.getName() + ", " + e.getMessage()); log.debug(e, e); return null; } }
From source file:org.nuxeo.ecm.platform.ui.web.restAPI.ThreadSafeRestletFilter.java
@Override protected void doHandle(Request request, Response response) { if (getNext() != null) { try {/* ww w . j a v a 2 s . c o m*/ // get a new instance of the restlet each time it is called. Restlet next = getNext().getClass().newInstance(); next.handle(request, response); } catch (ReflectiveOperationException e) { log.error("Restlet handling error", e); response.setEntity("Error while getting a new Restlet instance: " + e.getMessage(), MediaType.TEXT_PLAIN); } } else { response.setStatus(Status.CLIENT_ERROR_NOT_FOUND); } }