All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ibm.maximo.oslc.QuerySelect Maven / Gradle / Ivy

Go to download

The Maximo REST client library provides a set of driver API's which can be consumed by an JAVA based web component that would like to interface with a Maximo instance

There is a newer version: 1.0.2
Show newest version
/*
* Licensed Materials - Property of IBM
*
* (C) COPYRIGHT IBM CORP. 2015 All Rights Reserved
*
* US Government Users Restricted Rights - Use, duplication or
* disclosure restricted by GSA ADP Schedule Contract with
* IBM Corp.
 */

package com.ibm.maximo.oslc;
import java.util.*;

public class QuerySelect {
	
	//a.b.*,a.c,x.y.z,x.f.g,x.y.e == a{b{*},c},x{y{z,e},f{g}}
	private Map map = new HashMap();
	public String select(String... selectClause)
	{
		StringBuffer strb = new StringBuffer();
		
		for(String s : selectClause)
		{
			if(s.startsWith("$"))//dynamic attributes
			{
				strb.append(s.substring(1)+",");
			}
			else if(s.indexOf('.')>0)
			{
				String[] tokens = s.split("\\.");
				this.handleTokens(tokens, 0, map);
			}
			else
			{
				strb.append(s+",");
			}
		}
		this.map2String(strb, map);
		if(strb.toString().endsWith(","))
		{
			strb.deleteCharAt(strb.toString().length()-1);
		}

		return strb.toString();
	}
	
	private void map2String(StringBuffer strb, Map map)
	{
		//if(map.size()==0) return;
		//if(strb.length()>0 && strb.toString().charAt(strb.toString().length()-1)!='{') strb.append(",");
		Set set = map.entrySet();
		for(Map.Entry entry : set)
		{
			String key = (String)entry.getKey();
			Map value = (Map)entry.getValue();
			if(value == null || value.size()==0)
			{
				strb.append(key+",");
			}
			else
			{
				strb.append(key+"{");
				this.map2String(strb,value);
				if(strb.toString().endsWith(","))
				{
					strb.deleteCharAt(strb.toString().length()-1);
				}
				strb.append("},");
			}
		}
	}
	
	private void handleTokens(String[] tokens, int index, Map selectMap)
	{
		if(tokens.length




© 2015 - 2024 Weber Informatics LLC | Privacy Policy