src/share/jaxws_classes/com/sun/tools/internal/xjc/model/CPropertyInfo.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.internal.xjc.model;
  27 
  28 import java.lang.annotation.Annotation;
  29 import java.util.Collection;
  30 import java.util.Map;
  31 
  32 import javax.xml.bind.annotation.XmlSchemaType;
  33 import javax.xml.bind.annotation.XmlTransient;
  34 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
  35 import javax.xml.namespace.QName;
  36 
  37 import com.sun.codemodel.internal.JClass;
  38 import com.sun.codemodel.internal.JJavaName;
  39 import com.sun.codemodel.internal.JType;
  40 import com.sun.tools.internal.xjc.Plugin;
  41 import com.sun.tools.internal.xjc.generator.bean.field.FieldRenderer;
  42 import com.sun.tools.internal.xjc.model.nav.NClass;
  43 import com.sun.tools.internal.xjc.model.nav.NType;

  44 import com.sun.xml.internal.bind.api.impl.NameConverter;
  45 import com.sun.xml.internal.bind.v2.WellKnownNamespace;
  46 import com.sun.xml.internal.bind.v2.model.core.PropertyInfo;
  47 import com.sun.xml.internal.bind.v2.runtime.RuntimeUtil;
  48 import com.sun.xml.internal.xsom.XSComponent;
  49 
  50 import org.xml.sax.Locator;
  51 
  52 /**
  53  * Model of a property to be generated.
  54  *
  55  * @author Kohsuke Kawaguchi
  56  */
  57 public abstract class CPropertyInfo implements PropertyInfo<NType,NClass>, CCustomizable {
  58 
  59     @XmlTransient
  60     private CClassInfo parent;
  61     private String privateName;
  62     private String publicName;
  63     private final boolean isCollection;


  88 
  89     /**
  90      * Specifies how the field is generated by the backend.
  91      */
  92     @XmlJavaTypeAdapter(RuntimeUtil.ToStringAdapter.class)
  93     public FieldRenderer realization;
  94 
  95     /**
  96      * If non-null, keeps the default value in Java representation.
  97      *
  98      * If {@link #isCollection} is true, this field is always null,
  99      * for we don't handle default values for a list.
 100      */
 101     public CDefaultValue defaultValue;
 102 
 103     private final CCustomizations customizations;
 104 
 105     protected CPropertyInfo(String name, boolean collection, XSComponent source,
 106                             CCustomizations customizations, Locator locator) {
 107         this.publicName = name;
 108         String n = NameConverter.standard.toVariableName(name);








 109         if(!JJavaName.isJavaIdentifier(n))
 110             n = '_'+n;  // avoid colliding with the reserved names like 'abstract'.
 111         this.privateName = n;
 112 
 113         this.isCollection = collection;
 114         this.locator = locator;
 115         if(customizations==null)
 116             this.customizations = CCustomizations.EMPTY;
 117         else
 118             this.customizations = customizations;
 119         this.source = source;
 120     }
 121 
 122     // called from CClassInfo when added
 123     final void setParent( CClassInfo parent ) {
 124         assert this.parent==null;
 125         assert parent!=null;
 126         this.parent = parent;
 127         customizations.setParent(parent.model,this);
 128     }


   1 /*
   2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.internal.xjc.model;
  27 
  28 import java.lang.annotation.Annotation;
  29 import java.util.Collection;
  30 import java.util.Map;
  31 

  32 import javax.xml.bind.annotation.XmlTransient;
  33 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
  34 import javax.xml.namespace.QName;
  35 
  36 import com.sun.codemodel.internal.JClass;
  37 import com.sun.codemodel.internal.JJavaName;
  38 import com.sun.codemodel.internal.JType;

  39 import com.sun.tools.internal.xjc.generator.bean.field.FieldRenderer;
  40 import com.sun.tools.internal.xjc.model.nav.NClass;
  41 import com.sun.tools.internal.xjc.model.nav.NType;
  42 import com.sun.tools.internal.xjc.reader.Ring;
  43 import com.sun.xml.internal.bind.api.impl.NameConverter;
  44 import com.sun.xml.internal.bind.v2.WellKnownNamespace;
  45 import com.sun.xml.internal.bind.v2.model.core.PropertyInfo;
  46 import com.sun.xml.internal.bind.v2.runtime.RuntimeUtil;
  47 import com.sun.xml.internal.xsom.XSComponent;
  48 
  49 import org.xml.sax.Locator;
  50 
  51 /**
  52  * Model of a property to be generated.
  53  *
  54  * @author Kohsuke Kawaguchi
  55  */
  56 public abstract class CPropertyInfo implements PropertyInfo<NType,NClass>, CCustomizable {
  57 
  58     @XmlTransient
  59     private CClassInfo parent;
  60     private String privateName;
  61     private String publicName;
  62     private final boolean isCollection;


  87 
  88     /**
  89      * Specifies how the field is generated by the backend.
  90      */
  91     @XmlJavaTypeAdapter(RuntimeUtil.ToStringAdapter.class)
  92     public FieldRenderer realization;
  93 
  94     /**
  95      * If non-null, keeps the default value in Java representation.
  96      *
  97      * If {@link #isCollection} is true, this field is always null,
  98      * for we don't handle default values for a list.
  99      */
 100     public CDefaultValue defaultValue;
 101 
 102     private final CCustomizations customizations;
 103 
 104     protected CPropertyInfo(String name, boolean collection, XSComponent source,
 105                             CCustomizations customizations, Locator locator) {
 106         this.publicName = name;
 107         String n = null;
 108 
 109         Model m = Ring.get(Model.class);
 110         if (m != null) {
 111             n = m.getNameConverter().toVariableName(name);
 112         } else {
 113             n = NameConverter.standard.toVariableName(name);
 114         }
 115 
 116         if(!JJavaName.isJavaIdentifier(n))
 117             n = '_'+n;  // avoid colliding with the reserved names like 'abstract'.
 118         this.privateName = n;
 119 
 120         this.isCollection = collection;
 121         this.locator = locator;
 122         if(customizations==null)
 123             this.customizations = CCustomizations.EMPTY;
 124         else
 125             this.customizations = customizations;
 126         this.source = source;
 127     }
 128 
 129     // called from CClassInfo when added
 130     final void setParent( CClassInfo parent ) {
 131         assert this.parent==null;
 132         assert parent!=null;
 133         this.parent = parent;
 134         customizations.setParent(parent.model,this);
 135     }