List of usage examples for java.lang InstantiationException getMessage
public String getMessage()
From source file:de.tarent.maven.plugins.pkg.Utils.java
/** * Sets all unset properties, either to the values of the parent or to a * (hard-coded) default value if the property is not set in the parent. * //from ww w . j a v a 2s . co m * <p> * Using this method the packaging plugin can generate a merge of the * default and a distro-specific configuration. * </p> * * @param child * @param parent * @return * @throws MojoExecutionException */ public static TargetConfiguration mergeConfigurations(TargetConfiguration child, TargetConfiguration parent) throws MojoExecutionException { if (child.isReady()) { throw new MojoExecutionException( String.format("target configuration '%s' is already merged.", child.getTarget())); } Field[] allFields = TargetConfiguration.class.getDeclaredFields(); for (Field field : allFields) { field.setAccessible(true); if (field.getAnnotation(MergeMe.class) != null) { try { Object defaultValue = new Object(); IMerge merger; if (field.getAnnotation(MergeMe.class).defaultValueIsNull()) { defaultValue = null; } if (field.getType() == Properties.class) { if (defaultValue != null) { defaultValue = new Properties(); } merger = new PropertiesMerger(); } else if (field.getType() == List.class) { if (defaultValue != null) { defaultValue = new ArrayList<Object>(); } merger = new CollectionMerger(); } else if (field.getType() == Set.class) { if (defaultValue != null) { defaultValue = new HashSet<Object>(); } merger = new CollectionMerger(); } else if (field.getType() == String.class) { if (defaultValue != null) { defaultValue = field.getAnnotation(MergeMe.class).defaultString(); } merger = new ObjectMerger(); } else if (field.getType() == Boolean.class) { defaultValue = field.getAnnotation(MergeMe.class).defaultBoolean(); merger = new ObjectMerger(); } else { merger = new ObjectMerger(); } Object childValue = field.get(child); Object parentValue = field.get(parent); try { field.set(child, merger.merge(childValue, parentValue, defaultValue)); } catch (InstantiationException e) { throw new MojoExecutionException("Error merging configurations", e); } } catch (SecurityException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (IllegalArgumentException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (IllegalAccessException e) { throw new MojoExecutionException(e.getMessage(), e); } } } child.setReady(true); return child; }
From source file:com.dc.tes.adapter.startup.remote.StartUpRemoteForReply.java
/** * "?"?,???// w ww . j a v a2s . c o m * @param props ???(ComLayer.config.xml) */ public void startAdapter(Properties props) { String adapterName = props.getProperty("CHANNELNAME"); try { String clsName = "com.dc.tes.adapterlib." + (String) props.get("adapterPlugIn"); m_replyAdapterInstance = (IReplyAdapter) ConfigHelper.class.getClassLoader().loadClass(clsName) .newInstance(); System.out.println("???" + clsName); log.error("???" + clsName); // License m_props.setProperty("SIMTYPE", m_replyAdapterInstance.AdapterType()); m_adpterHelper = new DefaultReplyAdapterHelper(m_props); // byte[] config = m_adpterHelper.reg2TES(); // ? if (m_replyAdapterInstance.Init(new DefaultReplyAdapterEnvContext(config, m_adpterHelper))) { m_adpterHelper.SetConfigProperty(m_replyAdapterInstance.GetAdapterConfigProperties()); System.out.println("??" + adapterName + "?Init?."); log.info("??" + adapterName + "?Init?."); // ??? m_replyAdapterInstance.Start(); } else { m_adpterHelper.unReg2TES(); // ?m_replyAdapterInstance.Stop() System.out.println("??" + adapterName + "?Init."); log.error("??" + adapterName + "?Init."); } } catch (InstantiationException e) { log.error("??!?"); System.out.println("??!?"); } catch (IllegalAccessException e) { log.error("??!?[" + e.getMessage() + "]"); System.out.println( "??!?[" + e.getMessage() + "]"); } catch (ClassNotFoundException e) { log.error("???!?[" + e.getMessage() + "]"); System.out.println( "???!?[" + e.getMessage() + "]"); } catch (Exception e) { log.error("??[" + e.getMessage()); System.out.println("??[" + e.getMessage()); } System.out.println("??" + adapterName + "??."); log.info("??" + adapterName + "??."); }
From source file:cz.muni.fi.mir.mathmlcanonicalization.MathMLCanonicalizer.java
/** * Loads configuration from XML file, overriding the properties. *///from w ww . j a v a2 s . c o m private void loadXMLConfiguration(InputStream xmlConfigurationStream) throws ConfigException, XMLStreamException { assert xmlConfigurationStream != null; final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); final XMLStreamReader reader = inputFactory.createXMLStreamReader(xmlConfigurationStream); boolean config = false; Module module = null; while (reader.hasNext()) { final int event = reader.next(); switch (event) { case XMLStreamConstants.START_ELEMENT: { String name = reader.getLocalName(); if (name.equals("config")) { config = true; break; } if (config && name.equals("module")) { if (reader.getAttributeCount() == 1) { final String attributeName = reader.getAttributeLocalName(0); final String attributeValue = reader.getAttributeValue(0); if (attributeName.equals("name") && attributeValue != null) { String fullyQualified = Settings.class.getPackage().getName() + ".modules." + attributeValue; try { Class<?> moduleClass = Class.forName(fullyQualified); module = (Module) moduleClass.newInstance(); } catch (InstantiationException ex) { LOGGER.log(Level.SEVERE, ex.getMessage(), ex); throw new ConfigException("cannot instantiate module " + attributeValue, ex); } catch (IllegalAccessException ex) { LOGGER.log(Level.SEVERE, ex.getMessage(), ex); throw new ConfigException("cannot access module " + attributeValue, ex); } catch (ClassNotFoundException ex) { LOGGER.log(Level.SEVERE, ex.getMessage(), ex); throw new ConfigException("cannot load module " + attributeValue, ex); } } } } if (config && name.equals("property")) { if (reader.getAttributeCount() == 1) { final String attributeName = reader.getAttributeLocalName(0); final String attributeValue = reader.getAttributeValue(0); if (attributeName.equals("name") && attributeValue != null) { if (module == null) { if (Settings.isProperty(attributeValue)) { Settings.setProperty(attributeValue, reader.getElementText()); } else { throw new ConfigException("configuration not valid\n" + "Tried to override non-existing global property " + attributeValue); } } else { if (module.isProperty(attributeValue)) { module.setProperty(attributeValue, reader.getElementText()); } else { throw new ConfigException("configuration not valid\n" + "configuration tried to override non-existing property " + attributeValue); } } } } } break; } case XMLStreamConstants.END_ELEMENT: { if (config && reader.getLocalName().equals("module")) { addModule(module); module = null; } if (config && reader.getLocalName().equals("config")) { config = false; } } } } }
From source file:org.codehaus.groovy.grails.scaffolding.DefaultScaffoldDomain.java
public Object newInstance() { try {//from w w w .ja v a 2 s .c om return this.persistentClass.newInstance(); } catch (InstantiationException e) { throw new ScaffoldingException("Unable to instantiate persistent class [" + persistentClass + "] for scaffolding: " + e.getMessage(), e); } catch (IllegalAccessException e) { throw new ScaffoldingException("Unable to instantiate persistent class [" + persistentClass + "] for scaffolding: " + e.getMessage(), e); } }
From source file:org.apache.cocoon.components.language.programming.java.JavaLanguage.java
/** * Compile a source file yielding a loadable class file. * * @param name The object program base file name * @param baseDirectory The directory containing the object program file * @param encoding The encoding expected in the source file or * <code>null</code> if it is the platform's default encoding * @exception LanguageException If an error occurs during compilation *///from w w w . ja v a 2 s . c om protected void compile(String name, File baseDirectory, String encoding) throws LanguageException { try { LanguageCompiler compiler = (LanguageCompiler) this.compilerClass.newInstance(); // AbstractJavaCompiler is LogEnabled if (compiler instanceof LogEnabled) { ((LogEnabled) compiler).enableLogging(getLogger()); } if (compiler instanceof Serviceable) { ((Serviceable) compiler).service(this.manager); } int pos = name.lastIndexOf(File.separatorChar); String filename = name.substring(pos + 1); final String basePath = baseDirectory.getCanonicalPath(); String filepath = basePath + File.separator + name + "." + getSourceExtension(); compiler.setFile(filepath); compiler.setSource(basePath); compiler.setDestination(basePath); compiler.setClasspath(basePath + this.classpath); compiler.setCompilerComplianceLevel(compilerComplianceLevel); if (encoding != null) { compiler.setEncoding(encoding); } if (getLogger().isDebugEnabled()) { getLogger().debug("Compiling " + filepath); } if (!compiler.compile()) { StringBuffer message = new StringBuffer("Error compiling "); message.append(filename); message.append(":\n"); List errors = compiler.getErrors(); CompilerError[] compilerErrors = new CompilerError[errors.size()]; errors.toArray(compilerErrors); throw new LanguageException(message.toString(), filepath, compilerErrors); } } catch (InstantiationException e) { getLogger().warn("Could not instantiate the compiler", e); throw new LanguageException("Could not instantiate the compiler: " + e.getMessage()); } catch (IllegalAccessException e) { getLogger().warn("Could not access the compiler class", e); throw new LanguageException("Could not access the compiler class: " + e.getMessage()); } catch (IOException e) { getLogger().warn("Error during compilation", e); throw new LanguageException("Error during compilation: " + e.getMessage()); } catch (ServiceException e) { getLogger().warn("Could not initialize the compiler", e); throw new LanguageException("Could not initialize the compiler: " + e.getMessage()); } }
From source file:org.codehaus.groovy.grails.scaffolding.DefaultScaffoldDomain.java
public void setPersistentClass(Class persistentClass) { if (persistentClass == null) throw new IllegalArgumentException("Argument 'persistentClass' cannot be null"); this.persistentClass = persistentClass; try {//from ww w. j av a 2 s .c o m this.bean = new BeanWrapperImpl(persistentClass.newInstance()); } catch (InstantiationException e) { throw new ScaffoldingException("Unable to instantiate persistent class [" + persistentClass + "] for scaffolding: " + e.getMessage(), e); } catch (IllegalAccessException e) { throw new ScaffoldingException("Unable to instantiate persistent class [" + persistentClass + "] for scaffolding: " + e.getMessage(), e); } }
From source file:nonjsp.application.BuildComponentFromTagImpl.java
public UIComponent createComponentForTag(String shortTagName) { UIComponent result = null;// w w w.j a v a 2 s . c om if (!tagHasComponent(shortTagName)) { return result; } String className = (String) classMap.get(shortTagName); Class componentClass; // PENDING(edburns): this can be way optimized try { componentClass = Util.loadClass(className); result = (UIComponent) componentClass.newInstance(); } catch (IllegalAccessException iae) { throw new RuntimeException("Can't create instance for " + className + ": " + iae.getMessage()); } catch (InstantiationException ie) { throw new RuntimeException("Can't create instance for " + className + ": " + ie.getMessage()); } catch (ClassNotFoundException e) { throw new RuntimeException("Can't find class for " + className + ": " + e.getMessage()); } return result; }
From source file:org.kepler.metadata.MetadataParser.java
private ParserInterface createParser(String metadataType) { ParserInterface parser = null;/*from www.j av a2 s. com*/ if (metadataType != null) { if (metadataTypeClassMapList != null) { for (MetadataTypeParserMap map : metadataTypeClassMapList) { if (map != null) { if (metadataType.equals(map.getMetadataType())) { String className = map.getClassName(); if (className != null) { try { Class classDefinition = Class.forName(className); parser = (ParserInterface) classDefinition.newInstance(); break; } catch (InstantiationException e) { logger.warn("MetadataPaser.createParser - can't get the parser object since " + e.getMessage()); continue; } catch (IllegalAccessException e) { logger.warn("MetadataPaser.createParser - can't get the parser object since " + e.getMessage()); continue; } catch (ClassNotFoundException e) { logger.warn("MetadataPaser.createParser - can't get the parser object since " + e.getMessage()); continue; } } } } } } } return parser; }
From source file:net.duckling.falcon.api.orm.DAOUtils.java
/*** * rowMapper?map??/* w ww . j a v a 2 s .c o m*/ * * @param Class * objClass * @param map * Map<,?>,???map * @return RowMapper * */ public RowMapper<T> getRowMapper(final Map<String, String> map) { return new RowMapper<T>() { @SuppressWarnings("unchecked") @Override public T mapRow(ResultSet rs, int index) throws SQLException { Object obj = null; try { obj = objClass.newInstance(); for (int i = 0; i < fields.length; i++) { Field field = fields[i]; field.getName(); setValueToObj(field, obj, rs); } } catch (InstantiationException e) { LOG.debug(e.getMessage(), e); } catch (IllegalAccessException e) { LOG.debug(e.getMessage(), e); } revertMapping(map, obj, rs); return (T) obj; } }; }
From source file:com.dc.tes.adapter.startup.remote.StartUpRemoteForRequest.java
private void startAdapter(Properties props) { String adapterName = props.getProperty("CHANNELNAME"); IRequestAdapter adapterInstance = null; try {//from ww w . jav a 2s .co m String clsName = "com.dc.tes.adapterlib." + (String) props.get("adapterPlugIn"); adapterInstance = (IRequestAdapter) ConfigHelper.class.getClassLoader().loadClass(clsName) .newInstance(); System.out.println("????" + clsName); // License m_props.setProperty("SIMTYPE", adapterInstance.AdapterType()); m_adpterHelper = new DefaultRequestAdapterHelper(m_props, adapterInstance); // byte[] config = m_adpterHelper.reg2TES(); // ? if (adapterInstance.Init(new DefaultRequestAdapterEnvContext(config))) { m_adpterHelper.SetConfigProperty(adapterInstance.GetAdapterConfigProperties()); System.out.println("??" + adapterName + "?Init?."); log.info("???" + adapterName + "?Init?."); log.error("???" + adapterName + "?Init?."); // ??? m_adpterHelper.startServer(); } else { m_adpterHelper.unReg2TES(); // ?m_requestAdapterHelper.stopServer() System.out.println("???" + adapterName + "?Init."); log.error("???" + adapterName + "?Init."); } } catch (InstantiationException e) { log.error("?!?"); System.out.println("?!?"); // ?stopServer } catch (IllegalAccessException e) { log.error("?!?[" + e.getMessage() + "]"); System.out.println("?!?[" + e.getMessage() + "]"); // ?stopServer } catch (ClassNotFoundException e) { log.error("??!?[" + e.getMessage() + "]"); System.out.println("??!?[" + e.getMessage() + "]"); // ?stopServer } catch (ClosedByInterruptException e) { // ?? shutdownAdapter(); log.info("??" + adapterName + ""); System.out.println("??" + adapterName + ""); } catch (Exception e) { // ?? shutdownAdapter(); log.error("?" + adapterName + "?![" + e.getMessage() + "]"); System.out.println("?" + adapterName + "?![" + e.getMessage() + "]"); } System.out.println("??" + adapterName + "??."); log.info("??" + adapterName + "??."); }