Namespace.java 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /**
  2. * Licensed Materials - Property of IBM
  3. *
  4. * IBM Cognos Products: CAMAAA
  5. *
  6. * (C) Copyright IBM Corp. 2005, 2012
  7. *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
  9. * IBM Corp.
  10. */
  11. import java.util.Locale;
  12. import com.cognos.CAM_AAA.authentication.INamespace;
  13. import com.cognos.CAM_AAA.authentication.INamespaceConfiguration;
  14. import com.cognos.CAM_AAA.authentication.ISearchFilter;
  15. import com.cognos.CAM_AAA.authentication.ISearchFilterConditionalExpression;
  16. import com.cognos.CAM_AAA.authentication.ISearchFilterFunctionCall;
  17. import com.cognos.CAM_AAA.authentication.ISearchFilterRelationExpression;
  18. import com.cognos.CAM_AAA.authentication.UnrecoverableException;
  19. public class Namespace extends UiClass implements INamespace
  20. {
  21. /**
  22. *
  23. */
  24. public Namespace()
  25. {
  26. super(null);
  27. capabilities = new String[6];
  28. capabilities[0] = CapabilityCaseSensitive;
  29. capabilities[1] = CapabilityContains;
  30. capabilities[2] = CapabilityEquals;
  31. capabilities[3] = CapabilitySort;
  32. capabilities[4] = CapabilityStartsWith;
  33. capabilities[5] = CapabilityEndsWith;
  34. namespaceFormat = "http://developer.cognos.com/schemas/CAM/AAANamespaceFormat/2/";
  35. }
  36. /**
  37. * @param theObjectID
  38. */
  39. public Namespace(String theObjectID)
  40. {
  41. super(theObjectID);
  42. capabilities = new String[6];
  43. capabilities[0] = CapabilityCaseSensitive;
  44. capabilities[1] = CapabilityContains;
  45. capabilities[2] = CapabilityEquals;
  46. capabilities[3] = CapabilitySort;
  47. capabilities[4] = CapabilityStartsWith;
  48. capabilities[5] = CapabilityEndsWith;
  49. namespaceFormat = "http://developer.cognos.com/schemas/CAM/AAANamespaceFormat/2/";
  50. }
  51. /*
  52. * (non-Javadoc)
  53. *
  54. * @see com.cognos.CAM_AAA.authentication.INamespace#init(com.cognos.CAM_AAA.authentication.INamespaceConfiguration)
  55. */
  56. public void init(INamespaceConfiguration theNamespaceConfiguration)
  57. throws UnrecoverableException
  58. {
  59. setObjectID(theNamespaceConfiguration.getID());
  60. addName(theNamespaceConfiguration.getServerLocale(),
  61. theNamespaceConfiguration.getDisplayName());
  62. }
  63. /*
  64. * (non-Javadoc)
  65. *
  66. * @see com.cognos.CAM_AAA.authentication.INamespace#destroy()
  67. */
  68. public void destroy()
  69. {
  70. }
  71. /*
  72. * (non-Javadoc)
  73. *
  74. * @see com.cognos.CAM_AAA.authentication.INamespace#getNamespaceFormat()
  75. */
  76. public String getNamespaceFormat()
  77. {
  78. return namespaceFormat;
  79. }
  80. /*
  81. * (non-Javadoc)
  82. *
  83. * @see com.cognos.CAM_AAA.authentication.INamespace#setNamespaceFormat(java.lang.String)
  84. */
  85. public void setNamespaceFormat(String theNamespaceFormat)
  86. {
  87. namespaceFormat = theNamespaceFormat;
  88. }
  89. /*
  90. * (non-Javadoc)
  91. *
  92. * @see com.cognos.CAM_AAA.authentication.INamespace#getCapabilities()
  93. */
  94. public String[] getCapabilities()
  95. {
  96. return capabilities;
  97. }
  98. /*
  99. * (non-Javadoc)
  100. *
  101. * @see com.cognos.CAM_AAA.authentication.IBaseClass#getHasChildren()
  102. */
  103. public boolean getHasChildren()
  104. {
  105. return true;
  106. }
  107. /**
  108. * @param theFilter
  109. * @return
  110. */
  111. public boolean matchesFilter(ISearchFilter theFilter)
  112. {
  113. if (theFilter == null)
  114. {
  115. return true;
  116. }
  117. switch (theFilter.getSearchFilterType())
  118. {
  119. case ISearchFilter.ConditionalExpression :
  120. {
  121. ISearchFilterConditionalExpression item = (ISearchFilterConditionalExpression) theFilter;
  122. String operator = item.getOperator();
  123. ISearchFilter[] filters = item.getFilters();
  124. if (filters.length > 0)
  125. {
  126. boolean retval = false;
  127. for (int i = 1; i < filters.length; i++)
  128. {
  129. retval = this.matchesFilter(filters[i]);
  130. if (operator
  131. .equals(ISearchFilterConditionalExpression.ConditionalAnd))
  132. {
  133. if (retval == false)
  134. {
  135. return false;
  136. }
  137. }
  138. else if (operator
  139. .equals(ISearchFilterConditionalExpression.ConditionalOr))
  140. {
  141. if (retval == true)
  142. {
  143. return true;
  144. }
  145. }
  146. else
  147. {
  148. return false;
  149. }
  150. }
  151. }
  152. }
  153. break;
  154. case ISearchFilter.FunctionCall :
  155. {
  156. ISearchFilterFunctionCall item = (ISearchFilterFunctionCall) theFilter;
  157. String functionName = item.getFunctionName();
  158. if (functionName.equals(ISearchFilterFunctionCall.Contains))
  159. {
  160. String[] parameter = item.getParameters();
  161. String propertyName = parameter[0];
  162. String value = parameter[1];
  163. if (propertyName.compareTo("@objectClass") == 0)
  164. {
  165. return ("namespace".indexOf(value) > 0);
  166. }
  167. else if (propertyName.equals("@defaultName")
  168. || propertyName.equals("@name"))
  169. {
  170. Locale[] locales = this.getAvailableNameLocales();
  171. if (locales != null)
  172. {
  173. for (int i = 0; i < locales.length; i++)
  174. {
  175. if (this.getName(locales[i]).indexOf(value) != -1)
  176. {
  177. return true;
  178. }
  179. }
  180. }
  181. }
  182. return false;
  183. }
  184. else if (functionName
  185. .compareTo(ISearchFilterFunctionCall.StartsWith) == 0)
  186. {
  187. String[] parameter = item.getParameters();
  188. String propertyName = parameter[0];
  189. String value = parameter[1];
  190. if (propertyName.compareTo("@objectClass") == 0)
  191. {
  192. return ("namespace".startsWith(value));
  193. }
  194. else if (propertyName.compareTo("@defaultName") == 0
  195. || propertyName.compareTo("@name") == 0)
  196. {
  197. Locale[] locales = this.getAvailableNameLocales();
  198. if (locales != null)
  199. {
  200. for (int i = 0; i < locales.length; i++)
  201. {
  202. if (this.getName(locales[i]).startsWith(
  203. value))
  204. {
  205. return true;
  206. }
  207. }
  208. }
  209. }
  210. return false;
  211. }
  212. else if (functionName
  213. .compareTo(ISearchFilterFunctionCall.EndsWith) == 0)
  214. {
  215. String[] parameter = item.getParameters();
  216. String propertyName = parameter[0];
  217. String value = parameter[1];
  218. if (propertyName.compareTo("@objectClass") == 0)
  219. {
  220. return ("namespace".endsWith(value));
  221. }
  222. else if (propertyName.compareTo("@defaultName") == 0
  223. || propertyName.compareTo("@name") == 0)
  224. {
  225. Locale[] locales = this.getAvailableNameLocales();
  226. if (locales != null)
  227. {
  228. for (int i = 0; i < locales.length; i++)
  229. {
  230. if (this.getName(locales[i])
  231. .endsWith(value))
  232. {
  233. return true;
  234. }
  235. }
  236. }
  237. }
  238. return false;
  239. }
  240. else
  241. {
  242. return false;
  243. }
  244. }
  245. case ISearchFilter.RelationalExpression :
  246. {
  247. ISearchFilterRelationExpression item = (ISearchFilterRelationExpression) theFilter;
  248. String propertyName = item.getPropertyName();
  249. String constraint = item.getConstraint();
  250. String operator = item.getOperator();
  251. if (propertyName.equals("@objectClass"))
  252. {
  253. if (constraint.equals("namespace"))
  254. {
  255. return (operator
  256. .equals(ISearchFilterRelationExpression.EqualTo));
  257. }
  258. else
  259. {
  260. return false;
  261. }
  262. }
  263. else if (propertyName.equals("@defaultName")
  264. || propertyName.equals("@name"))
  265. {
  266. if (operator
  267. .equals(ISearchFilterRelationExpression.EqualTo))
  268. {
  269. Locale[] locales = this.getAvailableNameLocales();
  270. if (locales != null)
  271. {
  272. for (int i = 0; i < locales.length; i++)
  273. {
  274. if (this.getName(locales[i]).compareTo(
  275. constraint) == 0)
  276. {
  277. return true;
  278. }
  279. }
  280. }
  281. return false;
  282. }
  283. else if (operator
  284. .equals(ISearchFilterRelationExpression.NotEqual))
  285. {
  286. Locale[] locales = this.getAvailableNameLocales();
  287. if (locales != null)
  288. {
  289. for (int i = 0; i < locales.length; i++)
  290. {
  291. if (this.getName(locales[i]).compareTo(
  292. constraint) != 0)
  293. {
  294. return true;
  295. }
  296. }
  297. }
  298. return false;
  299. }
  300. }
  301. }
  302. }
  303. return false;
  304. }
  305. private String[] capabilities;
  306. private String namespaceFormat;
  307. }