001: /**********************************************************************
002: Copyright (c) 2007 Thomas Marti and others. All rights reserved.
003: Licensed under the Apache License, Version 2.0 (the "License");
004: you may not use this file except in compliance with the License.
005: You may obtain a copy of the License at
006:
007: http://www.apache.org/licenses/LICENSE-2.0
008:
009: Unless required by applicable law or agreed to in writing, software
010: distributed under the License is distributed on an "AS IS" BASIS,
011: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: See the License for the specific language governing permissions and
013: limitations under the License.
014:
015: Contributors:
016: ...
017: **********************************************************************/package org.jpox.store.mapping;
018:
019: import java.awt.geom.Arc2D;
020:
021: import org.jpox.ClassLoaderResolver;
022: import org.jpox.ClassNameConstants;
023: import org.jpox.ObjectManager;
024: import org.jpox.metadata.AbstractMemberMetaData;
025: import org.jpox.store.DatastoreAdapter;
026: import org.jpox.store.DatastoreContainerObject;
027: import org.jpox.store.expression.LogicSetExpression;
028: import org.jpox.store.expression.QueryExpression;
029: import org.jpox.store.expression.ScalarExpression;
030:
031: /**
032: * Mapping for java.awt.geom.Arc2D.Float, maps the x, y, width, height, start and extent values to float-precision datastore fields.
033: *
034: * @version $Revision: 1.20 $
035: */
036: public class Arc2dFloatMapping extends SingleFieldMultiMapping {
037:
038: private static final Arc2D.Float sampleValue = new Arc2D.Float();
039:
040: /* (non-Javadoc)
041: * @see org.jpox.store.mapping.JavaTypeMapping#initialize()
042: */
043: public void initialize(DatastoreAdapter dba,
044: AbstractMemberMetaData fmd,
045: DatastoreContainerObject container, ClassLoaderResolver clr) {
046: super .initialize(dba, fmd, container, clr);
047:
048: addDatastoreField(ClassNameConstants.INT); // Type
049: addDatastoreField(ClassNameConstants.FLOAT); // X
050: addDatastoreField(ClassNameConstants.FLOAT); // Y
051: addDatastoreField(ClassNameConstants.FLOAT); // Width
052: addDatastoreField(ClassNameConstants.FLOAT); // Height
053: addDatastoreField(ClassNameConstants.FLOAT); // Start
054: addDatastoreField(ClassNameConstants.FLOAT); // Extent
055: }
056:
057: /* (non-Javadoc)
058: * @see org.jpox.store.mapping.JavaTypeMapping#getJavaType()
059: */
060: public Class getJavaType() {
061: return Arc2D.Float.class;
062: }
063:
064: /* (non-Javadoc)
065: * @see org.jpox.store.mapping.JavaTypeMapping#getSampleValue()
066: */
067: public Object getSampleValue(ClassLoaderResolver clr) {
068: return sampleValue;
069: }
070:
071: /* (non-Javadoc)
072: * @see org.jpox.store.mapping.JavaTypeMapping#setObject(org.jpox.ObjectManager, java.lang.Object, int[], java.lang.Object)
073: */
074: public void setObject(ObjectManager om, Object preparedStatement,
075: int[] exprIndex, Object value) {
076: Arc2D.Float arc = (Arc2D.Float) value;
077: if (arc == null) {
078: for (int i = 0; i < exprIndex.length; i++) {
079: getDataStoreMapping(i).setObject(preparedStatement,
080: exprIndex[i], null);
081: }
082: } else {
083: getDataStoreMapping(0).setInt(preparedStatement,
084: exprIndex[0], arc.getArcType());
085: getDataStoreMapping(1).setFloat(preparedStatement,
086: exprIndex[1], arc.x);
087: getDataStoreMapping(2).setFloat(preparedStatement,
088: exprIndex[2], arc.y);
089: getDataStoreMapping(3).setFloat(preparedStatement,
090: exprIndex[3], arc.width);
091: getDataStoreMapping(4).setFloat(preparedStatement,
092: exprIndex[4], arc.height);
093: getDataStoreMapping(5).setFloat(preparedStatement,
094: exprIndex[5], arc.start);
095: getDataStoreMapping(6).setFloat(preparedStatement,
096: exprIndex[6], arc.extent);
097: }
098: }
099:
100: /* (non-Javadoc)
101: * @see org.jpox.store.mapping.JavaTypeMapping#getObject(org.jpox.ObjectManager, java.lang.Object, int[])
102: */
103: public Object getObject(ObjectManager om, Object resultSet,
104: int[] exprIndex) {
105: // Check for null entries
106: if (getDataStoreMapping(0).getObject(resultSet, exprIndex[0]) == null) {
107: return null;
108: }
109:
110: int type = getDataStoreMapping(0).getInt(resultSet,
111: exprIndex[0]);
112: float x = getDataStoreMapping(1).getFloat(resultSet,
113: exprIndex[1]);
114: float y = getDataStoreMapping(2).getFloat(resultSet,
115: exprIndex[2]);
116: float width = getDataStoreMapping(3).getFloat(resultSet,
117: exprIndex[3]);
118: float height = getDataStoreMapping(4).getFloat(resultSet,
119: exprIndex[4]);
120: float start = getDataStoreMapping(5).getFloat(resultSet,
121: exprIndex[5]);
122: float extent = getDataStoreMapping(6).getFloat(resultSet,
123: exprIndex[6]);
124: return new Arc2D.Float(x, y, width, height, start, extent, type);
125: }
126:
127: // --------------------------------- JDOQL Query Methods -------------------------------------------
128:
129: /* (non-Javadoc)
130: * @see org.jpox.store.mapping.JavaTypeMapping#newLiteral(org.jpox.store.query.QueryStatement, java.lang.Object)
131: */
132: public ScalarExpression newLiteral(QueryExpression qs, Object value) {
133: return null;
134: }
135:
136: /* (non-Javadoc)
137: * @see org.jpox.store.mapping.JavaTypeMapping#newScalarExpression(org.jpox.store.query.QueryStatement, org.jpox.store.expression.TableExpression)
138: */
139: public ScalarExpression newScalarExpression(QueryExpression qs,
140: LogicSetExpression te) {
141: return null;
142: }
143: }
|