001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.openjpa.meta;
020:
021: import java.io.File;
022: import java.io.Serializable;
023:
024: import org.apache.openjpa.lib.meta.SourceTracker;
025: import org.apache.openjpa.lib.xml.Commentable;
026:
027: /**
028: * Metadata about a persistence-aware type.
029: *
030: * @author Pinaki Poddar
031: */
032: public class NonPersistentMetaData implements Comparable,
033: SourceTracker, Commentable, MetaDataContext, Serializable {
034: public static final int TYPE_PERSISTENCE_AWARE = 1;
035: public static final int TYPE_NON_MAPPED_INTERFACE = 2;
036:
037: private final MetaDataRepository _repos;
038: private final Class _class;
039: private final int _type;
040:
041: private File _srcFile = null;
042: private int _srcType = SRC_OTHER;
043: private String[] _comments = null;
044: private int _listIndex = -1;
045:
046: protected NonPersistentMetaData(Class cls,
047: MetaDataRepository repos, int type) {
048: _repos = repos;
049: _class = cls;
050: _type = type;
051: }
052:
053: /**
054: * Owning repository.
055: */
056: public MetaDataRepository getRepository() {
057: return _repos;
058: }
059:
060: /**
061: * Persistence-aware type.
062: */
063: public Class getDescribedType() {
064: return _class;
065: }
066:
067: /**
068: * The type of metadata.
069: */
070: public int getType() {
071: return _type;
072: }
073:
074: /**
075: * The index in which this class was listed in the metadata. Defaults to
076: * <code>-1</code> if this class was not listed in the metadata.
077: */
078: public int getListingIndex() {
079: return _listIndex;
080: }
081:
082: /**
083: * The index in which this field was listed in the metadata. Defaults to
084: * <code>-1</code> if this class was not listed in the metadata.
085: */
086: public void setListingIndex(int index) {
087: _listIndex = index;
088: }
089:
090: public File getSourceFile() {
091: return _srcFile;
092: }
093:
094: public Object getSourceScope() {
095: return null;
096: }
097:
098: public int getSourceType() {
099: return _srcType;
100: }
101:
102: public void setSource(File file, int srcType) {
103: _srcFile = file;
104: _srcType = srcType;
105: }
106:
107: public String getResourceName() {
108: return _class.getName();
109: }
110:
111: public String[] getComments() {
112: return (_comments == null) ? ClassMetaData.EMPTY_COMMENTS
113: : _comments;
114: }
115:
116: public void setComments(String[] comments) {
117: _comments = comments;
118: }
119:
120: public int compareTo(Object o) {
121: if (o == this )
122: return 0;
123: if (!(o instanceof NonPersistentMetaData))
124: return 1;
125: NonPersistentMetaData other = (NonPersistentMetaData) o;
126: if (_type != other.getType())
127: return _type - other.getType();
128: return _class.getName().compareTo(
129: other.getDescribedType().getName());
130: }
131: }
|