001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * 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, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.openejb.core.cmp.cmp2;
018:
019: import org.objectweb.asm.Type;
020:
021: public class CmrField {
022: private final String name;
023: private final CmrStyle cmrStyle;
024: private final Type type;
025: private final Type proxyType;
026: private final String relatedName;
027: private final boolean synthetic;
028:
029: public CmrField(String fieldName, String fieldType,
030: String cmpImplClass, String local, String relatedName,
031: boolean synthetic) {
032: this .synthetic = synthetic;
033: this .name = fieldName;
034: if (fieldType == null) {
035: cmrStyle = CmrStyle.SINGLE;
036: } else if ("java.util.Collection".equals(fieldType)) {
037: cmrStyle = CmrStyle.COLLECTION;
038: } else if ("java.util.Set".equals(fieldType)) {
039: cmrStyle = CmrStyle.SET;
040: } else {
041: throw new IllegalArgumentException("Unsupported fieldType "
042: + fieldType);
043: }
044: type = Type.getType("L" + cmpImplClass.replace('.', '/') + ";");
045: if (local != null) {
046: proxyType = Type.getType("L" + local.replace('.', '/')
047: + ";");
048: } else {
049: proxyType = null;
050: }
051: this .relatedName = relatedName;
052: }
053:
054: public String getName() {
055: return name;
056: }
057:
058: public boolean isSynthetic() {
059: return synthetic;
060: }
061:
062: public CmrStyle getCmrStyle() {
063: return cmrStyle;
064: }
065:
066: public Type getType() {
067: return type;
068: }
069:
070: public Type getProxyType() {
071: return proxyType;
072: }
073:
074: public Type getInitialValueType() {
075: return cmrStyle.getIntiCollectionType();
076: }
077:
078: public String getRelatedName() {
079: return relatedName;
080: }
081:
082: public String getDescriptor() {
083: Type collectionType = cmrStyle.getCollectionType();
084: if (collectionType == null) {
085: return type.getDescriptor();
086: }
087: return collectionType.getDescriptor();
088: }
089:
090: public String getGenericSignature() {
091: Type collectionType = cmrStyle.getCollectionType();
092: if (collectionType == null) {
093: return null;
094: }
095: return createSignature(collectionType, type);
096: }
097:
098: public String getProxyDescriptor() {
099: Type collectionType = cmrStyle.getCollectionType();
100: if (collectionType == null) {
101: return proxyType.getDescriptor();
102: }
103: return collectionType.getDescriptor();
104: }
105:
106: public String getAccessorInternalName() {
107: return cmrStyle.getAccessorType().getInternalName();
108: }
109:
110: public String getAccessorDescriptor() {
111: return cmrStyle.getAccessorType().getDescriptor();
112: }
113:
114: public String getAccessorGenericSignature() {
115: Type collectionType = cmrStyle.getCollectionType();
116: if (collectionType == null) {
117: return null;
118: }
119: return createSignature(cmrStyle.getAccessorType(), type,
120: proxyType);
121: }
122:
123: private static String createSignature(Type type,
124: Type... genericTypes) {
125: StringBuilder builder = new StringBuilder();
126: builder.append("L").append(type.getInternalName());
127: if (genericTypes.length > 0) {
128: builder.append("<");
129: for (Type genericType : genericTypes) {
130: builder.append(genericType.getDescriptor());
131: }
132: builder.append(">");
133: }
134: builder.append(";");
135: return builder.toString();
136: }
137: }
|