List of usage examples for java.lang ClassLoader loadClass
public Class<?> loadClass(String name) throws ClassNotFoundException
From source file:org.jsonschema2pojo.integration.AdditionalPropertiesIT.java
@Test public void jacksonCanSerializeOurAdditionalProperties() throws ClassNotFoundException, IOException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, InstantiationException { ClassLoader resultsClassLoader = schemaRule .generateAndCompile("/schema/additionalProperties/defaultAdditionalProperties.json", "com.example"); Class<?> classWithAdditionalProperties = resultsClassLoader .loadClass("com.example.DefaultAdditionalProperties"); String jsonWithAdditionalProperties = "{\"a\":1, \"b\":2};"; Object instanceWithAdditionalProperties = mapper.readValue(jsonWithAdditionalProperties, classWithAdditionalProperties); JsonNode jsonNode = mapper.readTree(mapper.writeValueAsString(instanceWithAdditionalProperties)); assertThat(jsonNode.path("a").asText(), is("1")); assertThat(jsonNode.path("b").asInt(), is(2)); }
From source file:org.jsonschema2pojo.integration.AdditionalPropertiesIT.java
@Test(expected = NoSuchMethodException.class) public void additionalPropertiesBuilderAbsentIfNotConfigured() throws SecurityException, NoSuchMethodException, ClassNotFoundException { ClassLoader resultsClassLoader = schemaRule .generateAndCompile("/schema/additionalProperties/additionalPropertiesObject.json", "com.example"); Class<?> classWithNoAdditionalProperties = resultsClassLoader .loadClass("com.example.AdditionalPropertiesObject"); Class<?> propertyValueType = resultsClassLoader.loadClass("com.example.AdditionalPropertiesObjectProperty"); // builder with these types should not exist: Method builderMethod = classWithNoAdditionalProperties.getMethod("withAdditionalProperty", String.class, propertyValueType);/*from www .j a v a2 s . c o m*/ assertThat("the builder method returns this type", builderMethod.getReturnType(), typeEqualTo(classWithNoAdditionalProperties)); fail("additional properties builder found when not requested"); }
From source file:com.google.gdt.eclipse.designer.uibinder.parser.UiBinderParser.java
/** * Implementation of {@link #parse()}.//w w w .jav a 2 s . c om */ private void parse0() throws Exception { m_context.setParsing(true); m_context.notifyAboutToParse(); fillMap_pathToElement(); // load Binder Object createdBinder; { ClassLoader classLoader = m_context.getClassLoader(); String binderClassName = m_context.getBinderClassName(); Class<?> binderClass = classLoader.loadClass(binderClassName); Class<?> classGWT = classLoader.loadClass("com.google.gwt.core.client.GWT"); createdBinder = ReflectionUtils.invokeMethod(classGWT, "create(java.lang.Class)", binderClass); createModels(createdBinder); } // render Widget(s) ReflectionUtils.invokeMethod(createdBinder, "createAndBindUi(java.lang.Object)", (Object) null); buildHierarchy(); // done m_context.setParsing(false); new UiConstructorSupport(m_context); new UiChildSupport(m_context); NameSupport.decoratePresentationWithName(m_rootModel); XmlObjectUtils.callRootProcessors(m_rootModel); XmlObjectUtils.registerTagResolvers(m_rootModel); new UiBinderStaticFieldSupport(m_rootModel); NameSupport.removeName_onDelete(m_rootModel); NameSupport.ensureFieldProvided_onCreate(m_rootModel); new EventHandlersSupport(m_rootModel); new StylePropertySupport(m_context); GlobalStateXml.activate(m_rootModel); m_rootModel.getBroadcast(ObjectInfoTreeComplete.class).invoke(); m_rootModel.refresh_dispose(); }
From source file:com.panet.imeta.job.JobEntryLoader.java
public Class<?> loadClass(JobPlugin sp, String className) throws KettleStepLoaderException { try {//from w w w . j a va 2 s.c o m switch (sp.getType()) { case JobPlugin.TYPE_NATIVE: return Class.forName(className); case JobPlugin.TYPE_PLUGIN: ClassLoader cl = getClassLoader(sp); return cl.loadClass(className); default: throw new KettleStepLoaderException("Unknown plugin type : " + sp.getType()); } } catch (Exception e) { throw new KettleStepLoaderException(e); } }
From source file:org.jsonschema2pojo.integration.AdditionalPropertiesIT.java
@Test public void additionalPropertiesWorkWithAllVisibility() throws ClassNotFoundException, SecurityException, NoSuchMethodException, JsonProcessingException, IOException { mapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false); mapper.configure(MapperFeature.AUTO_DETECT_SETTERS, false); mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(Visibility.ANY)); ClassLoader resultsClassLoader = schemaRule .generateAndCompile("/schema/additionalProperties/defaultAdditionalProperties.json", "com.example"); Class<?> classWithAdditionalProperties = resultsClassLoader .loadClass("com.example.DefaultAdditionalProperties"); String jsonWithAdditionalProperties = "{\"a\":1, \"b\":2};"; Object instanceWithAdditionalProperties = mapper.readValue(jsonWithAdditionalProperties, classWithAdditionalProperties); JsonNode jsonNode = mapper.readTree(mapper.writeValueAsString(instanceWithAdditionalProperties)); assertThat(jsonNode.path("a").asText(), is("1")); assertThat(jsonNode.path("b").asInt(), is(2)); assertThat(jsonNode.has("additionalProperties"), is(false)); }
From source file:org.jsonschema2pojo.integration.AdditionalPropertiesIT.java
@Test @SuppressWarnings("unchecked") public void jacksonCanDeserializeOurAdditionalProperties() throws ClassNotFoundException, IOException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { ClassLoader resultsClassLoader = schemaRule .generateAndCompile("/schema/additionalProperties/defaultAdditionalProperties.json", "com.example"); Class<?> classWithAdditionalProperties = resultsClassLoader .loadClass("com.example.DefaultAdditionalProperties"); Object deserialized = mapper.readValue("{\"a\":\"1\", \"b\":2}", classWithAdditionalProperties); Method getter = classWithAdditionalProperties.getMethod("getAdditionalProperties"); assertThat(getter.invoke(deserialized), is(notNullValue())); assertThat(((Map<String, Object>) getter.invoke(deserialized)).containsKey("a"), is(true)); assertThat((String) ((Map<String, Object>) getter.invoke(deserialized)).get("a"), is("1")); assertThat(((Map<String, Object>) getter.invoke(deserialized)).containsKey("b"), is(true)); assertThat((Integer) ((Map<String, Object>) getter.invoke(deserialized)).get("b"), is(2)); }
From source file:org.jsonschema2pojo.integration.EnumIT.java
@Test @SuppressWarnings("unchecked") public void enumAtRootCreatesATopLevelType() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/enum/enumAsRoot.json", "com.example"); Class<Enum> rootEnumClass = (Class<Enum>) resultsClassLoader.loadClass("com.example.enums.EnumAsRoot"); assertThat(rootEnumClass.isEnum(), is(true)); assertThat(isPublic(rootEnumClass.getModifiers()), is(true)); }
From source file:org.jsonschema2pojo.integration.EnumIT.java
@Test @SuppressWarnings("unchecked") public void doubleEnumAtRootCreatesIntBackedEnum() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/enum/doubleEnumAsRoot.json", "com.example"); Class<Enum> rootEnumClass = (Class<Enum>) resultsClassLoader .loadClass("com.example.enums.DoubleEnumAsRoot"); assertThat(rootEnumClass.isEnum(), is(true)); assertThat(rootEnumClass.getDeclaredMethod("fromValue", Double.class), is(notNullValue())); assertThat(isPublic(rootEnumClass.getModifiers()), is(true)); }
From source file:org.jsonschema2pojo.integration.EnumIT.java
@Test @SuppressWarnings("unchecked") public void enumWithNullValue() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/enum/enumWithNullValue.json", "com.example"); Class<Enum> nullEnumClass = (Class<Enum>) resultsClassLoader.loadClass("com.example.EnumWithNullValue"); assertThat(nullEnumClass.isEnum(), is(true)); assertThat(nullEnumClass.getEnumConstants().length, is(1)); }
From source file:org.jsonschema2pojo.integration.EnumIT.java
@Test @SuppressWarnings("unchecked") public void intEnumAtRootCreatesIntBackedEnum() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/enum/integerEnumAsRoot.json", "com.example"); Class<Enum> rootEnumClass = (Class<Enum>) resultsClassLoader .loadClass("com.example.enums.IntegerEnumAsRoot"); assertThat(rootEnumClass.isEnum(), is(true)); assertThat(rootEnumClass.getDeclaredMethod("fromValue", Integer.class), is(notNullValue())); assertThat(isPublic(rootEnumClass.getModifiers()), is(true)); }