1. /*
  2. * Copyright 2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.apache.commons.betwixt.schema;
  17. import java.beans.IntrospectionException;
  18. import org.apache.commons.betwixt.ElementDescriptor;
  19. /**
  20. * @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
  21. * @version $Revision: 1.2 $
  22. */
  23. public class SimpleLocalElement extends LocalElement {
  24. private String type;
  25. public SimpleLocalElement(String name, String type) {
  26. super(name);
  27. setType(type);
  28. }
  29. public SimpleLocalElement(
  30. TranscriptionConfiguration configuration,
  31. ElementDescriptor descriptor,
  32. Schema schema)
  33. throws IntrospectionException {
  34. super(descriptor, schema);
  35. setType(configuration.getDataTypeMapper().toXMLSchemaDataType(descriptor.getPropertyType()));
  36. }
  37. public String getType() {
  38. return type;
  39. }
  40. public void setType(String string) {
  41. type = string;
  42. }
  43. public int hashCode() {
  44. return getName().hashCode();
  45. }
  46. public boolean equals(Object obj) {
  47. boolean result = false;
  48. if (obj instanceof SimpleLocalElement) {
  49. SimpleLocalElement simpleLocalElement = (SimpleLocalElement) obj;
  50. result =
  51. isEqual(getName(), simpleLocalElement.getName()) &&
  52. isEqual(getType(), simpleLocalElement.getType());
  53. }
  54. return result;
  55. }
  56. private boolean isEqual(String one, String two) {
  57. if (one == null) {
  58. return (two == null);
  59. }
  60. return one.equals(two);
  61. }
  62. public String toString() {
  63. StringBuffer buffer = new StringBuffer();
  64. buffer.append("<element name='");
  65. buffer.append(getName());
  66. buffer.append("' type='");
  67. buffer.append(getType());
  68. buffer.append("'/>");
  69. return buffer.toString();
  70. }
  71. }