feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,65 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import javax.xml.bind.annotation.XmlTransient;
import com.sun.xml.internal.xsom.XSComponent;
import org.xml.sax.Locator;
/**
* Partial default implementation of {@link CElement}.
*
* @author Kohsuke Kawaguchi
*/
abstract class AbstractCElement extends AbstractCTypeInfoImpl implements CElement {
/**
* The location in the source file where this class was declared.
*/
@XmlTransient
private final Locator locator;
private boolean isAbstract;
protected AbstractCElement(Model model, XSComponent source, Locator locator, CCustomizations customizations) {
super(model, source, customizations);
this.locator = locator;
}
public Locator getLocator() {
return locator;
}
public boolean isAbstract() {
return isAbstract;
}
public void setAbstract() {
isAbstract = true;
}
}

View File

@@ -0,0 +1,111 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import javax.activation.MimeType;
import com.sun.codemodel.internal.JExpression;
import com.sun.tools.internal.xjc.outline.Outline;
import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
import com.sun.xml.internal.bind.v2.model.core.ID;
import com.sun.xml.internal.bind.v2.runtime.Location;
import com.sun.xml.internal.xsom.XSComponent;
import com.sun.xml.internal.xsom.XmlString;
/**
* Partial implementation of {@link CTypeInfo}.
*
* <p>
* The inheritance of {@link TypeUse} by {@link CTypeInfo}
* isn't a normal inheritance (see {@link CTypeInfo} for more.)
* This class implments methods on {@link TypeUse} for {@link CTypeInfo}.
*
* @author Kohsuke Kawaguchi
*/
abstract class AbstractCTypeInfoImpl implements CTypeInfo {
private final CCustomizations customizations;
private final XSComponent source;
protected AbstractCTypeInfoImpl(Model model, XSComponent source, CCustomizations customizations) {
if(customizations==null)
customizations = CCustomizations.EMPTY;
else
customizations.setParent(model,this);
this.customizations = customizations;
this.source = source;
}
public final boolean isCollection() {
return false;
}
public final CAdapter getAdapterUse() {
return null;
}
public final ID idUse() {
return ID.NONE;
}
public final XSComponent getSchemaComponent() {
return source;
}
/**
* @deprecated
* why are you calling an unimplemented method?
*/
public final boolean canBeReferencedByIDREF() {
// we aren't doing any error check in XJC, so no point in implementing this method.
throw new UnsupportedOperationException();
}
/**
* No default {@link MimeType}.
*/
public MimeType getExpectedMimeType() {
return null;
}
public CCustomizations getCustomizations() {
return customizations;
}
// this is just a convenient default
public JExpression createConstant(Outline outline, XmlString lexical) {
return null;
}
public final Locatable getUpstream() {
throw new UnsupportedOperationException();
}
public final Location getLocation() {
throw new UnsupportedOperationException();
}
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import java.util.Set;
import java.util.Map;
import java.util.HashMap;
import java.util.HashSet;
import com.sun.tools.internal.xjc.api.ClassNameAllocator;
/**
* {@link ClassNameAllocator} filter that performs automatic name conflict resolution.
*
* @author Kohsuke Kawaguchi
*/
public class AutoClassNameAllocator implements ClassNameAllocator {
private final ClassNameAllocator core;
private final Map<String,Set<String>> names = new HashMap<String,Set<String>>();
public AutoClassNameAllocator(ClassNameAllocator core) {
this.core = core;
}
public String assignClassName(String packageName, String className) {
className = determineName(packageName, className);
if(core!=null)
className = core.assignClassName(packageName,className);
return className;
}
private String determineName(String packageName, String className) {
Set<String> s = names.get(packageName);
if(s==null) {
s = new HashSet<String>();
names.put(packageName,s);
}
if(s.add(className))
return className;
for(int i=2;true;i++) {
if(s.add(className+i))
return className+i;
}
}
}

View File

@@ -0,0 +1,119 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
import javax.xml.bind.annotation.adapters.NormalizedStringAdapter;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import com.sun.codemodel.internal.JClass;
import com.sun.tools.internal.xjc.model.nav.EagerNClass;
import com.sun.tools.internal.xjc.model.nav.NClass;
import com.sun.tools.internal.xjc.model.nav.NType;
import com.sun.tools.internal.xjc.model.nav.NavigatorImpl;
import com.sun.tools.internal.xjc.outline.Aspect;
import com.sun.tools.internal.xjc.outline.Outline;
import com.sun.xml.internal.bind.v2.model.core.Adapter;
/**
* Extended {@link Adapter} for use within XJC.
*
* @author Kohsuke Kawaguchi
*/
public final class CAdapter extends Adapter<NType,NClass> {
/**
* If non-null, the same as {@link #adapterType} but more conveniently typed.
*/
private JClass adapterClass1;
/**
* If non-null, the same as {@link #adapterType} but more conveniently typed.
*/
private Class<? extends XmlAdapter> adapterClass2;
/**
* When the adapter class is statically known to us.
*
* @param copy
* true to copy the adapter class into the user package,
* or otherwise just refer to the class specified via the
* adapter parameter.
*/
public CAdapter(Class<? extends XmlAdapter> adapter, boolean copy) {
super(getRef(adapter,copy),NavigatorImpl.theInstance);
this.adapterClass1 = null;
this.adapterClass2 = adapter;
}
static NClass getRef( final Class<? extends XmlAdapter> adapter, boolean copy ) {
if(copy) {
// TODO: this is a hack. the code generation should be defered until
// the backend. (right now constant generation happens in the front-end)
return new EagerNClass(adapter) {
@Override
public JClass toType(Outline o, Aspect aspect) {
return o.addRuntime(adapter);
}
public String fullName() {
// TODO: implement this method later
throw new UnsupportedOperationException();
}
};
} else {
return NavigatorImpl.theInstance.ref(adapter);
}
}
public CAdapter(JClass adapter) {
super( NavigatorImpl.theInstance.ref(adapter), NavigatorImpl.theInstance);
this.adapterClass1 = adapter;
this.adapterClass2 = null;
}
public JClass getAdapterClass(Outline o) {
if(adapterClass1==null)
adapterClass1 = o.getCodeModel().ref(adapterClass2);
return adapterType.toType(o, Aspect.EXPOSED);
}
/**
* Returns true if the adapter is for whitespace normalization.
* Such an adapter can be ignored when producing a list.
*/
public boolean isWhitespaceAdapter() {
return adapterClass2==CollapsedStringAdapter.class || adapterClass2==NormalizedStringAdapter.class;
}
/**
* Returns the adapter class if the adapter type is statically known to XJC.
* <p>
* This method is mostly for enabling certain optimized code generation.
*/
public Class<? extends XmlAdapter> getAdapterIfKnown() {
return adapterClass2;
}
}

View File

@@ -0,0 +1,99 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import javax.xml.namespace.QName;
import com.sun.codemodel.internal.JType;
import com.sun.xml.internal.bind.v2.model.util.ArrayInfoUtil;
import com.sun.tools.internal.xjc.model.nav.NClass;
import com.sun.tools.internal.xjc.model.nav.NType;
import com.sun.tools.internal.xjc.outline.Aspect;
import com.sun.tools.internal.xjc.outline.Outline;
import com.sun.xml.internal.bind.v2.model.core.ArrayInfo;
import com.sun.xml.internal.xsom.XSComponent;
import org.xml.sax.Locator;
/**
* Because XJC doesn't generate the array binding, this class will
* never show up in the model constructed by XJC.
*
* <p>
* This class is nevertheless defined to make the type checker happy.
*
* @author Kohsuke Kawaguchi
*/
public final class CArrayInfo extends AbstractCTypeInfoImpl implements ArrayInfo<NType,NClass>, CNonElement, NType {
private final CNonElement itemType;
private final QName typeName;
public CArrayInfo(Model model,CNonElement itemType, XSComponent source, CCustomizations customizations) {
super(model,source,customizations);
this.itemType = itemType;
assert itemType.getTypeName()!=null;
this.typeName = ArrayInfoUtil.calcArrayTypeName(itemType.getTypeName());
}
public CNonElement getItemType() {
return itemType;
}
public QName getTypeName() {
return typeName;
}
public boolean isSimpleType() {
return false;
}
@Deprecated // guaranteed to return this
public CNonElement getInfo() {
return this;
}
public JType toType(Outline o, Aspect aspect) {
return itemType.toType(o,aspect).array();
}
public NType getType() {
return this;
}
public boolean isBoxedType() {
return false;
}
public String fullName() {
return itemType.getType().fullName()+"[]";
}
public Locator getLocator() {
return Model.EMPTY_LOCATOR;
}
}

View File

@@ -0,0 +1,92 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import javax.xml.namespace.QName;
import com.sun.tools.internal.xjc.model.nav.NClass;
import com.sun.tools.internal.xjc.model.nav.NType;
import com.sun.xml.internal.bind.v2.model.core.AttributePropertyInfo;
import com.sun.xml.internal.bind.v2.model.core.PropertyKind;
import com.sun.xml.internal.xsom.XSComponent;
import com.sun.istack.internal.Nullable;
import org.xml.sax.Locator;
/**
* {@link AttributePropertyInfo} for the compiler.
*
* @author Kohsuke Kawaguchi
*/
public final class CAttributePropertyInfo extends CSingleTypePropertyInfo implements AttributePropertyInfo<NType,NClass> {
private final QName attName;
private final boolean isRequired;
/**
* @param type
* Represents the bound type of this attribute.
* @param typeName
* XML Schema type name of this attribute. Optional for other schema languages.
*/
public CAttributePropertyInfo(String name, XSComponent source, CCustomizations customizations,
Locator locator, QName attName, TypeUse type, @Nullable QName typeName,
boolean required ) {
super(name, type, typeName, source, customizations, locator);
isRequired = required;
this.attName = attName;
}
public boolean isRequired() {
return isRequired;
}
public QName getXmlName() {
return attName;
}
/**
* An optional attribute can never be unboxable,
* for we need null to represent the absence.
*/
public boolean isUnboxable() {
if(!isRequired) return false;
return super.isUnboxable();
}
@Override
public boolean isOptionalPrimitive() {
return !isRequired && super.isUnboxable();
}
public <V> V accept(CPropertyVisitor<V> visitor) {
return visitor.onAttribute(this);
}
public final PropertyKind kind() {
return PropertyKind.ATTRIBUTE;
}
}

View File

@@ -0,0 +1,405 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import java.awt.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
import javax.activation.DataHandler;
import javax.activation.MimeType;
import javax.xml.bind.DatatypeConverter;
import javax.xml.bind.annotation.XmlIDREF;
import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
import javax.xml.bind.annotation.adapters.NormalizedStringAdapter;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.datatype.Duration;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import javax.xml.transform.Source;
import com.sun.codemodel.internal.JExpr;
import com.sun.codemodel.internal.JExpression;
import com.sun.codemodel.internal.JType;
import com.sun.tools.internal.xjc.model.nav.NClass;
import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
import com.sun.xml.internal.bind.v2.model.core.BuiltinLeafInfo;
import com.sun.xml.internal.bind.v2.model.core.Element;
import com.sun.xml.internal.bind.v2.model.core.LeafInfo;
import com.sun.xml.internal.bind.v2.runtime.Location;
import com.sun.tools.internal.xjc.model.nav.NType;
import com.sun.tools.internal.xjc.model.nav.NavigatorImpl;
import com.sun.tools.internal.xjc.outline.Aspect;
import com.sun.tools.internal.xjc.outline.Outline;
import com.sun.tools.internal.xjc.runtime.ZeroOneBooleanAdapter;
import com.sun.tools.internal.xjc.util.NamespaceContextAdapter;
import com.sun.xml.internal.bind.v2.WellKnownNamespace;
import com.sun.xml.internal.bind.v2.model.core.ID;
import com.sun.xml.internal.xsom.XSComponent;
import com.sun.xml.internal.xsom.XmlString;
import org.xml.sax.Locator;
/**
* Encapsulates the default handling for leaf classes (which are bound
* to text in XML.) In particular this class knows how to convert
* the lexical value into the Java class according to this default rule.
*
* <p>
* This represents the spec-defined default handling for the Java
* type ({@link #getType()}.
*
* <p>
* For those Java classes (such as {@link String} or {@link Boolean})
* where the spec designates a specific default handling, there are
* constants in this class (such as {@link #STRING} or {@link #BOOLEAN}.)
*
* <p>
* The generated type-safe enum classes are also a leaf class,
* and as such there are {@link CEnumLeafInfo} that represents it
* as {@link CBuiltinLeafInfo}.
*
* <p>
* This class represents the <b>default handling</b>, and therefore
* we can only have one instance per one {@link NType}. Handling of
* other XML Schema types (such as xs:token) are represented as
* a general {@link TypeUse} objects.
*
*
* @author Kohsuke Kawaguchi
*/
public abstract class CBuiltinLeafInfo implements CNonElement, BuiltinLeafInfo<NType,NClass>, LeafInfo<NType,NClass>, Location {
private final NType type;
/**
* Can be null for anonymous types.
*/
private final QName typeName;
private final QName[] typeNames;
private final ID id;
// no derived class other than the spec-defined ones. definitely not for enum.
private CBuiltinLeafInfo(NType typeToken, ID id, QName... typeNames) {
this.type = typeToken;
this.typeName = typeNames.length>0?typeNames[0]:null;
this.typeNames = typeNames;
this.id = id;
}
/**
* Gets the code model representation of this type.
*/
public JType toType(Outline o, Aspect aspect) {
return getType().toType(o,aspect);
}
/**
* Since {@link CBuiltinLeafInfo} represents a default binding,
* it is never a collection.
*/
@Deprecated
public final boolean isCollection() {
return false;
}
/**
* Guaranteed to return this.
*/
@Deprecated
public CNonElement getInfo() {
return this;
}
public ID idUse() {
return id;
}
/**
* {@link CBuiltinLeafInfo} never has a default associated MIME type.
*/
public MimeType getExpectedMimeType() {
return null;
}
@Deprecated
public final CAdapter getAdapterUse() {
return null;
}
public Locator getLocator() {
return Model.EMPTY_LOCATOR;
}
public final XSComponent getSchemaComponent() {
throw new UnsupportedOperationException("TODO. If you hit this, let us know.");
}
/**
* Creates a {@link TypeUse} that represents a collection of this {@link CBuiltinLeafInfo}.
*/
public final TypeUse makeCollection() {
return TypeUseFactory.makeCollection(this);
}
/**
* Creates a {@link TypeUse} that represents an adapted use of this {@link CBuiltinLeafInfo}.
*/
public final TypeUse makeAdapted( Class<? extends XmlAdapter> adapter, boolean copy ) {
return TypeUseFactory.adapt(this,adapter,copy);
}
/**
* Creates a {@link TypeUse} that represents a MIME-type assocaited version of this {@link CBuiltinLeafInfo}.
*/
public final TypeUse makeMimeTyped( MimeType mt ) {
return TypeUseFactory.makeMimeTyped(this,mt);
}
/**
* @deprecated always return false at this level.
*/
public final boolean isElement() {
return false;
}
/**
* @deprecated always return null at this level.
*/
public final QName getElementName() {
return null;
}
/**
* @deprecated always return null at this level.
*/
public final Element<NType,NClass> asElement() {
return null;
}
/**
* A reference to the representation of the type.
*/
public NType getType() {
return type;
}
/**
* Returns all the type names recognized by this bean info.
*
* @return
* do not modify the returned array.
*/
public final QName[] getTypeNames() {
return typeNames;
}
/**
* Leaf-type cannot be referenced from IDREF.
*
* @deprecated
* why are you calling a method whose return value is always known?
*/
public final boolean canBeReferencedByIDREF() {
return false;
}
public QName getTypeName() {
return typeName;
}
public Locatable getUpstream() {
return null;
}
public Location getLocation() {
// this isn't very accurate, but it's not too bad
// doing it correctly need leaves to hold navigator.
// otherwise revisit the design so that we take navigator as a parameter
return this;
}
public boolean isSimpleType() {
return true;
}
/**
* {@link CBuiltinLeafInfo} for Java classes that have
* the spec defined built-in binding semantics.
*/
private static abstract class Builtin extends CBuiltinLeafInfo {
protected Builtin(Class c, String typeName) {
this(c,typeName,com.sun.xml.internal.bind.v2.model.core.ID.NONE);
}
protected Builtin(Class c, String typeName, ID id) {
super(NavigatorImpl.theInstance.ref(c), id, new QName(WellKnownNamespace.XML_SCHEMA,typeName));
LEAVES.put(getType(),this);
}
/**
* No vendor customization in the built-in classes.
*/
public CCustomizations getCustomizations() {
return CCustomizations.EMPTY;
}
}
private static final class NoConstantBuiltin extends Builtin {
public NoConstantBuiltin(Class c, String typeName) {
super(c, typeName);
}
public JExpression createConstant(Outline outline, XmlString lexical) {
return null;
}
}
/**
* All built-in leaves.
*/
public static final Map<NType,CBuiltinLeafInfo> LEAVES = new HashMap<NType,CBuiltinLeafInfo>();
public static final CBuiltinLeafInfo ANYTYPE = new NoConstantBuiltin(Object.class,"anyType");
public static final CBuiltinLeafInfo STRING = new Builtin(String.class,"string") {
public JExpression createConstant(Outline outline, XmlString lexical) {
return JExpr.lit(lexical.value);
}
};
public static final CBuiltinLeafInfo BOOLEAN = new Builtin(Boolean.class,"boolean") {
public JExpression createConstant(Outline outline, XmlString lexical) {
return JExpr.lit(DatatypeConverter.parseBoolean(lexical.value));
}
};
public static final CBuiltinLeafInfo INT = new Builtin(Integer.class,"int") {
public JExpression createConstant(Outline outline, XmlString lexical) {
return JExpr.lit(DatatypeConverter.parseInt(lexical.value));
}
};
public static final CBuiltinLeafInfo LONG = new Builtin(Long.class,"long") {
public JExpression createConstant(Outline outline, XmlString lexical) {
return JExpr.lit(DatatypeConverter.parseLong(lexical.value));
}
};
public static final CBuiltinLeafInfo BYTE = new Builtin(Byte.class,"byte") {
public JExpression createConstant(Outline outline, XmlString lexical) {
return JExpr.cast(
outline.getCodeModel().BYTE,
JExpr.lit(DatatypeConverter.parseByte(lexical.value)));
}
};
public static final CBuiltinLeafInfo SHORT = new Builtin(Short.class,"short") {
public JExpression createConstant(Outline outline, XmlString lexical) {
return JExpr.cast(
outline.getCodeModel().SHORT,
JExpr.lit(DatatypeConverter.parseShort(lexical.value)));
}
};
public static final CBuiltinLeafInfo FLOAT = new Builtin(Float.class,"float") {
public JExpression createConstant(Outline outline, XmlString lexical) {
return JExpr.lit(DatatypeConverter.parseFloat(lexical.value));
}
};
public static final CBuiltinLeafInfo DOUBLE = new Builtin(Double.class,"double") {
public JExpression createConstant(Outline outline, XmlString lexical) {
return JExpr.lit(DatatypeConverter.parseDouble(lexical.value));
}
};
public static final CBuiltinLeafInfo QNAME = new Builtin(QName.class,"QName") {
public JExpression createConstant(Outline outline, XmlString lexical) {
QName qn = DatatypeConverter.parseQName(lexical.value,new NamespaceContextAdapter(lexical));
return JExpr._new(outline.getCodeModel().ref(QName.class))
.arg(qn.getNamespaceURI())
.arg(qn.getLocalPart())
.arg(qn.getPrefix());
}
};
// XMLGregorianCalendar is mutable, so we can't support default values anyhow.
// For CALENAR we are uses a most unlikely name so as to avoid potential name
// conflicts in the furture.
public static final CBuiltinLeafInfo CALENDAR = new NoConstantBuiltin(XMLGregorianCalendar.class,"\u0000");
public static final CBuiltinLeafInfo DURATION = new NoConstantBuiltin(Duration.class,"duration");
public static final CBuiltinLeafInfo BIG_INTEGER = new Builtin(BigInteger.class,"integer") {
public JExpression createConstant(Outline outline, XmlString lexical) {
return JExpr._new(outline.getCodeModel().ref(BigInteger.class)).arg(lexical.value.trim());
}
};
public static final CBuiltinLeafInfo BIG_DECIMAL = new Builtin(BigDecimal.class,"decimal") {
public JExpression createConstant(Outline outline, XmlString lexical) {
return JExpr._new(outline.getCodeModel().ref(BigDecimal.class)).arg(lexical.value.trim());
}
};
public static final CBuiltinLeafInfo BASE64_BYTE_ARRAY = new Builtin(byte[].class,"base64Binary") {
public JExpression createConstant(Outline outline, XmlString lexical) {
return outline.getCodeModel().ref(DatatypeConverter.class).staticInvoke("parseBase64Binary").arg(lexical.value);
}
};
public static final CBuiltinLeafInfo DATA_HANDLER = new NoConstantBuiltin(DataHandler.class,"base64Binary");
public static final CBuiltinLeafInfo IMAGE = new NoConstantBuiltin(Image.class,"base64Binary");
public static final CBuiltinLeafInfo XML_SOURCE = new NoConstantBuiltin(Source.class,"base64Binary");
public static final TypeUse HEXBIN_BYTE_ARRAY =
STRING.makeAdapted(HexBinaryAdapter.class,false);
// TODO: not sure if they should belong here,
// but I couldn't find other places that fit.
public static final TypeUse TOKEN =
STRING.makeAdapted(CollapsedStringAdapter.class,false);
public static final TypeUse NORMALIZED_STRING =
STRING.makeAdapted(NormalizedStringAdapter.class,false);
public static final TypeUse ID = TypeUseFactory.makeID(TOKEN,com.sun.xml.internal.bind.v2.model.core.ID.ID);
/**
* boolean restricted to 0 or 1.
*/
public static final TypeUse BOOLEAN_ZERO_OR_ONE =
STRING.makeAdapted(ZeroOneBooleanAdapter.class,true);
/**
* IDREF.
*
* IDREF is has a whitespace normalization semantics of token, but
* we don't want {@link XmlJavaTypeAdapter} and {@link XmlIDREF} to interact.
*/
public static final TypeUse IDREF = TypeUseFactory.makeID(ANYTYPE,com.sun.xml.internal.bind.v2.model.core.ID.IDREF);
/**
* For all list of strings, such as NMTOKENS, ENTITIES.
*/
public static final TypeUse STRING_LIST =
STRING.makeCollection();
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
/**
* Either {@link CClassInfo} or {@link CClassRef}.
*
* @author Kohsuke Kawaguchi
*/
public interface CClass extends CNonElement, CElement {
// how can anything be CNonElement and CElement at the same time, you may ask.
}

View File

@@ -0,0 +1,501 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlID;
import javax.xml.bind.annotation.XmlIDREF;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.namespace.QName;
import com.sun.codemodel.internal.JClass;
import com.sun.codemodel.internal.JCodeModel;
import com.sun.codemodel.internal.JPackage;
import com.sun.istack.internal.Nullable;
import com.sun.tools.internal.xjc.Language;
import com.sun.tools.internal.xjc.model.nav.NClass;
import com.sun.tools.internal.xjc.model.nav.NType;
import com.sun.tools.internal.xjc.outline.Aspect;
import com.sun.tools.internal.xjc.outline.Outline;
import com.sun.tools.internal.xjc.reader.Ring;
import com.sun.tools.internal.xjc.reader.xmlschema.BGMBuilder;
import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIFactoryMethod;
import com.sun.xml.internal.bind.v2.model.core.ClassInfo;
import com.sun.xml.internal.bind.v2.model.core.Element;
import com.sun.xml.internal.xsom.XSComponent;
import org.xml.sax.Locator;
/**
* Mutable {@link ClassInfo} represenatation.
*
* <p>
* Schema parsers build these objects.
*
* @author Kohsuke Kawaguchi
*/
public final class CClassInfo extends AbstractCElement implements ClassInfo<NType,NClass>, CClassInfoParent, CClass, NClass {
@XmlIDREF
private CClass baseClass;
/**
* List of all subclasses, together with {@link #nextSibling}.
*
* If this class has no sub-class, this field is null. Otherwise,
* this field points to a sub-class of this class. From there you can enumerate
* all the sub-classes by using {@link #nextSibling}.
*/
private CClassInfo firstSubclass;
/**
* @see #firstSubclass
*/
private CClassInfo nextSibling = null;
/**
* @see #getTypeName()
*/
private final QName typeName;
/**
* Custom {@link #getSqueezedName() squeezed name}, if any.
*/
private /*almost final*/ @Nullable String squeezedName;
/**
* If this class also gets {@link XmlRootElement}, the class name.
*/
private final @Nullable QName elementName;
private boolean isOrdered = true;
private final List<CPropertyInfo> properties = new ArrayList<CPropertyInfo>();
/**
* TODO: revisit this design.
* we should at least do a basic encapsulation to avoid careless
* mistakes. Maybe we should even differ the javadoc generation
* by queueing runners.
*/
public String javadoc;
@XmlIDREF
private final CClassInfoParent parent;
/**
* short name.
*/
public final String shortName;
/**
* Optional user-specified implementation override class.
*/
private @Nullable String implClass;
/**
* The {@link Model} object to which this bean belongs.
*/
public final Model model;
/**
* @see #hasAttributeWildcard()
*/
private boolean hasAttributeWildcard;
public CClassInfo(Model model,JPackage pkg, String shortName, Locator location, QName typeName, QName elementName, XSComponent source, CCustomizations customizations) {
this(model,model.getPackage(pkg),shortName,location,typeName,elementName,source,customizations);
}
public CClassInfo(Model model,CClassInfoParent p, String shortName, Locator location, QName typeName, QName elementName, XSComponent source, CCustomizations customizations) {
super(model,source,location,customizations);
this.model = model;
this.parent = p;
this.shortName = model.allocator.assignClassName(parent,shortName);
this.typeName = typeName;
this.elementName = elementName;
Language schemaLanguage = model.options.getSchemaLanguage();
if ((schemaLanguage != null) &&
(schemaLanguage.equals(Language.XMLSCHEMA) || schemaLanguage.equals(Language.WSDL))) {
BIFactoryMethod factoryMethod = Ring.get(BGMBuilder.class).getBindInfo(source).get(BIFactoryMethod.class);
if(factoryMethod!=null) {
factoryMethod.markAsAcknowledged();
this.squeezedName = factoryMethod.name;
}
}
model.add(this);
}
public CClassInfo(Model model,JCodeModel cm, String fullName, Locator location, QName typeName, QName elementName, XSComponent source, CCustomizations customizations) {
super(model,source,location,customizations);
this.model = model;
int idx = fullName.indexOf('.');
if(idx<0) {
this.parent = model.getPackage(cm.rootPackage());
this.shortName = model.allocator.assignClassName(parent,fullName);
} else {
this.parent = model.getPackage(cm._package(fullName.substring(0,idx)));
this.shortName = model.allocator.assignClassName(parent,fullName.substring(idx+1));
}
this.typeName = typeName;
this.elementName = elementName;
model.add(this);
}
public boolean hasAttributeWildcard() {
return hasAttributeWildcard;
}
public void hasAttributeWildcard(boolean hasAttributeWildcard) {
this.hasAttributeWildcard = hasAttributeWildcard;
}
public boolean hasSubClasses() {
return firstSubclass!=null;
}
/**
* Returns true if a new attribute wildcard property needs to be
* declared on this class.
*/
public boolean declaresAttributeWildcard() {
return hasAttributeWildcard && !inheritsAttributeWildcard();
}
/**
* Returns true if this class inherits a wildcard attribute property
* from its ancestor classes.
*/
public boolean inheritsAttributeWildcard() {
if (getRefBaseClass() != null) {
CClassRef cref = (CClassRef)baseClass;
if (cref.getSchemaComponent().getForeignAttributes().size() > 0) {
return true;
}
} else {
for( CClassInfo c=getBaseClass(); c!=null; c=c.getBaseClass() ) {
if(c.hasAttributeWildcard)
return true;
}
}
return false;
}
public NClass getClazz() {
return this;
}
public CClassInfo getScope() {
return null;
}
@XmlID
public String getName() {
return fullName();
}
/**
* Returns the "squeezed name" of this bean token.
* <p>
* The squeezed name of a bean is the concatenation of
* the names of its outer classes and itself.
* <p>
* Thus if the bean is "org.acme.foo.Bean", then the squeezed name is "Bean",
* if the bean is "org.acme.foo.Outer1.Outer2.Bean", then "Outer1Outer2Bean".
* <p>
* This is used by the code generator
*/
@XmlElement
public String getSqueezedName() {
if (squeezedName != null) return squeezedName;
return calcSqueezedName.onBean(this);
}
private static final CClassInfoParent.Visitor<String> calcSqueezedName = new Visitor<String>() {
public String onBean(CClassInfo bean) {
return bean.parent.accept(this)+bean.shortName;
}
public String onElement(CElementInfo element) {
return element.parent.accept(this)+element.shortName();
}
public String onPackage(JPackage pkg) {
return "";
}
};
/**
* Returns a mutable list.
*/
public List<CPropertyInfo> getProperties() {
return properties;
}
public boolean hasValueProperty() {
throw new UnsupportedOperationException();
}
/**
* Gets a propery by name.
*/
public CPropertyInfo getProperty(String name) {
// TODO: does this method need to be fast?
for( CPropertyInfo p : properties )
if(p.getName(false).equals(name))
return p;
return null;
}
public boolean hasProperties() {
return !getProperties().isEmpty();
}
public boolean isElement() {
return elementName!=null;
}
/**
* Guaranteed to return this.
*/
@Deprecated
public CNonElement getInfo() {
return this;
}
public Element<NType,NClass> asElement() {
if(isElement())
return this;
else
return null;
}
public boolean isOrdered() {
return isOrdered;
}
/**
* @deprecated
* if you are calling this method directly, you must be doing something wrong.
*/
public boolean isFinal() {
return false;
}
public void setOrdered(boolean value) {
isOrdered = value;
}
public QName getElementName() {
return elementName;
}
public QName getTypeName() {
return typeName;
}
public boolean isSimpleType() {
throw new UnsupportedOperationException();
}
/**
* Returns the FQCN of this bean.
*/
public String fullName() {
String r = parent.fullName();
if(r.length()==0) return shortName;
else return r+'.'+shortName;
}
public CClassInfoParent parent() {
return parent;
}
public void setUserSpecifiedImplClass(String implClass) {
assert this.implClass==null;
assert implClass!=null;
this.implClass = implClass;
}
public String getUserSpecifiedImplClass() {
return implClass;
}
/**
* Adds a new property.
*/
public void addProperty(CPropertyInfo prop) {
if(prop.ref().isEmpty())
// this property isn't contributing anything
// this happens when you try to map an empty sequence to a property
return;
prop.setParent(this);
properties.add(prop);
}
/**
* This method accepts both {@link CClassInfo} (which means the base class
* is also generated), or {@link CClassRef} (which means the base class is
* already generated and simply referenced.)
*
* The latter is treated somewhat special --- from the rest of the model
* this external base class is invisible. This modeling might need more
* thoughts to get right.
*/
public void setBaseClass(CClass base) {
assert baseClass==null;
assert base!=null;
baseClass = base;
assert nextSibling==null;
if (base instanceof CClassInfo) {
CClassInfo realBase = (CClassInfo) base;
this.nextSibling = realBase.firstSubclass;
realBase.firstSubclass = this;
}
}
/**
* This inherited version returns null if this class extends from {@link CClassRef}.
*
* @see #getRefBaseClass()
*/
public CClassInfo getBaseClass() {
if (baseClass instanceof CClassInfo) {
return (CClassInfo) baseClass;
} else {
return null;
}
}
public CClassRef getRefBaseClass() {
if (baseClass instanceof CClassRef) {
return (CClassRef) baseClass;
} else {
return null;
}
}
/**
* Enumerates all the sub-classes of this class.
*/
public Iterator<CClassInfo> listSubclasses() {
return new Iterator<CClassInfo>() {
CClassInfo cur = firstSubclass;
public boolean hasNext() {
return cur!=null;
}
public CClassInfo next() {
CClassInfo r = cur;
cur = cur.nextSibling;
return r;
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
public CClassInfo getSubstitutionHead() {
CClassInfo c=getBaseClass();
while(c!=null && !c.isElement())
c=c.getBaseClass();
return c;
}
/**
* Interfaces to be implemented.
* Lazily constructed.
*/
private Set<JClass> _implements = null;
public void _implements(JClass c) {
if(_implements==null)
_implements = new HashSet<JClass>();
_implements.add(c);
}
/** Constructor declarations. array of {@link Constructor}s. */
private final List<Constructor> constructors = new ArrayList<Constructor>(1);
/** Creates a new constructor declaration and adds it. */
public void addConstructor( String... fieldNames ) {
constructors.add(new Constructor(fieldNames));
}
/** list all constructor declarations. */
public Collection<? extends Constructor> getConstructors() {
return constructors;
}
public final <T> T accept(Visitor<T> visitor) {
return visitor.onBean(this);
}
public JPackage getOwnerPackage() {
return parent.getOwnerPackage();
}
public final NClass getType() {
return this;
}
public final JClass toType(Outline o, Aspect aspect) {
switch(aspect) {
case IMPLEMENTATION:
return o.getClazz(this).implRef;
case EXPOSED:
return o.getClazz(this).ref;
default:
throw new IllegalStateException();
}
}
public boolean isBoxedType() {
return false;
}
public String toString() {
return fullName();
}
}

View File

@@ -0,0 +1,83 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import com.sun.codemodel.internal.JPackage;
/**
* Parent of a {@link CClassInfo}/{@link CElementInfo}.
*
* TODO: rename
*
* Either {@link CClassInfo} or {@link CClassInfoParent.Package}.
*/
public interface CClassInfoParent {
/**
* Returns the fully-qualified name.
*/
String fullName();
<T> T accept( Visitor<T> visitor );
/**
* Gets the nearest {@link JPackage}.
*/
JPackage getOwnerPackage();
/**
* Visitor of {@link CClassInfoParent}
*/
public static interface Visitor<T> {
T onBean( CClassInfo bean );
T onPackage( JPackage pkg );
T onElement( CElementInfo element );
}
/**
* {@link JPackage} as a {@link CClassInfoParent}.
*
* Use {@link Model#getPackage} to obtain an instance.
*/
public static final class Package implements CClassInfoParent {
public final JPackage pkg;
public Package(JPackage pkg) {
this.pkg = pkg;
}
public String fullName() {
return pkg.name();
}
public <T> T accept(Visitor<T> visitor) {
return visitor.onPackage(pkg);
}
public JPackage getOwnerPackage() {
return pkg;
}
}
}

View File

@@ -0,0 +1,134 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import javax.xml.namespace.QName;
import com.sun.codemodel.internal.JClass;
import com.sun.tools.internal.xjc.model.nav.NClass;
import com.sun.tools.internal.xjc.model.nav.NType;
import com.sun.tools.internal.xjc.outline.Aspect;
import com.sun.tools.internal.xjc.outline.Outline;
import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIClass;
import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIEnum;
import com.sun.xml.internal.xsom.XSComponent;
/**
* Refernece to an existing class.
*
* @author Kohsuke Kawaguchi
*/
public final class CClassRef extends AbstractCElement implements NClass, CClass {
private final String fullyQualifiedClassName;
/**
*
* @param decl
* The {@link BIClass} declaration that has {@link BIClass#getExistingClassRef()}
*/
public CClassRef(Model model, XSComponent source, BIClass decl, CCustomizations customizations) {
super(model, source, decl.getLocation(), customizations);
fullyQualifiedClassName = decl.getExistingClassRef();
assert fullyQualifiedClassName!=null;
}
/**
*
* @param decl
* The {@link BIClass} declaration that has {@link BIEnum#ref}
*/
public CClassRef(Model model, XSComponent source, BIEnum decl, CCustomizations customizations) {
super(model, source, decl.getLocation(), customizations);
fullyQualifiedClassName = decl.ref;
assert fullyQualifiedClassName!=null;
}
public void setAbstract() {
// assume that the referenced class is marked as abstract to begin with.
}
public boolean isAbstract() {
// no way to find out for sure
return false;
}
public NType getType() {
return this;
}
/**
* Cached for both performance and single identity.
*/
private JClass clazz;
public JClass toType(Outline o, Aspect aspect) {
if(clazz==null)
clazz = o.getCodeModel().ref(fullyQualifiedClassName);
return clazz;
}
public String fullName() {
return fullyQualifiedClassName;
}
public QName getTypeName() {
return null;
}
/**
* Guaranteed to return this.
*/
@Deprecated
public CNonElement getInfo() {
return this;
}
// are these going to bite us?
// we can compute some of them, but not all.
public CElement getSubstitutionHead() {
return null;
}
public CClassInfo getScope() {
return null;
}
public QName getElementName() {
return null;
}
public boolean isBoxedType() {
return false;
}
public boolean isSimpleType() {
return false;
}
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import com.sun.tools.internal.xjc.Plugin;
import com.sun.xml.internal.xsom.XSComponent;
import org.xml.sax.Locator;
/**
* Implemented by model components that can have customizations contributed by {@link Plugin}s.
*
* @author Kohsuke Kawaguchi
*/
public interface CCustomizable {
/**
* Gets the list of customizations attached to this model component.
*
* @return
* can be an empty list but never be null. The returned list is read-only.
* Do not modify.
*
* @see Plugin#getCustomizationURIs()
*/
CCustomizations getCustomizations();
/**
* Gets the source location in the schema from which this model component is created.
*
* @return never null.
*/
Locator getLocator();
/**
* If this model object is built from XML Schema,
* this property returns a schema component from which the model is built.
*
* @return
* null if the model is built from sources other than XML Schema
* (such as DTD.)
*/
XSComponent getSchemaComponent();
}

View File

@@ -0,0 +1,144 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import java.util.ArrayList;
import java.util.Collection;
import com.sun.tools.internal.xjc.Plugin;
/**
* Represents the list of {@link CPluginCustomization}s attached to a JAXB model component.
*
* <p>
* When {@link Plugin}s register the customization namespace URIs through {@link Plugin#getCustomizationURIs()},
* XJC will treat those URIs just like XJC's own extension "http://java.sun.com/xml/ns/xjc" and make them
* available as DOM nodes through {@link CPluginCustomization}. A {@link Plugin} can then access
* this information to change its behavior.
*
* @author Kohsuke Kawaguchi
*/
public final class CCustomizations extends ArrayList<CPluginCustomization> {
/**
* All {@link CCustomizations} used by a {@link Model} form a single linked list
* so that we can look for unacknowledged customizations later.
*
* @see CPluginCustomization#markAsAcknowledged()
* @see #setParent(Model,CCustomizable)
*/
/*package*/ CCustomizations next;
/**
* The owner model component that carries these customizations.
*/
private CCustomizable owner;
public CCustomizations() {
}
public CCustomizations(Collection<? extends CPluginCustomization> cPluginCustomizations) {
super(cPluginCustomizations);
}
/*package*/ void setParent(Model model,CCustomizable owner) {
if(this.owner!=null) return;
// // loop check
// for( CCustomizations c = model.customizations; c!=null; c=c.next )
// assert c!=this;
this.next = model.customizations;
model.customizations = this;
assert owner!=null;
this.owner = owner;
}
/**
* Gets the model component that carries this customization.
*
* @return never null.
*/
public CCustomizable getOwner() {
assert owner!=null;
return owner;
}
/**
* Finds the first {@link CPluginCustomization} that belongs to the given namespace URI.
* @return null if not found
*/
public CPluginCustomization find( String nsUri ) {
for (CPluginCustomization p : this) {
if(fixNull(p.element.getNamespaceURI()).equals(nsUri))
return p;
}
return null;
}
/**
* Finds the first {@link CPluginCustomization} that belongs to the given namespace URI and the local name.
* @return null if not found
*/
public CPluginCustomization find( String nsUri, String localName ) {
for (CPluginCustomization p : this) {
if(fixNull(p.element.getNamespaceURI()).equals(nsUri)
&& fixNull(p.element.getLocalName()).equals(localName))
return p;
}
return null;
}
private String fixNull(String s) {
if(s==null) return "";
else return s;
}
/**
* Convenient singleton instance that represents an empty {@link CCustomizations}.
*/
public static final CCustomizations EMPTY = new CCustomizations();
/**
* Merges two {@link CCustomizations} objects into one.
*/
public static CCustomizations merge(CCustomizations lhs, CCustomizations rhs) {
if(lhs==null || lhs.isEmpty()) return rhs;
if(rhs==null || rhs.isEmpty()) return lhs;
CCustomizations r = new CCustomizations(lhs);
r.addAll(rhs);
return r;
}
public boolean equals(Object o) {
return this==o;
}
public int hashCode() {
return System.identityHashCode(this);
}
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import com.sun.codemodel.internal.JExpression;
import com.sun.tools.internal.xjc.outline.Outline;
import com.sun.xml.internal.xsom.XmlString;
/**
* Object that computes the default value expression lazily.
*
* The computation is done lazily because often the default value
* needs to refer to things (such as enum classes) that are only generated
* after some of the outline is built.
*
* @author Kohsuke Kawaguchi
*/
public abstract class CDefaultValue {
public abstract JExpression compute(Outline outline);
/**
* Creates a new {@link CDefaultValue} that computes the default value
* by applying a lexical representation to a {@link TypeUse}.
*/
public static CDefaultValue create(final TypeUse typeUse, final XmlString defaultValue) {
return new CDefaultValue() {
public JExpression compute(Outline outline) {
return typeUse.createConstant(outline,defaultValue);
}
};
}
}

View File

@@ -0,0 +1,47 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import com.sun.tools.internal.xjc.model.nav.NClass;
import com.sun.tools.internal.xjc.model.nav.NType;
import com.sun.xml.internal.bind.v2.model.core.Element;
/**
* Either {@link CElementInfo}, {@link CClassInfo}, or {@link CClassRef}.
*
* @author Kohsuke Kawaguchi
*/
public interface CElement extends CTypeInfo, Element<NType,NClass> {
/**
* Marks this element as an abstract element.
*/
void setAbstract();
/**
* Returns true iff this element is an abstract element.
*/
boolean isAbstract();
}

View File

@@ -0,0 +1,297 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.namespace.QName;
import com.sun.codemodel.internal.JPackage;
import com.sun.codemodel.internal.JType;
import com.sun.istack.internal.Nullable;
import static com.sun.tools.internal.xjc.model.CElementPropertyInfo.CollectionMode.NOT_REPEATED;
import static com.sun.tools.internal.xjc.model.CElementPropertyInfo.CollectionMode.REPEATED_VALUE;
import com.sun.tools.internal.xjc.model.nav.NClass;
import com.sun.tools.internal.xjc.model.nav.NType;
import com.sun.tools.internal.xjc.model.nav.NavigatorImpl;
import com.sun.tools.internal.xjc.outline.Aspect;
import com.sun.tools.internal.xjc.outline.Outline;
import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIInlineBinaryData;
import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIFactoryMethod;
import com.sun.tools.internal.xjc.reader.xmlschema.BGMBuilder;
import com.sun.tools.internal.xjc.reader.Ring;
import com.sun.xml.internal.bind.v2.model.core.ElementInfo;
import com.sun.xml.internal.xsom.XSElementDecl;
import com.sun.xml.internal.xsom.XmlString;
import org.xml.sax.Locator;
/**
* {@link ElementInfo} implementation for the compile-time model.
*
* <p>
* As an NType, it represents the Java representation of this element
* (either JAXBElement&lt;T> or Foo).
*
* @author Kohsuke Kawaguchi
*/
public final class CElementInfo extends AbstractCElement
implements ElementInfo<NType,NClass>, NType, CClassInfoParent {
private final QName tagName;
/**
* Represents {@code JAXBElement&lt;ContentType>}.
*/
private NType type;
/**
* If this element produces its own class, the short name of that class.
* Otherwise null.
*/
private String className;
/**
* If this element is global, the element info is considered to be
* package-level, and this points to the package in which this element
* lives in.
*
* <p>
* For local elements, this points to the parent {@link CClassInfo}.
*/
public final CClassInfoParent parent;
private CElementInfo substitutionHead;
/**
* Lazily computed.
*/
private Set<CElementInfo> substitutionMembers;
/**
* {@link Model} that owns this object.
*/
private final Model model;
private CElementPropertyInfo property;
/**
* Custom {@link #getSqueezedName() squeezed name}, if any.
*/
private /*almost final*/ @Nullable String squeezedName;
/**
* Creates an element in the given parent.
*
* <p>
* When using this construction, {@link #initContentType(TypeUse, XSElementDecl, XmlString)}
* must not be invoked.
*/
public CElementInfo(Model model,QName tagName, CClassInfoParent parent, TypeUse contentType, XmlString defaultValue, XSElementDecl source, CCustomizations customizations, Locator location ) {
super(model,source,location,customizations);
this.tagName = tagName;
this.model = model;
this.parent = parent;
if(contentType!=null)
initContentType(contentType, source, defaultValue);
model.add(this);
}
/**
* Creates an element with a class in the given parent.
*
* <p>
* When using this construction, the caller must use
* {@link #initContentType(TypeUse, XSElementDecl, XmlString)} to fill in the content type
* later.
*
* This is to avoid a circular model construction dependency between buidling a type
* inside an element and element itself. To build a content type, you need to have
* {@link CElementInfo} for a parent, so we can't take it as a constructor parameter.
*/
public CElementInfo(Model model,QName tagName, CClassInfoParent parent, String className, CCustomizations customizations, Locator location ) {
this(model,tagName,parent,null,null,null,customizations,location);
this.className = className;
}
public void initContentType(TypeUse contentType, @Nullable XSElementDecl source, XmlString defaultValue) {
assert this.property==null; // must not be called twice
this.property = new CElementPropertyInfo("Value",
contentType.isCollection()?REPEATED_VALUE:NOT_REPEATED,
contentType.idUse(),
contentType.getExpectedMimeType(),
source,null,getLocator(),true);
this.property.setAdapter(contentType.getAdapterUse());
BIInlineBinaryData.handle(source,property);
property.getTypes().add(new CTypeRef(contentType.getInfo(),tagName,CTypeRef.getSimpleTypeName(source), true,defaultValue));
this.type = NavigatorImpl.createParameterizedType(
NavigatorImpl.theInstance.ref(JAXBElement.class),
getContentInMemoryType() );
BIFactoryMethod factoryMethod = Ring.get(BGMBuilder.class).getBindInfo(source).get(BIFactoryMethod.class);
if(factoryMethod!=null) {
factoryMethod.markAsAcknowledged();
this.squeezedName = factoryMethod.name;
}
}
public final String getDefaultValue() {
return getProperty().getTypes().get(0).getDefaultValue();
}
public final JPackage _package() {
return parent.getOwnerPackage();
}
public CNonElement getContentType() {
return getProperty().ref().get(0);
}
public NType getContentInMemoryType() {
if(getProperty().getAdapter()==null) {
NType itemType = getContentType().getType();
if(!property.isCollection())
return itemType;
return NavigatorImpl.createParameterizedType(List.class,itemType);
} else {
return getProperty().getAdapter().customType;
}
}
public CElementPropertyInfo getProperty() {
return property;
}
public CClassInfo getScope() {
if(parent instanceof CClassInfo)
return (CClassInfo)parent;
return null;
}
/**
* @deprecated why are you calling a method that returns this?
*/
public NType getType() {
return this;
}
public QName getElementName() {
return tagName;
}
public JType toType(Outline o, Aspect aspect) {
if(className==null)
return type.toType(o,aspect);
else
return o.getElement(this).implClass;
}
/**
* Returns the "squeezed name" of this element.
*
* @see CClassInfo#getSqueezedName()
*/
@XmlElement
public String getSqueezedName() {
if(squeezedName!=null) return squeezedName;
StringBuilder b = new StringBuilder();
CClassInfo s = getScope();
if(s!=null)
b.append(s.getSqueezedName());
if(className!=null)
b.append(className);
else
b.append( model.getNameConverter().toClassName(tagName.getLocalPart()));
return b.toString();
}
public CElementInfo getSubstitutionHead() {
return substitutionHead;
}
public Collection<CElementInfo> getSubstitutionMembers() {
if(substitutionMembers==null)
return Collections.emptyList();
else
return substitutionMembers;
}
public void setSubstitutionHead(CElementInfo substitutionHead) {
// don't set it twice
assert this.substitutionHead==null;
assert substitutionHead!=null;
this.substitutionHead = substitutionHead;
if(substitutionHead.substitutionMembers==null)
substitutionHead.substitutionMembers = new HashSet<CElementInfo>();
substitutionHead.substitutionMembers.add(this);
}
public boolean isBoxedType() {
return false;
}
public String fullName() {
if(className==null)
return type.fullName();
else {
String r = parent.fullName();
if(r.length()==0) return className;
else return r+'.'+className;
}
}
public <T> T accept(Visitor<T> visitor) {
return visitor.onElement(this);
}
public JPackage getOwnerPackage() {
return parent.getOwnerPackage();
}
public String shortName() {
return className;
}
/**
* True if this element has its own class
* (as opposed to be represented as an instance of {@link JAXBElement}.
*/
public boolean hasClass() {
return className!=null;
}
}

View File

@@ -0,0 +1,213 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.activation.MimeType;
import javax.xml.namespace.QName;
import com.sun.tools.internal.xjc.model.nav.NClass;
import com.sun.tools.internal.xjc.model.nav.NType;
import com.sun.tools.internal.xjc.reader.RawTypeSet;
import com.sun.xml.internal.bind.v2.model.core.ElementPropertyInfo;
import com.sun.xml.internal.bind.v2.model.core.ID;
import com.sun.xml.internal.bind.v2.model.core.PropertyKind;
import com.sun.xml.internal.xsom.XSComponent;
import org.xml.sax.Locator;
/**
* {@link ElementPropertyInfo} for the compiler.
*
* @author Kohsuke Kawaguchi
*/
public final class CElementPropertyInfo extends CPropertyInfo implements ElementPropertyInfo<NType,NClass> {
/**
* True if this property can never be absent legally.
*/
private final boolean required;
private final MimeType expectedMimeType;
/**
*
* <p>
* Currently, this is set inside {@link RawTypeSet} in a very ugly way.
*/
private CAdapter adapter;
private final boolean isValueList;
private ID id;
/**
* List of referenced types.
*/
private final List<CTypeRef> types = new ArrayList<CTypeRef>();
private final List<CNonElement> ref = new AbstractList<CNonElement>() {
public CNonElement get(int index) {
return getTypes().get(index).getTarget();
}
public int size() {
return getTypes().size();
}
};
// TODO: shouldn't they get id and expectedMimeType from TypeUses of CTypeRef?
public CElementPropertyInfo(String name, CollectionMode collection, ID id, MimeType expectedMimeType, XSComponent source,
CCustomizations customizations, Locator locator, boolean required) {
super(name, collection.col, source, customizations, locator);
this.required = required;
this.id = id;
this.expectedMimeType = expectedMimeType;
this.isValueList = collection.val;
}
public ID id() {
return id;
}
public List<CTypeRef> getTypes() {
return types;
}
public List<CNonElement> ref() {
return ref;
}
public QName getSchemaType() {
if(types.size()!=1)
// if more than one kind is here, can't produce @XmlSchemaType.
// TODO: is it allowed to have one generated if types
return null;
CTypeRef t = types.get(0);
if(needsExplicitTypeName(t.getTarget(),t.typeName))
return t.typeName;
else
return null;
}
/**
* XJC never uses the wrapper element. Always return null.
*/
@Deprecated
public QName getXmlName() {
return null;
}
public boolean isCollectionRequired() {
// in XJC, we never recognize a nillable collection pattern, so this is always false.
return false;
}
public boolean isCollectionNillable() {
// in XJC, we never recognize a nillable collection pattern, so this is always false.
return false;
}
public boolean isRequired() {
return required;
}
public boolean isValueList() {
return isValueList;
}
public boolean isUnboxable() {
if(!isCollection() && !required)
// if the property can be legally absent, it's not unboxable
return false;
// we need to have null to represent the absence of value. not unboxable.
for (CTypeRef t : getTypes()) {
if(t.isNillable())
return false;
}
return super.isUnboxable();
}
@Override
public boolean isOptionalPrimitive() {
// we need to have null to represent the absence of value. not unboxable.
for (CTypeRef t : getTypes()) {
if(t.isNillable())
return false;
}
return !isCollection() && !required && super.isUnboxable();
}
public <V> V accept(CPropertyVisitor<V> visitor) {
return visitor.onElement(this);
}
public CAdapter getAdapter() {
return adapter;
}
public void setAdapter(CAdapter a) {
assert adapter==null;
adapter = a;
}
public final PropertyKind kind() {
return PropertyKind.ELEMENT;
}
public MimeType getExpectedMimeType() {
return expectedMimeType;
}
public static enum CollectionMode {
NOT_REPEATED(false,false),
REPEATED_ELEMENT(true,false),
REPEATED_VALUE(true,true);
private final boolean col,val;
CollectionMode(boolean col,boolean val) {
this.col = col;
this.val = val;
}
public boolean isRepeated() { return col; }
}
@Override
public QName collectElementNames(Map<QName, CPropertyInfo> table) {
for (CTypeRef t : types) {
QName n = t.getTagName();
if(table.containsKey(n)) return n;
table.put(n, this);
}
return null;
}
}

View File

@@ -0,0 +1,96 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import com.sun.tools.internal.xjc.model.nav.NClass;
import com.sun.tools.internal.xjc.model.nav.NType;
import com.sun.xml.internal.bind.v2.model.core.EnumConstant;
import com.sun.xml.internal.xsom.XSComponent;
import org.xml.sax.Locator;
/**
* Enumeration constant.
*
* @author Kohsuke Kawaguchi
*/
public final class CEnumConstant implements EnumConstant<NType,NClass>, CCustomizable {
/** Name of the constant. */
public final String name;
/** Javadoc comment. Can be null. */
public final String javadoc;
/** Lexical representation of this enum constant. Always non-null. */
private final String lexical;
private CEnumLeafInfo parent;
private final XSComponent source;
private final CCustomizations customizations;
private final Locator locator;
/**
* @param name
*/
public CEnumConstant(String name, String javadoc, String lexical, XSComponent source, CCustomizations customizations, Locator loc) {
assert name!=null;
this.name = name;
this.javadoc = javadoc;
this.lexical = lexical;
this.source = source;
this.customizations = customizations;
this.locator = loc;
}
public CEnumLeafInfo getEnclosingClass() {
return parent;
}
/*package*/ void setParent(CEnumLeafInfo parent) {
this.parent = parent;
}
public String getLexicalValue() {
return lexical;
}
public String getName() {
return name;
}
public XSComponent getSchemaComponent() {
return source;
}
public CCustomizations getCustomizations() {
return customizations;
}
public Locator getLocator() {
return locator;
}
}

View File

@@ -0,0 +1,277 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import java.util.Collection;
import javax.activation.MimeType;
import javax.xml.namespace.QName;
import com.sun.codemodel.internal.JClass;
import com.sun.codemodel.internal.JExpression;
import com.sun.tools.internal.xjc.model.nav.NClass;
import com.sun.tools.internal.xjc.model.nav.NType;
import com.sun.tools.internal.xjc.outline.Aspect;
import com.sun.tools.internal.xjc.outline.Outline;
import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
import com.sun.xml.internal.bind.v2.model.core.EnumLeafInfo;
import com.sun.xml.internal.bind.v2.model.core.ID;
import com.sun.xml.internal.bind.v2.model.core.NonElement;
import com.sun.xml.internal.bind.v2.model.core.Element;
import com.sun.xml.internal.bind.v2.runtime.Location;
import com.sun.xml.internal.xsom.XSComponent;
import com.sun.xml.internal.xsom.XmlString;
import org.xml.sax.Locator;
/**
* Transducer that converts a string into an "enumeration class."
*
* The structure of the generated class needs to precisely
* follow the JAXB spec.
*
* @author
* <a href="mailto:kohsuke.kawaguchi@sun.com">Kohsuke KAWAGUCHI</a>
*/
public final class CEnumLeafInfo implements EnumLeafInfo<NType,NClass>, NClass, CNonElement
{
/**
* The {@link Model} object to which this bean belongs.
*/
public final Model model;
/**
* The parent into which the enum class should be generated.
*/
public final CClassInfoParent parent;
/**
* Short name of the generated type-safe enum.
*/
public final String shortName;
private final QName typeName;
private final XSComponent source;
/**
* Represents the underlying type of this enumeration
* and its conversion.
*
* <p>
* To parse XML into a constant, we use the base type
* to do lexical -> value, then use a map to pick up the right one.
*
* <p>
* Hence this also represents the type of the Java value.
* For example, if this is an enumeration of xs:int,
* then this field will be Java int.
*/
public final CNonElement base;
/**
* List of enum members.
*/
public final Collection<CEnumConstant> members;
private final CCustomizations customizations;
/**
* @see #getLocator()
*/
private final Locator sourceLocator;
public String javadoc;
public CEnumLeafInfo(Model model,
QName typeName,
CClassInfoParent container,
String shortName,
CNonElement base,
Collection<CEnumConstant> _members,
XSComponent source,
CCustomizations customizations,
Locator _sourceLocator) {
this.model = model;
this.parent = container;
this.shortName = model.allocator.assignClassName(parent,shortName);
this.base = base;
this.members = _members;
this.source = source;
if(customizations==null)
customizations = CCustomizations.EMPTY;
this.customizations = customizations;
this.sourceLocator = _sourceLocator;
this.typeName = typeName;
for( CEnumConstant mem : members )
mem.setParent(this);
model.add(this);
// TODO: can we take advantage of the fact that enum can be XmlRootElement?
}
/**
* Source line information that points to the place
* where this type-safe enum is defined.
* Used to report error messages.
*/
public Locator getLocator() {
return sourceLocator;
}
public QName getTypeName() {
return typeName;
}
public NType getType() {
return this;
}
/**
* @deprecated
* why are you calling the method whose return value is known?
*/
public boolean canBeReferencedByIDREF() {
return false;
}
public boolean isElement() {
return false;
}
public QName getElementName() {
return null;
}
public Element<NType,NClass> asElement() {
return null;
}
public NClass getClazz() {
return this;
}
public XSComponent getSchemaComponent() {
return source;
}
public JClass toType(Outline o, Aspect aspect) {
return o.getEnum(this).clazz;
}
public boolean isAbstract() {
return false;
}
public boolean isBoxedType() {
return false;
}
public String fullName() {
return parent.fullName()+'.'+shortName;
}
public boolean isPrimitive() {
return false;
}
public boolean isSimpleType() {
return true;
}
/**
* The spec says the value field in the enum class will be generated
* only under certain circumstances.
*
* @return
* true if the generated enum class should have the value field.
*/
public boolean needsValueField() {
for (CEnumConstant cec : members) {
if(!cec.getName().equals(cec.getLexicalValue()))
return true;
}
return false;
}
public JExpression createConstant(Outline outline, XmlString literal) {
// correctly identifying which constant it maps to is hard, so
// here I'm cheating
JClass type = toType(outline,Aspect.EXPOSED);
for (CEnumConstant mem : members) {
if(mem.getLexicalValue().equals(literal.value))
return type.staticRef(mem.getName());
}
return null;
}
@Deprecated
public boolean isCollection() {
return false;
}
@Deprecated
public CAdapter getAdapterUse() {
return null;
}
@Deprecated
public CNonElement getInfo() {
return this;
}
public ID idUse() {
return ID.NONE;
}
public MimeType getExpectedMimeType() {
return null;
}
public Collection<CEnumConstant> getConstants() {
return members;
}
public NonElement<NType,NClass> getBaseType() {
return base;
}
public CCustomizations getCustomizations() {
return customizations;
}
public Locatable getUpstream() {
throw new UnsupportedOperationException();
}
public Location getLocation() {
throw new UnsupportedOperationException();
}
}

View File

@@ -0,0 +1,59 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import com.sun.tools.internal.xjc.model.nav.NClass;
import com.sun.tools.internal.xjc.model.nav.NType;
import com.sun.xml.internal.bind.v2.model.core.NonElement;
/**
* {@link NonElement} at compile-time.
*
* <p>
* This interface implements {@link TypeUse} so that a {@link CNonElement}
* instance can be used as a {@link TypeUse} instance.
*
* @author Kohsuke Kawaguchi
*/
public interface CNonElement extends NonElement<NType,NClass>, TypeUse, CTypeInfo {
/**
* Guaranteed to return this.
*/
@Deprecated
CNonElement getInfo();
/**
* Guaranteed to return false.
*/
@Deprecated
boolean isCollection();
/**
* Guaranteed to return null.
*/
@Deprecated
CAdapter getAdapterUse();
}

View File

@@ -0,0 +1,80 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import com.sun.tools.internal.xjc.Plugin;
import org.w3c.dom.Element;
import org.xml.sax.Locator;
/**
* Vendor extension customization contributed from {@link Plugin}s.
*
* @author Kohsuke Kawaguchi
*/
public class CPluginCustomization {
/**
* The annotation found in a schema (or in an external binding file.)
*
* Always non-null.
*/
public final Element element;
/**
* The source location where this customization is placed.
*
* <p>
* When an error is found in this customization, this information
* should be used to point the user to the source of the problem.
*
* Always non-nul.
*/
public final Locator locator;
private boolean acknowledged;
/**
* When a {@link Plugin} "uses" this annotation, call this method
* to mark it.
*
* <p>
* {@link CPluginCustomization}s that are not marked will be
* reporeted as an error to users. This allows us to catch
* customizations that are not used by anybody.
*/
public void markAsAcknowledged() {
acknowledged = true;
}
public CPluginCustomization(Element element, Locator locator) {
this.element = element;
this.locator = locator;
}
public boolean isAcknowledged() {
return acknowledged;
}
}

View File

@@ -0,0 +1,342 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.Map;
import javax.xml.XMLConstants;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.namespace.QName;
import com.sun.codemodel.internal.JClass;
import com.sun.codemodel.internal.JJavaName;
import com.sun.codemodel.internal.JType;
import com.sun.tools.internal.xjc.generator.bean.field.FieldRenderer;
import com.sun.tools.internal.xjc.model.nav.NClass;
import com.sun.tools.internal.xjc.model.nav.NType;
import com.sun.tools.internal.xjc.reader.Ring;
import com.sun.xml.internal.bind.api.impl.NameConverter;
import com.sun.xml.internal.bind.v2.WellKnownNamespace;
import com.sun.xml.internal.bind.v2.model.core.PropertyInfo;
import com.sun.xml.internal.bind.v2.runtime.RuntimeUtil;
import com.sun.xml.internal.xsom.XSComponent;
import org.xml.sax.Locator;
/**
* Model of a property to be generated.
*
* @author Kohsuke Kawaguchi
*/
public abstract class CPropertyInfo implements PropertyInfo<NType,NClass>, CCustomizable {
@XmlTransient
private CClassInfo parent;
private String privateName;
private String publicName;
private final boolean isCollection;
@XmlTransient
public final Locator locator;
/**
* @see #getSchemaComponent()
*/
private final XSComponent source;
/**
* If the base type of the property is overriden,
* this field is set to non-null.
*/
public JType baseType;
/**
* Javadoc for this property. Must not be null.
*/
public String javadoc="";
/**
* Property with {@link @XmlInlineBinaryData}.
*/
public boolean inlineBinaryData;
/**
* Specifies how the field is generated by the backend.
*/
@XmlJavaTypeAdapter(RuntimeUtil.ToStringAdapter.class)
public FieldRenderer realization;
/**
* If non-null, keeps the default value in Java representation.
*
* If {@link #isCollection} is true, this field is always null,
* for we don't handle default values for a list.
*/
public CDefaultValue defaultValue;
private final CCustomizations customizations;
protected CPropertyInfo(String name, boolean collection, XSComponent source,
CCustomizations customizations, Locator locator) {
this.publicName = name;
String n = null;
Model m = Ring.get(Model.class);
if (m != null) {
n = m.getNameConverter().toVariableName(name);
} else {
n = NameConverter.standard.toVariableName(name);
}
if(!JJavaName.isJavaIdentifier(n))
n = '_'+n; // avoid colliding with the reserved names like 'abstract'.
this.privateName = n;
this.isCollection = collection;
this.locator = locator;
if(customizations==null)
this.customizations = CCustomizations.EMPTY;
else
this.customizations = customizations;
this.source = source;
}
// called from CClassInfo when added
final void setParent( CClassInfo parent ) {
assert this.parent==null;
assert parent!=null;
this.parent = parent;
customizations.setParent(parent.model,this);
}
public CTypeInfo parent() {
return parent;
}
public Locator getLocator() {
return locator;
}
/**
* If this model object is built from XML Schema,
* this property returns a schema component from which the model is built.
*
* @return
* null if the model is built from sources other than XML Schema
* (such as DTD.)
*/
public final XSComponent getSchemaComponent() {
return source;
}
public abstract CAdapter getAdapter();
/**
* Name of the property.
*
* <p>
* This method is implemented to follow the contract of
* {@link PropertyInfo#getName()}, and therefore it always
* returns the name of the annotated field.
* <p>
* This name is normally not useful for the rest of XJC,
* which usually wants to access the "public name" of the property.
* A "public name" of the property is a name like "FooBar" which
* is used as a seed for generating the accessor methods.
* This is the name controlled by the schema customization via users.
*
* <p>
* If the caller is calling this method statically, it's usually
* the sign of a mistake. Use {@link #getName(boolean)} method instead,
* which forces you to think about which name you want to get.
*
* @deprecated
* marked as deprecated so that we can spot the use of this method.
*
* @see #getName(boolean)
*/
public String getName() {
return getName(false);
}
/**
* Gets the name of the property.
*
* @param isPublic
* if true, this method returns a name like "FooBar", which
* should be used as a seed for generating user-visible names
* (such as accessors like "getFooBar".)
*
* <p>
* if false, this method returns the "name of the property"
* as defined in the j2s side of the spec. This name is usually
* something like "fooBar", which often corresponds to the XML
* element/attribute name of this property (for taking advantage
* of annotation defaulting as much as possible)
*/
public String getName(boolean isPublic) {
return isPublic?publicName:privateName;
}
/**
* Overrides the name of the property.
*
* This method can be used from {@link Plugin#postProcessModel(Model, ErrorHandler)}.
* But the caller should do so with the understanding that this is inherently
* dangerous method.
*/
public void setName(boolean isPublic, String newName) {
if(isPublic)
publicName = newName;
else
privateName = newName;
}
public String displayName() {
return parent.toString()+'#'+getName(false);
}
public boolean isCollection() {
return isCollection;
}
public abstract Collection<? extends CTypeInfo> ref();
/**
* Returns true if this property is "unboxable".
*
* <p>
* In general, a property often has to be capable of representing null
* to indicate the absence of the value. This requires properties
* to be generated as <tt>@XmlElement Float f</tt>, not as
* <tt>@XmlElement float f;</tt>. But this is slow.
*
* <p>
* Fortunately, there are cases where we know that the property can
* never legally be absent. When this condition holds we can generate
* the optimized "unboxed form".
*
* <p>
* The exact such conditions depend
* on the kind of properties, so refer to the implementation code
* for the details.
*
* <p>
* This method returns true when the property can be generated
* as "unboxed form", false otherwise.
*
* <p>
* When this property is a collection, this method returns true
* if items in the collection is unboxable. Obviously, the collection
* itself is always a reference type.
*/
public boolean isUnboxable() {
Collection<? extends CTypeInfo> ts = ref();
if(ts.size()!=1)
// if the property is heterogeneous, no way.
// ts.size()==0 is a special case that can happen for wildcards.
return false;
if(baseType!=null && (baseType instanceof JClass))
return false;
CTypeInfo t = ts.iterator().next();
// only a primitive type is eligible.
return t.getType().isBoxedType();
}
/**
* Returns true if this property needs to represent null
* just for the purpose of representing an absence of the property.
*/
public boolean isOptionalPrimitive() {
return false;
}
public CCustomizations getCustomizations() {
return customizations;
}
public boolean inlineBinaryData() {
return inlineBinaryData;
}
public abstract <V> V accept( CPropertyVisitor<V> visitor );
/**
* Checks if the given {@link TypeUse} would need an explicit {@link XmlSchemaType}
* annotation with the given type name.
*/
protected static boolean needsExplicitTypeName(TypeUse type, QName typeName) {
if(typeName==null)
// this is anonymous type. can't have @XmlSchemaType
return false;
if(!XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(typeName.getNamespaceURI()))
// if we put application-defined type name, it will be undefined
// by the time we generate a schema.
return false;
if(type.isCollection())
// there's no built-in binding for a list simple type,
// so any collection type always need @XmlSchemaType
return true;
QName itemType = type.getInfo().getTypeName();
if(itemType==null)
// this is somewhat strange case, as it means the bound type is anonymous
// but it's eventually derived by a named type and used.
// but we can certainly use typeName as @XmlSchemaType value here
return true;
// if it's the default type name for this item, then no need
return !itemType.equals(typeName);
}
/**
* Puts the element names that this property possesses to the map,
* so that we can find two properties that own the same element name,
* which is an error.
*
* @return
* null if no conflict was found. Otherwise return the QName that has the collision.
*/
public QName collectElementNames(Map<QName,CPropertyInfo> table) {
return null;
}
public final <A extends Annotation> A readAnnotation(Class<A> annotationType) {
throw new UnsupportedOperationException();
}
public final boolean hasAnnotation(Class<? extends Annotation> annotationType) {
throw new UnsupportedOperationException();
}
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
/**
* Visitor for {@link CPropertyInfo}.
*
* Ideally it should be defined on the runtime core model, but the runtime is on diet.
* Hence it's defined here.
*
* @see CPropertyInfo#accept(CPropertyVisitor)
*
* @author Kohsuke Kawaguchi
*/
public interface CPropertyVisitor<V> {
V onElement( CElementPropertyInfo p );
V onAttribute( CAttributePropertyInfo p );
V onValue( CValuePropertyInfo p );
V onReference( CReferencePropertyInfo p );
}

View File

@@ -0,0 +1,239 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.Map;
import javax.activation.MimeType;
import javax.xml.bind.annotation.W3CDomHandler;
import javax.xml.namespace.QName;
import com.sun.tools.internal.xjc.model.nav.NClass;
import com.sun.tools.internal.xjc.model.nav.NType;
import com.sun.tools.internal.xjc.model.nav.NavigatorImpl;
import com.sun.xml.internal.bind.v2.model.core.ID;
import com.sun.xml.internal.bind.v2.model.core.PropertyKind;
import com.sun.xml.internal.bind.v2.model.core.ReferencePropertyInfo;
import com.sun.xml.internal.bind.v2.model.core.WildcardMode;
import com.sun.xml.internal.xsom.XSComponent;
import org.xml.sax.Locator;
/**
* {@link ReferencePropertyInfo} for the compiler.
*
* @author Kohsuke Kawaguchi
*/
public final class CReferencePropertyInfo extends CPropertyInfo implements ReferencePropertyInfo<NType,NClass> {
/**
* True if this property can never be absent legally.
*/
private final boolean required;
/**
* List of referenced elements.
*/
private final Set<CElement> elements = new HashSet<CElement>();
private final boolean isMixed;
private WildcardMode wildcard;
private boolean dummy;
private boolean content;
private boolean isMixedExtendedCust = false;
public CReferencePropertyInfo(String name, boolean collection, boolean required, boolean isMixed, XSComponent source,
CCustomizations customizations, Locator locator, boolean dummy, boolean content, boolean isMixedExtended) { // 'dummy' and 'content' here for NHIN fix - a hack in order to be able to handle extended mixed types better
super(name, (collection||isMixed) && (!dummy), source, customizations, locator);
this.isMixed = isMixed;
this.required = required;
this.dummy = dummy;
this.content = content;
this.isMixedExtendedCust = isMixedExtended;
}
public Set<? extends CTypeInfo> ref() {
// if(wildcard==null && !isMixed())
// return getElements();
// ugly hack to get the signature right for substitution groups
// when a class is generated for elements,they don't form a nice type hierarchy,
// so the Java types of the substitution members need to be taken into account
// when computing the signature
final class RefList extends HashSet<CTypeInfo> {
RefList() {
super(elements.size());
addAll(elements);
}
@Override
public boolean addAll( Collection<? extends CTypeInfo> col ) {
boolean r = false;
for (CTypeInfo e : col) {
if(e instanceof CElementInfo) {
// UGLY. element substitution is implemented in a way that
// the derived elements are not assignable to base elements.
// so when we compute the signature, we have to take derived types
// into account
r |= addAll( ((CElementInfo)e).getSubstitutionMembers());
}
r |= add(e);
}
return r;
}
}
RefList r = new RefList();
if(wildcard!=null) {
if(wildcard.allowDom)
r.add(CWildcardTypeInfo.INSTANCE);
if(wildcard.allowTypedObject)
// we aren't really adding an AnyType.
// this is a kind of hack to generate Object as a signature
r.add(CBuiltinLeafInfo.ANYTYPE);
}
if(isMixed())
r.add(CBuiltinLeafInfo.STRING);
return r;
}
public Set<CElement> getElements() {
return elements;
}
public boolean isMixed() {
return isMixed;
}
public boolean isDummy() {
return dummy;
}
public boolean isContent() {
return content;
}
public boolean isMixedExtendedCust() {
return isMixedExtendedCust;
}
/**
* We'll never use a wrapper element in XJC. Always return null.
*/
@Deprecated
public QName getXmlName() {
return null;
}
/**
* Reference properties refer to elements, and none of the Java primitive type
* maps to an element. Thus a reference property is always unboxable.
*/
@Override
public boolean isUnboxable() {
return false;
}
// the same as above
@Override
public boolean isOptionalPrimitive() {
return false;
}
public <V> V accept(CPropertyVisitor<V> visitor) {
return visitor.onReference(this);
}
public CAdapter getAdapter() {
return null;
}
public final PropertyKind kind() {
return PropertyKind.REFERENCE;
}
/**
* A reference property can never be ID/IDREF because they always point to
* other element classes.
*/
public ID id() {
return ID.NONE;
}
public WildcardMode getWildcard() {
return wildcard;
}
public void setWildcard(WildcardMode mode) {
this.wildcard = mode;
}
public NClass getDOMHandler() {
// TODO: support other DOM handlers
if(getWildcard()!=null)
return NavigatorImpl.create(W3CDomHandler.class);
else
return null;
}
public MimeType getExpectedMimeType() {
return null;
}
public boolean isCollectionNillable() {
// in XJC, we never recognize a nillable collection pattern, so this is always false.
return false;
}
public boolean isCollectionRequired() {
// in XJC, we never recognize a nillable collection pattern, so this is always false.
return false;
}
// reference property cannot have a type.
public QName getSchemaType() {
return null;
}
public boolean isRequired() {
return required;
}
@Override
public QName collectElementNames(Map<QName, CPropertyInfo> table) {
for (CElement e : elements) {
QName n = e.getElementName();
if(table.containsKey(n))
return n;
table.put(n,this);
}
return null;
}
}

View File

@@ -0,0 +1,95 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import java.util.Collections;
import java.util.List;
import javax.activation.MimeType;
import javax.xml.namespace.QName;
import com.sun.xml.internal.bind.v2.model.core.ID;
import com.sun.xml.internal.xsom.XSComponent;
import org.xml.sax.Locator;
/**
* {@link CPropertyInfo} backed by a single {@link TypeUse}.
*
* @author Kohsuke Kawaguchi
*/
abstract class CSingleTypePropertyInfo extends CPropertyInfo {
protected final TypeUse type;
private final QName schemaType;
/**
*
* @param typeName
* XML Schema type name of this property's single value. Optional
* for other schema languages. This is used to determine if we should
* generate {@link @XmlSchemaType} annotation to improve the roundtrip.
*/
protected CSingleTypePropertyInfo(String name, TypeUse type, QName typeName, XSComponent source, CCustomizations customizations, Locator locator) {
super(name, type.isCollection(), source, customizations, locator);
this.type = type;
if(needsExplicitTypeName(type,typeName))
schemaType = typeName;
else
schemaType = null;
}
public QName getSchemaType() {
return schemaType;
}
public final ID id() {
return type.idUse();
}
public final MimeType getExpectedMimeType() {
return type.getExpectedMimeType();
}
public final List<? extends CTypeInfo> ref() {
return Collections.singletonList(getTarget());
}
public final CNonElement getTarget() {
CNonElement r = type.getInfo();
assert r!=null;
return r;
}
public final CAdapter getAdapter() {
return type.getAdapterUse();
}
public final CSingleTypePropertyInfo getSource() {
return this;
}
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import com.sun.codemodel.internal.JClass;
import com.sun.codemodel.internal.JType;
import com.sun.tools.internal.xjc.model.nav.NClass;
import com.sun.tools.internal.xjc.model.nav.NType;
import com.sun.tools.internal.xjc.outline.Aspect;
import com.sun.tools.internal.xjc.outline.Outline;
import com.sun.xml.internal.bind.v2.model.core.TypeInfo;
/**
* {@link TypeInfo} at the compile-time.
* Either {@link CClassInfo}, {@link CBuiltinLeafInfo}, or {@link CElementInfo}.
*
* @author Kohsuke Kawaguchi
*/
public interface CTypeInfo extends TypeInfo<NType,NClass>, CCustomizable {
/**
* Returns the {@link JClass} that represents the class being bound,
* under the given {@link Outline}.
*
* @see NType#toType(Outline, Aspect)
*/
JType toType(Outline o, Aspect aspect);
}

View File

@@ -0,0 +1,159 @@
/*
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import javax.xml.XMLConstants;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.namespace.QName;
import com.sun.tools.internal.xjc.model.nav.NClass;
import com.sun.tools.internal.xjc.model.nav.NType;
import com.sun.tools.internal.xjc.reader.xmlschema.BGMBuilder;
import com.sun.xml.internal.bind.v2.model.core.PropertyInfo;
import com.sun.xml.internal.bind.v2.model.core.TypeRef;
import com.sun.xml.internal.bind.v2.runtime.RuntimeUtil;
import com.sun.xml.internal.xsom.XSType;
import com.sun.xml.internal.xsom.XmlString;
import com.sun.xml.internal.xsom.XSElementDecl;
import com.sun.istack.internal.Nullable;
/**
* {@link TypeRef} for XJC.
*
* TODO: do we need the source schema component support here?
*
* @author Kohsuke Kawaguchi
*/
public final class CTypeRef implements TypeRef<NType,NClass> {
/**
* In-memory type.
*
* This is the type used when
*/
@XmlJavaTypeAdapter(RuntimeUtil.ToStringAdapter.class)
private final CNonElement type;
private final QName elementName;
/**
* XML Schema type name of {@link #type}, if available.
*/
/*package*/ final @Nullable QName typeName;
private final boolean nillable;
public final XmlString defaultValue;
public CTypeRef(CNonElement type, XSElementDecl decl) {
this(type, BGMBuilder.getName(decl),getSimpleTypeName(decl), decl.isNillable(), decl.getDefaultValue() );
}
public QName getTypeName() {
return typeName;
}
public static QName getSimpleTypeName(XSElementDecl decl) {
if(decl==null || !decl.getType().isSimpleType())
return null; // null if not simple type
return resolveSimpleTypeName(decl.getType());
}
/**
* Recursively search for type name.
*
* This is needed to find correct type for refs like:
*
*<xs:simpleType name="parent">
* <xs:restriction base="xs:date"/>
*</xs:simpleType>
*<xs:simpleType name="child">
* <xs:restriction base="parent"/>
*</xs:simpleType>
*
*<xs:element name="testField" type="child"/>
*
* @param declType given type
* @return simpleTypeName or null
*/
private static QName resolveSimpleTypeName(XSType declType) {
QName name = BGMBuilder.getName(declType);
QName result = null;
if (name != null && !XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(name.getNamespaceURI())) {
result = resolveSimpleTypeName(declType.getBaseType());
} else {
if ( !"anySimpleType".equals(declType.getName()) ) {
result = name;
}
}
return result;
}
public CTypeRef(CNonElement type, QName elementName, QName typeName, boolean nillable, XmlString defaultValue) {
assert type!=null;
assert elementName!=null;
this.type = type;
this.elementName = elementName;
this.typeName = typeName;
this.nillable = nillable;
this.defaultValue = defaultValue;
}
public CNonElement getTarget() {
return type;
}
public QName getTagName() {
return elementName;
}
public boolean isNillable() {
return nillable;
}
/**
* Inside XJC, use {@link #defaultValue} that has context information.
* This method is to override the one defined in the runtime model.
*
* @see #defaultValue
*/
public String getDefaultValue() {
if(defaultValue!=null)
return defaultValue.value;
else
return null;
}
public boolean isLeaf() {
// TODO: implement this method later
throw new UnsupportedOperationException();
}
public PropertyInfo<NType, NClass> getSource() {
// TODO: implement this method later
throw new UnsupportedOperationException();
}
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import javax.xml.namespace.QName;
import com.sun.tools.internal.xjc.model.nav.NClass;
import com.sun.tools.internal.xjc.model.nav.NType;
import com.sun.xml.internal.bind.v2.model.core.PropertyKind;
import com.sun.xml.internal.bind.v2.model.core.ValuePropertyInfo;
import com.sun.xml.internal.xsom.XSComponent;
import org.xml.sax.Locator;
/**
* {@link ValuePropertyInfo} implementation for XJC.
*
* @author Kohsuke Kawaguchi
*/
public final class CValuePropertyInfo extends CSingleTypePropertyInfo implements ValuePropertyInfo<NType,NClass> {
public CValuePropertyInfo(String name, XSComponent source, CCustomizations customizations, Locator locator, TypeUse type, QName typeName) {
super(name, type, typeName, source, customizations, locator);
}
public final PropertyKind kind() {
return PropertyKind.VALUE;
}
public <V> V accept(CPropertyVisitor<V> visitor) {
return visitor.onValue(this);
}
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import com.sun.codemodel.internal.JType;
import com.sun.tools.internal.xjc.model.nav.NClass;
import com.sun.tools.internal.xjc.model.nav.NType;
import com.sun.tools.internal.xjc.model.nav.NavigatorImpl;
import com.sun.tools.internal.xjc.outline.Aspect;
import com.sun.tools.internal.xjc.outline.Outline;
import com.sun.xml.internal.bind.v2.model.core.WildcardTypeInfo;
import org.w3c.dom.Element;
import org.xml.sax.Locator;
/**
* {@link CTypeInfo} for the DOM node.
*
* TODO: support other DOM models.
*
* @author Kohsuke Kawaguchi
*/
public final class CWildcardTypeInfo extends AbstractCTypeInfoImpl implements WildcardTypeInfo<NType,NClass> {
private CWildcardTypeInfo() {
super(null,null,null);
}
public static final CWildcardTypeInfo INSTANCE = new CWildcardTypeInfo();
public JType toType(Outline o, Aspect aspect) {
return o.getCodeModel().ref(Element.class);
}
public NType getType() {
return NavigatorImpl.create(Element.class);
}
public Locator getLocator() {
return Model.EMPTY_LOCATOR;
}
}

View File

@@ -0,0 +1,65 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import com.sun.codemodel.internal.JPackage;
import com.sun.tools.internal.xjc.api.ClassNameAllocator;
/**
* Wraps {@link ClassNameAllocator} and provides convenience.
*
* @author Kohsuke Kawaguchi
*/
final class ClassNameAllocatorWrapper implements ClassNameAllocator {
private final ClassNameAllocator core;
ClassNameAllocatorWrapper(ClassNameAllocator core) {
if(core==null)
core = new ClassNameAllocator() {
public String assignClassName(String packageName, String className) {
return className;
}
};
this.core = core;
}
public String assignClassName(String packageName, String className) {
return core.assignClassName(packageName,className);
}
public String assignClassName(JPackage pkg, String className) {
return core.assignClassName(pkg.name(),className);
}
public String assignClassName(CClassInfoParent parent, String className) {
if (parent instanceof CClassInfoParent.Package) {
CClassInfoParent.Package p = (CClassInfoParent.Package) parent;
return assignClassName(p.pkg,className);
}
// not a package-level class
return className;
}
}

View File

@@ -0,0 +1,65 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
/**
* Constructor declaration.
*
* <p>
* a constructor declaration consists of a set of fields to be initialized.
* For example, if a class is defined as:
*
* <pre>
* Class: Foo
* Field: String a
* Field: int b
* Field: BigInteger c
* </pre>
*
* Then a constructor declaration of {"a","c"} will conceptually
* generate the following consturctor:
*
* <pre>
* Foo( String _a, BigInteger _c ) {
* a=_a; c=_c;
* }
* </pre>
*
* (Only conceptually, because Foo will likely to become an interface
* so we can't simply generate a constructor like this.)
*
* @author
* <a href="mailto:kohsuke.kawaguchi@sun.com">Kohsuke KAWAGUCHI</a>
*/
public class Constructor
{
// Since Constructor is typically built when there is no FieldItem
// nor FieldUse, we need to rely on Strings.
public Constructor( String[] _fields ) { this.fields = _fields; }
/** array of field names to be initialized. */
public final String[] fields;
}

View File

@@ -0,0 +1,491 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.namespace.QName;
import javax.xml.transform.Result;
import com.sun.codemodel.internal.JClass;
import com.sun.codemodel.internal.JCodeModel;
import com.sun.codemodel.internal.JPackage;
import com.sun.tools.internal.xjc.ErrorReceiver;
import com.sun.tools.internal.xjc.Options;
import com.sun.tools.internal.xjc.Plugin;
import com.sun.tools.internal.xjc.api.ClassNameAllocator;
import com.sun.tools.internal.xjc.generator.bean.BeanGenerator;
import com.sun.tools.internal.xjc.generator.bean.ImplStructureStrategy;
import com.sun.tools.internal.xjc.model.nav.NClass;
import com.sun.tools.internal.xjc.model.nav.NType;
import com.sun.tools.internal.xjc.model.nav.NavigatorImpl;
import com.sun.tools.internal.xjc.outline.Outline;
import com.sun.tools.internal.xjc.reader.xmlschema.Messages;
import com.sun.tools.internal.xjc.util.ErrorReceiverFilter;
import com.sun.xml.internal.bind.api.impl.NameConverter;
import com.sun.xml.internal.bind.v2.model.core.Ref;
import com.sun.xml.internal.bind.v2.model.core.TypeInfoSet;
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
import com.sun.xml.internal.bind.v2.util.FlattenIterator;
import com.sun.xml.internal.xsom.XSComponent;
import com.sun.xml.internal.xsom.XSSchemaSet;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.LocatorImpl;
/**
* Root of the object model that represents the code that needs to be generated.
*
* <p>
* A {@link Model} is a schema language neutral representation of the
* result of a schema parsing. The back-end then works against this model
* to turn this into a series of Java source code.
*
* @author Kohsuke Kawaguchi
*/
public final class Model implements TypeInfoSet<NType,NClass,Void,Void>, CCustomizable {
/**
* Generated beans.
*/
private final Map<NClass,CClassInfo> beans = new LinkedHashMap<NClass,CClassInfo>();
/**
* Generated enums.
*/
private final Map<NClass,CEnumLeafInfo> enums = new LinkedHashMap<NClass,CEnumLeafInfo>();
/**
* The element mappings.
*/
private final Map<NClass/*scope*/,Map<QName,CElementInfo>> elementMappings =
new HashMap<NClass,Map<QName,CElementInfo>>();
private final Iterable<? extends CElementInfo> allElements =
new Iterable<CElementInfo>() {
public Iterator<CElementInfo> iterator() {
return new FlattenIterator<CElementInfo>(elementMappings.values());
}
};
/**
* {@link TypeUse}s for all named types.
* <p>
* I really don't want to promote the notion of a 'type' in any place except in the XML Schema code,
* but this needs to be exposed for JAX-RPC. A reference to a named XML type will be converted into
* a reference to a Java type with annotations.
*/
private final Map<QName,TypeUse> typeUses = new LinkedHashMap<QName, TypeUse>();
/**
* {@link NameConverter} to be used.
*/
private NameConverter nameConverter;
/**
* Single linked list that connects all {@link CCustomizations} that belong to this model.
*
* @see CCustomizations#next
*/
/*package*/ CCustomizations customizations;
/**
* This field controls the generation of package level annotations for s2j
*/
private boolean packageLevelAnnotations = true;
/**
* If this model was built from XML Schema, this field
* stores the root object of the parse schema model.
* Otherwise null.
*
* @sine 2.1.1
*/
public final XSSchemaSet schemaComponent;
private CCustomizations gloablCustomizations = new CCustomizations();
/**
* @param nc
* Usually this should be set in the constructor, but we do allow this parameter
* to be initially null, and then set later.
* @param schemaComponent
* The source schema model, if this is built from XSD.
*/
public Model( Options opts, JCodeModel cm, NameConverter nc, ClassNameAllocator allocator, XSSchemaSet schemaComponent ) {
this.options = opts;
this.codeModel = cm;
this.nameConverter = nc;
this.defaultSymbolSpace = new SymbolSpace(codeModel);
defaultSymbolSpace.setType(codeModel.ref(Object.class));
elementMappings.put(null,new HashMap<QName,CElementInfo>());
if(opts.automaticNameConflictResolution)
allocator = new AutoClassNameAllocator(allocator);
this.allocator = new ClassNameAllocatorWrapper(allocator);
this.schemaComponent = schemaComponent;
this.gloablCustomizations.setParent(this,this);
}
public void setNameConverter(NameConverter nameConverter) {
assert this.nameConverter==null;
assert nameConverter!=null;
this.nameConverter = nameConverter;
}
/**
* Gets the name converter that shall be used to parse XML names into Java names.
*/
public final NameConverter getNameConverter() {
return nameConverter;
}
public boolean isPackageLevelAnnotations() {
return packageLevelAnnotations;
}
public void setPackageLevelAnnotations(boolean packageLevelAnnotations) {
this.packageLevelAnnotations = packageLevelAnnotations;
}
/**
* This model uses this code model exclusively.
*/
@XmlTransient
public final JCodeModel codeModel;
/**
* Command-line options used for building this model.
*/
public final Options options;
/**
* True to generate serializable classes.
*/
@XmlAttribute
public boolean serializable;
/**
* serial version UID to be generated.
*
* null if not to generate serialVersionUID field.
*/
@XmlAttribute
public Long serialVersionUID;
/**
* If non-null, all the generated classes should eventually derive from this class.
*/
@XmlTransient
public JClass rootClass;
/**
* If non-null, all the generated interfaces should eventually derive from this interface.
*/
@XmlTransient
public JClass rootInterface;
/**
* Specifies the code generation strategy.
* Must not be null.
*/
public ImplStructureStrategy strategy = ImplStructureStrategy.BEAN_ONLY;
/**
* This allocator has the final say on deciding the class name.
* Must not be null.
*
* <p>
* Model classes are responsible for using the allocator.
* This allocator interaction should be transparent to the user/builder
* of the model.
*/
/*package*/ final ClassNameAllocatorWrapper allocator;
/**
* Default ID/IDREF symbol space. Any ID/IDREF without explicit
* reference to a symbol space is assumed to use this default
* symbol space.
*/
@XmlTransient
public final SymbolSpace defaultSymbolSpace;
/** All the defined {@link SymbolSpace}s keyed by their name. */
private final Map<String,SymbolSpace> symbolSpaces = new HashMap<String,SymbolSpace>();
public SymbolSpace getSymbolSpace( String name ) {
SymbolSpace ss = symbolSpaces.get(name);
if(ss==null)
symbolSpaces.put(name,ss=new SymbolSpace(codeModel));
return ss;
}
/**
* Fully-generate the source code into the given model.
*
* @return
* null if there was any errors. Otherwise it returns a valid
* {@link Outline} object, which captures how the model objects
* are mapped to the generated source code.
* <p>
* Add-ons can use those information to further augment the generated
* source code.
*/
public Outline generateCode(Options opt,ErrorReceiver receiver) {
ErrorReceiverFilter ehf = new ErrorReceiverFilter(receiver);
// run extensions // moved to BGMBuilder._build() - issue with hyperjaxb3
// for( Plugin ma : opt.activePlugins )
// ma.postProcessModel(this,ehf);
Outline o = BeanGenerator.generate(this, ehf);
try {// run extensions
for( Plugin ma : opt.activePlugins )
ma.run(o,opt,ehf);
} catch (SAXException e) {
// fatal error. error should have been reported
return null;
}
// check for unused plug-in customizations.
// these can be only checked after the plug-ins run, so it's here.
// the JAXB bindings are checked by XMLSchema's builder.
Set<CCustomizations> check = new HashSet<CCustomizations>();
for( CCustomizations c=customizations; c!=null; c=c.next ) {
if(!check.add(c)) {
throw new AssertionError(); // detect a loop
}
for (CPluginCustomization p : c) {
if(!p.isAcknowledged()) {
ehf.error(
p.locator,
Messages.format(
Messages.ERR_UNACKNOWLEDGED_CUSTOMIZATION,
p.element.getNodeName()
));
ehf.error(
c.getOwner().getLocator(),
Messages.format(
Messages.ERR_UNACKNOWLEDGED_CUSTOMIZATION_LOCATION));
}
}
}
if(ehf.hadError())
o = null;
return o;
}
/**
* Represents the "top-level binding".
*
* <p>
* This is used to support the use of a schema inside WSDL.
* For XML Schema, the top-level binding is a map from
* global element declarations to its representation class.
*
* <p>
* For other schema languages, it should follow the appendicies in
* WSDL (but in practice no one would use WSDL with a schema language
* other than XML Schema, so it doesn't really matter.)
*
* <p>
* This needs to be filled by the front-end.
*/
public final Map<QName,CClassInfo> createTopLevelBindings() {
Map<QName,CClassInfo> r = new HashMap<QName,CClassInfo>();
for( CClassInfo b : beans().values() ) {
if(b.isElement())
r.put(b.getElementName(),b);
}
return r;
}
public Navigator<NType,NClass,Void,Void> getNavigator() {
return NavigatorImpl.theInstance;
}
public CNonElement getTypeInfo(NType type) {
CBuiltinLeafInfo leaf = CBuiltinLeafInfo.LEAVES.get(type);
if(leaf!=null) return leaf;
return getClassInfo(getNavigator().asDecl(type));
}
public CBuiltinLeafInfo getAnyTypeInfo() {
return CBuiltinLeafInfo.ANYTYPE;
}
public CNonElement getTypeInfo(Ref<NType,NClass> ref) {
// TODO: handle XmlValueList
assert !ref.valueList;
return getTypeInfo(ref.type);
}
public Map<NClass,CClassInfo> beans() {
return beans;
}
public Map<NClass,CEnumLeafInfo> enums() {
return enums;
}
public Map<QName,TypeUse> typeUses() {
return typeUses;
}
/**
* No array mapping generation for XJC.
*/
public Map<NType, ? extends CArrayInfo> arrays() {
return Collections.emptyMap();
}
public Map<NType, ? extends CBuiltinLeafInfo> builtins() {
return CBuiltinLeafInfo.LEAVES;
}
public CClassInfo getClassInfo(NClass t) {
return beans.get(t);
}
public CElementInfo getElementInfo(NClass scope,QName name) {
Map<QName,CElementInfo> m = elementMappings.get(scope);
if(m!=null) {
CElementInfo r = m.get(name);
if(r!=null) return r;
}
return elementMappings.get(null).get(name);
}
public Map<QName,CElementInfo> getElementMappings(NClass scope) {
return elementMappings.get(scope);
}
public Iterable<? extends CElementInfo> getAllElements() {
return allElements;
}
/**
* @deprecated
* Always return null. Perhaps you are interested in {@link #schemaComponent}?
*/
public XSComponent getSchemaComponent() {
return null;
}
/**
* @deprecated
* No line number available for the "root" component.
*/
public Locator getLocator() {
LocatorImpl r = new LocatorImpl();
r.setLineNumber(-1);
r.setColumnNumber(-1);
return r;
}
/**
* Gets the global customizations.
*/
public CCustomizations getCustomizations() {
return gloablCustomizations;
}
/**
* Not implemented in the compile-time model.
*/
public Map<String, String> getXmlNs(String namespaceUri) {
return Collections.emptyMap();
}
public Map<String, String> getSchemaLocations() {
return Collections.emptyMap();
}
public XmlNsForm getElementFormDefault(String nsUri) {
throw new UnsupportedOperationException();
}
public XmlNsForm getAttributeFormDefault(String nsUri) {
throw new UnsupportedOperationException();
}
public void dump(Result out) {
// TODO
throw new UnsupportedOperationException();
}
/*package*/ void add( CEnumLeafInfo e ) {
enums.put( e.getClazz(), e );
}
/*package*/ void add( CClassInfo ci ) {
beans.put( ci.getClazz(), ci );
}
/*package*/ void add( CElementInfo ei ) {
NClass clazz = null;
if(ei.getScope()!=null)
clazz = ei.getScope().getClazz();
Map<QName,CElementInfo> m = elementMappings.get(clazz);
if(m==null)
elementMappings.put(clazz,m=new HashMap<QName,CElementInfo>());
m.put(ei.getElementName(),ei);
}
private final Map<JPackage,CClassInfoParent.Package> cache = new HashMap<JPackage,CClassInfoParent.Package>();
public CClassInfoParent.Package getPackage(JPackage pkg) {
CClassInfoParent.Package r = cache.get(pkg);
if(r==null)
cache.put(pkg,r=new CClassInfoParent.Package(pkg));
return r;
}
/*package*/ static final Locator EMPTY_LOCATOR;
static {
LocatorImpl l = new LocatorImpl();
l.setColumnNumber(-1);
l.setLineNumber(-1);
EMPTY_LOCATOR = l;
}
}

View File

@@ -0,0 +1,206 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import java.math.BigInteger;
/**
* represents a possible number of occurence.
*
* Usually, denoted by a pair of integers like (1,1) or (5,10).
* A special value "unbounded" is allowed as the upper bound.
*
* <p>
* For example, (0,unbounded) corresponds to the '*' occurence of DTD.
* (0,1) corresponds to the '?' occurence of DTD.
*
* @author
* <a href="mailto:kohsuke.kawaguchi@sun.com">Kohsuke KAWAGUCHI</a>
*/
public final class Multiplicity {
public final BigInteger min;
public final BigInteger max; // null is used to represent "unbounded".
public static Multiplicity create(BigInteger min, BigInteger max ) {
if (BigInteger.ZERO.equals(min) && max==null) return STAR;
if (BigInteger.ONE.equals(min) && max==null) return PLUS;
if (max!=null) {
if(BigInteger.ZERO.equals(min) && BigInteger.ZERO.equals(max)) return ZERO;
if(BigInteger.ZERO.equals(min) && BigInteger.ONE.equals(max)) return OPTIONAL;
if(BigInteger.ONE.equals(min) && BigInteger.ONE.equals(max)) return ONE;
}
return new Multiplicity(min, max);
}
public static Multiplicity create(int min, Integer max ) {
return Multiplicity.create(BigInteger.valueOf(min), BigInteger.valueOf(max.intValue()));
}
private Multiplicity(BigInteger min, BigInteger max) {
this.min = min;
this.max = max;
}
private Multiplicity(int min, int max) {
this(BigInteger.valueOf(min), BigInteger.valueOf(max));
}
private Multiplicity(int min, Integer max) {
this(BigInteger.valueOf(min), (max == null) ? null : BigInteger.valueOf(max));
}
@Override
public boolean equals(Object o) {
if (!(o instanceof Multiplicity)) return false;
Multiplicity that = (Multiplicity) o;
if (!this.min.equals(that.min)) return false;
if (this.max != null ? !this.max.equals(that.max) : that.max != null) return false;
return true;
}
@Override
public int hashCode() {
return min.add(max).intValue();
}
/** returns true if the multiplicity is (1,1). */
public boolean isUnique() {
if(max==null) return false;
return BigInteger.ONE.equals(min) && BigInteger.ONE.equals(max);
}
/** returns true if the multiplicity is (0,1) */
public boolean isOptional() {
if(max==null) return false;
return BigInteger.ZERO.equals(min) && BigInteger.ONE.equals(max);
}
/** returns true if the multiplicity is (0,1) or (1,1). */
public boolean isAtMostOnce() {
if(max==null) return false;
return max.compareTo(BigInteger.ONE)<=0;
}
/** returns true if the multiplicity is (0,0). */
public boolean isZero() {
if(max==null) return false;
return BigInteger.ZERO.equals(max);
}
/**
* Returns true if the multiplicity represented by this object
* completely includes the multiplicity represented by the
* other object. For example, we say [1,3] includes [1,2] but
* [2,4] doesn't include [1,3].
*/
public boolean includes( Multiplicity rhs ) {
if (rhs.min.compareTo(min) == -1) return false;
if (max==null) return true;
if (rhs.max==null) return false;
return rhs.max.compareTo(max) <= 0;
}
/**
* Returns the string representation of the 'max' property.
* Either a number or a token "unbounded".
*/
public String getMaxString() {
if(max==null) return "unbounded";
else return max.toString();
}
/** gets the string representation.
* mainly debug purpose.
*/
@Override
public String toString() {
return "("+min+','+getMaxString()+')';
}
/** the constant representing the (0,0) multiplicity. */
public static final Multiplicity ZERO = new Multiplicity(0,0);
/** the constant representing the (1,1) multiplicity. */
public static final Multiplicity ONE = new Multiplicity(1,1);
/** the constant representing the (0,1) multiplicity. */
public static final Multiplicity OPTIONAL = new Multiplicity(0,1);
/** the constant representing the (0,unbounded) multiplicity. */
public static final Multiplicity STAR = new Multiplicity(0,null);
/** the constant representing the (1,unbounded) multiplicity. */
public static final Multiplicity PLUS = new Multiplicity(1,null);
// arithmetic methods
public static Multiplicity choice( Multiplicity lhs, Multiplicity rhs ) {
return create(
lhs.min.min(rhs.min),
(lhs.max==null || rhs.max==null) ? null : lhs.max.max(rhs.max) );
}
public static Multiplicity group( Multiplicity lhs, Multiplicity rhs ) {
return create(
lhs.min.add(rhs.min),
(lhs.max==null || rhs.max==null) ? null : lhs.max.add(rhs.max) );
}
public static Multiplicity multiply( Multiplicity lhs, Multiplicity rhs ) {
BigInteger min = lhs.min.multiply(rhs.min);
BigInteger max;
if (isZero(lhs.max) || isZero(rhs.max))
max = BigInteger.ZERO;
else
if (lhs.max==null || rhs.max==null)
max = null;
else
max = lhs.max.multiply(rhs.max);
return create(min,max);
}
private static boolean isZero(BigInteger i) {
return (i != null && BigInteger.ZERO.equals(i));
}
public static Multiplicity oneOrMore( Multiplicity c ) {
if(c.max==null) return c; // (x,*) => (x,*)
if(BigInteger.ZERO.equals(c.max)) return c; // (0,0) => (0,0)
else return create( c.min, null ); // (x,y) => (x,*)
}
public Multiplicity makeOptional() {
if (BigInteger.ZERO.equals(min)) return this;
return create(BigInteger.ZERO, max);
}
public Multiplicity makeRepeated() {
if (max==null || BigInteger.ZERO.equals(max)) return this; // (0,0)* = (0,0) and (n,unbounded)* = (n,unbounded)
return create(min,null);
}
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import com.sun.tools.internal.xjc.outline.Outline;
/**
* Mark model components which does additional code generation.
*
* TODO: currently this is only used for enum xducers. Think about a way
* to generalize this.
*
* TODO: is this a sensible abstraction? Who's responsible for registering
* populatable components to the model? Isn't it better if the back end
* just gives every component a chance to build it automatically?
*
* @author Kohsuke Kawaguchi
*/
public interface Populatable {
public void populate( Model model, Outline context );
}

View File

@@ -0,0 +1,80 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import com.sun.codemodel.internal.JCodeModel;
import com.sun.codemodel.internal.JType;
/**
* Symbol space for ID/IDREF.
*
* In XJC, the whole ID space is considered to be splitted into
* one or more "symbol space". For an IDREF to match an ID, we impose
* additional restriction to the one stated in the XML rec.
*
* <p>
* That is, XJC'll require that the IDREF belongs to the same symbol
* space as the ID. Having this concept allows us to assign more
* specific type to IDREF.
*
* <p>
* See the design document for detail.
*
* @author
* <a href="mailto:kohsuke.kawaguchi@sun.com">Kohsuke KAWAGUCHI</a>
*/
public class SymbolSpace
{
private JType type;
private final JCodeModel codeModel;
public SymbolSpace( JCodeModel _codeModel ) {
this.codeModel = _codeModel;
}
/**
* Gets the Java type of this symbol space.
*
* <p>
* A symbol space is said to have a Java type X if all classes
* pointed by IDs belonging to this symbol space are assignable
* to X.
*/
public JType getType() {
if(type==null) return codeModel.ref(Object.class);
return type;
}
public void setType( JType _type ) {
if( this.type==null )
this.type = _type;
}
public String toString() {
if(type==null) return "undetermined";
else return type.name();
}
}

View File

@@ -0,0 +1,107 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import javax.activation.MimeType;
import com.sun.codemodel.internal.JExpression;
import com.sun.tools.internal.xjc.model.nav.NType;
import com.sun.tools.internal.xjc.outline.Outline;
import com.sun.xml.internal.bind.v2.model.core.ID;
import com.sun.xml.internal.xsom.XmlString;
/**
* Information about how another type is referenced.
*
* <p>
* In practice it is often easier to use {@link CTypeInfo}
* instead of {@link NType}, so this interface defines {@link #getInfo()}.
*
* @author Kohsuke Kawaguchi
* @see TypeUseImpl
*/
public interface TypeUse {
/**
* If the use can hold multiple values of the specified type.
*/
boolean isCollection();
/**
* If this type use is adapting the type, returns the adapter.
* Otherwise return null.
*/
CAdapter getAdapterUse();
/**
* Individual item type.
*/
CNonElement getInfo();
/**
* Whether the referenced type (individual item type in case of collection)
* is ID/IDREF.
*
* <p>
* ID is a property of a relationship. When a bean Foo has an ID property
* called 'bar' whose type is String, Foo isn't an ID, String isn't an ID,
* but this relationship is an ID (in the sense that Foo uses this String
* as an ID.)
*
* <p>
* The same thing can be said with IDREF. When Foo refers to Bar by means of
* IDREF, neither Foo nor Bar is IDREF.
*
* <p>
* That's why we have this method in {@link TypeUse}.
*/
ID idUse();
/**
* A {@link TypeUse} can have an associated MIME type.
*/
MimeType getExpectedMimeType();
/**
* Creates a constant for the given lexical value.
*
* <p>
* For example, to create a constant 1 for <tt>xs:int</tt>, you'd do:
* <pre>
* CBuiltinLeafInfo.INT.createConstant( codeModel, "1", null );
* </pre>
*
* <p>
* This method is invoked at the backend as a part of the code generation process.
*
* @throws IllegalStateException
* if the type isn't bound to a text in XML.
*
* @return null
* if the constant cannot be created for this {@link TypeUse}
* (such as when it's a collection)
*/
JExpression createConstant(Outline outline, XmlString lexical);
}

View File

@@ -0,0 +1,82 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import javax.activation.MimeType;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import com.sun.xml.internal.bind.v2.TODO;
import com.sun.xml.internal.bind.v2.model.core.Adapter;
import com.sun.xml.internal.bind.v2.model.core.ID;
/**
* Factory methods to create a new {@link TypeUse} from an existing one.
*
* @author Kohsuke Kawaguchi
*/
public final class TypeUseFactory {
private TypeUseFactory() {}
public static TypeUse makeID( TypeUse t, ID id ) {
if(t.idUse()!=ID.NONE)
// I don't think we let users tweak the idness, so
// this error must indicate an inconsistency within the RI/spec.
throw new IllegalStateException();
return new TypeUseImpl( t.getInfo(), t.isCollection(), id, t.getExpectedMimeType(), t.getAdapterUse() );
}
public static TypeUse makeMimeTyped( TypeUse t, MimeType mt ) {
if(t.getExpectedMimeType()!=null)
// I don't think we let users tweak the idness, so
// this error must indicate an inconsistency within the RI/spec.
throw new IllegalStateException();
return new TypeUseImpl( t.getInfo(), t.isCollection(), t.idUse(), mt, t.getAdapterUse() );
}
public static TypeUse makeCollection( TypeUse t ) {
if(t.isCollection()) return t;
CAdapter au = t.getAdapterUse();
if(au!=null && !au.isWhitespaceAdapter()) {
// we can't process this right now.
// for now bind to a weaker type
TODO.checkSpec();
return CBuiltinLeafInfo.STRING_LIST;
}
return new TypeUseImpl( t.getInfo(), true, t.idUse(), t.getExpectedMimeType(), null );
}
public static TypeUse adapt(TypeUse t, CAdapter adapter) {
assert t.getAdapterUse()==null; // TODO: we don't know how to handle double adapters yet.
return new TypeUseImpl(t.getInfo(),t.isCollection(),t.idUse(),t.getExpectedMimeType(),adapter);
}
/**
* Creates a new adapter {@link TypeUse} by using the existing {@link Adapter} class.
*/
public static TypeUse adapt( TypeUse t, Class<? extends XmlAdapter> adapter, boolean copy ) {
return adapt( t, new CAdapter(adapter,copy) );
}
}

View File

@@ -0,0 +1,129 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model;
import javax.activation.MimeType;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import com.sun.codemodel.internal.JExpr;
import com.sun.codemodel.internal.JExpression;
import com.sun.codemodel.internal.JStringLiteral;
import com.sun.tools.internal.xjc.outline.Outline;
import com.sun.xml.internal.bind.v2.ClassFactory;
import com.sun.xml.internal.bind.v2.model.core.ID;
import com.sun.xml.internal.xsom.XmlString;
/**
* General-purpose {@link TypeUse} implementation.
*
* @author Kohsuke Kawaguchi
*/
final class TypeUseImpl implements TypeUse {
private final CNonElement coreType;
private final boolean collection;
private final CAdapter adapter;
private final ID id;
private final MimeType expectedMimeType;
public TypeUseImpl(CNonElement itemType, boolean collection, ID id, MimeType expectedMimeType, CAdapter adapter) {
this.coreType = itemType;
this.collection = collection;
this.id = id;
this.expectedMimeType = expectedMimeType;
this.adapter = adapter;
}
public boolean isCollection() {
return collection;
}
public CNonElement getInfo() {
return coreType;
}
public CAdapter getAdapterUse() {
return adapter;
}
public ID idUse() {
return id;
}
public MimeType getExpectedMimeType() {
return expectedMimeType;
}
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof TypeUseImpl)) return false;
final TypeUseImpl that = (TypeUseImpl) o;
if (collection != that.collection) return false;
if (this.id != that.id ) return false;
if (adapter != null ? !adapter.equals(that.adapter) : that.adapter != null) return false;
if (coreType != null ? !coreType.equals(that.coreType) : that.coreType != null) return false;
return true;
}
public int hashCode() {
int result;
result = (coreType != null ? coreType.hashCode() : 0);
result = 29 * result + (collection ? 1 : 0);
result = 29 * result + (adapter != null ? adapter.hashCode() : 0);
return result;
}
public JExpression createConstant(Outline outline, XmlString lexical) {
if(isCollection()) return null;
if(adapter==null) return coreType.createConstant(outline, lexical);
// [RESULT] new Adapter().unmarshal(CONSTANT);
JExpression cons = coreType.createConstant(outline, lexical);
Class<? extends XmlAdapter> atype = adapter.getAdapterIfKnown();
// try to run the adapter now rather than later.
if(cons instanceof JStringLiteral && atype!=null) {
JStringLiteral scons = (JStringLiteral) cons;
XmlAdapter a = ClassFactory.create(atype);
try {
Object value = a.unmarshal(scons.str);
if(value instanceof String) {
return JExpr.lit((String)value);
}
} catch (Exception e) {
// assume that we can't eagerly bind this
}
}
return JExpr._new(adapter.getAdapterClass(outline)).invoke("unmarshal").arg(cons);
}
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model.nav;
import java.lang.reflect.Modifier;
import java.util.HashSet;
import java.util.Set;
import com.sun.codemodel.internal.JClass;
import com.sun.tools.internal.xjc.outline.Aspect;
import com.sun.tools.internal.xjc.outline.Outline;
/**
* @author Kohsuke Kawaguchi
*/
public class EagerNClass extends EagerNType implements NClass {
/*package*/ final Class c;
public EagerNClass(Class type) {
super(type);
this.c = type;
}
@Override
public boolean isBoxedType() {
return boxedTypes.contains(c);
}
@Override
public JClass toType(Outline o, Aspect aspect) {
return o.getCodeModel().ref(c);
}
public boolean isAbstract() {
return Modifier.isAbstract(c.getModifiers());
}
private static final Set<Class> boxedTypes = new HashSet<Class>();
static {
boxedTypes.add(Boolean.class);
boxedTypes.add(Character.class);
boxedTypes.add(Byte.class);
boxedTypes.add(Short.class);
boxedTypes.add(Integer.class);
boxedTypes.add(Long.class);
boxedTypes.add(Float.class);
boxedTypes.add(Double.class);
}
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model.nav;
import java.lang.reflect.Type;
import com.sun.codemodel.internal.JType;
import com.sun.tools.internal.xjc.outline.Aspect;
import com.sun.tools.internal.xjc.outline.Outline;
/**
* @author Kohsuke Kawaguchi
*/
class EagerNType implements NType {
/*package*/ final Type t;
public EagerNType(Type type) {
this.t = type;
assert t!=null;
}
public JType toType(Outline o, Aspect aspect) {
try {
return o.getCodeModel().parseType(t.toString());
} catch (ClassNotFoundException e) {
throw new NoClassDefFoundError(e.getMessage());
}
}
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof EagerNType)) return false;
final EagerNType eagerNType = (EagerNType) o;
return t.equals(eagerNType.t);
}
public boolean isBoxedType() {
return false;
}
public int hashCode() {
return t.hashCode();
}
public String fullName() {
return Utils.REFLECTION_NAVIGATOR.getTypeName(t);
}
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model.nav;
import com.sun.codemodel.internal.JClass;
import com.sun.tools.internal.xjc.outline.Aspect;
import com.sun.tools.internal.xjc.outline.Outline;
/**
* @author Kohsuke Kawaguchi
*/
public interface NClass extends NType {
JClass toType(Outline o, Aspect aspect);
boolean isAbstract();
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model.nav;
import com.sun.codemodel.internal.JClass;
import com.sun.tools.internal.xjc.outline.Aspect;
import com.sun.tools.internal.xjc.outline.Outline;
/**
* @author Kohsuke Kawaguchi
*/
class NClassByJClass implements NClass {
/*package*/ final JClass clazz;
NClassByJClass(JClass clazz) {
this.clazz = clazz;
}
public JClass toType(Outline o, Aspect aspect) {
return clazz;
}
public boolean isAbstract() {
return clazz.isAbstract();
}
public boolean isBoxedType() {
return clazz.getPrimitiveType()!=null;
}
public String fullName() {
return clazz.fullName();
}
}

View File

@@ -0,0 +1,78 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model.nav;
import com.sun.codemodel.internal.JClass;
import com.sun.tools.internal.xjc.outline.Aspect;
import com.sun.tools.internal.xjc.outline.Outline;
/**
* Parameterized type.
*
* @author Kohsuke Kawaguchi
*/
final class NParameterizedType implements NClass {
final NClass rawType;
final NType[] args;
NParameterizedType(NClass rawType, NType[] args) {
this.rawType = rawType;
this.args = args;
assert args.length>0;
}
public JClass toType(Outline o, Aspect aspect) {
JClass r = rawType.toType(o,aspect);
for( NType arg : args )
r = r.narrow(arg.toType(o,aspect).boxify());
return r;
}
public boolean isAbstract() {
return rawType.isAbstract();
}
public boolean isBoxedType() {
return false;
}
public String fullName() {
StringBuilder buf = new StringBuilder();
buf.append(rawType.fullName());
buf.append('<');
for( int i=0; i<args.length; i++ ) {
if(i!=0)
buf.append(',');
buf.append(args[i].fullName());
}
buf.append('>');
return buf.toString();
}
}

View File

@@ -0,0 +1,77 @@
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model.nav;
import com.sun.codemodel.internal.JType;
import com.sun.tools.internal.xjc.outline.Aspect;
import com.sun.tools.internal.xjc.outline.Outline;
/**
* A type.
*
* See the package documentaion for details.
*
* @author Kohsuke Kawaguchi
*/
public interface NType {
/**
* Returns the representation of this type in code model.
* <p>
* This operation requires the whole model to be built,
* and hence it takes {@link Outline}.
* <p>
* Under some code generation strategy, some bean classes
* are considered implementation specific (such as impl.FooImpl class)
* These classes always have accompanying "exposed" type (such as
* the Foo interface).
* <p>
* For such Jekyll and Hyde type, the aspect parameter determines
* which personality is returned.
*
* @param aspect
* If {@link Aspect#IMPLEMENTATION}, this method returns the
* implementation specific class that this type represents.
* If {@link Aspect#EXPOSED}, this method returns the
* publicly exposed type that this type represents.
*
* For ordinary classes, the aspect parameter is meaningless.
*
*/
JType toType(Outline o, Aspect aspect);
/**
* Returns true iff this type represents a class that has a unboxed form.
*
* For example, for {@link String} this is false, but for {@link Integer}
* this is true.
*/
boolean isBoxedType();
/**
* Human readable name of this type.
*/
String fullName();
}

View File

@@ -0,0 +1,336 @@
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model.nav;
import java.lang.reflect.Type;
import java.util.Collection;
import com.sun.codemodel.internal.JClass;
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
import com.sun.xml.internal.bind.v2.runtime.Location;
/**
* {@link Navigator} implementation for XJC.
*
* Most of the Navigator methods are used for parsing the model, which doesn't happen
* in XJC. So Most of the methods aren't really implemented. Implementations should
* be filled in as needed.
*
* @author Kohsuke Kawaguchi
*/
public final class NavigatorImpl implements Navigator<NType,NClass,Void,Void> {
public static final NavigatorImpl theInstance = new NavigatorImpl();
private NavigatorImpl() {
}
public NClass getSuperClass(NClass nClass) {
throw new UnsupportedOperationException();
}
public NType getBaseClass(NType nt, NClass base) {
if(nt instanceof EagerNType) {
EagerNType ent = (EagerNType) nt;
if (base instanceof EagerNClass) {
EagerNClass enc = (EagerNClass) base;
return create(Utils.REFLECTION_NAVIGATOR.getBaseClass(ent.t, enc.c));
}
// lazy class can never be a base type of an eager type
return null;
}
if (nt instanceof NClassByJClass) {
NClassByJClass nnt = (NClassByJClass) nt;
if (base instanceof EagerNClass) {
EagerNClass enc = (EagerNClass) base;
return ref(nnt.clazz.getBaseClass(enc.c));
}
}
throw new UnsupportedOperationException();
}
public String getClassName(NClass nClass) {
throw new UnsupportedOperationException();
}
public String getTypeName(NType type) {
return type.fullName();
}
public String getClassShortName(NClass nClass) {
throw new UnsupportedOperationException();
}
public Collection<? extends Void> getDeclaredFields(NClass nClass) {
throw new UnsupportedOperationException();
}
public Void getDeclaredField(NClass clazz, String fieldName) {
throw new UnsupportedOperationException();
}
public Collection<? extends Void> getDeclaredMethods(NClass nClass) {
throw new UnsupportedOperationException();
}
public NClass getDeclaringClassForField(Void aVoid) {
throw new UnsupportedOperationException();
}
public NClass getDeclaringClassForMethod(Void aVoid) {
throw new UnsupportedOperationException();
}
public NType getFieldType(Void aVoid) {
throw new UnsupportedOperationException();
}
public String getFieldName(Void aVoid) {
throw new UnsupportedOperationException();
}
public String getMethodName(Void aVoid) {
throw new UnsupportedOperationException();
}
public NType getReturnType(Void aVoid) {
throw new UnsupportedOperationException();
}
public NType[] getMethodParameters(Void aVoid) {
throw new UnsupportedOperationException();
}
public boolean isStaticMethod(Void aVoid) {
throw new UnsupportedOperationException();
}
public boolean isFinalMethod(Void aVoid) {
throw new UnsupportedOperationException();
}
public boolean isSubClassOf(NType sub, NType sup) {
throw new UnsupportedOperationException();
}
public NClass ref(Class c) {
return create(c);
}
public NClass ref(JClass c) {
if(c==null) return null;
return new NClassByJClass(c);
}
public NType use(NClass nc) {
return nc;
}
public NClass asDecl(NType nt) {
if(nt instanceof NClass)
return (NClass)nt;
else
return null;
}
public NClass asDecl(Class c) {
return ref(c);
}
public boolean isArray(NType nType) {
throw new UnsupportedOperationException();
}
public boolean isArrayButNotByteArray(NType t) {
throw new UnsupportedOperationException();
}
public NType getComponentType(NType nType) {
throw new UnsupportedOperationException();
}
public NType getTypeArgument(NType nt, int i) {
if (nt instanceof EagerNType) {
EagerNType ent = (EagerNType) nt;
return create(Utils.REFLECTION_NAVIGATOR.getTypeArgument(ent.t,i));
}
if (nt instanceof NClassByJClass) {
NClassByJClass nnt = (NClassByJClass) nt;
return ref(nnt.clazz.getTypeParameters().get(i));
}
throw new UnsupportedOperationException();
}
public boolean isParameterizedType(NType nt) {
if (nt instanceof EagerNType) {
EagerNType ent = (EagerNType) nt;
return Utils.REFLECTION_NAVIGATOR.isParameterizedType(ent.t);
}
if (nt instanceof NClassByJClass) {
NClassByJClass nnt = (NClassByJClass) nt;
return nnt.clazz.isParameterized();
}
throw new UnsupportedOperationException();
}
public boolean isPrimitive(NType type) {
throw new UnsupportedOperationException();
}
public NType getPrimitive(Class primitiveType) {
return create(primitiveType);
}
@SuppressWarnings("FinalStaticMethod")
public static final NType create(Type t) {
if(t==null) return null;
if(t instanceof Class)
return create((Class)t);
return new EagerNType(t);
}
public static NClass create( Class c ) {
if(c==null) return null;
return new EagerNClass(c);
}
/**
* Creates a {@link NType} representation for a parameterized type
* {@code RawType&lt;ParamType1,ParamType2,...> }.
*/
public static NType createParameterizedType( NClass rawType, NType... args ) {
return new NParameterizedType(rawType,args);
}
public static NType createParameterizedType( Class rawType, NType... args ) {
return new NParameterizedType(create(rawType),args);
}
public Location getClassLocation(final NClass c) {
// not really needed for XJC but doesn't hurt to have one
return new Location() {
@Override
public String toString() {
return c.fullName();
}
};
}
public Location getFieldLocation(Void v) {
throw new IllegalStateException();
}
public Location getMethodLocation(Void v) {
throw new IllegalStateException();
}
public boolean hasDefaultConstructor(NClass nClass) {
throw new UnsupportedOperationException();
}
public boolean isStaticField(Void aVoid) {
throw new IllegalStateException();
}
public boolean isPublicMethod(Void aVoid) {
throw new IllegalStateException();
}
public boolean isPublicField(Void aVoid) {
throw new IllegalStateException();
}
public boolean isEnum(NClass c) {
return isSubClassOf(c,create(Enum.class));
}
public <T> NType erasure(NType type) {
if(type instanceof NParameterizedType) {
NParameterizedType pt = (NParameterizedType) type;
return pt.rawType;
}
return type;
}
public boolean isAbstract(NClass clazz) {
return clazz.isAbstract();
}
/**
* @deprecated
* no class generated by XJC is final.
*/
public boolean isFinal(NClass clazz) {
return false;
}
public Void[] getEnumConstants(NClass clazz) {
throw new UnsupportedOperationException();
}
public NType getVoidType() {
return ref(void.class);
}
public String getPackageName(NClass clazz) {
// TODO: implement this method later
throw new UnsupportedOperationException();
}
@Override
public NClass loadObjectFactory(NClass referencePoint, String pkg) {
throw new UnsupportedOperationException();
}
public boolean isBridgeMethod(Void method) {
throw new UnsupportedOperationException();
}
public boolean isOverriding(Void method,NClass clazz) {
throw new UnsupportedOperationException();
}
public boolean isInterface(NClass clazz) {
throw new UnsupportedOperationException();
}
public boolean isTransient(Void f) {
throw new UnsupportedOperationException();
}
public boolean isInnerClass(NClass clazz) {
throw new UnsupportedOperationException();
}
@Override
public boolean isSameType(NType t1, NType t2) {
throw new UnsupportedOperationException();
}
}

View File

@@ -0,0 +1,94 @@
/*
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.tools.internal.xjc.model.nav;
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Utils class.
*
* WARNING: If you are doing any changes don't forget to change other Utils classes in different packages.
*
* Has *package private* access to avoid inappropriate usage.
*/
final class Utils {
private static final Logger LOGGER = Logger.getLogger(Utils.class.getName());
/**
* static ReflectionNavigator field to avoid usage of reflection every time we use it.
*/
static final Navigator<Type, Class, Field, Method> REFLECTION_NAVIGATOR;
static { // we statically initializing REFLECTION_NAVIGATOR property
try {
final Class refNav = Class.forName("com.sun.xml.internal.bind.v2.model.nav.ReflectionNavigator");
// requires accessClassInPackage privilege
final Method getInstance = AccessController.doPrivileged(
new PrivilegedAction<Method>() {
@Override
public Method run() {
try {
Method getInstance = refNav.getDeclaredMethod("getInstance");
getInstance.setAccessible(true);
return getInstance;
} catch (NoSuchMethodException e) {
throw new IllegalStateException("ReflectionNavigator.getInstance can't be found");
}
}
}
);
//noinspection unchecked
REFLECTION_NAVIGATOR = (Navigator<Type, Class, Field, Method>) getInstance.invoke(null);
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Can't find ReflectionNavigator class");
} catch (InvocationTargetException e) {
throw new IllegalStateException("ReflectionNavigator.getInstance throws the exception");
} catch (IllegalAccessException e) {
throw new IllegalStateException("ReflectionNavigator.getInstance method is inaccessible");
} catch (SecurityException e) {
LOGGER.log(Level.FINE, "Unable to access ReflectionNavigator.getInstance", e);
throw e;
}
}
/**
* private constructor to avoid util class instantiating
*/
private Utils() {
}
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Implementation of the {@link com.sun.xml.internal.bind.v2.model.core} package for XJC.
*
* <p>
* This model is the recipes for the code generation.
* It captures the essence of the JAXB-bound beans,
* so that the actual Java code can be generated from this object model
* mechanically without knowing anything about how the model was built.
*
* <p>
* Most of the classes/interfaces in this package has one-to-one relationship
* with the parameterized core model in the {@link com.sun.xml.internal.bind.v2.model.core} package.
* Refer to the core model for better documentation.
*
* <p>
* The model for XJC also exposes a few additional information on top of the core model.
* Those are defined in this package. This includes such information as:
*
* <dl>
* <dt>Source location information
* <dd>{@link Locator} object that can be used to tell where the model components
* are created from in terms of the source file. Useful for error reporting.
*
* <dt>Source schema component
* <dd>{@link XSComponent} object from which the model components are created from.
* See {@link CCustomizable#getSchemaComponent()} for example.
*
* <dt>Plugin customizations
* <dd>See {@link CCustomizable}.
* </dl>
*/
package com.sun.tools.internal.xjc.model;