List of usage examples for javax.xml.bind JAXB unmarshal
public static <T> T unmarshal(Source xml, Class<T> type)
From source file:org.ebayopensource.turmeric.tools.library.utils.TypeLibraryUtilities.java
/** * //from www .ja va 2 s . c om * @param libraryNames list of library names for which the namespace information has to be derived. * @param projectRoot optional - If passed, the TypeInformation.xml file would be looked under this folder first. Only if not found the claasloaders * would be used to find the TypeInformaion.xml file * @param parentClassLoader optional - If passed this classloaded would be used to locate the TypeInformation.xml file * before trying to make use of the context class loader. * @return */ public static Map<String, String> getLibrariesNameSpace(List<String> libraryNames, TypeLibraryCodeGenContext ctx, ClassLoader parentClassLoader) { Map<String, String> libNSMap = new HashMap<String, String>(libraryNames.size()); for (String currLibraryName : libraryNames) { InputStream inputStream = null; try { String nameSpace = null; if (ctx != null && !ctx.isProjectRootBlank()) { String typeInformationFilePath = TypeLibraryUtilities.getTypeInfoFolder(ctx, currLibraryName); typeInformationFilePath = normalizePath(typeInformationFilePath) + TypeLibraryConstants.TYPE_INFORMATION_FILE_NAME; File typeInfoFile = new File(typeInformationFilePath); if (typeInfoFile.exists()) { try { inputStream = new FileInputStream(typeInfoFile); } catch (FileNotFoundException e) { getLogger().log(Level.WARNING, "Exception while getting file from path " + typeInfoFile.getAbsolutePath()); } } } if (inputStream == null) { String typeInfoFileRelativePath = getTypeInformationFileRelativePath(currLibraryName); inputStream = getInputStreamForAFileFromClasspath(typeInfoFileRelativePath, parentClassLoader); } if (inputStream != null) { TypeLibraryType typeLibraryType = JAXB.unmarshal(inputStream, TypeLibraryType.class); if (typeLibraryType != null) { nameSpace = typeLibraryType.getLibraryNamespace(); } libNSMap.put(currLibraryName, nameSpace); } } finally { CodeGenUtil.closeQuietly(inputStream); } } return libNSMap; }
From source file:org.ebayopensource.turmeric.tools.library.utils.TypeLibraryUtilities.java
public static Map<String, Set<String>> findDependentLibrariesAndTypesForAType(TypeLibraryCodeGenContext ctx, String typeLibraryName, String typeName) throws Exception { getLogger().log(Level.INFO,//from w w w . j a v a2 s.co m "Input params for findDependentLibrariesForAType \n" + "projectRoot :" + ctx.getProjectRoot() + "\n" + "typelibrary name :" + typeLibraryName + "\n" + "typeName :" + typeName); Map<String, Set<String>> depLibraryAndTypeNamesMap = new HashMap<String, Set<String>>(); TypeLibraryDependencyType typeLibraryDependencyType = null; if (!ctx.isProjectRootBlank()) { String typeDefsFolder = TypeLibraryUtilities.getTypeDepFolder(ctx, typeLibraryName); File typeDepFile = new File( typeDefsFolder + File.separator + TypeLibraryConstants.TYPE_DEPENDENCIES_FILE_NAME); if (!typeDepFile.exists()) return depLibraryAndTypeNamesMap; //Its not mandatory for a project to have TypeDependencies.xml file FileInputStream fis = null; try { fis = new FileInputStream(typeDepFile); typeLibraryDependencyType = JAXB.unmarshal(fis, TypeLibraryDependencyType.class); } catch (IOException e) { getLogger().log(Level.WARNING, "Could not find the " + TypeLibraryConstants.TYPE_DEPENDENCIES_FILE_NAME + " for the library " + typeLibraryName + " in the method findDependentLibrariesAndTypesForAType in TypeLibraryUtilities , \n the file was searched at location " + typeDepFile.getAbsolutePath(), e); return depLibraryAndTypeNamesMap; } finally { IOUtils.closeQuietly(fis); } } if (typeLibraryDependencyType == null) typeLibraryDependencyType = getTypeLibraryDependencyTypeForLibrary(typeLibraryName); getLogger().log(Level.INFO, "Calling function findDependantLibrariesRecursivelyAtInvidualTypeLevel for type : " + typeName); ProcessedType typeToBeProcessed = new ProcessedType(typeName, typeLibraryName); Set<ProcessedType> processedTypes = new HashSet<ProcessedType>(); findDependantLibrariesAndTypesRecursivelyAtIndividualTypeLevel(typeLibraryDependencyType, typeToBeProcessed, depLibraryAndTypeNamesMap, processedTypes); return depLibraryAndTypeNamesMap; }
From source file:org.eclipse.swordfish.internal.resolver.backend.base.impl.HttpClientProxy.java
private Object mapResponse(String response, Class<? extends Object> etnityType) { Object responseObject = null; Reader responseReader = new StringReader(response); ClassLoader cl = Thread.currentThread().getContextClassLoader(); try {//from ww w . j a v a2s .c o m Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); responseObject = JAXB.unmarshal(responseReader, etnityType); } finally { Thread.currentThread().setContextClassLoader(cl); } return responseObject; }
From source file:org.eclipse.swordfish.plugins.resolver.proxy.impl.HttpCilentProxy.java
@Override public ClientResponse invoke(ClientRequest request) { ClientResponse response = new ClientResponseImpl(); HttpMethodBase method = getMethod(request.getMethod()); try {//from w w w . ja v a2 s .c om method.setURI(new URI(request.getURI().toString(), true)); int statusCode = getClient().executeMethod(method); response.setStatus(Status.get(statusCode)); String responseBody = method.getResponseBodyAsString(); if (request.getEntityType() != null) { Reader responseReader = new StringReader(responseBody); ClassLoader cl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); response.setEntity(JAXB.unmarshal(responseReader, request.getEntityType())); } finally { Thread.currentThread().setContextClassLoader(cl); } } else { response.setEntity(responseBody); } } catch (HttpException e) { response.setStatus(Status.ERROR); response.setEntity(e); } catch (IOException e) { response.setStatus(Status.ERROR); response.setEntity(e); } finally { if (method != null) { method.releaseConnection(); } } return response; }
From source file:org.jivesoftware.openfire.crowd.CrowdManager.java
/** * Get all the users from Crowd/*w w w. j av a2s.c om*/ * @return a List of User containing all the users stored in Crowd * @throws RemoteException */ public List<User> getAllUsers() throws RemoteException { if (LOG.isDebugEnabled()) LOG.debug("fetching all crowd users"); int maxResults = 100; int startIndex = 0; List<User> results = new ArrayList<User>(); StringBuilder request = new StringBuilder("search?entity-type=user&expand=user&restriction=active%3dtrue") .append("&max-results=").append(maxResults).append("&start-index="); try { while (true) { GetMethod get = createGetMethodXmlResponse(crowdServer.resolve(request.toString() + startIndex)); Users users = null; try { int httpCode = client.executeMethod(get); if (httpCode != 200) { handleHTTPError(get); } users = JAXB.unmarshal(get.getResponseBodyAsStream(), Users.class); } finally { get.releaseConnection(); } if (users != null && users.user != null) { for (User user : users.user) { user.name = JID.escapeNode(user.name); results.add(user); } if (users.user.size() != maxResults) { break; } else { startIndex += maxResults; } } else { break; } } } catch (IOException ioe) { handleError(ioe); } return results; }
From source file:org.jivesoftware.openfire.crowd.CrowdManager.java
/** * Get all the crowd groups/*from w ww .j av a 2s. c o m*/ * @return a List of group names * @throws RemoteException */ public List<String> getAllGroupNames() throws RemoteException { if (LOG.isDebugEnabled()) LOG.debug("fetch all crowd groups"); int maxResults = 100; int startIndex = 0; List<String> results = new ArrayList<String>(); StringBuilder request = new StringBuilder("search?entity-type=group&restriction=active%3dtrue") .append("&max-results=").append(maxResults).append("&start-index="); try { while (true) { GetMethod get = createGetMethodXmlResponse(crowdServer.resolve(request.toString() + startIndex)); Groups groups = null; try { int httpCode = client.executeMethod(get); if (httpCode != 200) { handleHTTPError(get); } groups = JAXB.unmarshal(get.getResponseBodyAsStream(), Groups.class); } finally { get.releaseConnection(); } if (groups != null && groups.group != null) { for (Group group : groups.group) { results.add(group.name); } if (groups.group.size() != maxResults) { break; } else { startIndex += maxResults; } } else { break; } } } catch (IOException ioe) { handleError(ioe); } return results; }
From source file:org.jivesoftware.openfire.crowd.CrowdManager.java
/** * Get all the groups of a given username * @param username/*from w w w. j a v a2 s . c om*/ * @return a List of groups name * @throws RemoteException */ public List<String> getUserGroups(String username) throws RemoteException { username = JID.unescapeNode(username); if (LOG.isDebugEnabled()) LOG.debug("fetch all crowd groups for user:" + username); int maxResults = 100; int startIndex = 0; List<String> results = new ArrayList<String>(); StringBuilder request = new StringBuilder("user/group/nested?username=").append(urlEncode(username)) .append("&max-results=").append(maxResults).append("&start-index="); try { while (true) { GetMethod get = createGetMethodXmlResponse(crowdServer.resolve(request.toString() + startIndex)); Groups groups = null; try { int httpCode = client.executeMethod(get); if (httpCode != 200) { handleHTTPError(get); } groups = JAXB.unmarshal(get.getResponseBodyAsStream(), Groups.class); } finally { get.releaseConnection(); } if (groups != null && groups.group != null) { for (Group group : groups.group) { results.add(group.name); } if (groups.group.size() != maxResults) { break; } else { startIndex += maxResults; } } else { break; } } } catch (IOException ioe) { handleError(ioe); } return results; }
From source file:org.jivesoftware.openfire.crowd.CrowdManager.java
/** * Get the description of a group from crowd * @param groupName/*from w ww .ja v a2 s . c om*/ * @return a Group object * @throws RemoteException */ public Group getGroup(String groupName) throws RemoteException { if (LOG.isDebugEnabled()) LOG.debug("Get group:" + groupName + " from crowd"); GetMethod get = createGetMethodXmlResponse(crowdServer.resolve("group?groupname=" + urlEncode(groupName))); Group group = null; try { int httpCode = client.executeMethod(get); if (httpCode != 200) { handleHTTPError(get); } group = JAXB.unmarshal(get.getResponseBodyAsStream(), Group.class); } catch (IOException ioe) { handleError(ioe); } finally { get.releaseConnection(); } return group; }
From source file:org.jivesoftware.openfire.crowd.CrowdManager.java
/** * Get the members of the given group// w w w . jav a 2 s . com * @param groupName * @return a List of String with the usernames members of the given group * @throws RemoteException */ public List<String> getGroupMembers(String groupName) throws RemoteException { if (LOG.isDebugEnabled()) LOG.debug("Get all members for group:" + groupName); int maxResults = 100; int startIndex = 0; List<String> results = new ArrayList<String>(); StringBuilder request = new StringBuilder("group/user/nested?groupname=").append(urlEncode(groupName)) .append("&max-results=").append(maxResults).append("&start-index="); try { while (true) { GetMethod get = createGetMethodXmlResponse(crowdServer.resolve(request.toString() + startIndex)); Users users = null; try { int httpCode = client.executeMethod(get); if (httpCode != 200) { handleHTTPError(get); } users = JAXB.unmarshal(get.getResponseBodyAsStream(), Users.class); } finally { get.releaseConnection(); } if (users != null && users.user != null) { for (org.jivesoftware.openfire.crowd.jaxb.User user : users.user) { results.add(JID.escapeNode(user.name)); } if (users.user.size() != maxResults) { break; } else { startIndex += maxResults; } } else { break; } } } catch (IOException ioe) { handleError(ioe); } return results; }
From source file:org.metaservice.api.messaging.config.JAXBMetaserviceDescriptorImpl.java
public static void main(String[] args) throws FileNotFoundException { StringWriter w = new StringWriter(); MetaserviceDescriptor descriptor = JAXB.unmarshal(new FileInputStream(new File( "C:\\Users\\ilo\\dev\\metaservice.org\\metaservice-core-deb\\src\\main\\resources\\metaservice.xml")), JAXBMetaserviceDescriptorImpl.class); // System.err.println(descriptor.getCrawlerList()); // System.err.println(descriptor.getTemplateList()); // System.err.println(descriptor); System.err.println(descriptor); }