List of usage examples for java.util List getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.apache.hise.utils.XQueryEvaluator.java
public List evaluateExpression(String expr, org.w3c.dom.Node contextNode) { try {/*from w w w . j av a2 s . c o m*/ contextObjectTL.set(contextObject); { FunctionLibraryList fll = new FunctionLibraryList(); fll.addFunctionLibrary(jel); config.setExtensionBinder("java", fll); } StaticQueryContext sqc = new StaticQueryContext(config); for (Map.Entry<String, String> namespace : namespaces.entrySet()) { sqc.declareNamespace(namespace.getKey(), namespace.getValue()); } for (QName var : vars.keySet()) { sqc.declareGlobalVariable(StructuredQName.fromClarkName(var.toString()), SequenceType.SINGLE_ITEM, convertJavaToSaxon(vars.get(var)), false); } DynamicQueryContext dqc = new DynamicQueryContext(config); XQueryExpression e = sqc.compileQuery(expr); if (contextNode != null) { if (!(contextNode instanceof Document || contextNode instanceof DocumentFragment)) { try { contextNode = DOMUtils.parse(DOMUtils.domToString(contextNode)); } catch (Exception e1) { throw new RuntimeException("", e1); } // DocumentFragment frag = contextNode.getOwnerDocument().createDocumentFragment(); // frag.appendChild(contextNode); // contextNode = frag; } dqc.setContextItem(new DocumentWrapper(contextNode, "", config)); } List value = e.evaluate(dqc); List value2 = new ArrayList(); for (Object o : value) { Object o2 = o; if (o2 instanceof NodeInfo) { try { Node o3 = DOMUtils.parse(DOMUtils.domToString(NodeOverNodeInfo.wrap((NodeInfo) o2))) .getDocumentElement(); o2 = o3; } catch (Exception e1) { throw new RuntimeException("Error converting result", e1); } } // o2 = JavaDOMWrapper.unwrap(o2); value2.add(o2); } __log.debug("result for expression " + expr + " " + value2 + " value class " + (value2 == null ? null : value2.getClass())); return value2; } catch (XPathException e) { __log.error("Expression: \n" + expr, e); throw new RuntimeException(e); } finally { contextObjectTL.set(null); } }
From source file:org.eclipse.emf.teneo.hibernate.mapping.elist.HibernatePersistableFeatureMap.java
/** Overridden because general list type is not supported as a replacement */ @Override/* w w w . java 2 s.c o m*/ public void replaceDelegate(List<FeatureMap.Entry> newDelegate) { if (newDelegate instanceof PersistentList) { AssertUtil.assertTrue( "This elist " + logString + " contains a different list than the " + " passed list", ((PersistentList) newDelegate).isWrapper(delegate)); super.replaceDelegate(newDelegate); } else if (newDelegate instanceof PersistentBag) { AssertUtil.assertTrue( "This elist " + logString + " contains a different list than the " + " passed list", ((PersistentBag) newDelegate).isWrapper(delegate)); super.replaceDelegate(newDelegate); } else { throw new HbMapperException("Type " + newDelegate.getClass().getName() + " can not be " + " used as a replacement for elist " + logString); } }
From source file:com.redblackit.web.server.EchoServletTest.java
/** * Do test/*from ww w. ja v a 2 s . co m*/ * * @param method * @param hasBody if content should be expected */ private void doTest(String method, boolean hasBody) throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod(method); request.setRequestURI(this.requestURI); final String msg = "doTest:" + method + ":hasBody=" + hasBody; logger.debug(msg + ":this=" + this); for (String headerName : headersMap.keySet()) { List<String> values = headersMap.get(headerName); if (values.size() == 1) { request.addHeader(headerName, values.get(0)); } else { request.addHeader(headerName, values); } Enumeration<String> headerValues = request.getHeaders(headerName); int hi = 0; while (headerValues.hasMoreElements()) { logger.debug(msg + "request:header[" + headerName + "," + hi + "]=" + headerValues.nextElement()); ++hi; } Assert.assertTrue(msg + "TEST ERROR:request:header[" + headerName + "]=" + values + ":shouldn't be empty (" + values.getClass() + ")", hi > 0); } int expectedContentLength = 0; if (hasBody && body != null && body.length() > 0) { request.setContent(body.getBytes()); expectedContentLength = request.getContentLength(); } MockHttpServletResponse response = new MockHttpServletResponse(); echoServlet.service(request, response); String responseBody = response.getContentAsString(); Assert.assertEquals("response code:" + response, HttpServletResponse.SC_OK, response.getStatus()); Assert.assertEquals("requestURI and Location", requestURI, response.getHeader("Location")); Map<String, List<String>> responseHeadersMap = new TreeMap<String, List<String>>(); for (String headerName : response.getHeaderNames()) { List<String> values = response.getHeaders(headerName); int hi = 0; for (String value : values) { logger.debug(msg + ":response:header[" + headerName + "," + hi + "]=" + value); ++hi; } if (hi == 0) { logger.debug(msg + ":response:header[" + headerName + "]=" + values + ":is empty (" + values.getClass() + ")"); values = Arrays.asList(new String[] { "" }); } if (!(headerName.equals("Location") || headerName.equals("Content-Length"))) { responseHeadersMap.put(headerName, values); } } Assert.assertEquals("headers (excluding Location and Content-Length)", headersMap, responseHeadersMap); if (hasBody) { Assert.assertEquals("body", (body == null ? "" : body), responseBody); } else { Assert.assertEquals("body", "", responseBody); } Assert.assertEquals("contentLength", expectedContentLength, response.getContentLength()); }
From source file:com.liferay.petra.json.web.service.client.BaseJSONWebServiceClientImpl.java
@Override public <V, T> List<V> doGetToList(Class<T> clazz, String url, Map<String, String> parameters, Map<String, String> headers) throws JSONWebServiceInvocationException, JSONWebServiceSerializeException, JSONWebServiceTransportException { String json = doGet(url, parameters, headers); if (json == null) { return Collections.emptyList(); }//from w ww . j a v a 2 s .c om try { TypeFactory typeFactory = _objectMapper.getTypeFactory(); List<V> list = new ArrayList<V>(); JavaType javaType = typeFactory.constructCollectionType(list.getClass(), clazz); return _objectMapper.readValue(json, javaType); } catch (IOException ioe) { throw _getJSONWebServiceSerializeException(json, clazz); } }
From source file:org.eclipse.emf.teneo.mapping.elist.PersistableEMap.java
/** Sets the delegatelist to a persistablelist */ protected void setDelegateEList(InternalEObject owner, EStructuralFeature feature, List<BasicEMap.Entry<K, V>> delegateORMList) { assert (owner.eClass().getFeatureID(feature) == featureID); // NOTE BEWARE: the delegateEList is a member of the superclass! delegateEList = createDelegateEList(owner, feature, delegateORMList); logString = "EMap with entry eclass: " + entryEClass.getName() + " of member " + feature.getName() + " owned by " + owner.getClass().getName() + " with delegate list " + delegateORMList.getClass().getName(); if (log.isDebugEnabled()) { log.debug("Created/reset elist " + logString); }//w w w . j ava 2 s .co m if (delegateORMList instanceof EList<?>) { setLoaded(true); } else if (delegateORMList instanceof ArrayList<?>) { // already loaded // lists are // packaged in // an elist setLoaded(delegateORMList.size() > 0); } if (isLoaded) { // force the map to be computed, this sets the internal entrydata/size member get(null); } }
From source file:fr.cls.atoll.motu.processor.wps.StringList.java
public static void testBuildWPS() { //String serverURL = "http://atoll-dev.cls.fr:30080/atoll-motuservlet/services"; String serverURL = "http://atoll-dev.cls.fr:30080/atoll-motuservlet/services"; try {//from ww w.j av a2s . c om // ServiceMetadata serviceMetadata = new ServiceMetadata(); // URL url = null; // Set<SVOperationMetadataType> listOperation = new HashSet<SVOperationMetadataType>(); // // url = new // // // URL("file:///c:/Documents and Settings/dearith/Mes documents/Atoll/SchemaIso/TestServiceMetadataOK.xml"); // url = // Organizer.findResource("src/main/resources/fmpp/out/serviceMetadata_motu-opendap-mercator.xml"); // serviceMetadata.getOperations(url, listOperation); Map<String, ParameterValue<?>> dataInputValues = new HashMap<String, ParameterValue<?>>(); List<String> list = new ArrayList<String>(); list.add("a"); list.add("b"); list.add("c"); ParameterDescriptor<String> descriptor = new DefaultParameterDescriptor<String>("service", String.class, null, null); ParameterValue<?> parameter = new Parameter<String>(descriptor); parameter.setValue("myservice"); System.out.println(descriptor.getName().getCode()); dataInputValues.put(descriptor.getName().getCode(), parameter); ParameterDescriptor<List<String>> descriptor2 = new DefaultParameterDescriptor<List<String>>("variable", (Class<List<String>>) list.getClass(), null, null); parameter = new Parameter<List<String>>(descriptor2); parameter.setValue(list); System.out.println(descriptor2.getName().getCode()); dataInputValues.put(descriptor2.getName().getCode(), parameter); // Map geobbox = new HashMap<String, String>(); // String geobbox ="-10, -60, 45, 120"; double[] geobbox = new double[] { -10d, -60d, 45d, 120d }; System.out.println(geobbox.getClass()); ParameterValue<?> parameterValue = WPSFactory.createParameter("geobbox", geobbox.getClass(), geobbox); System.out.println(parameterValue.getValue().getClass()); dataInputValues.put(parameterValue.getDescriptor().getName().getCode(), parameterValue); double depth = 0d; parameterValue = WPSFactory.createParameter("lowdepth", depth); System.out.println(parameterValue.getValue().getClass()); dataInputValues.put(parameterValue.getDescriptor().getName().getCode(), parameterValue); OperationMetadata operationMetadata = new OperationMetadata(); operationMetadata.setInvocationName("ExtractData"); operationMetadata.setParameterValueMap(dataInputValues); WPSFactory wpsFactory = new WPSFactory(); Execute execute = WPSFactory.createExecuteProcessRequest(operationMetadata, null, false); FileWriter writer = new FileWriter("WPSExecute.xml"); WPSInfo wpInfo = WPSFactory.getWpsInfo(serverURL); String schemaLocationKey = String.format("%s%s", wpInfo.getProcessDescriptions().getService(), wpInfo.getProcessDescriptions().getVersion()); WPSFactory.marshallExecute(execute, writer, WPSFactory.getSchemaLocations().get(schemaLocationKey)); dataInputValues.clear(); Long val = 1023654l; // Integer val = 1023654; // Double val = 1023654d; // String val = "1023654"; System.out.println(val.getClass()); parameterValue = WPSFactory.createParameter("requestid", val.getClass(), val); System.out.println(parameterValue.getValue().getClass()); dataInputValues.put(parameterValue.getDescriptor().getName().getCode(), parameterValue); operationMetadata.setInvocationName("CompressExtraction"); operationMetadata.setParameterValueMap(dataInputValues); execute = wpsFactory.createExecuteProcessRequest(operationMetadata, null, false); writer = new FileWriter("WPSExecute2.xml"); WPSFactory.marshallExecute(execute, writer, WPSFactory.getSchemaLocations().get(schemaLocationKey)); } catch (MotuException e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println(e.notifyException()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MotuMarshallException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.pentaho.metaverse.impl.model.kettle.json.TransMetaJsonDeserializerTest.java
@Test public void testWriteJsonFields() throws Exception { JsonNode fields = mock(JsonNode.class); ObjectId stepId = new StringObjectId("id"); List<Map<String, Object>> fieldLists = new ArrayList<Map<String, Object>>(); Map<String, Object> fieldMap0 = new HashMap<String, Object>() { {/*from w w w.ja v a 2 s . com*/ put("name", "Test 1"); put("int", 2); put("long", 3L); put("double", 3.0D); put("bool", true); put("null", null); } }; Map<String, Object> fieldMap1 = new HashMap<String, Object>() { { put("name", "Test 2"); put("int", 2); put("long", 3L); put("double", 3.0D); put("bool", true); put("null", null); } }; fieldLists.add(fieldMap0); fieldLists.add(fieldMap1); when(fields.toString()).thenReturn("mockedFields"); when(mapper.readValue("mockedFields", fieldLists.getClass())).then(invocationOnMock -> fieldLists); deserializer.writeJsonFields(fields, mapper, stepId); verify(repo).saveStepAttribute(null, stepId, 0, "name", "Test 1"); verify(repo).saveStepAttribute(null, stepId, 1, "name", "Test 2"); verify(repo, times(2)).saveStepAttribute(any(ObjectId.class), eq(stepId), anyInt(), eq("int"), anyInt()); verify(repo, times(2)).saveStepAttribute(any(ObjectId.class), eq(stepId), anyInt(), eq("long"), eq(3L)); verify(repo, times(2)).saveStepAttribute(any(ObjectId.class), eq(stepId), anyInt(), eq("double"), eq(3.0D)); verify(repo, times(2)).saveStepAttribute(any(ObjectId.class), eq(stepId), anyInt(), eq("bool"), eq(true)); verify(repo, times(2)).saveStepAttribute(any(ObjectId.class), eq(stepId), anyInt(), eq("null"), anyString()); }
From source file:ddf.catalog.CatalogFrameworkImplTest.java
/** * Tests that multiple ResourceReaders with the same scheme will be invoked if the first one did * not return a Response./*from w w w. j a va 2 s . c om*/ * * @throws Exception */ @Test public void testGetResourceToTestSecondResourceReaderWithSameSchemeGetsCalledIfFirstDoesNotReturnAnything() throws Exception { String localProviderName = "ddf"; String metacardId = "123"; final String EXPECTED = "result from mockResourceResponse2"; final String DDF = "ddf"; // The resource's URI URI metacardUri = new URI( "http:///27+Nov+12+12%3A30%3A04?MyPhotograph%0Ahttp%3A%2F%2F172.18.14.53%3A8080%2Fabc%2Fimages%2FActionable.jpg%0AMyAttachment%0Ahttp%3A%2F%2F172.18.14.53%3A8080%2Fabc#abc.xyz.dao.URLResourceOptionDataAccessObject"); // Mock a Catalog Provider CatalogProvider provider = mock(CatalogProvider.class); when(provider.getId()).thenReturn(localProviderName); when(provider.isAvailable(isA(SourceMonitor.class))).thenReturn(true); when(provider.isAvailable()).thenReturn(true); // Mock register the provider in the container // Mock the source poller SourcePoller mockPoller = mock(SourcePoller.class); when(mockPoller.isAvailable(isA(Source.class))).thenReturn(Boolean.TRUE); // Create two ResourceReaders. The first should not return anything // and the second should. ResourceReader resourceReader1 = mock(ResourceReader.class); ResourceReader resourceReader2 = mock(ResourceReader.class); // Set the supported Schemes so that both ResourceReaders use // the same scheme ("DAD") Set<String> supportedSchemes = new HashSet<String>(); supportedSchemes.add("DAD"); when(resourceReader1.getSupportedSchemes()).thenReturn(supportedSchemes); when(resourceReader2.getSupportedSchemes()).thenReturn(supportedSchemes); List<ResourceReader> resourceReaders = new ArrayList<ResourceReader>(); resourceReaders.add(resourceReader1); resourceReaders.add(resourceReader2); // Set up the requests and responses. The first ResourceReader will return null // and the second one will retrieve a value, showing that if more than one // ResourceReader with the same scheme are used, they will be called until a // response is returned ResourceRequest mockResourceRequest = mock(ResourceRequest.class); URI myURI = new URI("DAD", "host", "/path", "fragment"); when(mockResourceRequest.getAttributeValue()).thenReturn(myURI); when(mockResourceRequest.getAttributeName()) .thenReturn(new String(ResourceRequest.GET_RESOURCE_BY_PRODUCT_URI)); Result result = mock(Result.class); Metacard metacard = mock(Metacard.class); when(metacard.getResourceURI()).thenReturn(myURI); when(result.getMetacard()).thenReturn(metacard); List<Result> results = new ArrayList<Result>(); results.add(result); QueryResponse queryResponse = mock(QueryResponse.class); when(queryResponse.getResults()).thenReturn(results); List<Source> federatedSources = new ArrayList<Source>(); FederationStrategy strategy = mock(FederationStrategy.class); when(strategy.federate(isA(federatedSources.getClass()), isA(QueryRequest.class))) .thenReturn(queryResponse); ResourceResponse mockResourceResponse1 = mock(ResourceResponse.class); when(mockResourceResponse1.getRequest()).thenReturn(mockResourceRequest); when(mockResourceResponse1.getResource()).thenReturn(null); when(resourceReader1.retrieveResource(any(URI.class), anyMap())).thenReturn(null); Resource mockResource = mock(Resource.class); when(mockResource.getName()).thenReturn(EXPECTED); ResourceResponse mockResourceResponse2 = mock(ResourceResponse.class); when(mockResourceResponse2.getResource()).thenReturn(mockResource); when(resourceReader2.retrieveResource(any(URI.class), anyMap())).thenReturn(mockResourceResponse2); CatalogFrameworkImpl framework = new CatalogFrameworkImpl( Collections.singletonList((CatalogProvider) provider), null, new ArrayList<PreIngestPlugin>(), new ArrayList<PostIngestPlugin>(), new ArrayList<PreQueryPlugin>(), new ArrayList<PostQueryPlugin>(), new ArrayList<PreResourcePlugin>(), new ArrayList<PostResourcePlugin>(), new ArrayList<ConnectedSource>(), null, resourceReaders, strategy, null, mockPoller); framework.bind(provider); framework.setId(DDF); ResourceResponse response = framework.getResource(mockResourceRequest, false, DDF); // Verify that the Response is as expected org.junit.Assert.assertEquals(EXPECTED, response.getResource().getName()); // Verify that resourceReader1 was called 1 time // This line is equivalent to verify(resourceReader1, // times(1)).retrieveResource(any(URI.class), anyMap()); verify(resourceReader1).retrieveResource(any(URI.class), anyMap()); }
From source file:es.logongas.ix3.web.controllers.SearchHelper.java
public Object executeNamedSearchParameters(Principal principal, DataSession dataSession, CRUDBusinessProcess crudBusinessProcess, String namedSearch, Map<String, Object> filter, PageRequest pageRequest, List<Order> orders, SearchResponse searchResponse) throws BusinessException { try {/*from w w w . j av a 2 s. c o m*/ if (getNamedSearchType(crudBusinessProcess, namedSearch) != NameSearchType.PARAMETERS) { throw new RuntimeException("El mtodo '" + namedSearch + "' de '" + crudBusinessProcess.getClass() + "' debe ser de tipo Parameters"); } if (filter == null) { filter = new HashMap<String, Object>(); } if (orders == null) { orders = new ArrayList<Order>(); } Class businessProcessArgumentsClass = getBusinessProcessMethodArguments(crudBusinessProcess, namedSearch); Object businessProcessArgument = businessProcessArgumentsClass.newInstance(); for (Field field : businessProcessArgumentsClass.getFields()) { Class parameterClass = field.getType(); if (parameterClass.isAssignableFrom(PageRequest.class) == true) { field.set(businessProcessArgument, pageRequest); } else if (parameterClass.isAssignableFrom(orders.getClass()) == true) { field.set(businessProcessArgument, orders); } else if (parameterClass.isAssignableFrom(SearchResponse.class) == true) { field.set(businessProcessArgument, searchResponse); } else if (parameterClass.isAssignableFrom(Principal.class) == true) { field.set(businessProcessArgument, principal); } else if (parameterClass.isAssignableFrom(DataSession.class) == true) { field.set(businessProcessArgument, dataSession); } else { Object parameterValue = filter.get(field.getName()); field.set(businessProcessArgument, parameterValue); } } Method method = ReflectionUtil.getDeclaredMethod(crudBusinessProcess.getClass(), namedSearch); Object result = method.invoke(crudBusinessProcess, businessProcessArgument); return result; } catch (InvocationTargetException ex) { BusinessException businessException = ExceptionUtil.getBusinessExceptionFromThrowable(ex); if (businessException != null) { throw businessException; } else { throw new RuntimeException(ex); } } catch (RuntimeException ex) { throw ex; } catch (BusinessException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:es.logongas.ix3.web.controllers.SearchHelper.java
public Object executeNamedSearchFilters(Principal principal, DataSession dataSession, CRUDBusinessProcess crudBusinessProcess, String namedSearch, Filters filters, PageRequest pageRequest, List<Order> orders, SearchResponse searchResponse) throws BusinessException { try {/* www . j a v a 2 s . c o m*/ if (getNamedSearchType(crudBusinessProcess, namedSearch) != NameSearchType.FILTER) { throw new RuntimeException("El mtodo '" + namedSearch + "' de '" + crudBusinessProcess.getClass() + "' debe ser de tipo Filter"); } if (filters == null) { filters = new Filters(); } if (orders == null) { orders = new ArrayList<Order>(); } Class businessProcessArgumentsClass = getBusinessProcessMethodArguments(crudBusinessProcess, namedSearch); Object businessProcessArgument = businessProcessArgumentsClass.newInstance(); for (Field field : businessProcessArgumentsClass.getFields()) { Class parameterClass = field.getType(); if (parameterClass.isAssignableFrom(filters.getClass()) == true) { field.set(businessProcessArgument, filters); } else if (parameterClass.isAssignableFrom(PageRequest.class) == true) { field.set(businessProcessArgument, pageRequest); } else if (parameterClass.isAssignableFrom(orders.getClass()) == true) { field.set(businessProcessArgument, orders); } else if (parameterClass.isAssignableFrom(SearchResponse.class) == true) { field.set(businessProcessArgument, searchResponse); } else if (parameterClass.isAssignableFrom(Principal.class) == true) { field.set(businessProcessArgument, principal); } else if (parameterClass.isAssignableFrom(DataSession.class) == true) { field.set(businessProcessArgument, dataSession); } else { throw new RuntimeException("El tipo del argumento no es vlido"); } } Method method = ReflectionUtil.getMethod(crudBusinessProcess.getClass(), namedSearch); Object result = method.invoke(crudBusinessProcess, businessProcessArgument); return result; } catch (InvocationTargetException ex) { BusinessException businessException = ExceptionUtil.getBusinessExceptionFromThrowable(ex); if (businessException != null) { throw businessException; } else { throw new RuntimeException(ex); } } catch (RuntimeException ex) { throw ex; } catch (BusinessException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException(ex); } }