PageRenderTime 29ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/plugins/com.liferay.ide.xml.search.ui/src/com/liferay/ide/xml/search/ui/TempMarker.java

https://gitlab.com/4615833/liferay-ide
Java | 187 lines | 136 code | 34 blank | 17 comment | 5 complexity | 0cb0db4f9e28b52479bdb5e3cdd2c1bf MD5 | raw file
  1. /*******************************************************************************
  2. * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU Lesser General Public License as published by the Free
  6. * Software Foundation; either version 2.1 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  12. * details.
  13. *
  14. *******************************************************************************/
  15. package com.liferay.ide.xml.search.ui;
  16. import com.liferay.ide.core.util.CoreUtil;
  17. import java.util.ArrayList;
  18. import java.util.HashMap;
  19. import java.util.List;
  20. import java.util.Map;
  21. import org.eclipse.core.resources.IFile;
  22. import org.eclipse.core.resources.IMarker;
  23. import org.eclipse.core.resources.IResource;
  24. import org.eclipse.core.runtime.CoreException;
  25. import org.eclipse.core.runtime.Path;
  26. import org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation;
  27. /**
  28. * @author Gregory Amerson
  29. */
  30. @SuppressWarnings( "restriction" )
  31. public class TempMarker implements IMarker
  32. {
  33. private final TemporaryAnnotation annotation;
  34. private final Map<String, Object> attributes;
  35. private final long creationTime;
  36. private final IFile file;
  37. private final String type;
  38. public TempMarker( TemporaryAnnotation temp )
  39. {
  40. this.annotation = temp;
  41. this.attributes = new HashMap<String, Object>();
  42. this.creationTime = System.currentTimeMillis();
  43. for( Object key : this.annotation.getAttributes().keySet() )
  44. {
  45. this.attributes.put( key.toString(), this.annotation.getAttributes().get( key ) );
  46. }
  47. this.file =
  48. CoreUtil.getWorkspaceRoot().getFile(
  49. Path.fromPortableString( (String) this.attributes.get( XMLSearchConstants.FULL_PATH ) ) );
  50. this.type = (String) this.attributes.get( XMLSearchConstants.MARKER_TYPE );
  51. }
  52. @Override
  53. public void delete() throws CoreException
  54. {
  55. }
  56. @Override
  57. public boolean exists()
  58. {
  59. return false;
  60. }
  61. @SuppressWarnings( "rawtypes" )
  62. @Override
  63. public Object getAdapter( Class adapter )
  64. {
  65. return null;
  66. }
  67. @Override
  68. public Object getAttribute( String attributeName ) throws CoreException
  69. {
  70. return annotation.getAttributes().get( attributeName );
  71. }
  72. @Override
  73. public boolean getAttribute( String attributeName, boolean defaultValue )
  74. {
  75. final Object value = annotation.getAttributes().get( attributeName );
  76. return value instanceof Boolean ? Boolean.parseBoolean( value.toString() ) : defaultValue;
  77. }
  78. @Override
  79. public int getAttribute( String attributeName, int defaultValue )
  80. {
  81. final Object value = annotation.getAttributes().get( attributeName );
  82. return value instanceof Integer ? Integer.parseInt( value.toString() ) : defaultValue;
  83. }
  84. @Override
  85. public String getAttribute( String attributeName, String defaultValue )
  86. {
  87. final Object value = annotation.getAttributes().get( attributeName );
  88. return value != null ? value.toString() : defaultValue;
  89. }
  90. @Override
  91. public Map<String, Object> getAttributes() throws CoreException
  92. {
  93. return this.attributes;
  94. }
  95. @Override
  96. public Object[] getAttributes( String[] attributeNames ) throws CoreException
  97. {
  98. final List<Object> retval = new ArrayList<Object>();
  99. for( String attributeName : attributeNames )
  100. {
  101. if( this.attributes.get( attributeName ) != null )
  102. {
  103. retval.add( this.attributes.get( attributeName ) );
  104. }
  105. }
  106. return retval.toArray( new Object[0] );
  107. }
  108. @Override
  109. public long getCreationTime() throws CoreException
  110. {
  111. return this.creationTime;
  112. }
  113. @Override
  114. public long getId()
  115. {
  116. return -1;
  117. }
  118. @Override
  119. public IResource getResource()
  120. {
  121. return this.file;
  122. }
  123. @Override
  124. public String getType() throws CoreException
  125. {
  126. return this.type;
  127. }
  128. @Override
  129. public boolean isSubtypeOf( String superType ) throws CoreException
  130. {
  131. return false;
  132. }
  133. @Override
  134. public void setAttribute( String attributeName, boolean value ) throws CoreException
  135. {
  136. }
  137. @Override
  138. public void setAttribute( String attributeName, int value ) throws CoreException
  139. {
  140. }
  141. @Override
  142. public void setAttribute( String attributeName, Object value ) throws CoreException
  143. {
  144. }
  145. @Override
  146. public void setAttributes( Map<String, ? extends Object> attributes ) throws CoreException
  147. {
  148. }
  149. @Override
  150. public void setAttributes( String[] attributeNames, Object[] values ) throws CoreException
  151. {
  152. }
  153. }