001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018
019 package org.apache.commons.betwixt.strategy;
020
021 import org.apache.commons.betwixt.IntrospectionConfiguration;
022
023 /**
024 * Strategy for binding simple types.
025 * Simple types (in xml) have no attributes or child elements.
026 * For Betwixt, these are converted to and from strings
027 * and these strings used to populate either attributes or element body's.
028 * @author <a href='http://commons.apache.org/'>Apache Commons Team</a>
029 * @version $Revision: 561314 $
030 */
031 public abstract class SimpleTypeMapper {
032
033 /**
034 * Enumerates binding options for simple types.
035 * Simple types (in xml) have no attributes or child elements.
036 * For Betwixt, these are converted to and from strings
037 * and these strings used to populate either attributes or element body's.
038 * @author <a href='http://commons.apache.org/'>Apache Commons Team</a>
039 * @version $Revision: 561314 $
040 */
041 public static class Binding {
042 public static final Binding ELEMENT = new Binding(1);
043 public static final Binding ATTRIBUTE = new Binding(2);
044
045 private static final int ELEMENT_CODE = 1;
046 private static final int ATTRIBUTE_CODE = 2;
047
048 private int code;
049 private Binding(int code) {
050 this.code = code;
051 }
052
053
054 /**
055 * Equals compatible with the enumeration.
056 */
057 public boolean equals( Object obj ) {
058 boolean result = false;
059 if ( obj == this ) {
060 result = true;
061 }
062 return result;
063 }
064
065 /**
066 * Implementation compatible with equals
067 */
068 public int hashCode() {
069 return code;
070 }
071
072 /**
073 * Generate something appropriate for logging.
074 */
075 public String toString() {
076 String result = "[Binding]";
077 switch (code) {
078 case ELEMENT_CODE:
079 result = "[Binding: ELEMENT]";
080 break;
081
082 case ATTRIBUTE_CODE:
083 result = "[Binding: ATTRIBUTE]";
084 break;
085 }
086 return result;
087 }
088 }
089
090 /**
091 * <p>Specifies the binding of a simple type.
092 * </p><p>
093 * <strong>Note:</strong> the xml name to which this property will be bound
094 * cannot be known at this stage (since it depends
095 * </p>
096 * @param propertyName the name of the property (to be bound)
097 * @param propertyType the type of the property (to be bound)
098 * @param configuration the current IntrospectionConfiguration
099 */
100 public abstract SimpleTypeMapper.Binding bind(
101 String propertyName,
102 Class propertyType,
103 IntrospectionConfiguration configuration);
104 }