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: */package org.apache.cxf.endpoint.dynamic;
019:
020: import java.util.logging.Logger;
021:
022: import javax.xml.namespace.QName;
023:
024: import com.sun.codemodel.JType;
025: import com.sun.tools.xjc.api.Mapping;
026: import com.sun.tools.xjc.api.S2JJAXBModel;
027: import com.sun.tools.xjc.api.TypeAndAnnotation;
028:
029: import org.apache.cxf.common.classloader.ClassLoaderUtils;
030: import org.apache.cxf.common.i18n.Message;
031: import org.apache.cxf.common.util.PrimitiveUtils;
032: import org.apache.cxf.service.ServiceModelVisitor;
033: import org.apache.cxf.service.factory.ServiceConstructionException;
034: import org.apache.cxf.service.model.MessagePartInfo;
035: import org.apache.cxf.service.model.OperationInfo;
036: import org.apache.cxf.service.model.ServiceInfo;
037:
038: public class TypeClassInitializer extends ServiceModelVisitor {
039: private static final Logger LOG = Logger
040: .getLogger(TypeClassInitializer.class.getName());
041:
042: S2JJAXBModel model;
043:
044: public TypeClassInitializer(ServiceInfo serviceInfo,
045: S2JJAXBModel model) {
046: super (serviceInfo);
047: this .model = model;
048: }
049:
050: @Override
051: public void begin(MessagePartInfo part) {
052: OperationInfo op = part.getMessageInfo().getOperation();
053: if (op.isUnwrappedCapable() && !op.isUnwrapped()) {
054: return;
055: }
056:
057: QName name;
058: if (part.isElement()) {
059: name = part.getElementQName();
060: } else {
061: name = part.getTypeQName();
062: }
063: Mapping mapping = model.get(name);
064:
065: //String clsName = null;
066: JType jType = null;
067: if (mapping != null) {
068:
069: jType = mapping.getType().getTypeClass();
070:
071: }
072:
073: if (jType == null) {
074: TypeAndAnnotation typeAndAnnotation = model
075: .getJavaType(part.getTypeQName());
076: if (typeAndAnnotation != null) {
077: jType = typeAndAnnotation.getTypeClass();
078: }
079: }
080:
081: if (jType == null) {
082: throw new ServiceConstructionException(new Message(
083: "NO_JAXB_CLASS", LOG, name));
084: }
085:
086: Class cls;
087:
088: //JClass jclass;
089: try {
090: if (!jType.isPrimitive()) {
091: cls = ClassLoaderUtils.loadClass(jType.fullName(),
092: getClass());
093: } else {
094: cls = PrimitiveUtils.getClass(jType.fullName());
095: }
096: } catch (ClassNotFoundException e) {
097: throw new ServiceConstructionException(e);
098: }
099:
100: part.setTypeClass(cls);
101:
102: super.begin(part);
103: }
104:
105: }
|