List of usage examples for java.lang ClassNotFoundException getCause
public synchronized Throwable getCause()
From source file:org.ohmage.spring.ConfigurationSingletonValidityTester.java
/** * Makes sure that the packages set on construction contain beans in the * ApplicationContext that have been instantiated. Requires that the classes * have a static instance() method to invoke. * //from ww w.ja v a2 s . c o m * @param applicationContext The Spring ApplicationContext to query for * class instance existence. * * @throws IllegalStateException if any class in classNames cannot be * found in the ApplicationContext, does not have a static instance() * method, is not accessible due to security constraints, or if the * underlying instance() method throws an Exception. */ private void validate(ApplicationContext applicationContext) { Object tmp = null; Object[] noArgs = new Object[] {}; for (String className : classNames) { try { String javaStyleClassName = className.substring(0, className.length() - 6).replace('/', '.'); // Ignore inner classes if (javaStyleClassName.contains("$")) { if (logger.isDebugEnabled()) { logger.debug("Skipping inner class " + javaStyleClassName); } continue; } // Ignore classes that are ignorable if (classesToIgnore != null && classesToIgnore.contains(javaStyleClassName)) { if (logger.isDebugEnabled()) { logger.debug("Ignoring " + javaStyleClassName); } continue; } Class<?> clazz = Class.forName(javaStyleClassName); if (logger.isDebugEnabled()) { logger.debug("Sanity check for the existence of " + clazz + " in the ApplicationContext"); } tmp = applicationContext.getBean(clazz); Method m = tmp.getClass().getDeclaredMethod("instance"); // Invoke the static instance() method with no arguments. // If nothing is returned, the class is missing from the XML // config (i.e., no singleton exists in the application context if (m.invoke(null, noArgs) == null) { throw new IllegalStateException( "Invalid singleton configuration. No instance exists in the ApplicationContext" + " for class " + className); } } catch (ClassNotFoundException e) { throw new IllegalStateException("Could not find class in ApplicationContext: " + className, e); } catch (BeansException e) { throw new IllegalStateException("Could not find bean in ApplicationContext for class: " + className, e); } catch (NoSuchMethodException e) { throw new IllegalStateException("No instance() method found on class: " + className, e); } catch (IllegalAccessException e) { throw new IllegalStateException("Could not access class: " + className, e); } catch (InvocationTargetException e) { throw new IllegalStateException("Exception thrown when invoking instance() on class: " + className, e.getCause()); } } logger.info("Done with singleton instantion check for the following packages: " + Arrays.toString(packageDirectoryNames)); }
From source file:org.compass.gps.device.jpa.embedded.openjpa.CompassProductDerivation.java
private OpenJPAEntityManagerFactory toEntityManagerFactory(BrokerFactory factory) { try {//from w w w. ja v a2 s. co m Class cls; try { cls = Class.forName("org.apache.openjpa.persistence.JPAFacadeHelper"); } catch (ClassNotFoundException e) { cls = OpenJPAPersistence.class; } return (OpenJPAEntityManagerFactory) cls.getMethod("toEntityManagerFactory", BrokerFactory.class) .invoke(null, factory); } catch (NoSuchMethodException e) { throw new IllegalStateException(e); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } catch (InvocationTargetException e) { if (e.getCause() instanceof RuntimeException) throw (RuntimeException) e.getCause(); else throw new RuntimeException(e); } }
From source file:org.drools.guvnor.server.RepositoryPackageService.java
private SingleScenarioResult runScenario(Scenario scenario, PackageItem item, ClassLoader cl, RuleBase rulebase, RuleCoverageListener coverage) throws DetailedSerializationException { Package bin = rulebase.getPackages()[0]; Set<String> imps = bin.getImports().keySet(); Set<String> allImps = new HashSet<String>(imps); if (bin.getGlobals() != null) { for (Object o : bin.getGlobals().keySet()) { allImps.add(bin.getGlobals().get(o)); }/*from w ww. j ava 2 s .c o m*/ } allImps.add(bin.getName() + ".*"); // need this for Generated beans to // work ClassTypeResolver classTypeResolver = new ClassTypeResolver(allImps, cl); SessionConfiguration sessionConfiguration = new SessionConfiguration(); sessionConfiguration.setClockType(ClockType.PSEUDO_CLOCK); sessionConfiguration.setKeepReference(false); InternalWorkingMemory workingMemory = (InternalWorkingMemory) rulebase .newStatefulSession(sessionConfiguration, null); if (coverage != null) workingMemory.addEventListener(coverage); try { AuditLogReporter logger = new AuditLogReporter(workingMemory); new ScenarioRunner(scenario, classTypeResolver, workingMemory); SingleScenarioResult singleScenarioresult = new SingleScenarioResult(); singleScenarioresult.auditLog = logger.buildReport(); singleScenarioresult.result = new ScenarioRunResult(null, scenario); return singleScenarioresult; } catch (ClassNotFoundException e) { log.error("Unable to load a required class.", e); throw new DetailedSerializationException("Unable to load a required class.", e.getMessage()); } catch (ConsequenceException e) { String messageShort = "There was an error executing the consequence of rule [" + e.getRule().getName() + "]"; String messageLong = e.getMessage(); if (e.getCause() != null) { messageLong += "\nCAUSED BY " + e.getCause().getMessage(); } log.error(messageShort + ": " + messageLong, e); throw new DetailedSerializationException(messageShort, messageLong); } catch (Exception e) { log.error("Unable to run the scenario.", e); throw new DetailedSerializationException("Unable to run the scenario.", e.getMessage()); } }
From source file:org.modeldriven.fuml.assembly.ElementAssembler.java
public void assembleReferenceFeatures() { try {// w ww.j ava 2 s. com StreamNode eventNode = (StreamNode) source; if (references == null) return; Iterator<XmiReference> iter = references.iterator(); while (iter.hasNext()) { XmiReference reference = iter.next(); this.assembleReferenceFeature(reference); } } catch (ClassNotFoundException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (NoSuchMethodException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (InvocationTargetException e) { log.error(e.getCause().getMessage(), e.getCause()); throw new AssemblyException(e.getCause()); } catch (IllegalAccessException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (InstantiationException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (NoSuchFieldException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } }
From source file:org.modeldriven.fuml.assembly.ElementAssembler.java
@SuppressWarnings("unchecked") public void registerElement() { try {//from w w w. j a va2 s .c o m if (!(this.target instanceof Type)) return; Type targetType = (Type) this.target; ElementAssembler assembler = this; // FIXME: generalize this hack using associations in metamodel. For incremental // assembly where we remove chunks of XMI from the parent (packagedElement), this // scheme breaks because it relies on a continuous graph. String qualifiedPackageName = ""; fUML.Syntax.Classes.Kernel.Package parentPackage = null; if (assembler.getParentAssembler() != null && assembler.getParentAssembler().getTarget() instanceof fUML.Syntax.Classes.Kernel.Package) { parentPackage = (fUML.Syntax.Classes.Kernel.Package) assembler.getParentAssembler().getTarget(); } for (int i = 0; (assembler = assembler.getParentAssembler()) != null; i++) { if (assembler.getTarget() instanceof fUML.Syntax.Classes.Kernel.Package) { fUML.Syntax.Classes.Kernel.Package pckg = (fUML.Syntax.Classes.Kernel.Package) assembler .getTarget(); String name = pckg.name; if (i > 0) qualifiedPackageName = name + "." + qualifiedPackageName; else qualifiedPackageName = name; } else break; } // FIXME: generalize this hack using associations in metamodel String libraryObjectClassName = null; if (qualifiedPackageName != null && qualifiedPackageName.trim().length() > 0) libraryObjectClassName = qualifiedPackageName + "." + targetType.name; else libraryObjectClassName = targetType.name; targetType.qualifiedName = libraryObjectClassName; if (parentPackage != null) targetType.package_ = parentPackage; if (!(targetType instanceof fUML.Syntax.Classes.Kernel.Class_)) return; fUML.Syntax.Classes.Kernel.Class_ targetClass = (fUML.Syntax.Classes.Kernel.Class_) targetType; String implObjectClassName = FumlConfiguration.getInstance() .findExecutionClassName(libraryObjectClassName); if (implObjectClassName == null) return; // not mapped - we're not interested Classifier implClassifier = metadata.getClassifierByQualifiedName(implObjectClassName); if (implClassifier == null) { if (log.isDebugEnabled()) log.debug("(expected) no classifier found for mapped library class '" + implObjectClassName + "' for library class, " + libraryObjectClassName); } log.info("mapped " + targetType.name + " to " + implObjectClassName); Object object = ReflectionUtils.instanceForName(implObjectClassName); if (object instanceof ImplementationObject) { ImplementationObject execution = (ImplementationObject) object; execution.types.add(targetClass); log.info("adding to locus: " + execution.getClass().getName()); Environment.getInstance().locus.add(execution); } else if (object instanceof OpaqueBehaviorExecution) { OpaqueBehaviorExecution execution = (OpaqueBehaviorExecution) object; execution.types.add(targetClass); Environment.getInstance().locus.factory.addPrimitiveBehaviorPrototype(execution); } else log.warn("unknown instance, " + object.getClass().getName()); } catch (ClassNotFoundException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (NoSuchMethodException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (InvocationTargetException e) { log.error(e.getCause().getMessage(), e.getCause()); throw new AssemblyException(e.getCause()); } catch (IllegalAccessException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (InstantiationException e) { if (e.getCause() != null) log.error(e.getCause().getMessage(), e.getCause()); else log.error(e.getMessage(), e); throw new AssemblyException(e); } }
From source file:org.modeldriven.fuml.assembly.ElementAssembler.java
@SuppressWarnings("unchecked") public void assembleElementClass() { try {/*from w w w .j a v a 2 s . c o m*/ String packageName = metadata.getJavaPackageNameForClass(this.prototype); String instancecClassName = this.prototype.getDelegate().name; // TODO: We have a keyword map, but unclear whether upper-case 'Class' should be mapped. Definately 'class' is. if ("Class".equals(instancecClassName)) instancecClassName = instancecClassName + "_"; String qualifiedName = packageName + "." + instancecClassName; FumlObject object = null; ImportAdapter importAdapter = FumlConfiguration.getInstance().findImportAdapter(instancecClassName); if (importAdapter == null || importAdapter.getType().ordinal() != ImportAdapterType.ASSEMBLY.ordinal()) { object = (FumlObject) ReflectionUtils.instanceForName(qualifiedName); } else { AssemblyAdapter adapter = (AssemblyAdapter) ReflectionUtils .instanceForName(importAdapter.getAdapterClassName()); object = adapter.assembleElement((StreamNode) this.source); } if (this.xmiId != null) object.setXmiId(this.xmiId.getValue()); else object.setXmiId(UUIDGenerator.instance().getIdString36()); // synthesize one if (this.xmiHref != null) object.setHref(this.xmiHref.getValue()); if (this.xmiId == null && this.xmiHref == null) log.warn("found (" + object.getClass().getName() + ") element with no xmi:id or href"); object.setXmiNamespace(this.xmiNamespace); if (object instanceof Element) { if (object instanceof PrimitiveType) { if (object.getHref() == null) throw new AssemblyException("expected 'href' attribute for primitive type"); // FIXME; gotta be a better way! URI resolver?? // Note: Path map variables allow for portability of URIs. The actual location // indicated by a URI depends on the run-time binding of the path variable. Thus, different // environments can work with the same resource URIs even though the // resources are stored in different physical locations. int idx = object.getHref().lastIndexOf("#"); String suffix = object.getHref().substring(idx + 1); if (suffix.equals("Integer")) this.target = Environment.getInstance().getInteger(); else if (suffix.equals("String")) this.target = Environment.getInstance().getString(); else if (suffix.equals("Boolean")) this.target = Environment.getInstance().getBoolean(); else if (suffix.equals("UnlimitedNatural")) this.target = Environment.getInstance().getUnlimitedNatural(); else throw new AssemblyException("unknown type, " + object.getHref()); //this.target = (Element) object; if (this.target == null) throw new AssemblyException("could not determine target object for prototype, " + this.prototype.getXmiNamespace() + "#" + this.prototype.getName()); } else { this.target = (Element) object; if (this.target == null) throw new AssemblyException("could not determine target object for prototype, " + this.prototype.getXmiNamespace() + "#" + this.prototype.getName()); if (log.isDebugEnabled()) log.debug("constructing class " + this.target.getClass().getName()); } } else if (object instanceof Comment) { this.targetComment = (Comment) object; if (this.targetComment == null) throw new AssemblyException("could not determine target object for prototype, " + this.prototype.getXmiNamespace() + "#" + this.prototype.getName()); } else throw new AssemblyException("unknown instance, " + object.getClass().getName()); } catch (ClassNotFoundException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (NoSuchMethodException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (InvocationTargetException e) { log.error(e.getCause().getMessage(), e.getCause()); throw new AssemblyException(e.getCause()); } catch (IllegalAccessException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (InstantiationException e) { if (e.getCause() != null) log.error(e.getCause().getMessage(), e.getCause()); else log.error(e.getMessage(), e); throw new AssemblyException(e); } }
From source file:org.modeldriven.fuml.assembly.ElementAssembler.java
public void assemleFeatures() { try {// w w w . j a v a 2 s . c om NamespaceDomain domain = null; // only lookup as needed StreamNode eventNode = (StreamNode) source; Location loc = eventNode.getLocation(); if (log.isDebugEnabled()) log.debug("element line/column: " + loc.getLineNumber() + ":" + loc.getColumnNumber()); // look at XML attributes Iterator<Attribute> attributes = eventNode.getAttributes(); while (attributes != null && attributes.hasNext()) { Attribute xmlAttrib = attributes.next(); QName name = xmlAttrib.getName(); String prefix = name.getPrefix(); if (prefix != null && prefix.length() > 0) continue; // not applicable to current // element/association-end. if ("href".equals(name.getLocalPart())) continue; // FIXME: find/write URI resolver Property property = this.prototype.findProperty(name.getLocalPart()); if (property == null) { if (domain == null) domain = FumlConfiguration.getInstance().findNamespaceDomain(source.getNamespaceURI()); ValidationExemption exemption = FumlConfiguration.getInstance() .findValidationExemptionByProperty(ValidationExemptionType.UNDEFINED_PROPERTY, this.prototype, name.getLocalPart(), source.getNamespaceURI(), domain); if (exemption == null) { throw new ValidationException(new ValidationError(eventNode, name.getLocalPart(), ErrorCode.UNDEFINED_PROPERTY, ErrorSeverity.FATAL)); } else { if (log.isDebugEnabled()) log.debug("undefined property exemption found within domain '" + exemption.getDomain().toString() + "' for property '" + this.prototype.getName() + "." + name.getLocalPart() + "' - ignoring error"); continue; // ignore attrib } } Classifier type = property.getType(); if (this.modelSupport.isReferenceAttribute(property)) { XmiReferenceAttribute reference = new XmiReferenceAttribute(source, xmlAttrib, this.getPrototype()); this.addReference(reference); continue; } String value = xmlAttrib.getValue(); if (value == null || value.length() == 0) { String defaultValue = property.findPropertyDefault(); if (defaultValue != null) { value = defaultValue; if (log.isDebugEnabled()) log.debug("using default '" + String.valueOf(value) + "' for enumeration feature <" + type.getName() + "> " + this.getPrototype().getName() + "." + property.getName()); } } this.assembleNonReferenceFeature(property, value, type); } // look at model properties not found in above attribute set List<Property> properties = this.prototype.getNamedProperties(); for (Property property : properties) { QName name = new QName(property.getName()); String value = eventNode.getAttributeValue(name); if (value != null && value.trim().length() > 0) continue; // handled above String defaultValue = property.findPropertyDefault(); if (defaultValue != null) { Classifier type = property.getType(); if (log.isDebugEnabled()) log.debug("using default: '" + String.valueOf(defaultValue) + "' for enumeration feature <" + type.getName() + "> " + this.getPrototype().getName() + "." + property.getName()); this.assembleNonReferenceFeature(property, defaultValue, type); continue; } if (!property.isRequired()) continue; // don't bother digging further for a value if (eventNode.findChildByName(property.getName()) != null) continue; // it has such a child, let if (this.modelSupport.isReferenceAttribute(property) && FumlConfiguration.getInstance().hasReferenceMapping(this.prototype, property)) { ReferenceMappingType mappingType = FumlConfiguration.getInstance() .getReferenceMappingType(this.prototype, property); if (mappingType == ReferenceMappingType.PARENT) { if (parent != null && parent.getXmiId() != null && parent.getXmiId().length() > 0) { XmiMappedReference reference = new XmiMappedReference(source, property.getName(), new String[] { parent.getXmiId() }, this.prototype); this.addReference(reference); continue; } else log.warn("no parent XMI id found, ignoring mapping for, " + this.prototype.getName() + "." + property.getName()); } else log.warn("unrecognized mapping type, " + mappingType.value() + " ignoring mapping for, " + this.prototype.getName() + "." + property.getName()); } if (!property.isDerived()) { if (domain == null) domain = FumlConfiguration.getInstance().findNamespaceDomain(source.getNamespaceURI()); ValidationExemption exemption = FumlConfiguration.getInstance() .findValidationExemptionByProperty(ValidationExemptionType.REQUIRED_PROPERTY, this.prototype, name.getLocalPart(), source.getNamespaceURI(), domain); if (exemption == null) { if (log.isDebugEnabled()) log.debug("throwing " + ErrorCode.PROPERTY_REQUIRED.toString() + " error for " + this.prototype.getName() + "." + property.getName()); throw new ValidationException(new ValidationError(eventNode, property.getName(), ErrorCode.PROPERTY_REQUIRED, ErrorSeverity.FATAL)); } else { if (log.isDebugEnabled()) log.debug("required property exemption found within domain '" + exemption.getDomain().toString() + "' for property '" + this.prototype.getName() + "." + name.getLocalPart() + "' - ignoring error"); continue; // ignore property } } } } catch (ClassNotFoundException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (NoSuchMethodException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (InvocationTargetException e) { log.error(e.getCause().getMessage(), e.getCause()); throw new AssemblyException(e.getCause()); } catch (IllegalAccessException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (InstantiationException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (NoSuchFieldException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } }
From source file:org.sakaiproject.cheftool.VelocityPortletPaneledAction.java
/** * Dispatch to a "processAction" method based on reflection in a helper class. * /*from w w w . j ava 2 s .c om*/ * @param methodBase * The base name of the method to call. * @param methodExt * The end name of the method to call. * @param req * The HttpServletRequest. * @param res * The HttpServletResponse * @throws PortletExcption, * IOException, just like the "do" methods. */ protected void helperActionDispatch(String methodBase, String methodExt, HttpServletRequest req, HttpServletResponse res, String className) { String methodName = null; try { // the method signature Class[] signature = new Class[1]; signature[0] = RunData.class; // the method name methodName = methodBase + methodExt; Class cls = Class.forName(className); // find a method of this class with this name and signature Method method = cls.getMethod(methodName, signature); // parameters - the context for a "do" should not be used, so we will send in null Object[] args = new Object[1]; args[0] = (JetspeedRunData) req.getAttribute(ATTR_RUNDATA); // make the call method.invoke(this, args); } catch (ClassNotFoundException e) { M_log.warn("Exception helper class not found " + e); } catch (NoSuchMethodException e) { M_log.warn("Exception calling method " + methodName + " " + e); } catch (IllegalAccessException e) { M_log.warn("Exception calling method " + methodName + " " + e); } catch (InvocationTargetException e) { String xtra = ""; if (e.getCause() != null) xtra = " (Caused by " + e.getCause() + ")"; M_log.warn("Exception calling method " + methodName + " " + e + xtra); } }
From source file:hu.sztaki.lpds.pgportal.services.asm.ASMService.java
private void loadASMWorkflows(String userId) { try {//from w w w. j av a 2 s. c o m ArrayList<ASMWorkflow> storedworkflows = getWorkflows(userId); workflows.put(userId, storedworkflows); for (int i = 0; i < storedworkflows.size(); ++i) { updateASMWorkflowStatus(userId, storedworkflows.get(i).getWorkflowName()); } } catch (ClassNotFoundException ex) { throw new ASM_GeneralWebServiceException(ex.getCause(), userId); } catch (InstantiationException ex) { throw new ASM_GeneralWebServiceException(ex.getCause(), userId); } catch (IllegalAccessException ex) { throw new ASM_GeneralWebServiceException(ex.getCause(), userId); } }
From source file:hu.sztaki.lpds.pgportal.services.asm.ASMService.java
private synchronized ArrayList<RepositoryWorkflowBean> getWorkflowsFromRepository2Array(String owner, String type, Long id) throws ASM_UnknownErrorException { try {//w ww . jav a2s . c o m // get repository workflow item list from wfs... Hashtable hsh = new Hashtable(); ServiceType st = InformationBase.getI().getService("wfs", "portal", hsh, new Vector()); PortalWfsClient wfsClient = (PortalWfsClient) Class.forName(st.getClientObject()).newInstance(); wfsClient.setServiceURL(st.getServiceUrl()); wfsClient.setServiceID(st.getServiceID()); RepositoryWorkflowBean bean = new RepositoryWorkflowBean(); bean.setId(id); bean.setUserID(owner); bean.setWorkflowType(type); Vector<RepositoryWorkflowBean> wfList = (Vector<RepositoryWorkflowBean>) wfsClient .getRepositoryItems(bean); ArrayList<RepositoryWorkflowBean> ret_list = new ArrayList<RepositoryWorkflowBean>(); if (wfList == null) { throw new ASM_UnknownErrorException(); } else { for (RepositoryWorkflowBean repbean : wfList) { ret_list.add(repbean); } return ret_list; } } catch (ClassNotFoundException ex) { throw new ASM_GeneralWebServiceException(ex.getCause(), owner); } catch (InstantiationException ex) { throw new ASM_GeneralWebServiceException(ex.getCause(), owner); } catch (IllegalAccessException ex) { throw new ASM_GeneralWebServiceException(ex.getCause(), owner); } }