feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessOrder;
|
||||
import javax.xml.bind.annotation.XmlAccessorOrder;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlAccessorOrderWriter
|
||||
extends JAnnotationWriter<XmlAccessorOrder>
|
||||
{
|
||||
|
||||
|
||||
XmlAccessorOrderWriter value(XmlAccessOrder value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlAccessorTypeWriter
|
||||
extends JAnnotationWriter<XmlAccessorType>
|
||||
{
|
||||
|
||||
|
||||
XmlAccessorTypeWriter value(XmlAccessType value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAnyAttribute;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlAnyAttributeWriter
|
||||
extends JAnnotationWriter<XmlAnyAttribute>
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAnyElement;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlAnyElementWriter
|
||||
extends JAnnotationWriter<XmlAnyElement>
|
||||
{
|
||||
|
||||
|
||||
XmlAnyElementWriter value(Class value);
|
||||
|
||||
XmlAnyElementWriter value(JType value);
|
||||
|
||||
XmlAnyElementWriter lax(boolean value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttachmentRef;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlAttachmentRefWriter
|
||||
extends JAnnotationWriter<XmlAttachmentRef>
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlAttributeWriter
|
||||
extends JAnnotationWriter<XmlAttribute>
|
||||
{
|
||||
|
||||
|
||||
XmlAttributeWriter name(String value);
|
||||
|
||||
XmlAttributeWriter namespace(String value);
|
||||
|
||||
XmlAttributeWriter required(boolean value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElementDecl;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlElementDeclWriter
|
||||
extends JAnnotationWriter<XmlElementDecl>
|
||||
{
|
||||
|
||||
|
||||
XmlElementDeclWriter name(String value);
|
||||
|
||||
XmlElementDeclWriter scope(Class value);
|
||||
|
||||
XmlElementDeclWriter scope(JType value);
|
||||
|
||||
XmlElementDeclWriter namespace(String value);
|
||||
|
||||
XmlElementDeclWriter defaultValue(String value);
|
||||
|
||||
XmlElementDeclWriter substitutionHeadNamespace(String value);
|
||||
|
||||
XmlElementDeclWriter substitutionHeadName(String value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElementRef;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlElementRefWriter
|
||||
extends JAnnotationWriter<XmlElementRef>
|
||||
{
|
||||
|
||||
|
||||
XmlElementRefWriter name(String value);
|
||||
|
||||
XmlElementRefWriter type(Class value);
|
||||
|
||||
XmlElementRefWriter type(JType value);
|
||||
|
||||
XmlElementRefWriter namespace(String value);
|
||||
|
||||
XmlElementRefWriter required(boolean value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElementRefs;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlElementRefsWriter
|
||||
extends JAnnotationWriter<XmlElementRefs>
|
||||
{
|
||||
|
||||
|
||||
XmlElementRefWriter value();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlElementWrapperWriter
|
||||
extends JAnnotationWriter<XmlElementWrapper>
|
||||
{
|
||||
|
||||
|
||||
XmlElementWrapperWriter name(String value);
|
||||
|
||||
XmlElementWrapperWriter namespace(String value);
|
||||
|
||||
XmlElementWrapperWriter required(boolean value);
|
||||
|
||||
XmlElementWrapperWriter nillable(boolean value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlElementWriter
|
||||
extends JAnnotationWriter<XmlElement>
|
||||
{
|
||||
|
||||
|
||||
XmlElementWriter name(String value);
|
||||
|
||||
XmlElementWriter type(Class value);
|
||||
|
||||
XmlElementWriter type(JType value);
|
||||
|
||||
XmlElementWriter namespace(String value);
|
||||
|
||||
XmlElementWriter defaultValue(String value);
|
||||
|
||||
XmlElementWriter required(boolean value);
|
||||
|
||||
XmlElementWriter nillable(boolean value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElements;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlElementsWriter
|
||||
extends JAnnotationWriter<XmlElements>
|
||||
{
|
||||
|
||||
|
||||
XmlElementWriter value();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlEnumValue;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlEnumValueWriter
|
||||
extends JAnnotationWriter<XmlEnumValue>
|
||||
{
|
||||
|
||||
|
||||
XmlEnumValueWriter value(String value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlEnum;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlEnumWriter
|
||||
extends JAnnotationWriter<XmlEnum>
|
||||
{
|
||||
|
||||
|
||||
XmlEnumWriter value(Class value);
|
||||
|
||||
XmlEnumWriter value(JType value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlIDREF;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlIDREFWriter
|
||||
extends JAnnotationWriter<XmlIDREF>
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlID;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlIDWriter
|
||||
extends JAnnotationWriter<XmlID>
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlInlineBinaryData;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlInlineBinaryDataWriter
|
||||
extends JAnnotationWriter<XmlInlineBinaryData>
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlJavaTypeAdapterWriter
|
||||
extends JAnnotationWriter<XmlJavaTypeAdapter>
|
||||
{
|
||||
|
||||
|
||||
XmlJavaTypeAdapterWriter type(Class value);
|
||||
|
||||
XmlJavaTypeAdapterWriter type(JType value);
|
||||
|
||||
XmlJavaTypeAdapterWriter value(Class value);
|
||||
|
||||
XmlJavaTypeAdapterWriter value(JType value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlList;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlListWriter
|
||||
extends JAnnotationWriter<XmlList>
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlMimeType;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlMimeTypeWriter
|
||||
extends JAnnotationWriter<XmlMimeType>
|
||||
{
|
||||
|
||||
|
||||
XmlMimeTypeWriter value(String value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlMixed;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlMixedWriter
|
||||
extends JAnnotationWriter<XmlMixed>
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlNs;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlNsWriter
|
||||
extends JAnnotationWriter<XmlNs>
|
||||
{
|
||||
|
||||
|
||||
XmlNsWriter prefix(String value);
|
||||
|
||||
XmlNsWriter namespaceURI(String value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRegistry;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlRegistryWriter
|
||||
extends JAnnotationWriter<XmlRegistry>
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlRootElementWriter
|
||||
extends JAnnotationWriter<XmlRootElement>
|
||||
{
|
||||
|
||||
|
||||
XmlRootElementWriter name(String value);
|
||||
|
||||
XmlRootElementWriter namespace(String value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlSchemaType;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlSchemaTypeWriter
|
||||
extends JAnnotationWriter<XmlSchemaType>
|
||||
{
|
||||
|
||||
|
||||
XmlSchemaTypeWriter name(String value);
|
||||
|
||||
XmlSchemaTypeWriter type(Class value);
|
||||
|
||||
XmlSchemaTypeWriter type(JType value);
|
||||
|
||||
XmlSchemaTypeWriter namespace(String value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlSchemaTypes;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlSchemaTypesWriter
|
||||
extends JAnnotationWriter<XmlSchemaTypes>
|
||||
{
|
||||
|
||||
|
||||
XmlSchemaTypeWriter value();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlNsForm;
|
||||
import javax.xml.bind.annotation.XmlSchema;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlSchemaWriter
|
||||
extends JAnnotationWriter<XmlSchema>
|
||||
{
|
||||
|
||||
|
||||
XmlSchemaWriter location(String value);
|
||||
|
||||
XmlSchemaWriter namespace(String value);
|
||||
|
||||
XmlNsWriter xmlns();
|
||||
|
||||
XmlSchemaWriter elementFormDefault(XmlNsForm value);
|
||||
|
||||
XmlSchemaWriter attributeFormDefault(XmlNsForm value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlSeeAlso;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlSeeAlsoWriter
|
||||
extends JAnnotationWriter<XmlSeeAlso>
|
||||
{
|
||||
|
||||
|
||||
XmlSeeAlsoWriter value(Class value);
|
||||
|
||||
XmlSeeAlsoWriter value(JType value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlTransientWriter
|
||||
extends JAnnotationWriter<XmlTransient>
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlTypeWriter
|
||||
extends JAnnotationWriter<XmlType>
|
||||
{
|
||||
|
||||
|
||||
XmlTypeWriter name(String value);
|
||||
|
||||
XmlTypeWriter namespace(String value);
|
||||
|
||||
XmlTypeWriter propOrder(String value);
|
||||
|
||||
XmlTypeWriter factoryClass(Class value);
|
||||
|
||||
XmlTypeWriter factoryClass(JType value);
|
||||
|
||||
XmlTypeWriter factoryMethod(String value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlValue;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlValueWriter
|
||||
extends JAnnotationWriter<XmlValue>
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,834 @@
|
||||
/*
|
||||
* 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.generator.bean;
|
||||
|
||||
import static com.sun.tools.internal.xjc.outline.Aspect.EXPOSED;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.annotation.XmlAttachmentRef;
|
||||
import javax.xml.bind.annotation.XmlID;
|
||||
import javax.xml.bind.annotation.XmlIDREF;
|
||||
import javax.xml.bind.annotation.XmlMimeType;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import com.sun.codemodel.internal.ClassType;
|
||||
import com.sun.codemodel.internal.JAnnotatable;
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.codemodel.internal.JClassAlreadyExistsException;
|
||||
import com.sun.codemodel.internal.JClassContainer;
|
||||
import com.sun.codemodel.internal.JCodeModel;
|
||||
import com.sun.codemodel.internal.JDefinedClass;
|
||||
import com.sun.codemodel.internal.JEnumConstant;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JFieldVar;
|
||||
import com.sun.codemodel.internal.JForEach;
|
||||
import com.sun.codemodel.internal.JInvocation;
|
||||
import com.sun.codemodel.internal.JJavaName;
|
||||
import com.sun.codemodel.internal.JMethod;
|
||||
import com.sun.codemodel.internal.JMod;
|
||||
import com.sun.codemodel.internal.JPackage;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.codemodel.internal.fmt.JStaticJavaFile;
|
||||
import com.sun.tools.internal.xjc.AbortException;
|
||||
import com.sun.tools.internal.xjc.ErrorReceiver;
|
||||
import com.sun.tools.internal.xjc.api.SpecVersion;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlAnyAttributeWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlEnumValueWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlEnumWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlJavaTypeAdapterWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlMimeTypeWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlRootElementWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlSeeAlsoWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlTypeWriter;
|
||||
import com.sun.tools.internal.xjc.generator.bean.field.FieldRenderer;
|
||||
import com.sun.tools.internal.xjc.model.CAdapter;
|
||||
import com.sun.tools.internal.xjc.model.CAttributePropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CClassInfo;
|
||||
import com.sun.tools.internal.xjc.model.CClassInfoParent;
|
||||
import com.sun.tools.internal.xjc.model.CElementInfo;
|
||||
import com.sun.tools.internal.xjc.model.CEnumConstant;
|
||||
import com.sun.tools.internal.xjc.model.CEnumLeafInfo;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CTypeRef;
|
||||
import com.sun.tools.internal.xjc.model.Model;
|
||||
import com.sun.tools.internal.xjc.model.CClassRef;
|
||||
import com.sun.tools.internal.xjc.outline.Aspect;
|
||||
import com.sun.tools.internal.xjc.outline.ClassOutline;
|
||||
import com.sun.tools.internal.xjc.outline.EnumConstantOutline;
|
||||
import com.sun.tools.internal.xjc.outline.EnumOutline;
|
||||
import com.sun.tools.internal.xjc.outline.FieldOutline;
|
||||
import com.sun.tools.internal.xjc.outline.Outline;
|
||||
import com.sun.tools.internal.xjc.outline.PackageOutline;
|
||||
import com.sun.tools.internal.xjc.util.CodeModelClassFactory;
|
||||
import com.sun.xml.internal.bind.v2.model.core.PropertyInfo;
|
||||
import com.sun.xml.internal.bind.v2.runtime.SwaRefAdapterMarker;
|
||||
import com.sun.xml.internal.xsom.XmlString;
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import com.sun.tools.internal.xjc.model.CReferencePropertyInfo;
|
||||
|
||||
/**
|
||||
* Generates fields and accessors.
|
||||
*/
|
||||
public final class BeanGenerator implements Outline {
|
||||
|
||||
/** Simplifies class/interface creation and collision detection. */
|
||||
private final CodeModelClassFactory codeModelClassFactory;
|
||||
private final ErrorReceiver errorReceiver;
|
||||
/** all {@link PackageOutline}s keyed by their {@link PackageOutline#_package}. */
|
||||
private final Map<JPackage, PackageOutlineImpl> packageContexts = new LinkedHashMap<JPackage, PackageOutlineImpl>();
|
||||
/** all {@link ClassOutline}s keyed by their {@link ClassOutline#target}. */
|
||||
private final Map<CClassInfo, ClassOutlineImpl> classes = new LinkedHashMap<CClassInfo, ClassOutlineImpl>();
|
||||
/** all {@link EnumOutline}s keyed by their {@link EnumOutline#target}. */
|
||||
private final Map<CEnumLeafInfo, EnumOutline> enums = new LinkedHashMap<CEnumLeafInfo, EnumOutline>();
|
||||
/**
|
||||
* Generated runtime classes.
|
||||
*/
|
||||
private final Map<Class, JClass> generatedRuntime = new LinkedHashMap<Class, JClass>();
|
||||
/** the model object which we are processing. */
|
||||
private final Model model;
|
||||
private final JCodeModel codeModel;
|
||||
/**
|
||||
* for each property, the information about the generated field.
|
||||
*/
|
||||
private final Map<CPropertyInfo, FieldOutline> fields = new LinkedHashMap<CPropertyInfo, FieldOutline>();
|
||||
/**
|
||||
* elements that generate classes to the generated classes.
|
||||
*/
|
||||
/*package*/ final Map<CElementInfo, ElementOutlineImpl> elements = new LinkedHashMap<CElementInfo, ElementOutlineImpl>();
|
||||
|
||||
/**
|
||||
* Generates beans into code model according to the BGM,
|
||||
* and produces the reflection model.
|
||||
*
|
||||
* @param _errorReceiver
|
||||
* This object will receive all the errors discovered
|
||||
* during the back-end stage.
|
||||
*
|
||||
* @return
|
||||
* returns a {@link Outline} which will in turn
|
||||
* be used to further generate marshaller/unmarshaller,
|
||||
* or null if the processing fails (errors should have been
|
||||
* reported to the error recevier.)
|
||||
*/
|
||||
public static Outline generate(Model model, ErrorReceiver _errorReceiver) {
|
||||
|
||||
try {
|
||||
return new BeanGenerator(model, _errorReceiver);
|
||||
} catch (AbortException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private BeanGenerator(Model _model, ErrorReceiver _errorReceiver) {
|
||||
|
||||
this.model = _model;
|
||||
this.codeModel = model.codeModel;
|
||||
this.errorReceiver = _errorReceiver;
|
||||
this.codeModelClassFactory = new CodeModelClassFactory(errorReceiver);
|
||||
|
||||
// build enum classes
|
||||
for (CEnumLeafInfo p : model.enums().values()) {
|
||||
enums.put(p, generateEnumDef(p));
|
||||
}
|
||||
|
||||
JPackage[] packages = getUsedPackages(EXPOSED);
|
||||
|
||||
// generates per-package code and remember the results as contexts.
|
||||
for (JPackage pkg : packages) {
|
||||
getPackageContext(pkg);
|
||||
}
|
||||
|
||||
// create the class definitions for all the beans first.
|
||||
// this should also fill in PackageContext#getClasses
|
||||
for (CClassInfo bean : model.beans().values()) {
|
||||
getClazz(bean);
|
||||
}
|
||||
|
||||
// compute the package-level setting
|
||||
for (PackageOutlineImpl p : packageContexts.values()) {
|
||||
p.calcDefaultValues();
|
||||
}
|
||||
|
||||
JClass OBJECT = codeModel.ref(Object.class);
|
||||
|
||||
// inheritance relationship needs to be set before we generate fields, or otherwise
|
||||
// we'll fail to compute the correct type signature (namely the common base type computation)
|
||||
for (ClassOutlineImpl cc : getClasses()) {
|
||||
|
||||
// setup inheritance between implementation hierarchy.
|
||||
CClassInfo superClass = cc.target.getBaseClass();
|
||||
if (superClass != null) {
|
||||
// use the specified super class
|
||||
model.strategy._extends(cc, getClazz(superClass));
|
||||
} else {
|
||||
CClassRef refSuperClass = cc.target.getRefBaseClass();
|
||||
if (refSuperClass != null) {
|
||||
cc.implClass._extends(refSuperClass.toType(this, EXPOSED));
|
||||
} else {
|
||||
// use the default one, if any
|
||||
if (model.rootClass != null && cc.implClass._extends().equals(OBJECT)) {
|
||||
cc.implClass._extends(model.rootClass);
|
||||
}
|
||||
if (model.rootInterface != null) {
|
||||
cc.ref._implements(model.rootInterface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if serialization support is turned on, generate
|
||||
// [RESULT]
|
||||
// class ... implements Serializable {
|
||||
// private static final long serialVersionUID = <id>;
|
||||
// ....
|
||||
// }
|
||||
if (model.serializable) {
|
||||
cc.implClass._implements(Serializable.class);
|
||||
if (model.serialVersionUID != null) {
|
||||
cc.implClass.field(
|
||||
JMod.PRIVATE | JMod.STATIC | JMod.FINAL,
|
||||
codeModel.LONG,
|
||||
"serialVersionUID",
|
||||
JExpr.lit(model.serialVersionUID));
|
||||
}
|
||||
}
|
||||
|
||||
CClassInfoParent base = cc.target.parent();
|
||||
if ((base != null) && (base instanceof CClassInfo)) {
|
||||
String pkg = base.getOwnerPackage().name();
|
||||
String shortName = base.fullName().substring(base.fullName().indexOf(pkg)+pkg.length()+1);
|
||||
if (cc.target.shortName.equals(shortName)) {
|
||||
getErrorReceiver().error(cc.target.getLocator(), Messages.ERR_KEYNAME_COLLISION.format(shortName));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// fill in implementation classes
|
||||
for (ClassOutlineImpl co : getClasses()) {
|
||||
generateClassBody(co);
|
||||
}
|
||||
|
||||
for (EnumOutline eo : enums.values()) {
|
||||
generateEnumBody(eo);
|
||||
}
|
||||
|
||||
// create factories for the impl-less elements
|
||||
for (CElementInfo ei : model.getAllElements()) {
|
||||
getPackageContext(ei._package()).objectFactoryGenerator().populate(ei);
|
||||
}
|
||||
|
||||
if (model.options.debugMode) {
|
||||
generateClassList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a class that knows how to create an instance of JAXBContext
|
||||
*
|
||||
* <p>
|
||||
* This is used in the debug mode so that a new properly configured
|
||||
* {@link JAXBContext} object can be used.
|
||||
*/
|
||||
@SuppressWarnings("CallToThreadDumpStack")
|
||||
private void generateClassList() {
|
||||
try {
|
||||
JDefinedClass jc = codeModel.rootPackage()._class("JAXBDebug");
|
||||
JMethod m = jc.method(JMod.PUBLIC | JMod.STATIC, JAXBContext.class, "createContext");
|
||||
JVar $classLoader = m.param(ClassLoader.class, "classLoader");
|
||||
m._throws(JAXBException.class);
|
||||
JInvocation inv = codeModel.ref(JAXBContext.class).staticInvoke("newInstance");
|
||||
m.body()._return(inv);
|
||||
|
||||
switch (model.strategy) {
|
||||
case INTF_AND_IMPL: {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
for (PackageOutlineImpl po : packageContexts.values()) {
|
||||
if (buf.length() > 0) {
|
||||
buf.append(':');
|
||||
}
|
||||
buf.append(po._package().name());
|
||||
}
|
||||
inv.arg(buf.toString()).arg($classLoader);
|
||||
break;
|
||||
}
|
||||
case BEAN_ONLY:
|
||||
for (ClassOutlineImpl cc : getClasses()) {
|
||||
inv.arg(cc.implRef.dotclass());
|
||||
}
|
||||
for (PackageOutlineImpl po : packageContexts.values()) {
|
||||
inv.arg(po.objectFactory().dotclass());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
} catch (JClassAlreadyExistsException e) {
|
||||
e.printStackTrace();
|
||||
// after all, we are in the debug mode. a little sloppiness is OK.
|
||||
// this error is not fatal. just continue.
|
||||
}
|
||||
}
|
||||
|
||||
public Model getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public JCodeModel getCodeModel() {
|
||||
return codeModel;
|
||||
}
|
||||
|
||||
public JClassContainer getContainer(CClassInfoParent parent, Aspect aspect) {
|
||||
CClassInfoParent.Visitor<JClassContainer> v;
|
||||
switch (aspect) {
|
||||
case EXPOSED:
|
||||
v = exposedContainerBuilder;
|
||||
break;
|
||||
case IMPLEMENTATION:
|
||||
v = implContainerBuilder;
|
||||
break;
|
||||
default:
|
||||
assert false;
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return parent.accept(v);
|
||||
}
|
||||
|
||||
public final JType resolve(CTypeRef ref, Aspect a) {
|
||||
return ref.getTarget().getType().toType(this, a);
|
||||
}
|
||||
private final CClassInfoParent.Visitor<JClassContainer> exposedContainerBuilder =
|
||||
new CClassInfoParent.Visitor<JClassContainer>() {
|
||||
|
||||
public JClassContainer onBean(CClassInfo bean) {
|
||||
return getClazz(bean).ref;
|
||||
}
|
||||
|
||||
public JClassContainer onElement(CElementInfo element) {
|
||||
// hmm...
|
||||
return getElement(element).implClass;
|
||||
}
|
||||
|
||||
public JClassContainer onPackage(JPackage pkg) {
|
||||
return model.strategy.getPackage(pkg, EXPOSED);
|
||||
}
|
||||
};
|
||||
private final CClassInfoParent.Visitor<JClassContainer> implContainerBuilder =
|
||||
new CClassInfoParent.Visitor<JClassContainer>() {
|
||||
|
||||
public JClassContainer onBean(CClassInfo bean) {
|
||||
return getClazz(bean).implClass;
|
||||
}
|
||||
|
||||
public JClassContainer onElement(CElementInfo element) {
|
||||
return getElement(element).implClass;
|
||||
}
|
||||
|
||||
public JClassContainer onPackage(JPackage pkg) {
|
||||
return model.strategy.getPackage(pkg, Aspect.IMPLEMENTATION);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns all <i>used</i> JPackages.
|
||||
*
|
||||
* A JPackage is considered as "used" if a ClassItem or
|
||||
* a InterfaceItem resides in that package.
|
||||
*
|
||||
* This value is dynamically calculated every time because
|
||||
* one can freely remove ClassItem/InterfaceItem.
|
||||
*
|
||||
* @return
|
||||
* Given the same input, the order of packages in the array
|
||||
* is always the same regardless of the environment.
|
||||
*/
|
||||
public final JPackage[] getUsedPackages(Aspect aspect) {
|
||||
Set<JPackage> s = new TreeSet<JPackage>();
|
||||
|
||||
for (CClassInfo bean : model.beans().values()) {
|
||||
JClassContainer cont = getContainer(bean.parent(), aspect);
|
||||
if (cont.isPackage()) {
|
||||
s.add((JPackage) cont);
|
||||
}
|
||||
}
|
||||
|
||||
for (CElementInfo e : model.getElementMappings(null).values()) {
|
||||
// at the first glance you might think we should be iterating all elements,
|
||||
// not just global ones, but if you think about it, local ones live inside
|
||||
// another class, so those packages are already enumerated when we were
|
||||
// walking over CClassInfos.
|
||||
s.add(e._package());
|
||||
}
|
||||
|
||||
return s.toArray(new JPackage[s.size()]);
|
||||
}
|
||||
|
||||
public ErrorReceiver getErrorReceiver() {
|
||||
return errorReceiver;
|
||||
}
|
||||
|
||||
public CodeModelClassFactory getClassFactory() {
|
||||
return codeModelClassFactory;
|
||||
}
|
||||
|
||||
public PackageOutlineImpl getPackageContext(JPackage p) {
|
||||
PackageOutlineImpl r = packageContexts.get(p);
|
||||
if (r == null) {
|
||||
r = new PackageOutlineImpl(this, model, p);
|
||||
packageContexts.put(p, r);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the minimum {@link JDefinedClass} skeleton
|
||||
* without filling in its body.
|
||||
*/
|
||||
private ClassOutlineImpl generateClassDef(CClassInfo bean) {
|
||||
ImplStructureStrategy.Result r = model.strategy.createClasses(this, bean);
|
||||
JClass implRef;
|
||||
|
||||
if (bean.getUserSpecifiedImplClass() != null) {
|
||||
// create a place holder for a user-specified class.
|
||||
JDefinedClass usr;
|
||||
try {
|
||||
usr = codeModel._class(bean.getUserSpecifiedImplClass());
|
||||
// but hide that file so that it won't be generated.
|
||||
usr.hide();
|
||||
} catch (JClassAlreadyExistsException e) {
|
||||
// it's OK for this to collide.
|
||||
usr = e.getExistingClass();
|
||||
}
|
||||
usr._extends(r.implementation);
|
||||
implRef = usr;
|
||||
} else {
|
||||
implRef = r.implementation;
|
||||
}
|
||||
|
||||
return new ClassOutlineImpl(this, bean, r.exposed, r.implementation, implRef);
|
||||
}
|
||||
|
||||
public Collection<ClassOutlineImpl> getClasses() {
|
||||
// make sure that classes are fully populated
|
||||
assert model.beans().size() == classes.size();
|
||||
return classes.values();
|
||||
}
|
||||
|
||||
public ClassOutlineImpl getClazz(CClassInfo bean) {
|
||||
ClassOutlineImpl r = classes.get(bean);
|
||||
if (r == null) {
|
||||
classes.put(bean, r = generateClassDef(bean));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
public ElementOutlineImpl getElement(CElementInfo ei) {
|
||||
ElementOutlineImpl def = elements.get(ei);
|
||||
if (def == null && ei.hasClass()) {
|
||||
// create one. in the constructor it adds itself to the elements.
|
||||
def = new ElementOutlineImpl(this, ei);
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
public EnumOutline getEnum(CEnumLeafInfo eli) {
|
||||
return enums.get(eli);
|
||||
}
|
||||
|
||||
public Collection<EnumOutline> getEnums() {
|
||||
return enums.values();
|
||||
}
|
||||
|
||||
public Iterable<? extends PackageOutline> getAllPackageContexts() {
|
||||
return packageContexts.values();
|
||||
}
|
||||
|
||||
public FieldOutline getField(CPropertyInfo prop) {
|
||||
return fields.get(prop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the body of a class.
|
||||
*
|
||||
*/
|
||||
private void generateClassBody(ClassOutlineImpl cc) {
|
||||
CClassInfo target = cc.target;
|
||||
|
||||
// used to simplify the generated annotations
|
||||
String mostUsedNamespaceURI = cc._package().getMostUsedNamespaceURI();
|
||||
|
||||
// [RESULT]
|
||||
// @XmlType(name="foo", targetNamespace="bar://baz")
|
||||
XmlTypeWriter xtw = cc.implClass.annotate2(XmlTypeWriter.class);
|
||||
writeTypeName(cc.target.getTypeName(), xtw, mostUsedNamespaceURI);
|
||||
|
||||
if (model.options.target.isLaterThan(SpecVersion.V2_1)) {
|
||||
// @XmlSeeAlso
|
||||
Iterator<CClassInfo> subclasses = cc.target.listSubclasses();
|
||||
if (subclasses.hasNext()) {
|
||||
XmlSeeAlsoWriter saw = cc.implClass.annotate2(XmlSeeAlsoWriter.class);
|
||||
while (subclasses.hasNext()) {
|
||||
CClassInfo s = subclasses.next();
|
||||
saw.value(getClazz(s).implRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (target.isElement()) {
|
||||
String namespaceURI = target.getElementName().getNamespaceURI();
|
||||
String localPart = target.getElementName().getLocalPart();
|
||||
|
||||
// [RESULT]
|
||||
// @XmlRootElement(name="foo", targetNamespace="bar://baz")
|
||||
XmlRootElementWriter xrew = cc.implClass.annotate2(XmlRootElementWriter.class);
|
||||
xrew.name(localPart);
|
||||
if (!namespaceURI.equals(mostUsedNamespaceURI)) // only generate if necessary
|
||||
{
|
||||
xrew.namespace(namespaceURI);
|
||||
}
|
||||
}
|
||||
|
||||
if (target.isOrdered()) {
|
||||
for (CPropertyInfo p : target.getProperties()) {
|
||||
if (!(p instanceof CAttributePropertyInfo)) {
|
||||
if (!((p instanceof CReferencePropertyInfo)
|
||||
&& ((CReferencePropertyInfo) p).isDummy())) {
|
||||
xtw.propOrder(p.getName(false));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// produce empty array
|
||||
xtw.getAnnotationUse().paramArray("propOrder");
|
||||
}
|
||||
|
||||
for (CPropertyInfo prop : target.getProperties()) {
|
||||
generateFieldDecl(cc, prop);
|
||||
}
|
||||
|
||||
if (target.declaresAttributeWildcard()) {
|
||||
generateAttributeWildcard(cc);
|
||||
}
|
||||
|
||||
// generate some class level javadoc
|
||||
cc.ref.javadoc().append(target.javadoc);
|
||||
|
||||
cc._package().objectFactoryGenerator().populate(cc);
|
||||
}
|
||||
|
||||
private void writeTypeName(QName typeName, XmlTypeWriter xtw, String mostUsedNamespaceURI) {
|
||||
if (typeName == null) {
|
||||
xtw.name("");
|
||||
} else {
|
||||
xtw.name(typeName.getLocalPart());
|
||||
final String typeNameURI = typeName.getNamespaceURI();
|
||||
if (!typeNameURI.equals(mostUsedNamespaceURI)) // only generate if necessary
|
||||
{
|
||||
xtw.namespace(typeNameURI);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an attribute wildcard property on a class.
|
||||
*/
|
||||
private void generateAttributeWildcard(ClassOutlineImpl cc) {
|
||||
String FIELD_NAME = "otherAttributes";
|
||||
String METHOD_SEED = model.getNameConverter().toClassName(FIELD_NAME);
|
||||
|
||||
JClass mapType = codeModel.ref(Map.class).narrow(QName.class, String.class);
|
||||
JClass mapImpl = codeModel.ref(HashMap.class).narrow(QName.class, String.class);
|
||||
|
||||
// [RESULT]
|
||||
// Map<QName,String> m = new HashMap<QName,String>();
|
||||
JFieldVar $ref = cc.implClass.field(JMod.PRIVATE,
|
||||
mapType, FIELD_NAME, JExpr._new(mapImpl));
|
||||
$ref.annotate2(XmlAnyAttributeWriter.class);
|
||||
|
||||
MethodWriter writer = cc.createMethodWriter();
|
||||
|
||||
JMethod $get = writer.declareMethod(mapType, "get" + METHOD_SEED);
|
||||
$get.javadoc().append(
|
||||
"Gets a map that contains attributes that aren't bound to any typed property on this class.\n\n"
|
||||
+ "<p>\n"
|
||||
+ "the map is keyed by the name of the attribute and \n"
|
||||
+ "the value is the string value of the attribute.\n"
|
||||
+ "\n"
|
||||
+ "the map returned by this method is live, and you can add new attribute\n"
|
||||
+ "by updating the map directly. Because of this design, there's no setter.\n");
|
||||
$get.javadoc().addReturn().append("always non-null");
|
||||
|
||||
$get.body()._return($ref);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the minimum {@link JDefinedClass} skeleton
|
||||
* without filling in its body.
|
||||
*/
|
||||
private EnumOutline generateEnumDef(CEnumLeafInfo e) {
|
||||
JDefinedClass type;
|
||||
|
||||
type = getClassFactory().createClass(
|
||||
getContainer(e.parent, EXPOSED), e.shortName, e.getLocator(), ClassType.ENUM);
|
||||
type.javadoc().append(e.javadoc);
|
||||
|
||||
return new EnumOutline(e, type) {
|
||||
|
||||
@Override
|
||||
public
|
||||
@NotNull
|
||||
Outline parent() {
|
||||
return BeanGenerator.this;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void generateEnumBody(EnumOutline eo) {
|
||||
JDefinedClass type = eo.clazz;
|
||||
CEnumLeafInfo e = eo.target;
|
||||
|
||||
XmlTypeWriter xtw = type.annotate2(XmlTypeWriter.class);
|
||||
writeTypeName(e.getTypeName(), xtw,
|
||||
eo._package().getMostUsedNamespaceURI());
|
||||
|
||||
JCodeModel cModel = model.codeModel;
|
||||
|
||||
// since constant values are never null, no point in using the boxed types.
|
||||
JType baseExposedType = e.base.toType(this, EXPOSED).unboxify();
|
||||
JType baseImplType = e.base.toType(this, Aspect.IMPLEMENTATION).unboxify();
|
||||
|
||||
|
||||
XmlEnumWriter xew = type.annotate2(XmlEnumWriter.class);
|
||||
xew.value(baseExposedType);
|
||||
|
||||
|
||||
boolean needsValue = e.needsValueField();
|
||||
|
||||
// for each member <m>,
|
||||
// [RESULT]
|
||||
// <EnumName>(<deserializer of m>(<value>));
|
||||
|
||||
Set<String> enumFieldNames = new HashSet<String>(); // record generated field names to detect collision
|
||||
|
||||
for (CEnumConstant mem : e.members) {
|
||||
String constName = mem.getName();
|
||||
|
||||
if (!JJavaName.isJavaIdentifier(constName)) {
|
||||
// didn't produce a name.
|
||||
getErrorReceiver().error(e.getLocator(),
|
||||
Messages.ERR_UNUSABLE_NAME.format(mem.getLexicalValue(), constName));
|
||||
}
|
||||
|
||||
if (!enumFieldNames.add(constName)) {
|
||||
getErrorReceiver().error(e.getLocator(), Messages.ERR_NAME_COLLISION.format(constName));
|
||||
}
|
||||
|
||||
// [RESULT]
|
||||
// <Const>(...)
|
||||
// ASSUMPTION: datatype is outline-independent
|
||||
JEnumConstant constRef = type.enumConstant(constName);
|
||||
if (needsValue) {
|
||||
constRef.arg(e.base.createConstant(this, new XmlString(mem.getLexicalValue())));
|
||||
}
|
||||
|
||||
if (!mem.getLexicalValue().equals(constName)) {
|
||||
constRef.annotate2(XmlEnumValueWriter.class).value(mem.getLexicalValue());
|
||||
}
|
||||
|
||||
// set javadoc
|
||||
if (mem.javadoc != null) {
|
||||
constRef.javadoc().append(mem.javadoc);
|
||||
}
|
||||
|
||||
eo.constants.add(new EnumConstantOutline(mem, constRef) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (needsValue) {
|
||||
// [RESULT]
|
||||
// final <valueType> value;
|
||||
JFieldVar $value = type.field(JMod.PRIVATE | JMod.FINAL, baseExposedType, "value");
|
||||
|
||||
// [RESULT]
|
||||
// public <valuetype> value() { return value; }
|
||||
type.method(JMod.PUBLIC, baseExposedType, "value").body()._return($value);
|
||||
|
||||
// [RESULT]
|
||||
// <constructor>(<valueType> v) {
|
||||
// this.value=v;
|
||||
// }
|
||||
{
|
||||
JMethod m = type.constructor(0);
|
||||
m.body().assign($value, m.param(baseImplType, "v"));
|
||||
}
|
||||
|
||||
// [RESULT]
|
||||
// public static <Const> fromValue(<valueType> v) {
|
||||
// for( <Const> c : <Const>.values() ) {
|
||||
// if(c.value == v) // or equals
|
||||
// return c;
|
||||
// }
|
||||
// throw new IllegalArgumentException(...);
|
||||
// }
|
||||
{
|
||||
JMethod m = type.method(JMod.PUBLIC | JMod.STATIC, type, "fromValue");
|
||||
JVar $v = m.param(baseExposedType, "v");
|
||||
JForEach fe = m.body().forEach(type, "c", type.staticInvoke("values"));
|
||||
JExpression eq;
|
||||
if (baseExposedType.isPrimitive()) {
|
||||
eq = fe.var().ref($value).eq($v);
|
||||
} else {
|
||||
eq = fe.var().ref($value).invoke("equals").arg($v);
|
||||
}
|
||||
|
||||
fe.body()._if(eq)._then()._return(fe.var());
|
||||
|
||||
JInvocation ex = JExpr._new(cModel.ref(IllegalArgumentException.class));
|
||||
|
||||
JExpression strForm;
|
||||
if (baseExposedType.isPrimitive()) {
|
||||
strForm = cModel.ref(String.class).staticInvoke("valueOf").arg($v);
|
||||
} else if (baseExposedType == cModel.ref(String.class)) {
|
||||
strForm = $v;
|
||||
} else {
|
||||
strForm = $v.invoke("toString");
|
||||
}
|
||||
m.body()._throw(ex.arg(strForm));
|
||||
}
|
||||
} else {
|
||||
// [RESULT]
|
||||
// public String value() { return name(); }
|
||||
type.method(JMod.PUBLIC, String.class, "value").body()._return(JExpr.invoke("name"));
|
||||
|
||||
// [RESULT]
|
||||
// public <Const> fromValue(String v) { return valueOf(v); }
|
||||
JMethod m = type.method(JMod.PUBLIC | JMod.STATIC, type, "fromValue");
|
||||
m.body()._return(JExpr.invoke("valueOf").arg(m.param(String.class, "v")));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the FieldRenderer used for the given FieldUse,
|
||||
* then generates the field declaration and accessor methods.
|
||||
*
|
||||
* The <code>fields</code> map will be updated with the newly
|
||||
* created FieldRenderer.
|
||||
*/
|
||||
private FieldOutline generateFieldDecl(ClassOutlineImpl cc, CPropertyInfo prop) {
|
||||
FieldRenderer fr = prop.realization;
|
||||
if (fr == null) // none is specified. use the default factory
|
||||
{
|
||||
fr = model.options.getFieldRendererFactory().getDefault();
|
||||
}
|
||||
|
||||
FieldOutline field = fr.generate(cc, prop);
|
||||
fields.put(prop, field);
|
||||
|
||||
return field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates {@link XmlJavaTypeAdapter} from {@link PropertyInfo} if necessary.
|
||||
* Also generates other per-property annotations
|
||||
* (such as {@link XmlID}, {@link XmlIDREF}, and {@link XmlMimeType} if necessary.
|
||||
*/
|
||||
public final void generateAdapterIfNecessary(CPropertyInfo prop, JAnnotatable field) {
|
||||
CAdapter adapter = prop.getAdapter();
|
||||
if (adapter != null) {
|
||||
if (adapter.getAdapterIfKnown() == SwaRefAdapterMarker.class) {
|
||||
field.annotate(XmlAttachmentRef.class);
|
||||
} else {
|
||||
// [RESULT]
|
||||
// @XmlJavaTypeAdapter( Foo.class )
|
||||
XmlJavaTypeAdapterWriter xjtw = field.annotate2(XmlJavaTypeAdapterWriter.class);
|
||||
xjtw.value(adapter.adapterType.toType(this, EXPOSED));
|
||||
}
|
||||
}
|
||||
|
||||
switch (prop.id()) {
|
||||
case ID:
|
||||
field.annotate(XmlID.class);
|
||||
break;
|
||||
case IDREF:
|
||||
field.annotate(XmlIDREF.class);
|
||||
break;
|
||||
}
|
||||
|
||||
if (prop.getExpectedMimeType() != null) {
|
||||
field.annotate2(XmlMimeTypeWriter.class).value(prop.getExpectedMimeType().toString());
|
||||
}
|
||||
}
|
||||
|
||||
public final JClass addRuntime(Class clazz) {
|
||||
JClass g = generatedRuntime.get(clazz);
|
||||
if (g == null) {
|
||||
// put code into a separate package to avoid name conflicts.
|
||||
JPackage implPkg = getUsedPackages(Aspect.IMPLEMENTATION)[0].subPackage("runtime");
|
||||
g = generateStaticClass(clazz, implPkg);
|
||||
generatedRuntime.put(clazz, g);
|
||||
}
|
||||
return g;
|
||||
}
|
||||
|
||||
public JClass generateStaticClass(Class src, JPackage out) {
|
||||
String shortName = getShortName(src.getName());
|
||||
|
||||
// some people didn't like our jars to contain files with .java extension,
|
||||
// so when we build jars, we'' use ".java_". But when we run from the workspace,
|
||||
// we want the original source code to be used, so we check both here.
|
||||
// see bug 6211503.
|
||||
URL res = src.getResource(shortName + ".java");
|
||||
if (res == null) {
|
||||
res = src.getResource(shortName + ".java_");
|
||||
}
|
||||
if (res == null) {
|
||||
throw new InternalError("Unable to load source code of " + src.getName() + " as a resource");
|
||||
}
|
||||
|
||||
JStaticJavaFile sjf = new JStaticJavaFile(out, shortName, res, null);
|
||||
out.addResourceFile(sjf);
|
||||
return sjf.getJClass();
|
||||
}
|
||||
|
||||
private String getShortName(String name) {
|
||||
return name.substring(name.lastIndexOf('.') + 1);
|
||||
}
|
||||
}
|
||||
@@ -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.generator.bean;
|
||||
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.codemodel.internal.JDefinedClass;
|
||||
import com.sun.tools.internal.xjc.model.CClassInfo;
|
||||
import com.sun.tools.internal.xjc.outline.ClassOutline;
|
||||
|
||||
/**
|
||||
* {@link ClassOutline} enhanced with schema2java specific
|
||||
* information.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public final class ClassOutlineImpl extends ClassOutline {
|
||||
private final BeanGenerator _parent;
|
||||
|
||||
|
||||
public MethodWriter createMethodWriter() {
|
||||
return _parent.getModel().strategy.createMethodWriter(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets {@link #_package} as {@link PackageOutlineImpl},
|
||||
* since it's guaranteed to be of that type.
|
||||
*/
|
||||
public PackageOutlineImpl _package() {
|
||||
return (PackageOutlineImpl)super._package();
|
||||
}
|
||||
|
||||
ClassOutlineImpl( BeanGenerator _parent,
|
||||
CClassInfo _target, JDefinedClass exposedClass, JDefinedClass _implClass, JClass _implRef ) {
|
||||
super(_target,exposedClass,_implRef,_implClass);
|
||||
this._parent = _parent;
|
||||
_package().classes.add(this);
|
||||
}
|
||||
|
||||
public BeanGenerator parent() {
|
||||
return _parent;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.generator.bean;
|
||||
|
||||
import com.sun.codemodel.internal.JDefinedClass;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JMod;
|
||||
import com.sun.codemodel.internal.JPackage;
|
||||
import com.sun.tools.internal.xjc.model.CElementInfo;
|
||||
import com.sun.tools.internal.xjc.model.Model;
|
||||
|
||||
/**
|
||||
* {@link ObjectFactoryGenerator} used when we generate
|
||||
* interfaces and implementations in separate packages.
|
||||
*
|
||||
* <p>
|
||||
* {@link #publicOFG} and {@link #privateOFG} gives you access to
|
||||
* {@code ObjectFactory}s in both packages, if you need to.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class DualObjectFactoryGenerator extends ObjectFactoryGenerator {
|
||||
public final ObjectFactoryGenerator publicOFG;
|
||||
public final ObjectFactoryGenerator privateOFG;
|
||||
|
||||
DualObjectFactoryGenerator(BeanGenerator outline, Model model, JPackage targetPackage) {
|
||||
this.publicOFG = new PublicObjectFactoryGenerator(outline,model,targetPackage);
|
||||
this.privateOFG = new PrivateObjectFactoryGenerator(outline,model,targetPackage);
|
||||
|
||||
// put the marker so that we can detect missing jaxb.properties
|
||||
publicOFG.getObjectFactory().field(JMod.PRIVATE|JMod.STATIC|JMod.FINAL,
|
||||
Void.class, "_useJAXBProperties", JExpr._null());
|
||||
}
|
||||
|
||||
void populate(CElementInfo ei) {
|
||||
publicOFG.populate(ei);
|
||||
privateOFG.populate(ei);
|
||||
}
|
||||
|
||||
void populate(ClassOutlineImpl cc) {
|
||||
publicOFG.populate(cc);
|
||||
privateOFG.populate(cc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the private version (which is what gets used at runtime.)
|
||||
*/
|
||||
public JDefinedClass getObjectFactory() {
|
||||
return privateOFG.getObjectFactory();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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.generator.bean;
|
||||
|
||||
|
||||
import javax.xml.bind.JAXBElement;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.codemodel.internal.JCodeModel;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JFieldVar;
|
||||
import com.sun.codemodel.internal.JInvocation;
|
||||
import com.sun.codemodel.internal.JMethod;
|
||||
import com.sun.codemodel.internal.JMod;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.tools.internal.xjc.model.CElementInfo;
|
||||
import com.sun.tools.internal.xjc.outline.Aspect;
|
||||
import com.sun.tools.internal.xjc.outline.ElementOutline;
|
||||
|
||||
/**
|
||||
* {@link ElementOutline} implementation.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
final class ElementOutlineImpl extends ElementOutline {
|
||||
private final BeanGenerator parent;
|
||||
|
||||
public BeanGenerator parent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
/*package*/ ElementOutlineImpl(BeanGenerator parent, CElementInfo ei) {
|
||||
super(ei,
|
||||
parent.getClassFactory().createClass(
|
||||
parent.getContainer( ei.parent, Aspect.EXPOSED ), ei.shortName(), ei.getLocator() ));
|
||||
this.parent = parent;
|
||||
parent.elements.put(ei,this);
|
||||
|
||||
JCodeModel cm = parent.getCodeModel();
|
||||
|
||||
implClass._extends(
|
||||
cm.ref(JAXBElement.class).narrow(
|
||||
target.getContentInMemoryType().toType(parent,Aspect.EXPOSED).boxify()));
|
||||
|
||||
if(ei.hasClass()) {
|
||||
JType implType = ei.getContentInMemoryType().toType(parent,Aspect.IMPLEMENTATION);
|
||||
JExpression declaredType = JExpr.cast(cm.ref(Class.class),implType.boxify().dotclass()); // why do we have to cast?
|
||||
JClass scope=null;
|
||||
if(ei.getScope()!=null)
|
||||
scope = parent.getClazz(ei.getScope()).implRef;
|
||||
JExpression scopeClass = scope==null?JExpr._null():scope.dotclass();
|
||||
JFieldVar valField = implClass.field(JMod.PROTECTED|JMod.FINAL|JMod.STATIC,QName.class,"NAME",createQName(cm,ei.getElementName()));
|
||||
|
||||
// take this opportunity to generate a constructor in the element class
|
||||
JMethod cons = implClass.constructor(JMod.PUBLIC);
|
||||
cons.body().invoke("super")
|
||||
.arg(valField)
|
||||
.arg(declaredType)
|
||||
.arg(scopeClass)
|
||||
.arg(cons.param(implType,"value"));
|
||||
|
||||
// generate no-arg constructor in the element class (bug #391; section 5.6.2 in JAXB spec 2.1)
|
||||
JMethod noArgCons = implClass.constructor(JMod.PUBLIC);
|
||||
noArgCons.body().invoke("super")
|
||||
.arg(valField)
|
||||
.arg(declaredType)
|
||||
.arg(scopeClass)
|
||||
.arg(JExpr._null());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an expression that evaluates to "new QName(...)"
|
||||
*/
|
||||
private JInvocation createQName(JCodeModel codeModel,QName name) {
|
||||
return JExpr._new(codeModel.ref(QName.class)).arg(name.getNamespaceURI()).arg(name.getLocalPart());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Use is subject to the license terms.
|
||||
*/
|
||||
package com.sun.tools.internal.xjc.generator.bean;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlEnum;
|
||||
import javax.xml.bind.annotation.XmlEnumValue;
|
||||
|
||||
import com.sun.codemodel.internal.JClassContainer;
|
||||
import com.sun.codemodel.internal.JDefinedClass;
|
||||
import com.sun.codemodel.internal.JDocComment;
|
||||
import com.sun.codemodel.internal.JMethod;
|
||||
import com.sun.codemodel.internal.JMod;
|
||||
import com.sun.codemodel.internal.JPackage;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlAccessorTypeWriter;
|
||||
import com.sun.tools.internal.xjc.model.CClassInfo;
|
||||
import com.sun.tools.internal.xjc.outline.Aspect;
|
||||
import com.sun.tools.internal.xjc.outline.Outline;
|
||||
|
||||
/**
|
||||
* Decides how a bean token is mapped to the generated classes.
|
||||
*
|
||||
* <p>
|
||||
* The actual implementations of this interface is tightly coupled with
|
||||
* the backend, but the front-end gets to choose which strategy to be used.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
@XmlEnum(Boolean.class)
|
||||
public enum ImplStructureStrategy {
|
||||
/**
|
||||
* Generates beans only. The simplest code generation.
|
||||
*/
|
||||
@XmlEnumValue("true")
|
||||
BEAN_ONLY() {
|
||||
protected Result createClasses(Outline outline, CClassInfo bean) {
|
||||
JClassContainer parent = outline.getContainer( bean.parent(), Aspect.EXPOSED );
|
||||
|
||||
JDefinedClass impl = outline.getClassFactory().createClass(
|
||||
parent,
|
||||
JMod.PUBLIC|(parent.isPackage()?0:JMod.STATIC)|(bean.isAbstract()?JMod.ABSTRACT:0),
|
||||
bean.shortName, bean.getLocator() );
|
||||
impl.annotate2(XmlAccessorTypeWriter.class).value(XmlAccessType.FIELD);
|
||||
|
||||
return new Result(impl,impl);
|
||||
}
|
||||
|
||||
protected JPackage getPackage(JPackage pkg, Aspect a) {
|
||||
return pkg;
|
||||
}
|
||||
|
||||
protected MethodWriter createMethodWriter(final ClassOutlineImpl target) {
|
||||
assert target.ref==target.implClass;
|
||||
|
||||
return new MethodWriter(target) {
|
||||
private final JDefinedClass impl = target.implClass;
|
||||
|
||||
private JMethod implMethod;
|
||||
|
||||
public JVar addParameter(JType type, String name) {
|
||||
return implMethod.param(type,name);
|
||||
}
|
||||
|
||||
public JMethod declareMethod(JType returnType, String methodName) {
|
||||
implMethod = impl.method( JMod.PUBLIC, returnType, methodName );
|
||||
return implMethod;
|
||||
}
|
||||
|
||||
public JDocComment javadoc() {
|
||||
return implMethod.javadoc();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected void _extends(ClassOutlineImpl derived, ClassOutlineImpl base) {
|
||||
derived.implClass._extends(base.implRef);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Generates the interfaces to describe beans (content interfaces)
|
||||
* and then the beans themselves in a hidden impl package.
|
||||
*
|
||||
* Similar to JAXB 1.0.
|
||||
*/
|
||||
@XmlEnumValue("false")
|
||||
INTF_AND_IMPL() {
|
||||
protected Result createClasses( Outline outline, CClassInfo bean ) {
|
||||
JClassContainer parent = outline.getContainer( bean.parent(), Aspect.EXPOSED );
|
||||
|
||||
JDefinedClass intf = outline.getClassFactory().createInterface(
|
||||
parent, bean.shortName, bean.getLocator() );
|
||||
|
||||
parent = outline.getContainer(bean.parent(), Aspect.IMPLEMENTATION);
|
||||
JDefinedClass impl = outline.getClassFactory().createClass(
|
||||
parent,
|
||||
JMod.PUBLIC|(parent.isPackage()?0:JMod.STATIC)|(bean.isAbstract()?JMod.ABSTRACT:0),
|
||||
bean.shortName+"Impl", bean.getLocator() );
|
||||
impl.annotate2(XmlAccessorTypeWriter.class).value(XmlAccessType.FIELD);
|
||||
|
||||
impl._implements(intf);
|
||||
|
||||
return new Result(intf,impl);
|
||||
}
|
||||
|
||||
protected JPackage getPackage(JPackage pkg, Aspect a) {
|
||||
switch(a) {
|
||||
case EXPOSED:
|
||||
return pkg;
|
||||
case IMPLEMENTATION:
|
||||
return pkg.subPackage("impl");
|
||||
default:
|
||||
assert false;
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
protected MethodWriter createMethodWriter(final ClassOutlineImpl target) {
|
||||
return new MethodWriter(target) {
|
||||
private final JDefinedClass intf = target.ref;
|
||||
private final JDefinedClass impl = target.implClass;
|
||||
|
||||
private JMethod intfMethod;
|
||||
private JMethod implMethod;
|
||||
|
||||
public JVar addParameter(JType type, String name) {
|
||||
// TODO: do we still need to deal with the case where intf is null?
|
||||
if(intf!=null)
|
||||
intfMethod.param(type,name);
|
||||
return implMethod.param(type,name);
|
||||
}
|
||||
|
||||
public JMethod declareMethod(JType returnType, String methodName) {
|
||||
if(intf!=null)
|
||||
intfMethod = intf.method( 0, returnType, methodName );
|
||||
implMethod = impl.method( JMod.PUBLIC, returnType, methodName );
|
||||
return implMethod;
|
||||
}
|
||||
|
||||
public JDocComment javadoc() {
|
||||
if(intf!=null)
|
||||
return intfMethod.javadoc();
|
||||
else
|
||||
return implMethod.javadoc();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected void _extends(ClassOutlineImpl derived, ClassOutlineImpl base) {
|
||||
derived.implClass._extends(base.implRef);
|
||||
derived.ref._implements(base.ref);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Creates class(es) for the given bean.
|
||||
*/
|
||||
protected abstract Result createClasses( Outline outline, CClassInfo bean );
|
||||
|
||||
/**
|
||||
* Gets the specified aspect of the given package.
|
||||
*/
|
||||
protected abstract JPackage getPackage( JPackage pkg, Aspect a );
|
||||
|
||||
protected abstract MethodWriter createMethodWriter( ClassOutlineImpl target );
|
||||
|
||||
/**
|
||||
* Sets up an inheritance relationship.
|
||||
*/
|
||||
protected abstract void _extends( ClassOutlineImpl derived, ClassOutlineImpl base );
|
||||
|
||||
public static final class Result {
|
||||
/**
|
||||
* Corresponds to {@link Aspect#EXPOSED}
|
||||
*/
|
||||
public final JDefinedClass exposed;
|
||||
/**
|
||||
* Corresponds to {@link Aspect#IMPLEMENTATION}
|
||||
*/
|
||||
public final JDefinedClass implementation;
|
||||
|
||||
public Result(JDefinedClass exposed, JDefinedClass implementation) {
|
||||
this.exposed = exposed;
|
||||
this.implementation = implementation;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.generator.bean;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Formats error messages.
|
||||
*/
|
||||
enum Messages {
|
||||
// AnnotationParser
|
||||
METHOD_COLLISION, // 3 args
|
||||
ERR_UNUSABLE_NAME, // 2 args
|
||||
ERR_KEYNAME_COLLISION, // 1 arg
|
||||
ERR_NAME_COLLISION, // 1 arg
|
||||
ILLEGAL_CONSTRUCTOR_PARAM, // 1 arg
|
||||
OBJECT_FACTORY_CONFLICT, // 1 arg
|
||||
OBJECT_FACTORY_CONFLICT_RELATED,
|
||||
;
|
||||
|
||||
private static final ResourceBundle rb = ResourceBundle.getBundle(Messages.class.getPackage().getName() + ".MessageBundle");
|
||||
|
||||
public String toString() {
|
||||
return format();
|
||||
}
|
||||
|
||||
public String format( Object... args ) {
|
||||
return MessageFormat.format( rb.getString(name()), args );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Use is subject to the license terms.
|
||||
*/
|
||||
package com.sun.tools.internal.xjc.generator.bean;
|
||||
|
||||
import com.sun.codemodel.internal.JCodeModel;
|
||||
import com.sun.codemodel.internal.JDocComment;
|
||||
import com.sun.codemodel.internal.JMethod;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.tools.internal.xjc.outline.ClassOutline;
|
||||
|
||||
/**
|
||||
* The back-end may or may not generate the content interface
|
||||
* separately from the implementation class. If so, a method
|
||||
* needs to be declared on both the interface and the implementation class.
|
||||
* <p>
|
||||
* This class hides those details and allow callers to declare
|
||||
* methods just once.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public abstract class MethodWriter {
|
||||
protected final JCodeModel codeModel;
|
||||
|
||||
protected MethodWriter(ClassOutline context) {
|
||||
this.codeModel = context.parent().getCodeModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Declares a method in both the interface and the implementation.
|
||||
*
|
||||
* @return
|
||||
* JMethod object that represents a newly declared method
|
||||
* on the implementation class.
|
||||
*/
|
||||
public abstract JMethod declareMethod( JType returnType, String methodName );
|
||||
|
||||
public final JMethod declareMethod( Class returnType, String methodName ) {
|
||||
return declareMethod( codeModel.ref(returnType), methodName );
|
||||
}
|
||||
|
||||
/**
|
||||
* To generate javadoc for the previously declared method, use this method
|
||||
* to obtain a {@link JDocComment} object. This may return a value
|
||||
* different from declareMethod().javadoc().
|
||||
*/
|
||||
public abstract JDocComment javadoc();
|
||||
|
||||
|
||||
/**
|
||||
* Adds a parameter to the previously declared method.
|
||||
*
|
||||
* @return
|
||||
* JVar object that represents a newly added parameter
|
||||
* on the implementation class.
|
||||
*/
|
||||
public abstract JVar addParameter( JType type, String name );
|
||||
|
||||
public final JVar addParameter( Class type, String name ) {
|
||||
return addParameter( codeModel.ref(type), name );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.generator.bean;
|
||||
|
||||
import com.sun.codemodel.internal.JDefinedClass;
|
||||
import com.sun.tools.internal.xjc.model.CElementInfo;
|
||||
|
||||
/**
|
||||
* Generates <code>ObjectFactory</code> then wraps it and provides
|
||||
* access to it.
|
||||
*
|
||||
* <p>
|
||||
* The ObjectFactory contains
|
||||
* factory methods for each schema derived content class
|
||||
*
|
||||
* @author
|
||||
* Ryan Shoemaker
|
||||
*/
|
||||
public abstract class ObjectFactoryGenerator {
|
||||
/**
|
||||
* Adds code for the given {@link CElementInfo} to ObjectFactory.
|
||||
*/
|
||||
abstract void populate( CElementInfo ei );
|
||||
|
||||
/**
|
||||
* Adds code that is relevant to a given {@link ClassOutlineImpl} to
|
||||
* ObjectFactory.
|
||||
*/
|
||||
abstract void populate( ClassOutlineImpl cc );
|
||||
|
||||
/**
|
||||
* Returns a reference to the generated (public) ObjectFactory
|
||||
*/
|
||||
public abstract JDefinedClass getObjectFactory();
|
||||
}
|
||||
@@ -0,0 +1,384 @@
|
||||
/*
|
||||
* 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.generator.bean;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.annotation.XmlInlineBinaryData;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.codemodel.internal.JCodeModel;
|
||||
import com.sun.codemodel.internal.JDefinedClass;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JFieldVar;
|
||||
import com.sun.codemodel.internal.JInvocation;
|
||||
import com.sun.codemodel.internal.JMethod;
|
||||
import com.sun.codemodel.internal.JMod;
|
||||
import com.sun.codemodel.internal.JPackage;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlElementDeclWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlRegistryWriter;
|
||||
import com.sun.tools.internal.xjc.model.CElementInfo;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.Constructor;
|
||||
import com.sun.tools.internal.xjc.model.Model;
|
||||
import com.sun.tools.internal.xjc.outline.Aspect;
|
||||
import com.sun.tools.internal.xjc.outline.FieldAccessor;
|
||||
import com.sun.tools.internal.xjc.outline.FieldOutline;
|
||||
import com.sun.xml.internal.bind.v2.TODO;
|
||||
|
||||
/**
|
||||
* Generates <code>ObjectFactory</code> then wraps it and provides
|
||||
* access to it.
|
||||
*
|
||||
* <p>
|
||||
* The ObjectFactory contains
|
||||
* factory methods for each schema derived content class
|
||||
*
|
||||
* @author
|
||||
* Ryan Shoemaker
|
||||
*/
|
||||
abstract class ObjectFactoryGeneratorImpl extends ObjectFactoryGenerator {
|
||||
|
||||
private final BeanGenerator outline;
|
||||
private final Model model;
|
||||
private final JCodeModel codeModel;
|
||||
/**
|
||||
* Ref to {@link Class}.
|
||||
*/
|
||||
private final JClass classRef;
|
||||
|
||||
/**
|
||||
* Reference to the generated ObjectFactory class.
|
||||
*/
|
||||
private final JDefinedClass objectFactory;
|
||||
|
||||
/** map of qname to the QName constant field. */
|
||||
private final HashMap<QName,JFieldVar> qnameMap = new HashMap<QName,JFieldVar>();
|
||||
|
||||
/**
|
||||
* Names of the element factory methods that are created.
|
||||
* Used to detect collisions.
|
||||
*
|
||||
* The value is used for reporting error locations.
|
||||
*/
|
||||
private final Map<String,CElementInfo> elementFactoryNames = new HashMap<String,CElementInfo>();
|
||||
|
||||
/**
|
||||
* Names of the value factory methods that are created.
|
||||
* Used to detect collisions.
|
||||
*
|
||||
* The value is used for reporting error locations.
|
||||
*/
|
||||
private final Map<String,ClassOutlineImpl> valueFactoryNames = new HashMap<String,ClassOutlineImpl>();
|
||||
|
||||
/**
|
||||
* Returns a reference to the generated (public) ObjectFactory
|
||||
*/
|
||||
public JDefinedClass getObjectFactory() {
|
||||
return objectFactory;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public ObjectFactoryGeneratorImpl( BeanGenerator outline, Model model, JPackage targetPackage ) {
|
||||
this.outline = outline;
|
||||
this.model = model;
|
||||
this.codeModel = this.model.codeModel;
|
||||
this.classRef = codeModel.ref(Class.class);
|
||||
|
||||
// create the ObjectFactory class skeleton
|
||||
objectFactory = this.outline.getClassFactory().createClass(
|
||||
targetPackage, "ObjectFactory", null );
|
||||
objectFactory.annotate2(XmlRegistryWriter.class);
|
||||
|
||||
// generate the default constructor
|
||||
//
|
||||
// m1 result:
|
||||
// public ObjectFactory() {}
|
||||
JMethod m1 = objectFactory.constructor(JMod.PUBLIC);
|
||||
m1.javadoc().append("Create a new ObjectFactory that can be used to " +
|
||||
"create new instances of schema derived classes " +
|
||||
"for package: " + targetPackage.name());
|
||||
|
||||
// add some class javadoc
|
||||
objectFactory.javadoc().append(
|
||||
"This object contains factory methods for each \n" +
|
||||
"Java content interface and Java element interface \n" +
|
||||
"generated in the " + targetPackage.name() + " package. \n" +
|
||||
"<p>An ObjectFactory allows you to programatically \n" +
|
||||
"construct new instances of the Java representation \n" +
|
||||
"for XML content. The Java representation of XML \n" +
|
||||
"content can consist of schema derived interfaces \n" +
|
||||
"and classes representing the binding of schema \n" +
|
||||
"type definitions, element declarations and model \n" +
|
||||
"groups. Factory methods for each of these are \n" +
|
||||
"provided in this class." );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds code for the given {@link CElementInfo} to ObjectFactory.
|
||||
*/
|
||||
protected final void populate( CElementInfo ei, Aspect impl, Aspect exposed ) {
|
||||
JType exposedElementType = ei.toType(outline,exposed);
|
||||
JType exposedType = ei.getContentInMemoryType().toType(outline,exposed);
|
||||
JType implType = ei.getContentInMemoryType().toType(outline,impl);
|
||||
String namespaceURI = ei.getElementName().getNamespaceURI();
|
||||
String localPart = ei.getElementName().getLocalPart();
|
||||
|
||||
JClass scope=null;
|
||||
if(ei.getScope()!=null)
|
||||
scope = outline.getClazz(ei.getScope()).implClass;
|
||||
|
||||
|
||||
JMethod m;
|
||||
|
||||
if(ei.isAbstract()) {
|
||||
// TODO: see the "Abstract elements and mighty IXmlElement" e-mail
|
||||
// that I sent to jaxb-tech
|
||||
TODO.checkSpec();
|
||||
}
|
||||
|
||||
{// collision check
|
||||
CElementInfo existing = elementFactoryNames.put(ei.getSqueezedName(),ei);
|
||||
if( existing!=null ) {
|
||||
outline.getErrorReceiver().error(existing.getLocator(),
|
||||
Messages.OBJECT_FACTORY_CONFLICT.format(ei.getSqueezedName()));
|
||||
outline.getErrorReceiver().error(ei.getLocator(),
|
||||
Messages.OBJECT_FACTORY_CONFLICT_RELATED.format());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// no arg constructor
|
||||
// [RESULT] if the element doesn't have its own class, something like:
|
||||
//
|
||||
// @XmlElementMapping(uri = "", name = "foo")
|
||||
// public JAXBElement<Foo> createFoo( Foo value ) {
|
||||
// return new JAXBElement<Foo>(
|
||||
// new QName("","foo"),(Class)FooImpl.class,scope,(FooImpl)value);
|
||||
// }
|
||||
// NOTE: when we generate value classes Foo==FooImpl
|
||||
//
|
||||
// [RESULT] otherwise
|
||||
//
|
||||
// @XmlElementMapping(uri = "", name = "foo")
|
||||
// public Foo createFoo( FooType value ) {
|
||||
// return new Foo((FooTypeImpl)value);
|
||||
// }
|
||||
// NOTE: when we generate value classes FooType==FooTypeImpl
|
||||
//
|
||||
// to deal with
|
||||
// new JAXBElement<List<String>>( ..., List.class, ... );
|
||||
// we sometimes have to produce (Class)List.class instead of just List.class
|
||||
|
||||
m = objectFactory.method( JMod.PUBLIC, exposedElementType, "create" + ei.getSqueezedName() );
|
||||
JVar $value = m.param(exposedType,"value");
|
||||
|
||||
JExpression declaredType;
|
||||
if(implType.boxify().isParameterized() || !exposedType.equals(implType))
|
||||
declaredType = JExpr.cast(classRef,implType.boxify().dotclass());
|
||||
else
|
||||
declaredType = implType.boxify().dotclass();
|
||||
JExpression scopeClass = scope==null?JExpr._null():scope.dotclass();
|
||||
|
||||
// build up the return extpression
|
||||
JInvocation exp = JExpr._new(exposedElementType);
|
||||
if(!ei.hasClass()) {
|
||||
exp.arg(getQNameInvocation(ei));
|
||||
exp.arg(declaredType);
|
||||
exp.arg(scopeClass);
|
||||
}
|
||||
if(implType==exposedType)
|
||||
exp.arg($value);
|
||||
else
|
||||
exp.arg(JExpr.cast(implType,$value));
|
||||
|
||||
m.body()._return( exp );
|
||||
|
||||
m.javadoc()
|
||||
.append("Create an instance of ")
|
||||
.append(exposedElementType)
|
||||
.append("}");
|
||||
|
||||
XmlElementDeclWriter xemw = m.annotate2(XmlElementDeclWriter.class);
|
||||
xemw.namespace(namespaceURI).name(localPart);
|
||||
if(scope!=null)
|
||||
xemw.scope(scope);
|
||||
|
||||
if(ei.getSubstitutionHead()!=null) {
|
||||
QName n = ei.getSubstitutionHead().getElementName();
|
||||
xemw.substitutionHeadNamespace(n.getNamespaceURI());
|
||||
xemw.substitutionHeadName(n.getLocalPart());
|
||||
}
|
||||
|
||||
if(ei.getDefaultValue()!=null)
|
||||
xemw.defaultValue(ei.getDefaultValue());
|
||||
|
||||
if(ei.getProperty().inlineBinaryData())
|
||||
m.annotate(XmlInlineBinaryData.class);
|
||||
|
||||
// if the element is adapter, put that annotation on the factory method
|
||||
outline.generateAdapterIfNecessary(ei.getProperty(),m);
|
||||
}
|
||||
|
||||
/**
|
||||
* return a JFieldVar that represents the QName field for the given information.
|
||||
*
|
||||
* if it doesn't exist, create a static field in the class and store a new JFieldVar.
|
||||
*/
|
||||
private JExpression getQNameInvocation(CElementInfo ei) {
|
||||
QName name = ei.getElementName();
|
||||
if(qnameMap.containsKey(name)) {
|
||||
return qnameMap.get(name);
|
||||
}
|
||||
|
||||
if(qnameMap.size()>1024)
|
||||
// stop gap measure to avoid 'code too large' error in javac.
|
||||
return createQName(name);
|
||||
|
||||
// [RESULT]
|
||||
// private static final QName _XYZ_NAME = new QName("uri", "local");
|
||||
JFieldVar qnameField = objectFactory.field(
|
||||
JMod.PRIVATE | JMod.STATIC | JMod.FINAL,
|
||||
QName.class,
|
||||
'_' + ei.getSqueezedName() + "_QNAME", createQName(name));
|
||||
|
||||
qnameMap.put(name, qnameField);
|
||||
|
||||
return qnameField;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an expression that evaluates to "new QName(...)"
|
||||
*/
|
||||
private JInvocation createQName(QName name) {
|
||||
return JExpr._new(codeModel.ref(QName.class)).arg(name.getNamespaceURI()).arg(name.getLocalPart());
|
||||
}
|
||||
|
||||
protected final void populate( ClassOutlineImpl cc, JClass sigType ) {
|
||||
// add static factory method for this class to JAXBContext.
|
||||
//
|
||||
// generate methods like:
|
||||
// public static final SIGTYPE createFoo() {
|
||||
// return new FooImpl();
|
||||
// }
|
||||
|
||||
if(!cc.target.isAbstract()) {
|
||||
JMethod m = objectFactory.method(
|
||||
JMod.PUBLIC, sigType, "create" + cc.target.getSqueezedName() );
|
||||
m.body()._return( JExpr._new(cc.implRef) );
|
||||
|
||||
// add some jdoc to avoid javadoc warnings in jdk1.4
|
||||
m.javadoc()
|
||||
.append("Create an instance of ")
|
||||
.append(cc.ref);
|
||||
}
|
||||
|
||||
|
||||
// add static factory methods for all the other constructors.
|
||||
Collection<? extends Constructor> consl = cc.target.getConstructors();
|
||||
if(consl.size()!=0) {
|
||||
// if we are going to add constructors with parameters,
|
||||
// first we need to have a default constructor.
|
||||
cc.implClass.constructor(JMod.PUBLIC);
|
||||
}
|
||||
|
||||
{// collision check
|
||||
String name = cc.target.getSqueezedName();
|
||||
ClassOutlineImpl existing = valueFactoryNames.put(name,cc);
|
||||
if( existing!=null ) {
|
||||
outline.getErrorReceiver().error(existing.target.getLocator(),
|
||||
Messages.OBJECT_FACTORY_CONFLICT.format(name));
|
||||
outline.getErrorReceiver().error(cc.target.getLocator(),
|
||||
Messages.OBJECT_FACTORY_CONFLICT_RELATED.format());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for( Constructor cons : consl ) {
|
||||
// method on ObjectFactory
|
||||
// [RESULT]
|
||||
// Foo createFoo( T1 a, T2 b, T3 c, ... ) throws JAXBException {
|
||||
// return new FooImpl(a,b,c,...);
|
||||
// }
|
||||
JMethod m = objectFactory.method( JMod.PUBLIC,
|
||||
cc.ref, "create" + cc.target.getSqueezedName() );
|
||||
JInvocation inv = JExpr._new(cc.implRef);
|
||||
m.body()._return(inv);
|
||||
|
||||
// let's not throw this exception.
|
||||
// m._throws(codeModel.ref(JAXBException.class));
|
||||
|
||||
// add some jdoc to avoid javadoc warnings in jdk1.4
|
||||
m.javadoc()
|
||||
.append( "Create an instance of " )
|
||||
.append( cc.ref )
|
||||
.addThrows(JAXBException.class).append("if an error occurs");
|
||||
|
||||
// constructor
|
||||
// [RESULT]
|
||||
// FooImpl( T1 a, T2 b, T3 c, ... ) {
|
||||
// }
|
||||
JMethod c = cc.implClass.constructor(JMod.PUBLIC);
|
||||
|
||||
for( String fieldName : cons.fields ) {
|
||||
CPropertyInfo field = cc.target.getProperty(fieldName);
|
||||
if(field==null) {
|
||||
outline.getErrorReceiver().error(cc.target.getLocator(),
|
||||
Messages.ILLEGAL_CONSTRUCTOR_PARAM.format(fieldName));
|
||||
continue;
|
||||
}
|
||||
|
||||
fieldName = camelize(fieldName);
|
||||
|
||||
FieldOutline fo = outline.getField(field);
|
||||
FieldAccessor accessor = fo.create(JExpr._this());
|
||||
|
||||
// declare a parameter on this factory method and set
|
||||
// it to the field
|
||||
inv.arg(m.param( fo.getRawType(), fieldName ));
|
||||
|
||||
JVar $var = c.param( fo.getRawType(), fieldName );
|
||||
accessor.fromRawValue(c.body(),'_'+fieldName,$var);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Change the first character to the lower case. */
|
||||
private static String camelize( String s ) {
|
||||
return Character.toLowerCase(s.charAt(0)) + s.substring(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
/*
|
||||
* 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.generator.bean;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.annotation.XmlNsForm;
|
||||
import javax.xml.bind.annotation.XmlSchema;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import com.sun.codemodel.internal.JDefinedClass;
|
||||
import com.sun.codemodel.internal.JPackage;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlSchemaWriter;
|
||||
import com.sun.tools.internal.xjc.model.CAttributePropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CClassInfo;
|
||||
import com.sun.tools.internal.xjc.model.CElement;
|
||||
import com.sun.tools.internal.xjc.model.CElementPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyVisitor;
|
||||
import com.sun.tools.internal.xjc.model.CReferencePropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CTypeRef;
|
||||
import com.sun.tools.internal.xjc.model.CValuePropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.Model;
|
||||
import com.sun.tools.internal.xjc.outline.PackageOutline;
|
||||
import com.sun.tools.internal.xjc.outline.Aspect;
|
||||
|
||||
/**
|
||||
* {@link PackageOutline} enhanced with schema2java specific
|
||||
* information.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com), Martin Grebac (martin.grebac@oracle.com)
|
||||
*/
|
||||
public final class PackageOutlineImpl implements PackageOutline {
|
||||
private final Model _model;
|
||||
private final JPackage _package;
|
||||
private final ObjectFactoryGenerator objectFactoryGenerator;
|
||||
|
||||
/*package*/ final Set<ClassOutlineImpl> classes = new HashSet<ClassOutlineImpl>();
|
||||
private final Set<ClassOutlineImpl> classesView = Collections.unmodifiableSet(classes);
|
||||
|
||||
private String mostUsedNamespaceURI;
|
||||
private XmlNsForm elementFormDefault;
|
||||
private XmlNsForm attributeFormDefault;
|
||||
|
||||
/**
|
||||
* The namespace URI most commonly used in classes in this package.
|
||||
* This should be used as the namespace URI for {@link XmlSchema#namespace()}.
|
||||
*
|
||||
* <p>
|
||||
* Null if no default
|
||||
*
|
||||
* @see #calcDefaultValues().
|
||||
*/
|
||||
public String getMostUsedNamespaceURI() {
|
||||
return mostUsedNamespaceURI;
|
||||
}
|
||||
|
||||
/**
|
||||
* The attribute form default for this package.
|
||||
* <p>
|
||||
* The value is computed by examining what would yield the smallest generated code.
|
||||
*/
|
||||
public XmlNsForm getAttributeFormDefault() {
|
||||
assert attributeFormDefault!=null;
|
||||
return attributeFormDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
* The element form default for this package.
|
||||
* <p>
|
||||
* The value is computed by examining what would yield the smallest generated code.
|
||||
*/
|
||||
public XmlNsForm getElementFormDefault() {
|
||||
assert elementFormDefault!=null;
|
||||
return elementFormDefault;
|
||||
}
|
||||
|
||||
public JPackage _package() {
|
||||
return _package;
|
||||
}
|
||||
|
||||
public ObjectFactoryGenerator objectFactoryGenerator() {
|
||||
return objectFactoryGenerator;
|
||||
}
|
||||
|
||||
public Set<ClassOutlineImpl> getClasses() {
|
||||
return classesView;
|
||||
}
|
||||
|
||||
public JDefinedClass objectFactory() {
|
||||
return objectFactoryGenerator.getObjectFactory();
|
||||
}
|
||||
|
||||
protected PackageOutlineImpl( BeanGenerator outline, Model model, JPackage _pkg ) {
|
||||
this._model = model;
|
||||
this._package = _pkg;
|
||||
switch(model.strategy) {
|
||||
case BEAN_ONLY:
|
||||
objectFactoryGenerator = new PublicObjectFactoryGenerator(outline,model,_pkg);
|
||||
break;
|
||||
case INTF_AND_IMPL:
|
||||
objectFactoryGenerator = new DualObjectFactoryGenerator(outline,model,_pkg);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the most common namespace URI in this package
|
||||
* (to put into {@link XmlSchema#namespace()} and what value
|
||||
* we should put into {@link XmlSchema#elementFormDefault()}.
|
||||
*
|
||||
* This method is called after {@link #classes} field is filled up.
|
||||
*/
|
||||
public void calcDefaultValues() {
|
||||
// short-circuit if xjc was told not to generate package level annotations in
|
||||
// package-info.java
|
||||
if(!_model.isPackageLevelAnnotations()) {
|
||||
mostUsedNamespaceURI = "";
|
||||
elementFormDefault = XmlNsForm.UNQUALIFIED;
|
||||
return;
|
||||
}
|
||||
|
||||
// used to visit properties
|
||||
CPropertyVisitor<Void> propVisitor = new CPropertyVisitor<Void>() {
|
||||
public Void onElement(CElementPropertyInfo p) {
|
||||
for (CTypeRef tr : p.getTypes()) {
|
||||
countURI(propUriCountMap, tr.getTagName());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onReference(CReferencePropertyInfo p) {
|
||||
for (CElement e : p.getElements()) {
|
||||
countURI(propUriCountMap, e.getElementName());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onAttribute(CAttributePropertyInfo p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onValue(CValuePropertyInfo p) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
for (ClassOutlineImpl co : classes) {
|
||||
CClassInfo ci = co.target;
|
||||
countURI(uriCountMap, ci.getTypeName());
|
||||
countURI(uriCountMap, ci.getElementName());
|
||||
|
||||
for( CPropertyInfo p : ci.getProperties() )
|
||||
p.accept(propVisitor);
|
||||
}
|
||||
mostUsedNamespaceURI = getMostUsedURI(uriCountMap);
|
||||
|
||||
elementFormDefault = getFormDefault();
|
||||
attributeFormDefault = XmlNsForm.UNQUALIFIED;
|
||||
try {
|
||||
XmlNsForm modelValue = _model.getAttributeFormDefault(mostUsedNamespaceURI);
|
||||
attributeFormDefault = modelValue;
|
||||
} catch (Exception e) {
|
||||
// ignore and accept default
|
||||
}
|
||||
|
||||
// generate package-info.java
|
||||
// we won't get this far if the user specified -npa
|
||||
if(!mostUsedNamespaceURI.equals("") || elementFormDefault==XmlNsForm.QUALIFIED || (attributeFormDefault == XmlNsForm.QUALIFIED)) {
|
||||
XmlSchemaWriter w = _model.strategy.getPackage(_package, Aspect.IMPLEMENTATION).annotate2(XmlSchemaWriter.class);
|
||||
if(!mostUsedNamespaceURI.equals(""))
|
||||
w.namespace(mostUsedNamespaceURI);
|
||||
if(elementFormDefault==XmlNsForm.QUALIFIED)
|
||||
w.elementFormDefault(elementFormDefault);
|
||||
if(attributeFormDefault==XmlNsForm.QUALIFIED)
|
||||
w.attributeFormDefault(attributeFormDefault);
|
||||
}
|
||||
}
|
||||
|
||||
// Map to keep track of how often each type or element uri is used in this package
|
||||
// mostly used to calculate mostUsedNamespaceURI
|
||||
private HashMap<String, Integer> uriCountMap = new HashMap<String, Integer>();
|
||||
|
||||
// Map to keep track of how often each property uri is used in this package
|
||||
// used to calculate elementFormDefault
|
||||
private HashMap<String, Integer> propUriCountMap = new HashMap<String, Integer>();
|
||||
|
||||
/**
|
||||
* pull the uri out of the specified QName and keep track of it in the
|
||||
* specified hash map
|
||||
*
|
||||
* @param qname
|
||||
*/
|
||||
private void countURI(HashMap<String, Integer> map, QName qname) {
|
||||
if (qname == null) return;
|
||||
|
||||
String uri = qname.getNamespaceURI();
|
||||
|
||||
if (map.containsKey(uri)) {
|
||||
map.put(uri, map.get(uri) + 1);
|
||||
} else {
|
||||
map.put(uri, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate through the hash map looking for the namespace used
|
||||
* most frequently. Ties are arbitrarily broken by the order
|
||||
* in which the map keys are iterated over.
|
||||
*
|
||||
* <p>
|
||||
* Because JAX-WS often reassigns the "" namespace URI,
|
||||
* and when that happens it unintentionally also renames (normally
|
||||
* unqualified) local elements, prefer non-"" URI when there's a tie.
|
||||
*/
|
||||
private String getMostUsedURI(HashMap<String, Integer> map) {
|
||||
String mostPopular = null;
|
||||
int count = 0;
|
||||
|
||||
for (Map.Entry<String,Integer> e : map.entrySet()) {
|
||||
String uri = e.getKey();
|
||||
int uriCount = e.getValue();
|
||||
if (mostPopular == null) {
|
||||
mostPopular = uri;
|
||||
count = uriCount;
|
||||
} else {
|
||||
if (uriCount > count || (uriCount==count && mostPopular.equals(""))) {
|
||||
mostPopular = uri;
|
||||
count = uriCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mostPopular == null) return "";
|
||||
return mostPopular;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the element form defaulting.
|
||||
*
|
||||
* Compare the most frequently used property URI to the most frequently used
|
||||
* element/type URI. If they match, then return QUALIFIED
|
||||
*/
|
||||
private XmlNsForm getFormDefault() {
|
||||
if (getMostUsedURI(propUriCountMap).equals("")) return XmlNsForm.UNQUALIFIED;
|
||||
else return XmlNsForm.QUALIFIED;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.generator.bean;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.codemodel.internal.JPackage;
|
||||
import com.sun.codemodel.internal.fmt.JPropertyFile;
|
||||
import com.sun.tools.internal.xjc.model.CElementInfo;
|
||||
import com.sun.tools.internal.xjc.model.Model;
|
||||
import com.sun.tools.internal.xjc.outline.Aspect;
|
||||
import com.sun.tools.internal.xjc.runtime.JAXBContextFactory;
|
||||
|
||||
/**
|
||||
* Generates private ObjectFactory.
|
||||
*
|
||||
* <p>
|
||||
* This class also puts a copy of {@link JAXBContextFactory}
|
||||
* to the impl package.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
final class PrivateObjectFactoryGenerator extends ObjectFactoryGeneratorImpl {
|
||||
public PrivateObjectFactoryGenerator(BeanGenerator outline, Model model, JPackage targetPackage) {
|
||||
super(outline, model, targetPackage.subPackage("impl"));
|
||||
|
||||
JPackage implPkg = targetPackage.subPackage("impl");
|
||||
|
||||
// put JAXBContextFactory into the impl package
|
||||
JClass factory = outline.generateStaticClass(JAXBContextFactory.class,implPkg);
|
||||
|
||||
// and then put jaxb.properties to point to it
|
||||
JPropertyFile jaxbProperties = new JPropertyFile("jaxb.properties");
|
||||
targetPackage.addResourceFile(jaxbProperties);
|
||||
jaxbProperties.add(
|
||||
JAXBContext.JAXB_CONTEXT_FACTORY,
|
||||
factory.fullName());
|
||||
}
|
||||
|
||||
void populate(CElementInfo ei) {
|
||||
populate(ei,Aspect.IMPLEMENTATION,Aspect.IMPLEMENTATION);
|
||||
}
|
||||
|
||||
void populate(ClassOutlineImpl cc) {
|
||||
populate(cc,cc.implRef);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.generator.bean;
|
||||
|
||||
import com.sun.codemodel.internal.JPackage;
|
||||
import com.sun.tools.internal.xjc.model.CElementInfo;
|
||||
import com.sun.tools.internal.xjc.model.Model;
|
||||
import com.sun.tools.internal.xjc.outline.Aspect;
|
||||
|
||||
/**
|
||||
* Generates public ObjectFactory.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
final class PublicObjectFactoryGenerator extends ObjectFactoryGeneratorImpl {
|
||||
public PublicObjectFactoryGenerator(BeanGenerator outline, Model model, JPackage targetPackage) {
|
||||
super(outline, model, targetPackage);
|
||||
}
|
||||
|
||||
void populate(CElementInfo ei) {
|
||||
populate(ei,Aspect.IMPLEMENTATION,Aspect.EXPOSED);
|
||||
}
|
||||
|
||||
void populate(ClassOutlineImpl cc) {
|
||||
populate(cc,cc.ref);
|
||||
}
|
||||
}
|
||||
@@ -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.generator.bean.field;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.W3CDomHandler;
|
||||
import javax.xml.bind.annotation.XmlList;
|
||||
import javax.xml.bind.annotation.XmlMixed;
|
||||
import javax.xml.bind.annotation.XmlNsForm;
|
||||
import javax.xml.bind.annotation.XmlValue;
|
||||
import javax.xml.bind.annotation.XmlInlineBinaryData;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import com.sun.codemodel.internal.JAnnotatable;
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.codemodel.internal.JCodeModel;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JFieldVar;
|
||||
import com.sun.codemodel.internal.JMod;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlAnyElementWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlAttributeWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlElementRefWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlElementRefsWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlElementWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlElementsWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlSchemaTypeWriter;
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.model.CAttributePropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CElement;
|
||||
import com.sun.tools.internal.xjc.model.CElementInfo;
|
||||
import com.sun.tools.internal.xjc.model.CElementPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CReferencePropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CTypeInfo;
|
||||
import com.sun.tools.internal.xjc.model.CTypeRef;
|
||||
import com.sun.tools.internal.xjc.model.CValuePropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.nav.NClass;
|
||||
import com.sun.tools.internal.xjc.outline.Aspect;
|
||||
import static com.sun.tools.internal.xjc.outline.Aspect.IMPLEMENTATION;
|
||||
import com.sun.tools.internal.xjc.outline.ClassOutline;
|
||||
import com.sun.tools.internal.xjc.outline.FieldAccessor;
|
||||
import com.sun.tools.internal.xjc.outline.FieldOutline;
|
||||
import com.sun.tools.internal.xjc.reader.TypeUtil;
|
||||
import com.sun.tools.internal.xjc.Options;
|
||||
import com.sun.tools.internal.xjc.api.SpecVersion;
|
||||
import com.sun.xml.internal.bind.api.impl.NameConverter;
|
||||
import com.sun.xml.internal.bind.v2.TODO;
|
||||
|
||||
/**
|
||||
* Useful base class for implementing {@link FieldOutline}.
|
||||
*
|
||||
* <p>
|
||||
* This class just provides a few utility methods and keep some
|
||||
* important variables so that they can be readily accessed any time.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
abstract class AbstractField implements FieldOutline {
|
||||
|
||||
protected final ClassOutlineImpl outline;
|
||||
|
||||
protected final CPropertyInfo prop;
|
||||
|
||||
protected final JCodeModel codeModel;
|
||||
|
||||
/**
|
||||
* The type of this field, which can hold all the possible types.
|
||||
*/
|
||||
protected final JType implType;
|
||||
|
||||
/**
|
||||
* The publicly visible type of this field.
|
||||
* If we are generating value classes implType==exposedType.
|
||||
*/
|
||||
protected final JType exposedType;
|
||||
|
||||
protected AbstractField( ClassOutlineImpl outline, CPropertyInfo prop ) {
|
||||
this.outline = outline;
|
||||
this.prop = prop;
|
||||
this.codeModel = outline.parent().getCodeModel();
|
||||
this.implType = getType(IMPLEMENTATION);
|
||||
this.exposedType = getType(Aspect.EXPOSED);
|
||||
}
|
||||
|
||||
public final ClassOutline parent() {
|
||||
return outline;
|
||||
}
|
||||
|
||||
public final CPropertyInfo getPropertyInfo() {
|
||||
return prop;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Annotate the field according to the recipes given as {@link CPropertyInfo}.
|
||||
*/
|
||||
protected void annotate( JAnnotatable field ) {
|
||||
|
||||
assert(field!=null);
|
||||
|
||||
/*
|
||||
TODO: consider moving this logic to somewhere else
|
||||
so that it can be better shared, for how a field gets
|
||||
annotated doesn't really depend on how we generate accessors.
|
||||
|
||||
so perhaps we should separate those two.
|
||||
*/
|
||||
|
||||
// TODO: consider a visitor
|
||||
if (prop instanceof CAttributePropertyInfo) {
|
||||
annotateAttribute(field);
|
||||
} else if (prop instanceof CElementPropertyInfo) {
|
||||
annotateElement(field);
|
||||
} else if (prop instanceof CValuePropertyInfo) {
|
||||
field.annotate(XmlValue.class);
|
||||
} else if (prop instanceof CReferencePropertyInfo) {
|
||||
annotateReference(field);
|
||||
}
|
||||
|
||||
outline.parent().generateAdapterIfNecessary(prop,field);
|
||||
|
||||
QName st = prop.getSchemaType();
|
||||
if(st!=null)
|
||||
field.annotate2(XmlSchemaTypeWriter.class)
|
||||
.name(st.getLocalPart())
|
||||
.namespace(st.getNamespaceURI());
|
||||
|
||||
if(prop.inlineBinaryData())
|
||||
field.annotate(XmlInlineBinaryData.class);
|
||||
}
|
||||
|
||||
private void annotateReference(JAnnotatable field) {
|
||||
CReferencePropertyInfo rp = (CReferencePropertyInfo) prop;
|
||||
|
||||
TODO.prototype();
|
||||
// this is just a quick hack to get the basic test working
|
||||
|
||||
Collection<CElement> elements = rp.getElements();
|
||||
|
||||
XmlElementRefWriter refw;
|
||||
if(elements.size()==1) {
|
||||
refw = field.annotate2(XmlElementRefWriter.class);
|
||||
CElement e = elements.iterator().next();
|
||||
refw.name(e.getElementName().getLocalPart())
|
||||
.namespace(e.getElementName().getNamespaceURI())
|
||||
.type(e.getType().toType(outline.parent(),IMPLEMENTATION));
|
||||
if(getOptions().target.isLaterThan(SpecVersion.V2_2))
|
||||
refw.required(rp.isRequired());
|
||||
} else
|
||||
if(elements.size()>1) {
|
||||
XmlElementRefsWriter refsw = field.annotate2(XmlElementRefsWriter.class);
|
||||
for( CElement e : elements ) {
|
||||
refw = refsw.value();
|
||||
refw.name(e.getElementName().getLocalPart())
|
||||
.namespace(e.getElementName().getNamespaceURI())
|
||||
.type(e.getType().toType(outline.parent(),IMPLEMENTATION));
|
||||
if(getOptions().target.isLaterThan(SpecVersion.V2_2))
|
||||
refw.required(rp.isRequired());
|
||||
}
|
||||
}
|
||||
|
||||
if(rp.isMixed())
|
||||
field.annotate(XmlMixed.class);
|
||||
|
||||
NClass dh = rp.getDOMHandler();
|
||||
if(dh!=null) {
|
||||
XmlAnyElementWriter xaew = field.annotate2(XmlAnyElementWriter.class);
|
||||
xaew.lax(rp.getWildcard().allowTypedObject);
|
||||
|
||||
final JClass value = dh.toType(outline.parent(),IMPLEMENTATION);
|
||||
if(!value.equals(codeModel.ref(W3CDomHandler.class))) {
|
||||
xaew.value(value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotate the element property 'field'
|
||||
*/
|
||||
private void annotateElement(JAnnotatable field) {
|
||||
CElementPropertyInfo ep = (CElementPropertyInfo) prop;
|
||||
List<CTypeRef> types = ep.getTypes();
|
||||
|
||||
if(ep.isValueList()) {
|
||||
field.annotate(XmlList.class);
|
||||
}
|
||||
|
||||
assert ep.getXmlName()==null;
|
||||
// if( eName!=null ) { // wrapper
|
||||
// XmlElementWrapperWriter xcw = field.annotate2(XmlElementWrapperWriter.class);
|
||||
// xcw.name(eName.getLocalPart())
|
||||
// .namespace(eName.getNamespaceURI());
|
||||
// }
|
||||
|
||||
if (types.size() == 1) {
|
||||
CTypeRef t = types.get(0);
|
||||
writeXmlElementAnnotation(field, t, resolve(t,IMPLEMENTATION), false);
|
||||
} else {
|
||||
for (CTypeRef t : types) {
|
||||
// generate @XmlElements
|
||||
writeXmlElementAnnotation(field, t, resolve(t,IMPLEMENTATION), true);
|
||||
}
|
||||
xesw = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the simplest XmlElement annotation possible taking all semantic optimizations
|
||||
* into account. This method is essentially equivalent to:
|
||||
*
|
||||
* xew.name(ctype.getTagName().getLocalPart())
|
||||
* .namespace(ctype.getTagName().getNamespaceURI())
|
||||
* .type(jtype)
|
||||
* .defaultValue(ctype.getDefaultValue());
|
||||
*
|
||||
* @param field
|
||||
* @param ctype
|
||||
* @param jtype
|
||||
* @param checkWrapper true if the method might need to generate XmlElements
|
||||
*/
|
||||
private void writeXmlElementAnnotation( JAnnotatable field, CTypeRef ctype, JType jtype,
|
||||
boolean checkWrapper ) {
|
||||
|
||||
// lazily create - we don't know if we need to generate anything yet
|
||||
XmlElementWriter xew = null;
|
||||
|
||||
// these values are used to determine how to optimize the generated annotation
|
||||
XmlNsForm formDefault = parent()._package().getElementFormDefault();
|
||||
String propName = prop.getName(false);
|
||||
|
||||
String enclosingTypeNS;
|
||||
|
||||
if(parent().target.getTypeName()==null)
|
||||
enclosingTypeNS = parent()._package().getMostUsedNamespaceURI();
|
||||
else
|
||||
enclosingTypeNS = parent().target.getTypeName().getNamespaceURI();
|
||||
|
||||
// generate the name property?
|
||||
String generatedName = ctype.getTagName().getLocalPart();
|
||||
if(!generatedName.equals(propName)) {
|
||||
if(xew == null) xew = getXew(checkWrapper, field);
|
||||
xew.name(generatedName);
|
||||
}
|
||||
|
||||
// generate the namespace property?
|
||||
String generatedNS = ctype.getTagName().getNamespaceURI();
|
||||
if (((formDefault == XmlNsForm.QUALIFIED) && !generatedNS.equals(enclosingTypeNS)) ||
|
||||
((formDefault == XmlNsForm.UNQUALIFIED) && !generatedNS.equals(""))) {
|
||||
if(xew == null) xew = getXew(checkWrapper, field);
|
||||
xew.namespace(generatedNS);
|
||||
}
|
||||
|
||||
// generate the required() property?
|
||||
CElementPropertyInfo ep = (CElementPropertyInfo) prop;
|
||||
if(ep.isRequired() && exposedType.isReference()) {
|
||||
if(xew == null) xew = getXew(checkWrapper, field);
|
||||
xew.required(true);
|
||||
}
|
||||
|
||||
// generate the type property?
|
||||
|
||||
// I'm not too sure if this is the right place to handle this, but
|
||||
// if the schema definition is requiring this element, we should point to a primitive type,
|
||||
// not wrapper type (to correctly carry forward the required semantics.)
|
||||
// if it's a collection, we can't use a primitive, however.
|
||||
if(ep.isRequired() && !prop.isCollection())
|
||||
jtype = jtype.unboxify();
|
||||
|
||||
// when generating code for 1.4, the runtime can't infer that ArrayList<Foo> derives
|
||||
// from Collection<Foo> (because List isn't parameterized), so always expclitly
|
||||
// generate @XmlElement(type=...)
|
||||
if( !jtype.equals(exposedType) || (getOptions().runtime14 && prop.isCollection())) {
|
||||
if(xew == null) xew = getXew(checkWrapper, field);
|
||||
xew.type(jtype);
|
||||
}
|
||||
|
||||
// generate defaultValue property?
|
||||
final String defaultValue = ctype.getDefaultValue();
|
||||
if (defaultValue!=null) {
|
||||
if(xew == null) xew = getXew(checkWrapper, field);
|
||||
xew.defaultValue(defaultValue);
|
||||
}
|
||||
|
||||
// generate the nillable property?
|
||||
if (ctype.isNillable()) {
|
||||
if(xew == null) xew = getXew(checkWrapper, field);
|
||||
xew.nillable(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Options} in the current compilation context.
|
||||
*/
|
||||
protected final Options getOptions() {
|
||||
return parent().parent().getModel().options;
|
||||
}
|
||||
|
||||
// ugly hack to lazily create
|
||||
private XmlElementsWriter xesw = null;
|
||||
|
||||
private XmlElementWriter getXew(boolean checkWrapper, JAnnotatable field) {
|
||||
XmlElementWriter xew;
|
||||
if(checkWrapper) {
|
||||
if(xesw==null) {
|
||||
xesw = field.annotate2(XmlElementsWriter.class);
|
||||
}
|
||||
xew = xesw.value();
|
||||
} else {
|
||||
xew = field.annotate2(XmlElementWriter.class);
|
||||
}
|
||||
return xew;
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotate the attribute property 'field'
|
||||
*/
|
||||
private void annotateAttribute(JAnnotatable field) {
|
||||
CAttributePropertyInfo ap = (CAttributePropertyInfo) prop;
|
||||
QName attName = ap.getXmlName();
|
||||
|
||||
// [RESULT]
|
||||
// @XmlAttribute(name="foo", required=true, namespace="bar://baz")
|
||||
XmlAttributeWriter xaw = field.annotate2(XmlAttributeWriter.class);
|
||||
|
||||
final String generatedName = attName.getLocalPart();
|
||||
final String generatedNS = attName.getNamespaceURI();
|
||||
|
||||
// Issue 570; always force generating name="" when do it when globalBindings underscoreBinding is set to non default value
|
||||
// generate name property?
|
||||
if(!generatedName.equals(ap.getName(false)) || !generatedName.equals(ap.getName(true)) || (outline.parent().getModel().getNameConverter() != NameConverter.standard)) {
|
||||
xaw.name(generatedName);
|
||||
}
|
||||
|
||||
// generate namespace property?
|
||||
if(!generatedNS.equals("")) { // assume attributeFormDefault == unqualified
|
||||
xaw.namespace(generatedNS);
|
||||
}
|
||||
|
||||
// generate required property?
|
||||
if(ap.isRequired()) {
|
||||
xaw.required(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Useful base class for implementing {@link FieldAccessor}.
|
||||
*/
|
||||
protected abstract class Accessor implements FieldAccessor {
|
||||
|
||||
/**
|
||||
* Evaluates to the target object this accessor should access.
|
||||
*/
|
||||
protected final JExpression $target;
|
||||
|
||||
protected Accessor( JExpression $target ) {
|
||||
this.$target = $target;
|
||||
}
|
||||
|
||||
public final FieldOutline owner() {
|
||||
return AbstractField.this;
|
||||
}
|
||||
|
||||
public final CPropertyInfo getPropertyInfo() {
|
||||
return prop;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// utility methods
|
||||
//
|
||||
//
|
||||
|
||||
/**
|
||||
* Generates the field declaration.
|
||||
*/
|
||||
protected final JFieldVar generateField( JType type ) {
|
||||
return outline.implClass.field( JMod.PROTECTED, type, prop.getName(false) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Case from {@link #exposedType} to {@link #implType} if necessary.
|
||||
*/
|
||||
protected final JExpression castToImplType( JExpression exp ) {
|
||||
if(implType==exposedType)
|
||||
return exp;
|
||||
else
|
||||
return JExpr.cast(implType,exp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the type of a {@link CPropertyInfo}
|
||||
* @param aspect
|
||||
*/
|
||||
protected JType getType(final Aspect aspect) {
|
||||
if(prop.getAdapter()!=null)
|
||||
return prop.getAdapter().customType.toType(outline.parent(),aspect);
|
||||
|
||||
final class TypeList extends ArrayList<JType> {
|
||||
void add( CTypeInfo t ) {
|
||||
add( t.getType().toType(outline.parent(),aspect) );
|
||||
if(t 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
|
||||
add( ((CElementInfo)t).getSubstitutionMembers());
|
||||
}
|
||||
}
|
||||
|
||||
void add( Collection<? extends CTypeInfo> col ) {
|
||||
for (CTypeInfo typeInfo : col)
|
||||
add(typeInfo);
|
||||
}
|
||||
}
|
||||
TypeList r = new TypeList();
|
||||
r.add(prop.ref());
|
||||
|
||||
JType t;
|
||||
if(prop.baseType!=null)
|
||||
t = prop.baseType;
|
||||
else
|
||||
t = TypeUtil.getCommonBaseType(codeModel,r);
|
||||
|
||||
// if item type is unboxable, convert t=Integer -> t=int
|
||||
// the in-memory data structure can't have primitives directly,
|
||||
// but this guarantees that items cannot legal hold null,
|
||||
// which helps us improve the boundary signature between our
|
||||
// data structure and user code
|
||||
if(prop.isUnboxable())
|
||||
t = t.unboxify();
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns contents to be added to javadoc.
|
||||
*/
|
||||
protected final List<Object> listPossibleTypes( CPropertyInfo prop ) {
|
||||
List<Object> r = new ArrayList<Object>();
|
||||
for( CTypeInfo tt : prop.ref() ) {
|
||||
JType t = tt.getType().toType(outline.parent(),Aspect.EXPOSED);
|
||||
if( t.isPrimitive() || t.isArray() )
|
||||
r.add(t.fullName());
|
||||
else {
|
||||
r.add(t);
|
||||
r.add("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* return the Java type for the given type reference in the model.
|
||||
*/
|
||||
private JType resolve(CTypeRef typeRef,Aspect a) {
|
||||
return outline.parent().resolve(typeRef,a);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.generator.bean.field;
|
||||
|
||||
import com.sun.codemodel.internal.JBlock;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JFieldRef;
|
||||
import com.sun.codemodel.internal.JFieldVar;
|
||||
import com.sun.codemodel.internal.JMod;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com), Martin Grebac
|
||||
*/
|
||||
abstract class AbstractFieldWithVar extends AbstractField {
|
||||
|
||||
/**
|
||||
* Field declaration of the actual list object that we use
|
||||
* to store data.
|
||||
*/
|
||||
private JFieldVar field;
|
||||
|
||||
/**
|
||||
* Invoke {@link #createField()} after calling the
|
||||
* constructor.
|
||||
*/
|
||||
AbstractFieldWithVar( ClassOutlineImpl outline, CPropertyInfo prop ) {
|
||||
super(outline,prop);
|
||||
}
|
||||
|
||||
protected final void createField() {
|
||||
field = outline.implClass.field( JMod.PROTECTED,
|
||||
getFieldType(), prop.getName(false) );
|
||||
|
||||
annotate(field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the getter method.
|
||||
*
|
||||
* <p>
|
||||
* This encapsulation is necessary because sometimes we use
|
||||
* {@code isXXXX} as the method name.
|
||||
*/
|
||||
protected String getGetterMethod() {
|
||||
if (getOptions().enableIntrospection) {
|
||||
return ((getFieldType().isPrimitive() &&
|
||||
getFieldType().boxify().getPrimitiveType()==codeModel.BOOLEAN) ?
|
||||
"is":"get") + prop.getName(true);
|
||||
} else {
|
||||
return (getFieldType().boxify().getPrimitiveType()==codeModel.BOOLEAN?"is":"get")+prop.getName(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type used to store the value of the field in memory.
|
||||
*/
|
||||
protected abstract JType getFieldType();
|
||||
|
||||
protected JFieldVar ref() { return field; }
|
||||
|
||||
public final JType getRawType() {
|
||||
return exposedType;
|
||||
}
|
||||
|
||||
protected abstract class Accessor extends AbstractField.Accessor {
|
||||
|
||||
protected Accessor(JExpression $target) {
|
||||
super($target);
|
||||
this.$ref = $target.ref(AbstractFieldWithVar.this.ref());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reference to the field bound by the target object.
|
||||
*/
|
||||
protected final JFieldRef $ref;
|
||||
|
||||
public final void toRawValue(JBlock block, JVar $var) {
|
||||
if (getOptions().enableIntrospection) {
|
||||
block.assign($var,$target.invoke(getGetterMethod()));
|
||||
} else {
|
||||
block.assign($var,$target.invoke(getGetterMethod()));
|
||||
}
|
||||
}
|
||||
|
||||
public final void fromRawValue(JBlock block, String uniqueName, JExpression $var) {
|
||||
block.invoke($target,("set"+prop.getName(true))).arg($var);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
/*
|
||||
* 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.generator.bean.field;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.codemodel.internal.JBlock;
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JFieldRef;
|
||||
import com.sun.codemodel.internal.JFieldVar;
|
||||
import com.sun.codemodel.internal.JMethod;
|
||||
import com.sun.codemodel.internal.JMod;
|
||||
import com.sun.codemodel.internal.JOp;
|
||||
import com.sun.codemodel.internal.JPrimitiveType;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
|
||||
/**
|
||||
* Common code for property renderer that generates a List as
|
||||
* its underlying data structure.
|
||||
*
|
||||
* <p>
|
||||
* For performance reasons, the actual list object used to store
|
||||
* data is lazily created.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
abstract class AbstractListField extends AbstractField {
|
||||
/** The field that stores the list. */
|
||||
protected JFieldVar field;
|
||||
|
||||
/**
|
||||
* a method that lazily initializes a List.
|
||||
* Lazily created.
|
||||
*
|
||||
* [RESULT]
|
||||
* List _getFoo() {
|
||||
* if(field==null)
|
||||
* field = create new list;
|
||||
* return field;
|
||||
* }
|
||||
*/
|
||||
private JMethod internalGetter;
|
||||
|
||||
/**
|
||||
* If this collection property is a collection of a primitive type,
|
||||
* this variable refers to that primitive type.
|
||||
* Otherwise null.
|
||||
*/
|
||||
protected final JPrimitiveType primitiveType;
|
||||
|
||||
protected final JClass listT = codeModel.ref(List.class).narrow(exposedType.boxify());
|
||||
|
||||
/**
|
||||
* True to create a new instance of List eagerly in the constructor.
|
||||
* False otherwise.
|
||||
*
|
||||
* <p>
|
||||
* Setting it to true makes the generated code slower (as more list instances need to be
|
||||
* allocated), but it works correctly if the user specifies the custom type of a list.
|
||||
*/
|
||||
private final boolean eagerInstanciation;
|
||||
|
||||
/**
|
||||
* Call {@link #generate()} method right after this.
|
||||
*/
|
||||
protected AbstractListField(ClassOutlineImpl outline, CPropertyInfo prop, boolean eagerInstanciation) {
|
||||
super(outline,prop);
|
||||
this.eagerInstanciation = eagerInstanciation;
|
||||
|
||||
if( implType instanceof JPrimitiveType ) {
|
||||
// primitive types don't have this tricky distinction
|
||||
assert implType==exposedType;
|
||||
primitiveType = (JPrimitiveType)implType;
|
||||
} else
|
||||
primitiveType = null;
|
||||
}
|
||||
|
||||
protected final void generate() {
|
||||
|
||||
// for the collectionType customization to take effect, the field needs to be strongly typed,
|
||||
// not just List<Foo>.
|
||||
field = outline.implClass.field( JMod.PROTECTED, listT, prop.getName(false) );
|
||||
if(eagerInstanciation)
|
||||
field.init(newCoreList());
|
||||
|
||||
annotate(field);
|
||||
|
||||
// generate the rest of accessors
|
||||
generateAccessors();
|
||||
}
|
||||
|
||||
private void generateInternalGetter() {
|
||||
internalGetter = outline.implClass.method(JMod.PROTECTED,listT,"_get"+prop.getName(true));
|
||||
if(!eagerInstanciation) {
|
||||
// if eagerly instanciated, the field can't be null
|
||||
fixNullRef(internalGetter.body());
|
||||
}
|
||||
internalGetter.body()._return(field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates statement(s) so that the successive {@link Accessor#ref(boolean)} with
|
||||
* true will always return a non-null list.
|
||||
*
|
||||
* This is useful to avoid generating redundant internal getter.
|
||||
*/
|
||||
protected final void fixNullRef(JBlock block) {
|
||||
block._if(field.eq(JExpr._null()))._then()
|
||||
.assign(field,newCoreList());
|
||||
}
|
||||
|
||||
public JType getRawType() {
|
||||
return codeModel.ref(List.class).narrow(exposedType.boxify());
|
||||
}
|
||||
|
||||
private JExpression newCoreList() {
|
||||
return JExpr._new(getCoreListType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Concrete class that implements the List interface.
|
||||
* Used as the actual data storage.
|
||||
*/
|
||||
protected abstract JClass getCoreListType();
|
||||
|
||||
|
||||
/** Generates accessor methods. */
|
||||
protected abstract void generateAccessors();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
protected abstract class Accessor extends AbstractField.Accessor {
|
||||
|
||||
/**
|
||||
* Reference to the {@link AbstractListField#field}
|
||||
* of the target object.
|
||||
*/
|
||||
protected final JFieldRef field;
|
||||
|
||||
protected Accessor( JExpression $target ) {
|
||||
super($target);
|
||||
field = $target.ref(AbstractListField.this.field);
|
||||
}
|
||||
|
||||
|
||||
protected final JExpression unbox( JExpression exp ) {
|
||||
if(primitiveType==null) return exp;
|
||||
else return primitiveType.unwrap(exp);
|
||||
}
|
||||
protected final JExpression box( JExpression exp ) {
|
||||
if(primitiveType==null) return exp;
|
||||
else return primitiveType.wrap(exp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to the List field that stores the data.
|
||||
* <p>
|
||||
* Using this method hides the fact that the list is lazily
|
||||
* created.
|
||||
*
|
||||
* @param canBeNull
|
||||
* if true, the returned expression may be null (this is
|
||||
* when the list is still not constructed.) This could be
|
||||
* useful when the caller can deal with null more efficiently.
|
||||
* When the list is null, it should be treated as if the list
|
||||
* is empty.
|
||||
*
|
||||
* if false, the returned expression will never be null.
|
||||
* This is the behavior users would see.
|
||||
*/
|
||||
protected final JExpression ref(boolean canBeNull) {
|
||||
if(canBeNull)
|
||||
return field;
|
||||
if(internalGetter==null)
|
||||
generateInternalGetter();
|
||||
return $target.invoke(internalGetter);
|
||||
}
|
||||
|
||||
public JExpression count() {
|
||||
return JOp.cond( field.eq(JExpr._null()), JExpr.lit(0), field.invoke("size") );
|
||||
}
|
||||
|
||||
public void unsetValues( JBlock body ) {
|
||||
body.assign(field,JExpr._null());
|
||||
}
|
||||
public JExpression hasSetValue() {
|
||||
return field.ne(JExpr._null()).cand(field.invoke("isEmpty").not());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
/*
|
||||
* 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.generator.bean.field;
|
||||
|
||||
import com.sun.codemodel.internal.JAssignmentTarget;
|
||||
import java.util.List;
|
||||
import com.sun.codemodel.internal.JBlock;
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JForLoop;
|
||||
import com.sun.codemodel.internal.JMethod;
|
||||
import com.sun.codemodel.internal.JMod;
|
||||
import com.sun.codemodel.internal.JOp;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.generator.bean.MethodWriter;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
|
||||
/**
|
||||
* Realizes a property as an "indexed property"
|
||||
* as specified in the JAXB spec.
|
||||
*
|
||||
* <p>
|
||||
* We will generate the following set of methods:
|
||||
* <pre>
|
||||
* T[] getX();
|
||||
* T getX( int idx );
|
||||
* void setX(T[] values);
|
||||
* void setX( int idx, T value );
|
||||
* </pre>
|
||||
*
|
||||
* We still use List as our back storage.
|
||||
* This renderer also handles boxing/unboxing if
|
||||
* T is a boxed type.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
final class ArrayField extends AbstractListField {
|
||||
|
||||
class Accessor extends AbstractListField.Accessor {
|
||||
protected Accessor( JExpression $target ) {
|
||||
super($target);
|
||||
}
|
||||
|
||||
public void toRawValue(JBlock block, JVar $var) {
|
||||
block.assign($var,$target.invoke($getAll));
|
||||
}
|
||||
|
||||
public void fromRawValue(JBlock block, String uniqueName, JExpression $var) {
|
||||
block.invoke($target,$setAll).arg($var);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JExpression hasSetValue() {
|
||||
return field.ne(JExpr._null()).cand(field.ref("length").gt(JExpr.lit(0)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private JMethod $setAll;
|
||||
|
||||
private JMethod $getAll;
|
||||
|
||||
ArrayField(ClassOutlineImpl context, CPropertyInfo prop) {
|
||||
super(context,prop,false);
|
||||
generateArray();
|
||||
}
|
||||
|
||||
protected final void generateArray() {
|
||||
field = outline.implClass.field( JMod.PROTECTED, getCoreListType(), prop.getName(false) );
|
||||
annotate(field);
|
||||
|
||||
// generate the rest of accessors
|
||||
generateAccessors();
|
||||
}
|
||||
|
||||
public void generateAccessors() {
|
||||
|
||||
MethodWriter writer = outline.createMethodWriter();
|
||||
Accessor acc = create(JExpr._this());
|
||||
JVar $idx,$value; JBlock body;
|
||||
|
||||
// [RESULT] T[] getX() {
|
||||
// if( <var>==null ) return new T[0];
|
||||
// T[] retVal = new T[this._return.length] ;
|
||||
// System.arraycopy(this._return, 0, "retVal", 0, this._return.length);
|
||||
// return (retVal);
|
||||
// }
|
||||
$getAll = writer.declareMethod( exposedType.array(),"get"+prop.getName(true));
|
||||
writer.javadoc().append(prop.javadoc);
|
||||
body = $getAll.body();
|
||||
|
||||
body._if( acc.ref(true).eq(JExpr._null()) )._then()
|
||||
._return(JExpr.newArray(exposedType,0));
|
||||
JVar var = body.decl(exposedType.array(), "retVal", JExpr.newArray(implType,acc.ref(true).ref("length")));
|
||||
body.add(codeModel.ref(System.class).staticInvoke("arraycopy")
|
||||
.arg(acc.ref(true)).arg(JExpr.lit(0))
|
||||
.arg(var)
|
||||
.arg(JExpr.lit(0)).arg(acc.ref(true).ref("length")));
|
||||
body._return(JExpr.direct("retVal"));
|
||||
|
||||
List<Object> returnTypes = listPossibleTypes(prop);
|
||||
writer.javadoc().addReturn().append("array of\n").append(returnTypes);
|
||||
|
||||
// [RESULT]
|
||||
// ET getX(int idx) {
|
||||
// if( <var>==null ) throw new IndexOutOfBoundsException();
|
||||
// return unbox(<var>.get(idx));
|
||||
// }
|
||||
JMethod $get = writer.declareMethod(exposedType,"get"+prop.getName(true));
|
||||
$idx = writer.addParameter(codeModel.INT,"idx");
|
||||
|
||||
$get.body()._if(acc.ref(true).eq(JExpr._null()))._then()
|
||||
._throw(JExpr._new(codeModel.ref(IndexOutOfBoundsException.class)));
|
||||
|
||||
writer.javadoc().append(prop.javadoc);
|
||||
$get.body()._return(acc.ref(true).component($idx));
|
||||
|
||||
writer.javadoc().addReturn().append("one of\n").append(returnTypes);
|
||||
|
||||
// [RESULT] int getXLength() {
|
||||
// if( <var>==null ) throw new IndexOutOfBoundsException();
|
||||
// return <ref>.length;
|
||||
// }
|
||||
JMethod $getLength = writer.declareMethod(codeModel.INT,"get"+prop.getName(true)+"Length");
|
||||
$getLength.body()._if(acc.ref(true).eq(JExpr._null()))._then()
|
||||
._return(JExpr.lit(0));
|
||||
$getLength.body()._return(acc.ref(true).ref("length"));
|
||||
|
||||
// [RESULT] void setX(ET[] values) {
|
||||
// int len = values.length;
|
||||
// for( int i=0; i<len; i++ )
|
||||
// <ref>[i] = values[i];
|
||||
// }
|
||||
$setAll = writer.declareMethod(
|
||||
codeModel.VOID,
|
||||
"set"+prop.getName(true));
|
||||
|
||||
writer.javadoc().append(prop.javadoc);
|
||||
$value = writer.addParameter(exposedType.array(),"values");
|
||||
JVar $len = $setAll.body().decl(codeModel.INT,"len", $value.ref("length"));
|
||||
|
||||
$setAll.body().assign(
|
||||
(JAssignmentTarget) acc.ref(true),
|
||||
castToImplTypeArray(JExpr.newArray(
|
||||
codeModel.ref(exposedType.erasure().fullName()),
|
||||
$len)));
|
||||
|
||||
JForLoop _for = $setAll.body()._for();
|
||||
JVar $i = _for.init( codeModel.INT, "i", JExpr.lit(0) );
|
||||
_for.test( JOp.lt($i,$len) );
|
||||
_for.update( $i.incr() );
|
||||
_for.body().assign(acc.ref(true).component($i), castToImplType(acc.box($value.component($i))));
|
||||
|
||||
writer.javadoc().addParam($value)
|
||||
.append("allowed objects are\n")
|
||||
.append(returnTypes);
|
||||
|
||||
// [RESULT] ET setX(int idx, ET value)
|
||||
// <ref>[idx] = value
|
||||
JMethod $set = writer.declareMethod(
|
||||
exposedType,
|
||||
"set"+prop.getName(true));
|
||||
$idx = writer.addParameter( codeModel.INT, "idx" );
|
||||
$value = writer.addParameter( exposedType, "value" );
|
||||
|
||||
writer.javadoc().append(prop.javadoc);
|
||||
|
||||
body = $set.body();
|
||||
body._return( JExpr.assign(acc.ref(true).component($idx),
|
||||
castToImplType(acc.box($value))));
|
||||
|
||||
writer.javadoc().addParam($value)
|
||||
.append("allowed object is\n")
|
||||
.append(returnTypes);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public JType getRawType() {
|
||||
return exposedType.array();
|
||||
}
|
||||
|
||||
protected JClass getCoreListType() {
|
||||
return exposedType.array();
|
||||
}
|
||||
|
||||
public Accessor create(JExpression targetObject) {
|
||||
return new Accessor(targetObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Case from {@link #exposedType} to array of {@link #implType} .
|
||||
*/
|
||||
protected final JExpression castToImplTypeArray( JExpression exp ) {
|
||||
return JExpr.cast(implType.array(), exp);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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.generator.bean.field;
|
||||
|
||||
import com.sun.codemodel.internal.JBlock;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JFieldVar;
|
||||
import com.sun.codemodel.internal.JMod;
|
||||
import com.sun.codemodel.internal.JPrimitiveType;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.outline.FieldAccessor;
|
||||
|
||||
/**
|
||||
* Realizes a property as a "public static final" property on the interface.
|
||||
* This class can handle both boxed/unboxed types and both
|
||||
* single/colllection.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
final class ConstField extends AbstractField {
|
||||
// /**
|
||||
// * Number of items in this property, when
|
||||
// * {@link #isCollection}==true.
|
||||
// */
|
||||
// private final int count=1;
|
||||
|
||||
/** Generated constant property on the interface. */
|
||||
private final JFieldVar $ref;
|
||||
|
||||
ConstField( ClassOutlineImpl outline, CPropertyInfo prop ) {
|
||||
super(outline,prop);
|
||||
|
||||
// we only support value constraints for a single-value property.
|
||||
assert !prop.isCollection();
|
||||
|
||||
JPrimitiveType ptype = implType.boxify().getPrimitiveType();
|
||||
|
||||
// generate the constant
|
||||
JExpression defaultValue = null;
|
||||
if(prop.defaultValue!=null)
|
||||
defaultValue = prop.defaultValue.compute(outline.parent());
|
||||
|
||||
$ref = outline.ref.field(JMod.PUBLIC|JMod.STATIC|JMod.FINAL,
|
||||
ptype!=null?ptype:implType, prop.getName(true), defaultValue );
|
||||
$ref.javadoc().append(prop.javadoc);
|
||||
|
||||
annotate($ref);
|
||||
}
|
||||
|
||||
public JType getRawType() {
|
||||
// if( isCollection ) return getInfo().array();
|
||||
return exposedType;
|
||||
}
|
||||
|
||||
|
||||
public FieldAccessor create(JExpression target) {
|
||||
return new Accessor(target);
|
||||
}
|
||||
|
||||
private class Accessor extends AbstractField.Accessor {
|
||||
|
||||
Accessor( JExpression $target ) {
|
||||
super($target);
|
||||
}
|
||||
|
||||
public void unsetValues( JBlock body ) {
|
||||
; // can't unset values
|
||||
}
|
||||
public JExpression hasSetValue() {
|
||||
return null; // can't generate the isSet/unset methods
|
||||
}
|
||||
public void toRawValue(JBlock block, JVar $var) {
|
||||
// TODO: rethink abstraction. Those constant fields
|
||||
// don't have "access" to them.
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void fromRawValue(JBlock block, String uniqueName, JExpression $var) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.generator.bean.field;
|
||||
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.outline.FieldOutline;
|
||||
|
||||
/**
|
||||
* {@link FieldRenderer} for possibly constant field.
|
||||
*
|
||||
* <p>
|
||||
* Since we don't know if the constant can be actually generated until
|
||||
* we get to the codemodel building phase, this renderer lazily
|
||||
* determines if it wants to generate a constant field or a normal property.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
final class ConstFieldRenderer implements FieldRenderer {
|
||||
|
||||
private final FieldRenderer fallback;
|
||||
|
||||
protected ConstFieldRenderer(FieldRenderer fallback) {
|
||||
this.fallback = fallback;
|
||||
}
|
||||
|
||||
public FieldOutline generate(ClassOutlineImpl outline, CPropertyInfo prop) {
|
||||
if(prop.defaultValue.compute(outline.parent())==null)
|
||||
return fallback.generate(outline, prop);
|
||||
else
|
||||
return new ConstField(outline,prop);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* 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.generator.bean.field;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.codemodel.internal.JBlock;
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JMethod;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.generator.bean.MethodWriter;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.outline.Aspect;
|
||||
import com.sun.xml.internal.bind.api.impl.NameConverter;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Realizes a property as an untyped {@link List}.
|
||||
*
|
||||
* <pre>
|
||||
* List getXXX();
|
||||
* </pre>
|
||||
*
|
||||
* <h2>Default value handling</h2>
|
||||
* <p>
|
||||
* Since unmarshaller just adds new values into the storage,
|
||||
* we can't fill the storage by default values at the time of
|
||||
* instanciation. (or oherwise values found in the document will
|
||||
* be appended to default values, where it should overwrite them.)
|
||||
* <p>
|
||||
* Therefore, when the object is created, the storage will be empty.
|
||||
* When the getXXX method is called, we'll check if the storage is
|
||||
* modified in anyway. If it is modified, it must mean that the values
|
||||
* are found in the document, so we just return it.
|
||||
*
|
||||
* Otherwise we will fill in default values and return it to the user.
|
||||
*
|
||||
* <p>
|
||||
* When a list has default values, its dirty flag is set to true.
|
||||
* Marshaller will check this and treat it appropriately.
|
||||
*
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public class ContentListField extends AbstractListField {
|
||||
|
||||
/**
|
||||
* A concrete class that implements the List interface.
|
||||
* An instance of this class will be used to store data
|
||||
* for this field.
|
||||
*/
|
||||
private final JClass coreList;
|
||||
|
||||
/** List getFIELD() method. */
|
||||
private JMethod $get;
|
||||
|
||||
/**
|
||||
* @param coreList
|
||||
* A concrete class that implements the List interface.
|
||||
* An instance of this class will be used to store data
|
||||
* for this field.
|
||||
*/
|
||||
protected ContentListField(ClassOutlineImpl context, CPropertyInfo prop, JClass coreList) {
|
||||
// the JAXB runtime picks ArrayList if the signature is List,
|
||||
// so don't do eager allocation if it's ArrayList.
|
||||
// otherwise we need to do eager allocation so that the collection type specified by the user
|
||||
// will be used.
|
||||
super(context, prop, false);
|
||||
this.coreList = coreList;
|
||||
generate();
|
||||
}
|
||||
|
||||
protected final JClass getCoreListType() {
|
||||
return coreList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateAccessors() {
|
||||
final MethodWriter writer = outline.createMethodWriter();
|
||||
final Accessor acc = create(JExpr._this());
|
||||
|
||||
// [RESULT]
|
||||
// List getXXX() {
|
||||
// return <ref>;
|
||||
// }
|
||||
$get = writer.declareMethod(listT,"get"+prop.getName(true));
|
||||
writer.javadoc().append(prop.javadoc);
|
||||
JBlock block = $get.body();
|
||||
fixNullRef(block); // avoid using an internal getter
|
||||
block._return(acc.ref(true));
|
||||
|
||||
String pname = NameConverter.standard.toVariableName(prop.getName(true));
|
||||
writer.javadoc().append(
|
||||
"Gets the value of the "+pname+" property.\n\n"+
|
||||
"<p>\n" +
|
||||
"This accessor method returns a reference to the live list,\n" +
|
||||
"not a snapshot. Therefore any modification you make to the\n" +
|
||||
"returned list will be present inside the JAXB object.\n" +
|
||||
"This is why there is not a <CODE>set</CODE> method for the " +pname+ " property.\n" +
|
||||
"\n"+
|
||||
"<p>\n" +
|
||||
"For example, to add a new item, do as follows:\n"+
|
||||
"<pre>\n"+
|
||||
" get"+prop.getName(true)+"().add(newItem);\n"+
|
||||
"</pre>\n"+
|
||||
"\n\n"
|
||||
);
|
||||
|
||||
writer.javadoc().append(
|
||||
"<p>\n" +
|
||||
"Objects of the following type(s) are allowed in the list\n")
|
||||
.append(listPossibleTypes(prop));
|
||||
}
|
||||
|
||||
public Accessor create(JExpression targetObject) {
|
||||
return new Accessor(targetObject);
|
||||
}
|
||||
|
||||
class Accessor extends AbstractListField.Accessor {
|
||||
protected Accessor( JExpression $target ) {
|
||||
super($target);
|
||||
}
|
||||
|
||||
public void toRawValue(JBlock block, JVar $var) {
|
||||
// [RESULT]
|
||||
// $<var>.addAll(bean.getLIST());
|
||||
// list.toArray( array );
|
||||
block.assign($var,JExpr._new(codeModel.ref(ArrayList.class).narrow(exposedType.boxify())).arg(
|
||||
$target.invoke($get)
|
||||
));
|
||||
}
|
||||
|
||||
public void fromRawValue(JBlock block, String uniqueName, JExpression $var) {
|
||||
// [RESULT]
|
||||
// bean.getLIST().addAll($<var>);
|
||||
JVar $list = block.decl(listT,uniqueName+'l',$target.invoke($get));
|
||||
block.invoke($list,"addAll").arg($var);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JType getType(final Aspect aspect) {
|
||||
if (Aspect.IMPLEMENTATION.equals(aspect)) {
|
||||
return super.getType(aspect);
|
||||
}
|
||||
return codeModel.ref(Serializable.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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.generator.bean.field;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CReferencePropertyInfo;
|
||||
import com.sun.tools.internal.xjc.outline.FieldOutline;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Default implementation of the FieldRendererFactory
|
||||
* that faithfully implements the semantics demanded by the JAXB spec.
|
||||
*
|
||||
* <p>
|
||||
* This class is just a facade --- it just determines which
|
||||
* {@link FieldRenderer} to use and just delegate the work.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
final class DefaultFieldRenderer implements FieldRenderer {
|
||||
|
||||
private final FieldRendererFactory frf;
|
||||
|
||||
/**
|
||||
* Use {@link FieldRendererFactory#getDefault()}.
|
||||
*/
|
||||
DefaultFieldRenderer(FieldRendererFactory frf) {
|
||||
this.frf = frf;
|
||||
}
|
||||
|
||||
public DefaultFieldRenderer(FieldRendererFactory frf, FieldRenderer defaultCollectionFieldRenderer ) {
|
||||
this.frf = frf;
|
||||
this.defaultCollectionFieldRenderer = defaultCollectionFieldRenderer;
|
||||
}
|
||||
|
||||
private FieldRenderer defaultCollectionFieldRenderer;
|
||||
|
||||
|
||||
public FieldOutline generate(ClassOutlineImpl outline, CPropertyInfo prop) {
|
||||
return decideRenderer(outline,prop).generate(outline,prop);
|
||||
}
|
||||
|
||||
private FieldRenderer decideRenderer(ClassOutlineImpl outline, CPropertyInfo prop) {
|
||||
|
||||
if (prop instanceof CReferencePropertyInfo) {
|
||||
CReferencePropertyInfo p = (CReferencePropertyInfo)prop;
|
||||
if (p.isDummy()) {
|
||||
return frf.getDummyList(outline.parent().getCodeModel().ref(ArrayList.class));
|
||||
}
|
||||
if (p.isContent() && (p.isMixedExtendedCust())) {
|
||||
return frf.getContentList(outline.parent().getCodeModel().ref(ArrayList.class).narrow(Serializable.class));
|
||||
}
|
||||
}
|
||||
|
||||
if(!prop.isCollection()) {
|
||||
// non-collection field
|
||||
|
||||
// TODO: check for bidning info for optionalPrimitiveType=boxed or
|
||||
// noHasMethod=false and noDeletedMethod=false
|
||||
if(prop.isUnboxable())
|
||||
// this one uses a primitive type as much as possible
|
||||
return frf.getRequiredUnboxed();
|
||||
else
|
||||
// otherwise use the default non-collection field
|
||||
return frf.getSingle();
|
||||
}
|
||||
|
||||
if( defaultCollectionFieldRenderer==null ) {
|
||||
return frf.getList(outline.parent().getCodeModel().ref(ArrayList.class));
|
||||
}
|
||||
|
||||
// this field is a collection field.
|
||||
// use untyped list as the default. This is consistent
|
||||
// to the JAXB spec.
|
||||
return defaultCollectionFieldRenderer;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* 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.generator.bean.field;
|
||||
|
||||
import com.sun.codemodel.internal.JAnnotatable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.codemodel.internal.JBlock;
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JMethod;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CReferencePropertyInfo;
|
||||
import com.sun.xml.internal.bind.annotation.OverrideAnnotationOf;
|
||||
|
||||
/**
|
||||
* Realizes a property as an untyped {@link List}.
|
||||
*
|
||||
* <pre>
|
||||
* List getXXX();
|
||||
* </pre>
|
||||
*
|
||||
* <h2>Default value handling</h2>
|
||||
* <p>
|
||||
* Since unmarshaller just adds new values into the storage,
|
||||
* we can't fill the storage by default values at the time of
|
||||
* instanciation. (or oherwise values found in the document will
|
||||
* be appended to default values, where it should overwrite them.)
|
||||
* <p>
|
||||
* Therefore, when the object is created, the storage will be empty.
|
||||
* When the getXXX method is called, we'll check if the storage is
|
||||
* modified in anyway. If it is modified, it must mean that the values
|
||||
* are found in the document, so we just return it.
|
||||
*
|
||||
* Otherwise we will fill in default values and return it to the user.
|
||||
*
|
||||
* <p>
|
||||
* When a list has default values, its dirty flag is set to true.
|
||||
* Marshaller will check this and treat it appropriately.
|
||||
*
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public class DummyListField extends AbstractListField {
|
||||
|
||||
/**
|
||||
* A concrete class that imp lements the List interface.
|
||||
* An instance of this class will be used to store data
|
||||
* for this field.
|
||||
*/
|
||||
private final JClass coreList;
|
||||
|
||||
|
||||
/** List getFIELD() method. */
|
||||
private JMethod $get;
|
||||
|
||||
/**
|
||||
* @param coreList
|
||||
* A concrete class that implements the List interface.
|
||||
* An instance of this class will be used to store data
|
||||
* for this field.
|
||||
*/
|
||||
protected DummyListField(ClassOutlineImpl context, CPropertyInfo prop, JClass coreList) {
|
||||
// the JAXB runtime picks ArrayList if the signature is List,
|
||||
// so don't do eager allocation if it's ArrayList.
|
||||
// otherwise we need to do eager allocation so that the collection type specified by the user
|
||||
// will be used.
|
||||
super(context, prop, !coreList.fullName().equals("java.util.ArrayList"));
|
||||
this.coreList = coreList.narrow(exposedType.boxify());
|
||||
generate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotate the field according to the recipes given as {@link CPropertyInfo}.
|
||||
*/
|
||||
@Override
|
||||
protected void annotate( JAnnotatable field ) {
|
||||
super.annotate(field);
|
||||
|
||||
if (prop instanceof CReferencePropertyInfo) {
|
||||
CReferencePropertyInfo pref = (CReferencePropertyInfo)prop;
|
||||
if (pref.isDummy()) {
|
||||
annotateDummy(field);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void annotateDummy(JAnnotatable field) {
|
||||
field.annotate(OverrideAnnotationOf.class);
|
||||
}
|
||||
|
||||
protected final JClass getCoreListType() {
|
||||
return coreList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateAccessors() { }
|
||||
|
||||
public Accessor create(JExpression targetObject) {
|
||||
return new Accessor(targetObject);
|
||||
}
|
||||
|
||||
class Accessor extends AbstractListField.Accessor {
|
||||
protected Accessor( JExpression $target ) {
|
||||
super($target);
|
||||
}
|
||||
|
||||
public void toRawValue(JBlock block, JVar $var) {
|
||||
// [RESULT]
|
||||
// $<var>.addAll(bean.getLIST());
|
||||
// list.toArray( array );
|
||||
block.assign($var,JExpr._new(codeModel.ref(ArrayList.class).narrow(exposedType.boxify())).arg(
|
||||
$target.invoke($get)
|
||||
));
|
||||
}
|
||||
|
||||
public void fromRawValue(JBlock block, String uniqueName, JExpression $var) {
|
||||
// [RESULT]
|
||||
// bean.getLIST().addAll($<var>);
|
||||
JVar $list = block.decl(listT,uniqueName+'l',$target.invoke($get));
|
||||
block.invoke($list,"addAll").arg($var);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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.generator.bean.field;
|
||||
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.outline.FieldOutline;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract model of one field in a generated class.
|
||||
*
|
||||
* <p>
|
||||
* Responsible for "realizing" a Java property by actually generating
|
||||
* members(s) to store the property value and a set of methods
|
||||
* to manipulate them.
|
||||
*
|
||||
* <p>
|
||||
* Objects that implement this interface also encapsulates the
|
||||
* <b>internal</b> access to the field.
|
||||
*
|
||||
* <p>
|
||||
* For discussion of the model this interface is representing, see
|
||||
* the "field meta model" design document.
|
||||
*
|
||||
* REVISIT:
|
||||
* refactor this to two interfaces that provide
|
||||
* (1) internal access and (2) external access.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public interface FieldRenderer {
|
||||
/**
|
||||
* Generates accesssors and fields for the given implementation
|
||||
* class, then return {@link FieldOutline} for accessing
|
||||
* the generated field.
|
||||
*/
|
||||
public FieldOutline generate( ClassOutlineImpl context, CPropertyInfo prop);
|
||||
|
||||
// //
|
||||
// // field renderers
|
||||
// //
|
||||
// public static final FieldRenderer DEFAULT
|
||||
// = new DefaultFieldRenderer();
|
||||
//
|
||||
// public static final FieldRenderer ARRAY
|
||||
// = new GenericFieldRenderer(ArrayField.class);
|
||||
//
|
||||
// public static final FieldRenderer REQUIRED_UNBOXED
|
||||
// = new GenericFieldRenderer(UnboxedField.class);
|
||||
//
|
||||
// public static final FieldRenderer SINGLE
|
||||
// = new GenericFieldRenderer(SingleField.class);
|
||||
//
|
||||
// public static final FieldRenderer SINGLE_PRIMITIVE_ACCESS
|
||||
// = new GenericFieldRenderer(SinglePrimitiveAccessField.class);
|
||||
//
|
||||
// public static final FieldRenderer JAXB_DEFAULT
|
||||
// = new DefaultFieldRenderer();
|
||||
}
|
||||
@@ -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.generator.bean.field;
|
||||
|
||||
import com.sun.tools.internal.xjc.Options;
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
|
||||
/**
|
||||
* Factory for {@link FieldRenderer}.
|
||||
*
|
||||
* <p>
|
||||
* This class can be overridden by a plugin to change the code generation
|
||||
* behavior of XJC. Note that such changes aren't composable; for a given
|
||||
* schema compilation, only one instance of {@link FieldRendererFactory} is
|
||||
* used.
|
||||
*
|
||||
* <p>
|
||||
* See {@link Options#fieldRendererFactory}
|
||||
*
|
||||
* <p>
|
||||
* To be more precise, since {@link FieldRenderer} is just a strategy pattern
|
||||
* and by itself is stateless, the "factory methods" don't necessarily need
|
||||
* to create new instances of {@link FieldRenderer} --- it can just return
|
||||
* a set of pre-created instances.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class FieldRendererFactory {
|
||||
|
||||
public FieldRenderer getDefault() {
|
||||
return DEFAULT;
|
||||
}
|
||||
public FieldRenderer getArray() {
|
||||
return ARRAY;
|
||||
}
|
||||
public FieldRenderer getRequiredUnboxed() {
|
||||
return REQUIRED_UNBOXED;
|
||||
}
|
||||
public FieldRenderer getSingle() {
|
||||
return SINGLE;
|
||||
}
|
||||
public FieldRenderer getSinglePrimitiveAccess() {
|
||||
return SINGLE_PRIMITIVE_ACCESS;
|
||||
}
|
||||
public FieldRenderer getList(JClass coreList) {
|
||||
return new UntypedListFieldRenderer(coreList);
|
||||
}
|
||||
public FieldRenderer getContentList(JClass coreList) {
|
||||
return new UntypedListFieldRenderer(coreList, false, true);
|
||||
}
|
||||
public FieldRenderer getDummyList(JClass coreList) {
|
||||
return new UntypedListFieldRenderer(coreList, true, false);
|
||||
}
|
||||
public FieldRenderer getConst(FieldRenderer fallback) {
|
||||
return new ConstFieldRenderer(fallback);
|
||||
}
|
||||
|
||||
private final FieldRenderer DEFAULT
|
||||
= new DefaultFieldRenderer(this);
|
||||
|
||||
private static final FieldRenderer ARRAY
|
||||
= new GenericFieldRenderer(ArrayField.class);
|
||||
|
||||
private static final FieldRenderer REQUIRED_UNBOXED
|
||||
= new GenericFieldRenderer(UnboxedField.class);
|
||||
|
||||
private static final FieldRenderer SINGLE
|
||||
= new GenericFieldRenderer(SingleField.class);
|
||||
|
||||
private static final FieldRenderer SINGLE_PRIMITIVE_ACCESS
|
||||
= new GenericFieldRenderer(SinglePrimitiveAccessField.class);
|
||||
}
|
||||
@@ -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.generator.bean.field;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.outline.FieldOutline;
|
||||
|
||||
/**
|
||||
* Creates
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public final class GenericFieldRenderer implements FieldRenderer {
|
||||
private Constructor constructor;
|
||||
|
||||
public GenericFieldRenderer( Class fieldClass ) {
|
||||
try {
|
||||
constructor = fieldClass.getDeclaredConstructor(new Class[]{ClassOutlineImpl.class,CPropertyInfo.class});
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new NoSuchMethodError(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public FieldOutline generate(ClassOutlineImpl context, CPropertyInfo prop) {
|
||||
try {
|
||||
return (FieldOutline)constructor.newInstance(new Object[]{context,prop});
|
||||
} catch (InstantiationException e) {
|
||||
throw new InstantiationError(e.getMessage());
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new IllegalAccessError(e.getMessage());
|
||||
} catch (InvocationTargetException e) {
|
||||
Throwable t = e.getTargetException();
|
||||
if(t instanceof RuntimeException)
|
||||
throw (RuntimeException)t;
|
||||
if(t instanceof Error)
|
||||
throw (Error)t;
|
||||
|
||||
// impossible
|
||||
throw new AssertionError(t);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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.generator.bean.field;
|
||||
|
||||
import com.sun.codemodel.internal.JBlock;
|
||||
import com.sun.codemodel.internal.JCodeModel;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.generator.bean.MethodWriter;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.outline.FieldAccessor;
|
||||
import com.sun.tools.internal.xjc.outline.FieldOutline;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public class IsSetField extends AbstractField {
|
||||
|
||||
private final FieldOutline core;
|
||||
|
||||
private final boolean generateUnSetMethod;
|
||||
private final boolean generateIsSetMethod;
|
||||
|
||||
protected IsSetField( ClassOutlineImpl outline, CPropertyInfo prop,
|
||||
FieldOutline core, boolean unsetMethod, boolean issetMethod ) {
|
||||
super(outline,prop);
|
||||
this.core = core;
|
||||
this.generateIsSetMethod = issetMethod;
|
||||
this.generateUnSetMethod = unsetMethod;
|
||||
|
||||
generate(outline,prop);
|
||||
}
|
||||
|
||||
|
||||
private void generate( ClassOutlineImpl outline, CPropertyInfo prop ) {
|
||||
// add isSetXXX and unsetXXX.
|
||||
MethodWriter writer = outline.createMethodWriter();
|
||||
|
||||
JCodeModel codeModel = outline.parent().getCodeModel();
|
||||
|
||||
FieldAccessor acc = core.create(JExpr._this());
|
||||
|
||||
if( generateIsSetMethod ) {
|
||||
// [RESULT] boolean isSetXXX()
|
||||
JExpression hasSetValue = acc.hasSetValue();
|
||||
if( hasSetValue==null ) {
|
||||
// this field renderer doesn't support the isSet/unset methods generation.
|
||||
// issue an error
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
writer.declareMethod(codeModel.BOOLEAN,"isSet"+this.prop.getName(true))
|
||||
.body()._return( hasSetValue );
|
||||
}
|
||||
|
||||
if( generateUnSetMethod ) {
|
||||
// [RESULT] void unsetXXX()
|
||||
acc.unsetValues(
|
||||
writer.declareMethod(codeModel.VOID,"unset"+this.prop.getName(true)).body() );
|
||||
}
|
||||
}
|
||||
|
||||
public JType getRawType() {
|
||||
return core.getRawType();
|
||||
}
|
||||
|
||||
public FieldAccessor create(JExpression targetObject) {
|
||||
return new Accessor(targetObject);
|
||||
}
|
||||
|
||||
private class Accessor extends AbstractField.Accessor {
|
||||
|
||||
private final FieldAccessor core;
|
||||
|
||||
Accessor( JExpression $target ) {
|
||||
super($target);
|
||||
this.core = IsSetField.this.core.create($target);
|
||||
}
|
||||
|
||||
|
||||
public void unsetValues( JBlock body ) {
|
||||
core.unsetValues(body);
|
||||
}
|
||||
public JExpression hasSetValue() {
|
||||
return core.hasSetValue();
|
||||
}
|
||||
public void toRawValue(JBlock block, JVar $var) {
|
||||
core.toRawValue(block,$var);
|
||||
}
|
||||
|
||||
public void fromRawValue(JBlock block, String uniqueName, JExpression $var) {
|
||||
core.fromRawValue(block,uniqueName,$var);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.generator.bean.field;
|
||||
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.outline.FieldOutline;
|
||||
|
||||
/**
|
||||
* FieldRenderer that wraps another field generator
|
||||
* and produces isSetXXX unsetXXX methods.
|
||||
*
|
||||
* <p>
|
||||
* This follows the decorator design pattern so that
|
||||
* the caller of FieldRenderer can forget about details
|
||||
* of the method generation.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public class IsSetFieldRenderer implements FieldRenderer {
|
||||
private final FieldRenderer core;
|
||||
private final boolean generateUnSetMethod;
|
||||
private final boolean generateIsSetMethod;
|
||||
|
||||
public IsSetFieldRenderer(
|
||||
FieldRenderer core,
|
||||
boolean generateUnSetMethod, boolean generateIsSetMethod ) {
|
||||
|
||||
this.core = core;
|
||||
this.generateUnSetMethod = generateUnSetMethod;
|
||||
this.generateIsSetMethod = generateIsSetMethod;
|
||||
}
|
||||
|
||||
public FieldOutline generate(ClassOutlineImpl context, CPropertyInfo prop) {
|
||||
return new IsSetField(context,prop,
|
||||
core.generate(context, prop),
|
||||
generateUnSetMethod,generateIsSetMethod);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.generator.bean.field;
|
||||
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Message resources
|
||||
*/
|
||||
public enum Messages {
|
||||
DEFAULT_GETTER_JAVADOC, // 1 arg
|
||||
DEFAULT_SETTER_JAVADOC, // 1 arg
|
||||
;
|
||||
|
||||
private static final ResourceBundle rb = ResourceBundle.getBundle(Messages.class.getName().substring(0, Messages.class.getName().lastIndexOf('.'))+ ".MessageBundle");
|
||||
|
||||
public String toString() {
|
||||
return format();
|
||||
}
|
||||
|
||||
public String format( Object... args ) {
|
||||
return MessageFormat.format( rb.getString(name()), args );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* 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.generator.bean.field;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.codemodel.internal.JBlock;
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JMethod;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.generator.bean.MethodWriter;
|
||||
import com.sun.tools.internal.xjc.model.CElement;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CReferencePropertyInfo;
|
||||
import com.sun.tools.internal.xjc.outline.Aspect;
|
||||
import com.sun.xml.internal.bind.api.impl.NameConverter;
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Realizes a property as an untyped {@link List}.
|
||||
*
|
||||
* <pre>
|
||||
* List getXXX();
|
||||
* </pre>
|
||||
*
|
||||
* <h2>Default value handling</h2>
|
||||
* <p>
|
||||
* Since unmarshaller just adds new values into the storage,
|
||||
* we can't fill the storage by default values at the time of
|
||||
* instanciation. (or oherwise values found in the document will
|
||||
* be appended to default values, where it should overwrite them.)
|
||||
* <p>
|
||||
* Therefore, when the object is created, the storage will be empty.
|
||||
* When the getXXX method is called, we'll check if the storage is
|
||||
* modified in anyway. If it is modified, it must mean that the values
|
||||
* are found in the document, so we just return it.
|
||||
*
|
||||
* Otherwise we will fill in default values and return it to the user.
|
||||
*
|
||||
* <p>
|
||||
* When a list has default values, its dirty flag is set to true.
|
||||
* Marshaller will check this and treat it appropriately.
|
||||
*
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public class NoExtendedContentField extends AbstractListField {
|
||||
|
||||
/**
|
||||
* A concrete class that implements the List interface.
|
||||
* An instance of this class will be used to store data
|
||||
* for this field.
|
||||
*/
|
||||
private final JClass coreList;
|
||||
|
||||
/** List getFIELD() method. */
|
||||
private JMethod $get;
|
||||
|
||||
/**
|
||||
* @param coreList
|
||||
* A concrete class that implements the List interface.
|
||||
* An instance of this class will be used to store data
|
||||
* for this field.
|
||||
*/
|
||||
protected NoExtendedContentField(ClassOutlineImpl context, CPropertyInfo prop, JClass coreList) {
|
||||
// the JAXB runtime picks ArrayList if the signature is List,
|
||||
// so don't do eager allocation if it's ArrayList.
|
||||
// otherwise we need to do eager allocation so that the collection type specified by the user
|
||||
// will be used.
|
||||
super(context, prop, false);
|
||||
this.coreList = coreList;
|
||||
generate();
|
||||
}
|
||||
|
||||
protected final JClass getCoreListType() {
|
||||
return coreList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateAccessors() {
|
||||
final MethodWriter writer = outline.createMethodWriter();
|
||||
final Accessor acc = create(JExpr._this());
|
||||
|
||||
// [RESULT]
|
||||
// List getXXX() {
|
||||
// return <ref>;
|
||||
// }
|
||||
$get = writer.declareMethod(listT,"get"+prop.getName(true));
|
||||
writer.javadoc().append(prop.javadoc);
|
||||
JBlock block = $get.body();
|
||||
fixNullRef(block); // avoid using an internal getter
|
||||
block._return(acc.ref(true));
|
||||
|
||||
String pname = NameConverter.standard.toVariableName(prop.getName(true));
|
||||
writer.javadoc().append(
|
||||
"Gets the value of the "+pname+" property.\n\n"+
|
||||
"<p>\n" +
|
||||
"This accessor method returns a reference to the live list,\n" +
|
||||
"not a snapshot. Therefore any modification you make to the\n" +
|
||||
"returned list will be present inside the JAXB object.\n" +
|
||||
"This is why there is not a <CODE>set</CODE> method for the " +pname+ " property.\n" +
|
||||
"\n"+
|
||||
"<p>\n" +
|
||||
"For example, to add a new item, do as follows:\n"+
|
||||
"<pre>\n"+
|
||||
" get"+prop.getName(true)+"().add(newItem);\n"+
|
||||
"</pre>\n"+
|
||||
"\n\n"
|
||||
);
|
||||
|
||||
writer.javadoc().append(
|
||||
"<p>\n" +
|
||||
"Objects of the following type(s) are allowed in the list\n")
|
||||
.append(listPossibleTypes(prop));
|
||||
}
|
||||
|
||||
public Accessor create(JExpression targetObject) {
|
||||
return new Accessor(targetObject);
|
||||
}
|
||||
|
||||
class Accessor extends AbstractListField.Accessor {
|
||||
protected Accessor( JExpression $target ) {
|
||||
super($target);
|
||||
}
|
||||
|
||||
public void toRawValue(JBlock block, JVar $var) {
|
||||
// [RESULT]
|
||||
// $<var>.addAll(bean.getLIST());
|
||||
// list.toArray( array );
|
||||
block.assign($var,JExpr._new(codeModel.ref(ArrayList.class).narrow(getType(Aspect.EXPOSED).boxify())).arg(
|
||||
$target.invoke($get)
|
||||
));
|
||||
}
|
||||
|
||||
public void fromRawValue(JBlock block, String uniqueName, JExpression $var) {
|
||||
// [RESULT]
|
||||
// bean.getLIST().addAll($<var>);
|
||||
JVar $list = block.decl(listT,uniqueName+'l',$target.invoke($get));
|
||||
block.invoke($list,"addAll").arg($var);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JType getType(final Aspect aspect) {
|
||||
if (Aspect.IMPLEMENTATION.equals(aspect)) {
|
||||
return super.getType(aspect);
|
||||
}
|
||||
|
||||
if (prop instanceof CReferencePropertyInfo) {
|
||||
Set<CElement> elements = ((CReferencePropertyInfo)prop).getElements();
|
||||
if ((elements != null) && (elements.size() > 0)) {
|
||||
return codeModel.ref(Serializable.class);
|
||||
}
|
||||
}
|
||||
|
||||
return codeModel.ref(String.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* 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.generator.bean.field;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.codemodel.internal.JBlock;
|
||||
import com.sun.codemodel.internal.JConditional;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JMethod;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.generator.bean.MethodWriter;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.outline.FieldAccessor;
|
||||
import com.sun.xml.internal.bind.api.impl.NameConverter;
|
||||
|
||||
/**
|
||||
* Realizes a property through one getter and one setter.
|
||||
* This renders:
|
||||
*
|
||||
* <pre>
|
||||
* T' field;
|
||||
* T getXXX() { ... }
|
||||
* void setXXX(T value) { ... }
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* Normally T'=T, but under some tricky circumstances they could be different
|
||||
* (like T'=Integer, T=int.)
|
||||
*
|
||||
* This realization is only applicable to fields with (1,1)
|
||||
* or (0,1) multiplicity.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public class SingleField extends AbstractFieldWithVar {
|
||||
|
||||
protected SingleField(ClassOutlineImpl context, CPropertyInfo prop) {
|
||||
this(context,prop,false);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param forcePrimitiveAccess
|
||||
* forces the setter/getter to expose the primitive type.
|
||||
* it's a pointless customization, but it's nevertheless in the spec.
|
||||
*/
|
||||
protected SingleField(ClassOutlineImpl context, CPropertyInfo prop, boolean forcePrimitiveAccess ) {
|
||||
super(context, prop);
|
||||
assert !exposedType.isPrimitive() && !implType.isPrimitive();
|
||||
|
||||
createField();
|
||||
|
||||
MethodWriter writer = context.createMethodWriter();
|
||||
NameConverter nc = context.parent().getModel().getNameConverter();
|
||||
|
||||
// [RESULT]
|
||||
// Type getXXX() {
|
||||
// #ifdef default value
|
||||
// if(value==null)
|
||||
// return defaultValue;
|
||||
// #endif
|
||||
// return value;
|
||||
// }
|
||||
JExpression defaultValue = null;
|
||||
if(prop.defaultValue!=null)
|
||||
defaultValue = prop.defaultValue.compute(outline.parent());
|
||||
|
||||
// if Type is a wrapper and we have a default value,
|
||||
// we can use the primitive type.
|
||||
JType getterType;
|
||||
if (getOptions().enableIntrospection) {
|
||||
if (forcePrimitiveAccess)
|
||||
getterType = exposedType.unboxify();
|
||||
else
|
||||
getterType = exposedType;
|
||||
} else {
|
||||
if (defaultValue != null || forcePrimitiveAccess)
|
||||
getterType = exposedType.unboxify();
|
||||
else
|
||||
getterType = exposedType;
|
||||
}
|
||||
|
||||
JMethod $get = writer.declareMethod( getterType,getGetterMethod() );
|
||||
String javadoc = prop.javadoc;
|
||||
if(javadoc.length()==0)
|
||||
javadoc = Messages.DEFAULT_GETTER_JAVADOC.format(nc.toVariableName(prop.getName(true)));
|
||||
writer.javadoc().append(javadoc);
|
||||
|
||||
|
||||
if(defaultValue==null) {
|
||||
$get.body()._return(ref());
|
||||
} else {
|
||||
JConditional cond = $get.body()._if(ref().eq(JExpr._null()));
|
||||
cond._then()._return(defaultValue);
|
||||
cond._else()._return(ref());
|
||||
}
|
||||
|
||||
List<Object> possibleTypes = listPossibleTypes(prop);
|
||||
writer.javadoc().addReturn()
|
||||
.append("possible object is\n")
|
||||
.append(possibleTypes);
|
||||
|
||||
// [RESULT]
|
||||
// void setXXX(Type newVal) {
|
||||
// this.value = newVal;
|
||||
// }
|
||||
JMethod $set = writer.declareMethod( codeModel.VOID, "set"+prop.getName(true) );
|
||||
JType setterType = exposedType;
|
||||
if(forcePrimitiveAccess) setterType = setterType.unboxify();
|
||||
JVar $value = writer.addParameter( setterType, "value" );
|
||||
JBlock body = $set.body();
|
||||
if ($value.type().equals(implType)) {
|
||||
body.assign(JExpr._this().ref(ref()), $value);
|
||||
} else {
|
||||
body.assign(JExpr._this().ref(ref()), castToImplType($value));
|
||||
}
|
||||
|
||||
// setter always get the default javadoc. See issue #381
|
||||
writer.javadoc().append(Messages.DEFAULT_SETTER_JAVADOC.format(nc.toVariableName(prop.getName(true))));
|
||||
writer.javadoc().addParam($value)
|
||||
.append("allowed object is\n")
|
||||
.append(possibleTypes);
|
||||
}
|
||||
|
||||
public final JType getFieldType() {
|
||||
return implType;
|
||||
}
|
||||
|
||||
public FieldAccessor create(JExpression targetObject) {
|
||||
return new Accessor(targetObject);
|
||||
}
|
||||
|
||||
protected class Accessor extends AbstractFieldWithVar.Accessor {
|
||||
protected Accessor(JExpression $target) {
|
||||
super($target);
|
||||
}
|
||||
|
||||
public void unsetValues( JBlock body ) {
|
||||
body.assign( $ref, JExpr._null() );
|
||||
}
|
||||
public JExpression hasSetValue() {
|
||||
return $ref.ne( JExpr._null() );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.generator.bean.field;
|
||||
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
|
||||
/**
|
||||
* {@link SingleField} that forces the primitive accessor type.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class SinglePrimitiveAccessField extends SingleField {
|
||||
protected SinglePrimitiveAccessField(ClassOutlineImpl context, CPropertyInfo prop) {
|
||||
super(context, prop,true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* 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.generator.bean.field;
|
||||
|
||||
import com.sun.codemodel.internal.JBlock;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JMethod;
|
||||
import com.sun.codemodel.internal.JPrimitiveType;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.generator.bean.MethodWriter;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.outline.Aspect;
|
||||
import com.sun.tools.internal.xjc.outline.FieldAccessor;
|
||||
import com.sun.xml.internal.bind.api.impl.NameConverter;
|
||||
|
||||
/**
|
||||
* A required primitive property.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public class UnboxedField extends AbstractFieldWithVar {
|
||||
|
||||
/**
|
||||
* The primitive version of {@link #implType} and {@link #exposedType}.
|
||||
*/
|
||||
private final JPrimitiveType ptype;
|
||||
|
||||
|
||||
protected UnboxedField( ClassOutlineImpl outline, CPropertyInfo prop ) {
|
||||
super(outline,prop);
|
||||
// primitive types don't have this distintion
|
||||
assert implType==exposedType;
|
||||
|
||||
ptype = (JPrimitiveType) implType;
|
||||
assert ptype!=null;
|
||||
|
||||
createField();
|
||||
|
||||
// apparently a required attribute can be still defaulted.
|
||||
// so this assertion is incorrect.
|
||||
// assert prop.defaultValue==null;
|
||||
|
||||
MethodWriter writer = outline.createMethodWriter();
|
||||
NameConverter nc = outline.parent().getModel().getNameConverter();
|
||||
|
||||
JBlock body;
|
||||
|
||||
// [RESULT]
|
||||
// Type getXXX() {
|
||||
// return value;
|
||||
// }
|
||||
JMethod $get = writer.declareMethod( ptype, getGetterMethod() );
|
||||
String javadoc = prop.javadoc;
|
||||
if(javadoc.length()==0)
|
||||
javadoc = Messages.DEFAULT_GETTER_JAVADOC.format(nc.toVariableName(prop.getName(true)));
|
||||
writer.javadoc().append(javadoc);
|
||||
|
||||
$get.body()._return(ref());
|
||||
|
||||
|
||||
// [RESULT]
|
||||
// void setXXX( Type value ) {
|
||||
// this.value = value;
|
||||
// }
|
||||
JMethod $set = writer.declareMethod( codeModel.VOID, "set"+prop.getName(true) );
|
||||
JVar $value = writer.addParameter( ptype, "value" );
|
||||
body = $set.body();
|
||||
body.assign(JExpr._this().ref(ref()),$value);
|
||||
// setter always get the default javadoc. See issue #381
|
||||
writer.javadoc().append(Messages.DEFAULT_SETTER_JAVADOC.format(nc.toVariableName(prop.getName(true))));
|
||||
|
||||
}
|
||||
|
||||
protected JType getType(Aspect aspect) {
|
||||
return super.getType(aspect).boxify().getPrimitiveType();
|
||||
}
|
||||
|
||||
protected JType getFieldType() {
|
||||
return ptype;
|
||||
}
|
||||
|
||||
public FieldAccessor create(JExpression targetObject) {
|
||||
return new Accessor(targetObject) {
|
||||
|
||||
public void unsetValues( JBlock body ) {
|
||||
// you can't unset a value
|
||||
}
|
||||
|
||||
public JExpression hasSetValue() {
|
||||
return JExpr.TRUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* 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.generator.bean.field;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.codemodel.internal.JBlock;
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JMethod;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.generator.bean.MethodWriter;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.xml.internal.bind.api.impl.NameConverter;
|
||||
|
||||
/**
|
||||
* Realizes a property as an untyped {@link List}.
|
||||
*
|
||||
* <pre>
|
||||
* List getXXX();
|
||||
* </pre>
|
||||
*
|
||||
* <h2>Default value handling</h2>
|
||||
* <p>
|
||||
* Since unmarshaller just adds new values into the storage,
|
||||
* we can't fill the storage by default values at the time of
|
||||
* instanciation. (or oherwise values found in the document will
|
||||
* be appended to default values, where it should overwrite them.)
|
||||
* <p>
|
||||
* Therefore, when the object is created, the storage will be empty.
|
||||
* When the getXXX method is called, we'll check if the storage is
|
||||
* modified in anyway. If it is modified, it must mean that the values
|
||||
* are found in the document, so we just return it.
|
||||
*
|
||||
* Otherwise we will fill in default values and return it to the user.
|
||||
*
|
||||
* <p>
|
||||
* When a list has default values, its dirty flag is set to true.
|
||||
* Marshaller will check this and treat it appropriately.
|
||||
*
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public class UntypedListField extends AbstractListField {
|
||||
|
||||
/**
|
||||
* A concrete class that implements the List interface.
|
||||
* An instance of this class will be used to store data
|
||||
* for this field.
|
||||
*/
|
||||
private final JClass coreList;
|
||||
|
||||
|
||||
/** List getFIELD() method. */
|
||||
private JMethod $get;
|
||||
|
||||
/**
|
||||
* @param coreList
|
||||
* A concrete class that implements the List interface.
|
||||
* An instance of this class will be used to store data
|
||||
* for this field.
|
||||
*/
|
||||
protected UntypedListField(ClassOutlineImpl context, CPropertyInfo prop, JClass coreList) {
|
||||
// the JAXB runtime picks ArrayList if the signature is List,
|
||||
// so don't do eager allocation if it's ArrayList.
|
||||
// otherwise we need to do eager allocation so that the collection type specified by the user
|
||||
// will be used.
|
||||
super(context, prop, !coreList.fullName().equals("java.util.ArrayList"));
|
||||
this.coreList = coreList.narrow(exposedType.boxify());
|
||||
generate();
|
||||
}
|
||||
|
||||
protected final JClass getCoreListType() {
|
||||
return coreList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateAccessors() {
|
||||
final MethodWriter writer = outline.createMethodWriter();
|
||||
final Accessor acc = create(JExpr._this());
|
||||
|
||||
// [RESULT]
|
||||
// List getXXX() {
|
||||
// return <ref>;
|
||||
// }
|
||||
$get = writer.declareMethod(listT,"get"+prop.getName(true));
|
||||
writer.javadoc().append(prop.javadoc);
|
||||
JBlock block = $get.body();
|
||||
fixNullRef(block); // avoid using an internal getter
|
||||
block._return(acc.ref(true));
|
||||
|
||||
String pname = NameConverter.standard.toVariableName(prop.getName(true));
|
||||
writer.javadoc().append(
|
||||
"Gets the value of the "+pname+" property.\n\n"+
|
||||
"<p>\n" +
|
||||
"This accessor method returns a reference to the live list,\n" +
|
||||
"not a snapshot. Therefore any modification you make to the\n" +
|
||||
"returned list will be present inside the JAXB object.\n" +
|
||||
"This is why there is not a <CODE>set</CODE> method for the " +pname+ " property.\n" +
|
||||
"\n"+
|
||||
"<p>\n" +
|
||||
"For example, to add a new item, do as follows:\n"+
|
||||
"<pre>\n"+
|
||||
" get"+prop.getName(true)+"().add(newItem);\n"+
|
||||
"</pre>\n"+
|
||||
"\n\n"
|
||||
);
|
||||
|
||||
writer.javadoc().append(
|
||||
"<p>\n" +
|
||||
"Objects of the following type(s) are allowed in the list\n")
|
||||
.append(listPossibleTypes(prop));
|
||||
}
|
||||
|
||||
public Accessor create(JExpression targetObject) {
|
||||
return new Accessor(targetObject);
|
||||
}
|
||||
|
||||
class Accessor extends AbstractListField.Accessor {
|
||||
protected Accessor( JExpression $target ) {
|
||||
super($target);
|
||||
}
|
||||
|
||||
public void toRawValue(JBlock block, JVar $var) {
|
||||
// [RESULT]
|
||||
// $<var>.addAll(bean.getLIST());
|
||||
// list.toArray( array );
|
||||
block.assign($var,JExpr._new(codeModel.ref(ArrayList.class).narrow(exposedType.boxify())).arg(
|
||||
$target.invoke($get)
|
||||
));
|
||||
}
|
||||
|
||||
public void fromRawValue(JBlock block, String uniqueName, JExpression $var) {
|
||||
// [RESULT]
|
||||
// bean.getLIST().addAll($<var>);
|
||||
JVar $list = block.decl(listT,uniqueName+'l',$target.invoke($get));
|
||||
block.invoke($list,"addAll").arg($var);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.generator.bean.field;
|
||||
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.outline.FieldOutline;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public final class UntypedListFieldRenderer implements FieldRenderer {
|
||||
|
||||
private JClass coreList;
|
||||
private boolean dummy;
|
||||
private boolean content;
|
||||
|
||||
protected UntypedListFieldRenderer( JClass coreList) {
|
||||
this(coreList, false, false);
|
||||
}
|
||||
|
||||
protected UntypedListFieldRenderer( JClass coreList, boolean dummy, boolean content) {
|
||||
this.coreList = coreList;
|
||||
this.dummy = dummy;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public FieldOutline generate(ClassOutlineImpl context, CPropertyInfo prop) {
|
||||
if (dummy) {
|
||||
return new DummyListField(context, prop, coreList);
|
||||
}
|
||||
if (content) {
|
||||
return new ContentListField(context, prop, coreList);
|
||||
}
|
||||
return new UntypedListField(context, prop, coreList);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* <h1>Code Generator</h1>.
|
||||
*
|
||||
* This package hosts code for generating CodeModel AST from {@link com.sun.tools.internal.xjc.model Model}
|
||||
* classes.
|
||||
*/
|
||||
package com.sun.tools.internal.xjc.generator;
|
||||
@@ -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.generator.util;
|
||||
|
||||
import com.sun.codemodel.internal.JBlock;
|
||||
|
||||
/**
|
||||
* Holds a reference to a {@link JBlock} object.
|
||||
*
|
||||
* <p>
|
||||
* This interface is usually used when one wants to create
|
||||
* a new JBlock object lazily.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public interface BlockReference {
|
||||
/**
|
||||
* @param create
|
||||
* If false, the method will return null if the block is
|
||||
* not yet created.
|
||||
*/
|
||||
JBlock get(boolean create);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.generator.util;
|
||||
|
||||
import com.sun.codemodel.internal.JBlock;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public class ExistingBlockReference implements BlockReference {
|
||||
private final JBlock block;
|
||||
|
||||
public ExistingBlockReference( JBlock _block ) {
|
||||
this.block = _block;
|
||||
}
|
||||
|
||||
public JBlock get(boolean create) {
|
||||
return block;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.generator.util;
|
||||
|
||||
import com.sun.codemodel.internal.JBlock;
|
||||
|
||||
/**
|
||||
* Lazy block reference.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public abstract class LazyBlockReference implements BlockReference {
|
||||
|
||||
private JBlock block = null;
|
||||
|
||||
/**
|
||||
* Called when a block needs to be created.
|
||||
* Only called once in the whole life time of this object.
|
||||
*/
|
||||
protected abstract JBlock create();
|
||||
|
||||
public JBlock get(boolean create) {
|
||||
if(!create) return block;
|
||||
if(block==null)
|
||||
block = create();
|
||||
return block;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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.generator.util;
|
||||
|
||||
import com.sun.codemodel.internal.JCodeModel;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JStringLiteral;
|
||||
import com.sun.xml.internal.bind.WhiteSpaceProcessor;
|
||||
|
||||
/**
|
||||
* Generates code that performs the whitespace normalization.
|
||||
*/
|
||||
public abstract class WhitespaceNormalizer
|
||||
{
|
||||
/**
|
||||
* Generates the expression that normalizes
|
||||
* the given expression (which evaluates to java.lang.String).
|
||||
*
|
||||
* @param codeModel
|
||||
* The owner code model object under which a new expression
|
||||
* will be created.
|
||||
*/
|
||||
public abstract JExpression generate( JCodeModel codeModel, JExpression literal );
|
||||
|
||||
/**
|
||||
* Parses "preserve","replace" or "collapse" into
|
||||
* the corresponding WhitespaceNormalizer object.
|
||||
*
|
||||
* @param method
|
||||
* Either "preserve", "replace", or "collapse"
|
||||
*
|
||||
* @exception IllegalArgumentException
|
||||
* when the specified method is invalid.
|
||||
*/
|
||||
public static WhitespaceNormalizer parse( String method ) {
|
||||
if( method.equals("preserve") )
|
||||
return PRESERVE;
|
||||
|
||||
if( method.equals("replace") )
|
||||
return REPLACE;
|
||||
|
||||
if( method.equals("collapse") )
|
||||
return COLLAPSE;
|
||||
|
||||
throw new IllegalArgumentException(method);
|
||||
}
|
||||
|
||||
public static final WhitespaceNormalizer PRESERVE = new WhitespaceNormalizer() {
|
||||
public JExpression generate( JCodeModel codeModel, JExpression literal ) {
|
||||
return literal;
|
||||
}
|
||||
};
|
||||
|
||||
public static final WhitespaceNormalizer REPLACE = new WhitespaceNormalizer() {
|
||||
public JExpression generate( JCodeModel codeModel, JExpression literal ) {
|
||||
// WhitespaceProcessor.replace(<literal>);
|
||||
if( literal instanceof JStringLiteral )
|
||||
// optimize
|
||||
return JExpr.lit( WhiteSpaceProcessor.replace(((JStringLiteral)literal).str) );
|
||||
else
|
||||
return codeModel.ref(WhiteSpaceProcessor.class)
|
||||
.staticInvoke("replace").arg(literal);
|
||||
}
|
||||
};
|
||||
|
||||
public static final WhitespaceNormalizer COLLAPSE = new WhitespaceNormalizer() {
|
||||
public JExpression generate( JCodeModel codeModel, JExpression literal ) {
|
||||
// WhitespaceProcessor.replace(<literal>);
|
||||
if( literal instanceof JStringLiteral )
|
||||
// optimize
|
||||
return JExpr.lit( WhiteSpaceProcessor.collapse(((JStringLiteral)literal).str) );
|
||||
else
|
||||
return codeModel.ref(WhiteSpaceProcessor.class)
|
||||
.staticInvoke("collapse").arg(literal);
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user