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

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

View File

@@ -0,0 +1,108 @@
package com.sun.accessibility.internal.resources;
import java.util.ListResourceBundle;
public final class accessibility extends ListResourceBundle {
protected final Object[][] getContents() {
return new Object[][] {
{ "active", "active" },
{ "alert", "alert" },
{ "armed", "armed" },
{ "awtcomponent", "AWT component" },
{ "busy", "busy" },
{ "canvas", "canvas" },
{ "checkbox", "check box" },
{ "checked", "checked" },
{ "childNodeOf", "child node of" },
{ "collapsed", "collapsed" },
{ "colorchooser", "color chooser" },
{ "columnheader", "column header" },
{ "combobox", "combo box" },
{ "controlledBy", "controlledBy" },
{ "controllerFor", "controllerFor" },
{ "desktopicon", "desktop icon" },
{ "desktoppane", "desktop pane" },
{ "dialog", "dialog" },
{ "directorypane", "directory pane" },
{ "editable", "editable" },
{ "editbar", "editbar" },
{ "embeddedBy", "embedded by" },
{ "embeds", "embeds" },
{ "enabled", "enabled" },
{ "expandable", "expandable" },
{ "expanded", "expanded" },
{ "filechooser", "file chooser" },
{ "filler", "filler" },
{ "flowsFrom", "flows from" },
{ "flowsTo", "flows to" },
{ "focusable", "focusable" },
{ "focused", "focused" },
{ "footer", "footer" },
{ "frame", "frame" },
{ "glasspane", "glass pane" },
{ "header", "header" },
{ "horizontal", "horizontal" },
{ "htmlcontainer", "HTML container" },
{ "iconified", "iconified" },
{ "indeterminate", "indeterminate" },
{ "internalframe", "internal frame" },
{ "label", "label" },
{ "labelFor", "label for" },
{ "labeledBy", "labeled by" },
{ "layeredpane", "layered pane" },
{ "list", "list" },
{ "listitem", "list item" },
{ "managesDescendants", "manages descendants" },
{ "memberOf", "member of" },
{ "menu", "menu" },
{ "menubar", "menu bar" },
{ "menuitem", "menu item" },
{ "modal", "modal" },
{ "multiline", "multiple line" },
{ "multiselectable", "multiselectable" },
{ "opaque", "opaque" },
{ "optionpane", "option pane" },
{ "pagetab", "page tab" },
{ "pagetablist", "page tab list" },
{ "panel", "panel" },
{ "paragraph", "paragraph" },
{ "parentWindowOf", "parent window of" },
{ "passwordtext", "password text" },
{ "popupmenu", "popup menu" },
{ "pressed", "pressed" },
{ "progressMonitor", "progress monitor" },
{ "progressbar", "progress bar" },
{ "pushbutton", "push button" },
{ "radiobutton", "radio button" },
{ "resizable", "resizable" },
{ "rootpane", "root pane" },
{ "rowheader", "row header" },
{ "ruler", "ruler" },
{ "scrollbar", "scroll bar" },
{ "scrollpane", "scroll pane" },
{ "selectable", "selectable" },
{ "selected", "selected" },
{ "separator", "separator" },
{ "showing", "showing" },
{ "singleline", "single line" },
{ "slider", "slider" },
{ "splitpane", "split pane" },
{ "subwindowOf", "subwindow of" },
{ "swingcomponent", "swing component" },
{ "table", "table" },
{ "text", "text" },
{ "togglebutton", "toggle button" },
{ "toggleexpand", "toggle expand" },
{ "toolbar", "tool bar" },
{ "tooltip", "tool tip" },
{ "transient", "transient" },
{ "tree", "tree" },
{ "truncated", "truncated" },
{ "unknown", "unknown" },
{ "vertical", "vertical" },
{ "viewport", "viewport" },
{ "visible", "visible" },
{ "window", "window" },
};
}
}

View File

@@ -0,0 +1,108 @@
package com.sun.accessibility.internal.resources;
import java.util.ListResourceBundle;
public final class accessibility_de extends ListResourceBundle {
protected final Object[][] getContents() {
return new Object[][] {
{ "active", "aktiv" },
{ "alert", "Alert" },
{ "armed", "aktiviert" },
{ "awtcomponent", "AWT-Komponente" },
{ "busy", "ausgelastet" },
{ "canvas", "Leinwand" },
{ "checkbox", "Kontrollk\u00E4stchen" },
{ "checked", "markiert" },
{ "childNodeOf", "untergeordneter Knoten von" },
{ "collapsed", "ausgeblendet" },
{ "colorchooser", "Farbauswahl" },
{ "columnheader", "Spaltenheader" },
{ "combobox", "Kombinationsfeld" },
{ "controlledBy", "controlledBy" },
{ "controllerFor", "controllerFor" },
{ "desktopicon", "Desktopsymbol" },
{ "desktoppane", "Desktopbereich" },
{ "dialog", "Dialogfeld" },
{ "directorypane", "Verzeichnisbereich" },
{ "editable", "bearbeitbar" },
{ "editbar", "Bearbeitungsleiste" },
{ "embeddedBy", "eingebettet in" },
{ "embeds", "bettet ein" },
{ "enabled", "aktiviert" },
{ "expandable", "erweiterbar" },
{ "expanded", "eingeblendet" },
{ "filechooser", "Dateiauswahl" },
{ "filler", "F\u00FCllbereich" },
{ "flowsFrom", "flie\u00DFt von" },
{ "flowsTo", "flie\u00DFt zu" },
{ "focusable", "fokussierbar" },
{ "focused", "fokussiert" },
{ "footer", "Footer" },
{ "frame", "Rahmen" },
{ "glasspane", "Glass Pane" },
{ "header", "Header" },
{ "horizontal", "horizontal" },
{ "htmlcontainer", "HTML-Container" },
{ "iconified", "minimiert" },
{ "indeterminate", "unbestimmt" },
{ "internalframe", "Innerer Rahmen" },
{ "label", "Label" },
{ "labelFor", "Label f\u00FCr" },
{ "labeledBy", "beschriftet von" },
{ "layeredpane", "Layered Pane" },
{ "list", "Liste" },
{ "listitem", "Listenelement" },
{ "managesDescendants", "verwaltet untergeordnete Objekte" },
{ "memberOf", "Mitglied von" },
{ "menu", "Men\u00FC" },
{ "menubar", "Men\u00FCleiste" },
{ "menuitem", "Men\u00FCpunkt" },
{ "modal", "modal" },
{ "multiline", "mehrzeilig" },
{ "multiselectable", "mehrfach ausw\u00E4hlbar" },
{ "opaque", "nicht transparent" },
{ "optionpane", "Optionsbereich" },
{ "pagetab", "Registerkarte" },
{ "pagetablist", "Registerkartenliste" },
{ "panel", "Bereich" },
{ "paragraph", "Absatz" },
{ "parentWindowOf", "\u00FCbergeordnetes Fenster von" },
{ "passwordtext", "Kennworttext" },
{ "popupmenu", "Popup-Men\u00FC" },
{ "pressed", "gedr\u00FCckt" },
{ "progressMonitor", "Fortschrittsmonitor" },
{ "progressbar", "Fortschrittsbalken" },
{ "pushbutton", "Schaltfl\u00E4che" },
{ "radiobutton", "Optionsfeld" },
{ "resizable", "skalierbar" },
{ "rootpane", "Root-Bereich" },
{ "rowheader", "Zeilenheader" },
{ "ruler", "Lineal" },
{ "scrollbar", "Bildlaufleiste" },
{ "scrollpane", "Bildlaufbereich" },
{ "selectable", "w\u00E4hlbar" },
{ "selected", "ausgew\u00E4hlt" },
{ "separator", "Trennzeichen" },
{ "showing", "angezeigt" },
{ "singleline", "einzeilig" },
{ "slider", "Schieberegler" },
{ "splitpane", "Split Pane" },
{ "subwindowOf", "Unterfenster von" },
{ "swingcomponent", "Swing-Komponente" },
{ "table", "Tabelle" },
{ "text", "Text" },
{ "togglebutton", "Umschaltfl\u00E4che" },
{ "toggleexpand", "einblenden umschalten" },
{ "toolbar", "Symbolleiste" },
{ "tooltip", "QuickInfo" },
{ "transient", "transient" },
{ "tree", "Baumstruktur" },
{ "truncated", "abgeschnitten" },
{ "unknown", "Unbekannt" },
{ "vertical", "vertikal" },
{ "viewport", "Viewport" },
{ "visible", "sichtbar" },
{ "window", "Fenster" },
};
}
}

View File

@@ -0,0 +1,107 @@
package com.sun.accessibility.internal.resources;
import java.util.ListResourceBundle;
public final class accessibility_en extends ListResourceBundle {
protected final Object[][] getContents() {
return new Object[][] {
{ "active", "active" },
{ "alert", "alert" },
{ "armed", "armed" },
{ "awtcomponent", "AWT component" },
{ "busy", "busy" },
{ "canvas", "canvas" },
{ "checkbox", "check box" },
{ "checked", "checked" },
{ "childNodeOf", "child node of" },
{ "collapsed", "collapsed" },
{ "colorchooser", "color chooser" },
{ "columnheader", "column header" },
{ "combobox", "combo box" },
{ "controlledBy", "controlledBy" },
{ "controllerFor", "controllerFor" },
{ "desktopicon", "desktop icon" },
{ "desktoppane", "desktop pane" },
{ "dialog", "dialog" },
{ "directorypane", "directory pane" },
{ "editable", "editable" },
{ "editbar", "editbar" },
{ "embeddedBy", "embedded by" },
{ "embeds", "embeds" },
{ "enabled", "enabled" },
{ "expandable", "expandable" },
{ "expanded", "expanded" },
{ "filechooser", "file chooser" },
{ "filler", "filler" },
{ "flowsFrom", "flows from" },
{ "flowsTo", "flows to" },
{ "focusable", "focusable" },
{ "focused", "focused" },
{ "footer", "footer" },
{ "frame", "frame" },
{ "glasspane", "glass pane" },
{ "header", "header" },
{ "horizontal", "horizontal" },
{ "htmlcontainer", "HTML container" },
{ "iconified", "iconified" },
{ "indeterminate", "indeterminate" },
{ "internalframe", "internal frame" },
{ "label", "label" },
{ "labelFor", "label for" },
{ "labeledBy", "labeled by" },
{ "layeredpane", "layered pane" },
{ "list", "list" },
{ "listitem", "list item" },
{ "managesDescendants", "manages descendants" },
{ "memberOf", "member of" },
{ "menu", "menu" },
{ "menubar", "menu bar" },
{ "menuitem", "menu item" },
{ "modal", "modal" },
{ "multiline", "multiple line" },
{ "multiselectable", "multiselectable" },
{ "opaque", "opaque" },
{ "optionpane", "option pane" },
{ "pagetab", "page tab" },
{ "pagetablist", "page tab list" },
{ "panel", "panel" },
{ "paragraph", "paragraph" },
{ "parentWindowOf", "parent window of" },
{ "passwordtext", "password text" },
{ "popupmenu", "popup menu" },
{ "pressed", "pressed" },
{ "progressMonitor", "progress monitor" },
{ "progressbar", "progress bar" },
{ "pushbutton", "push button" },
{ "radiobutton", "radio button" },
{ "resizable", "resizable" },
{ "rootpane", "root pane" },
{ "rowheader", "row header" },
{ "ruler", "ruler" },
{ "scrollbar", "scroll bar" },
{ "scrollpane", "scroll pane" },
{ "selectable", "selectable" },
{ "selected", "selected" },
{ "separator", "separator" },
{ "showing", "showing" },
{ "singleline", "single line" },
{ "slider", "slider" },
{ "splitpane", "split pane" },
{ "subwindowOf", "subwindow of" },
{ "swingcomponent", "swing component" },
{ "table", "table" },
{ "text", "text" },
{ "togglebutton", "toggle button" },
{ "toolbar", "tool bar" },
{ "tooltip", "tool tip" },
{ "transient", "transient" },
{ "tree", "tree" },
{ "truncated", "truncated" },
{ "unknown", "unknown" },
{ "vertical", "vertical" },
{ "viewport", "viewport" },
{ "visible", "visible" },
{ "window", "window" },
};
}
}

View File

@@ -0,0 +1,108 @@
package com.sun.accessibility.internal.resources;
import java.util.ListResourceBundle;
public final class accessibility_es extends ListResourceBundle {
protected final Object[][] getContents() {
return new Object[][] {
{ "active", "activo" },
{ "alert", "alerta" },
{ "armed", "armado" },
{ "awtcomponent", "componente AWT" },
{ "busy", "ocupado" },
{ "canvas", "lienzo" },
{ "checkbox", "casilla de control" },
{ "checked", "activado" },
{ "childNodeOf", "nodo secundario de" },
{ "collapsed", "reducido" },
{ "colorchooser", "selector de color" },
{ "columnheader", "cabecera de columna" },
{ "combobox", "cuadro combinado" },
{ "controlledBy", "controlledBy" },
{ "controllerFor", "controllerFor" },
{ "desktopicon", "icono de escritorio" },
{ "desktoppane", "panel de escritorio" },
{ "dialog", "cuadro de di\u00E1logo" },
{ "directorypane", "panel de directorio" },
{ "editable", "editable" },
{ "editbar", "barra de edici\u00F3n" },
{ "embeddedBy", "embebido por" },
{ "embeds", "embebe" },
{ "enabled", "activado" },
{ "expandable", "ampliable" },
{ "expanded", "ampliado" },
{ "filechooser", "selector de archivos" },
{ "filler", "rellenador" },
{ "flowsFrom", "procede de" },
{ "flowsTo", "llega a" },
{ "focusable", "enfocable" },
{ "focused", "enfocado" },
{ "footer", "pie" },
{ "frame", "marco" },
{ "glasspane", "panel de cristal" },
{ "header", "cabecera" },
{ "horizontal", "horizontal" },
{ "htmlcontainer", "Contenedor HTML" },
{ "iconified", "convertido en icono" },
{ "indeterminate", "indeterminada" },
{ "internalframe", "marco interno" },
{ "label", "etiqueta" },
{ "labelFor", "etiqueta para" },
{ "labeledBy", "etiquetado por" },
{ "layeredpane", "panel en capas" },
{ "list", "lista" },
{ "listitem", "elemento de lista" },
{ "managesDescendants", "gestiona descendientes" },
{ "memberOf", "miembro de" },
{ "menu", "men\u00FA" },
{ "menubar", "barra de men\u00FAs" },
{ "menuitem", "elemento de men\u00FA" },
{ "modal", "modal" },
{ "multiline", "l\u00EDnea m\u00FAltiple" },
{ "multiselectable", "multiseleccionable" },
{ "opaque", "opaco" },
{ "optionpane", "panel de opciones" },
{ "pagetab", "separador de p\u00E1gina" },
{ "pagetablist", "lista de separadores de p\u00E1gina" },
{ "panel", "panel" },
{ "paragraph", "p\u00E1rrafo" },
{ "parentWindowOf", "ventana principal de" },
{ "passwordtext", "texto de contrase\u00F1a" },
{ "popupmenu", "men\u00FA emergente" },
{ "pressed", "pulsado" },
{ "progressMonitor", "monitor de progreso" },
{ "progressbar", "barra de progreso" },
{ "pushbutton", "bot\u00F3n" },
{ "radiobutton", "bot\u00F3n de radio" },
{ "resizable", "redimensionable" },
{ "rootpane", "panel ra\u00EDz" },
{ "rowheader", "cabecera de filas" },
{ "ruler", "regla" },
{ "scrollbar", "barra de desplazamiento" },
{ "scrollpane", "panel de desplazamiento" },
{ "selectable", "seleccionable" },
{ "selected", "seleccionado" },
{ "separator", "separador" },
{ "showing", "mostrando" },
{ "singleline", "l\u00EDnea \u00FAnica" },
{ "slider", "deslizador" },
{ "splitpane", "panel de divisi\u00F3n" },
{ "subwindowOf", "ventana subordinada de" },
{ "swingcomponent", "componente swing" },
{ "table", "tabla" },
{ "text", "texto" },
{ "togglebutton", "bot\u00F3n conmutador" },
{ "toggleexpand", "conmutar ampliaci\u00F3n" },
{ "toolbar", "barra de herramientas" },
{ "tooltip", "ayuda de burbuja" },
{ "transient", "transitorio" },
{ "tree", "\u00E1rbol" },
{ "truncated", "truncado" },
{ "unknown", "desconocido" },
{ "vertical", "vertical" },
{ "viewport", "viewport" },
{ "visible", "visible" },
{ "window", "ventana" },
};
}
}

View File

@@ -0,0 +1,108 @@
package com.sun.accessibility.internal.resources;
import java.util.ListResourceBundle;
public final class accessibility_fr extends ListResourceBundle {
protected final Object[][] getContents() {
return new Object[][] {
{ "active", "actif" },
{ "alert", "alerte" },
{ "armed", "arm\u00E9" },
{ "awtcomponent", "composant AWT" },
{ "busy", "occup\u00E9" },
{ "canvas", "canevas" },
{ "checkbox", "case \u00E0 cocher" },
{ "checked", "coch\u00E9" },
{ "childNodeOf", "noeud enfant de" },
{ "collapsed", "r\u00E9duit" },
{ "colorchooser", "s\u00E9lecteur de couleurs" },
{ "columnheader", "en-t\u00EAte de colonne" },
{ "combobox", "liste d\u00E9roulante" },
{ "controlledBy", "contr\u00F4l\u00E9 par" },
{ "controllerFor", "contr\u00F4leur pour" },
{ "desktopicon", "ic\u00F4ne de bureau" },
{ "desktoppane", "panneau de bureau" },
{ "dialog", "bo\u00EEte de dialogue" },
{ "directorypane", "panneau de r\u00E9pertoires" },
{ "editable", "modifiable" },
{ "editbar", "barre d'\u00E9dition" },
{ "embeddedBy", "incorpor\u00E9 par" },
{ "embeds", "incorpore" },
{ "enabled", "activ\u00E9" },
{ "expandable", "extensible" },
{ "expanded", "d\u00E9velopp\u00E9" },
{ "filechooser", "s\u00E9lecteur de fichiers" },
{ "filler", "\u00E9l\u00E9ment de remplissage" },
{ "flowsFrom", "flux depuis" },
{ "flowsTo", "flux vers" },
{ "focusable", "zone d'entr\u00E9e possible" },
{ "focused", "avec zone d'entr\u00E9e" },
{ "footer", "pied de page" },
{ "frame", "cadre" },
{ "glasspane", "panneau de grossissement" },
{ "header", "en-t\u00EAte" },
{ "horizontal", "horizontal" },
{ "htmlcontainer", "conteneur HTML" },
{ "iconified", "r\u00E9duit \u00E0 une ic\u00F4ne" },
{ "indeterminate", "ind\u00E9termin\u00E9" },
{ "internalframe", "cadre interne" },
{ "label", "libell\u00E9" },
{ "labelFor", "libell\u00E9 de" },
{ "labeledBy", "libell\u00E9 par" },
{ "layeredpane", "panneau superpos\u00E9" },
{ "list", "liste" },
{ "listitem", "\u00E9l\u00E9ment de liste" },
{ "managesDescendants", "g\u00E8re les descendants" },
{ "memberOf", "membre de" },
{ "menu", "menu" },
{ "menubar", "barre de menus" },
{ "menuitem", "option de menu" },
{ "modal", "modal" },
{ "multiline", "ligne multiple" },
{ "multiselectable", "multis\u00E9lectionnable" },
{ "opaque", "opaque" },
{ "optionpane", "panneau d'options" },
{ "pagetab", "onglet de page" },
{ "pagetablist", "liste d'onglets de page" },
{ "panel", "panneau" },
{ "paragraph", "paragraphe" },
{ "parentWindowOf", "fen\u00EAtre parente de" },
{ "passwordtext", "texte de mot de passe" },
{ "popupmenu", "menu contextuel" },
{ "pressed", "enfonc\u00E9" },
{ "progressMonitor", "contr\u00F4le de la progression" },
{ "progressbar", "barre de progression" },
{ "pushbutton", "bouton" },
{ "radiobutton", "bouton radio" },
{ "resizable", "redimensionnable" },
{ "rootpane", "panneau racine" },
{ "rowheader", "en-t\u00EAte de ligne" },
{ "ruler", "r\u00E8gle" },
{ "scrollbar", "barre de d\u00E9filement" },
{ "scrollpane", "panneau de d\u00E9filement" },
{ "selectable", "s\u00E9lectionnable" },
{ "selected", "s\u00E9lectionn\u00E9" },
{ "separator", "s\u00E9parateur" },
{ "showing", "montrant" },
{ "singleline", "ligne unique" },
{ "slider", "curseur" },
{ "splitpane", "panneau divis\u00E9" },
{ "subwindowOf", "sous-fen\u00EAtre de" },
{ "swingcomponent", "composant Swing" },
{ "table", "tableau" },
{ "text", "texte" },
{ "togglebutton", "bouton de basculement" },
{ "toggleexpand", "activer/d\u00E9sactiver d\u00E9veloppement" },
{ "toolbar", "barre d'outils" },
{ "tooltip", "info-bulle" },
{ "transient", "non persistant" },
{ "tree", "arborescence" },
{ "truncated", "tronqu\u00E9" },
{ "unknown", "inconnu" },
{ "vertical", "vertical" },
{ "viewport", "lucarne" },
{ "visible", "visible" },
{ "window", "fen\u00EAtre" },
};
}
}

View File

@@ -0,0 +1,108 @@
package com.sun.accessibility.internal.resources;
import java.util.ListResourceBundle;
public final class accessibility_it extends ListResourceBundle {
protected final Object[][] getContents() {
return new Object[][] {
{ "active", "attivo" },
{ "alert", "avviso" },
{ "armed", "abilitato" },
{ "awtcomponent", "componente AWT" },
{ "busy", "occupato" },
{ "canvas", "sfondo" },
{ "checkbox", "casella di controllo" },
{ "checked", "verificato" },
{ "childNodeOf", "nodo figlio di" },
{ "collapsed", "compresso" },
{ "colorchooser", "selezione colori" },
{ "columnheader", "intestazione colonna" },
{ "combobox", "casella combinata" },
{ "controlledBy", "controlledBy" },
{ "controllerFor", "controllerFor" },
{ "desktopicon", "icona desktop" },
{ "desktoppane", "riquadro desktop" },
{ "dialog", "finestra di dialogo" },
{ "directorypane", "riquadro directory" },
{ "editable", "modificabile" },
{ "editbar", "barra di modifica" },
{ "embeddedBy", "incorporato da" },
{ "embeds", "incorpora" },
{ "enabled", "abilitato" },
{ "expandable", "espandibile" },
{ "expanded", "espanso" },
{ "filechooser", "selezione file" },
{ "filler", "utilit\u00E0 riempimento" },
{ "flowsFrom", "proviene da" },
{ "flowsTo", "va verso" },
{ "focusable", "attivabile in primo piano" },
{ "focused", "in primo piano" },
{ "footer", "pi\u00E8 di pagina" },
{ "frame", "cornice" },
{ "glasspane", "riquadro trasparente" },
{ "header", "intestazione" },
{ "horizontal", "orizzontale" },
{ "htmlcontainer", "Contenitore HTML" },
{ "iconified", "ridotto a icona" },
{ "indeterminate", "indeterminato" },
{ "internalframe", "cornice interna" },
{ "label", "etichetta" },
{ "labelFor", "etichetta per" },
{ "labeledBy", "etichetta di" },
{ "layeredpane", "riquadro a livelli" },
{ "list", "lista" },
{ "listitem", "voce lista" },
{ "managesDescendants", "gestisce i discendenti" },
{ "memberOf", "membro di" },
{ "menu", "menu" },
{ "menubar", "barra dei menu" },
{ "menuitem", "voce di menu" },
{ "modal", "modale" },
{ "multiline", "a righe multiple" },
{ "multiselectable", "multi-selezionabile" },
{ "opaque", "nascosto" },
{ "optionpane", "riquadro opzioni" },
{ "pagetab", "scheda pagina" },
{ "pagetablist", "lista schede pagina" },
{ "panel", "pannello" },
{ "paragraph", "paragrafo" },
{ "parentWindowOf", "finestra di livello superiore di" },
{ "passwordtext", "testo della password" },
{ "popupmenu", "menu popup" },
{ "pressed", "premuto" },
{ "progressMonitor", "stato avanzamento" },
{ "progressbar", "barra di avanzamento" },
{ "pushbutton", "pulsante" },
{ "radiobutton", "pulsante di scelta" },
{ "resizable", "ridimensionabile" },
{ "rootpane", "riquadro root" },
{ "rowheader", "intestazione di riga" },
{ "ruler", "righello" },
{ "scrollbar", "barra di scorrimento" },
{ "scrollpane", "riquadro scorrimento" },
{ "selectable", "selezionabile" },
{ "selected", "selezionato" },
{ "separator", "separatore" },
{ "showing", "visualizzato" },
{ "singleline", "a riga singola" },
{ "slider", "dispositivo di scorrimento" },
{ "splitpane", "riquadro doppio" },
{ "subwindowOf", "sottofinestra di" },
{ "swingcomponent", "componente swing" },
{ "table", "tabella" },
{ "text", "testo" },
{ "togglebutton", "interruttore" },
{ "toggleexpand", "attiva/disattiva espansione" },
{ "toolbar", "barra degli strumenti" },
{ "tooltip", "descrizione comandi" },
{ "transient", "transitorio" },
{ "tree", "albero" },
{ "truncated", "troncato" },
{ "unknown", "sconosciuto" },
{ "vertical", "verticale" },
{ "viewport", "viewport" },
{ "visible", "visibile" },
{ "window", "finestra" },
};
}
}

View File

@@ -0,0 +1,108 @@
package com.sun.accessibility.internal.resources;
import java.util.ListResourceBundle;
public final class accessibility_ja extends ListResourceBundle {
protected final Object[][] getContents() {
return new Object[][] {
{ "active", "\u30A2\u30AF\u30C6\u30A3\u30D6" },
{ "alert", "\u30A2\u30E9\u30FC\u30C8" },
{ "armed", "\u4F5C\u52D5\u6E96\u5099\u5B8C\u4E86" },
{ "awtcomponent", "AWT\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8" },
{ "busy", "\u30D3\u30B8\u30FC" },
{ "canvas", "\u30AD\u30E3\u30F3\u30D0\u30B9" },
{ "checkbox", "\u30C1\u30A7\u30C3\u30AF\u30FB\u30DC\u30C3\u30AF\u30B9" },
{ "checked", "\u30C1\u30A7\u30C3\u30AF" },
{ "childNodeOf", "child node of" },
{ "collapsed", "\u77ED\u7E2E" },
{ "colorchooser", "\u30AB\u30E9\u30FC\u30FB\u30C1\u30E5\u30FC\u30B6" },
{ "columnheader", "\u5217\u30D8\u30C3\u30C0\u30FC" },
{ "combobox", "\u30B3\u30F3\u30DC\u30FB\u30DC\u30C3\u30AF\u30B9" },
{ "controlledBy", "controlledBy" },
{ "controllerFor", "controllerFor" },
{ "desktopicon", "\u30C7\u30B9\u30AF\u30C8\u30C3\u30D7\u30FB\u30A2\u30A4\u30B3\u30F3" },
{ "desktoppane", "\u30C7\u30B9\u30AF\u30C8\u30C3\u30D7\u533A\u753B" },
{ "dialog", "\u30C0\u30A4\u30A2\u30ED\u30B0" },
{ "directorypane", "\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u533A\u753B" },
{ "editable", "\u7DE8\u96C6\u53EF\u80FD" },
{ "editbar", "\u7DE8\u96C6\u30D0\u30FC" },
{ "embeddedBy", "embedded by" },
{ "embeds", "\u57CB\u8FBC\u307F" },
{ "enabled", "\u6709\u52B9" },
{ "expandable", "\u5C55\u958B\u53EF\u80FD" },
{ "expanded", "\u5C55\u958B" },
{ "filechooser", "\u30D5\u30A1\u30A4\u30EB\u30FB\u30C1\u30E5\u30FC\u30B6" },
{ "filler", "\u30D5\u30A3\u30E9\u30FC" },
{ "flowsFrom", "flows from" },
{ "flowsTo", "flows to" },
{ "focusable", "\u30D5\u30A9\u30FC\u30AB\u30B9\u53EF\u80FD" },
{ "focused", "\u30D5\u30A9\u30FC\u30AB\u30B9" },
{ "footer", "\u30D5\u30C3\u30BF\u30FC" },
{ "frame", "\u30D5\u30EC\u30FC\u30E0" },
{ "glasspane", "\u30AC\u30E9\u30B9\u533A\u753B" },
{ "header", "\u30D8\u30C3\u30C0\u30FC" },
{ "horizontal", "\u6C34\u5E73" },
{ "htmlcontainer", "HTML\u30B3\u30F3\u30C6\u30CA" },
{ "iconified", "\u30A2\u30A4\u30B3\u30F3\u5316" },
{ "indeterminate", "\u4E0D\u78BA\u5B9A" },
{ "internalframe", "\u5185\u90E8\u30D5\u30EC\u30FC\u30E0" },
{ "label", "\u30E9\u30D9\u30EB" },
{ "labelFor", "label for" },
{ "labeledBy", "labeled by" },
{ "layeredpane", "\u968E\u5C64\u5316\u3055\u308C\u305F\u533A\u753B" },
{ "list", "\u30EA\u30B9\u30C8" },
{ "listitem", "\u30EA\u30B9\u30C8\u9805\u76EE" },
{ "managesDescendants", "\u5B50\u5B6B\u3092\u7BA1\u7406" },
{ "memberOf", "member of" },
{ "menu", "\u30E1\u30CB\u30E5\u30FC" },
{ "menubar", "\u30E1\u30CB\u30E5\u30FC\u30FB\u30D0\u30FC" },
{ "menuitem", "\u30E1\u30CB\u30E5\u30FC\u9805\u76EE" },
{ "modal", "\u30E2\u30FC\u30C0\u30EB" },
{ "multiline", "\u8907\u6570\u884C" },
{ "multiselectable", "\u8907\u6570\u9078\u629E\u53EF\u80FD" },
{ "opaque", "\u4E0D\u900F\u660E" },
{ "optionpane", "\u30AA\u30D7\u30B7\u30E7\u30F3\u533A\u753B" },
{ "pagetab", "\u30DA\u30FC\u30B8\u30FB\u30BF\u30D6" },
{ "pagetablist", "\u30DA\u30FC\u30B8\u30FB\u30BF\u30D6\u30FB\u30EA\u30B9\u30C8" },
{ "panel", "\u30D1\u30CD\u30EB" },
{ "paragraph", "\u6BB5\u843D" },
{ "parentWindowOf", "parent window of" },
{ "passwordtext", "\u30D1\u30B9\u30EF\u30FC\u30C9\u30FB\u30C6\u30AD\u30B9\u30C8" },
{ "popupmenu", "\u30DD\u30C3\u30D7\u30A2\u30C3\u30D7\u30FB\u30E1\u30CB\u30E5\u30FC" },
{ "pressed", "\u62BC\u4E0B" },
{ "progressMonitor", "\u9032\u6357\u30E2\u30CB\u30BF\u30FC" },
{ "progressbar", "\u9032\u6357\u30D0\u30FC" },
{ "pushbutton", "\u30D7\u30C3\u30B7\u30E5\u30FB\u30DC\u30BF\u30F3" },
{ "radiobutton", "\u30E9\u30B8\u30AA\u30FB\u30DC\u30BF\u30F3" },
{ "resizable", "\u30B5\u30A4\u30BA\u5909\u66F4\u53EF\u80FD" },
{ "rootpane", "\u30EB\u30FC\u30C8\u533A\u753B" },
{ "rowheader", "\u884C\u30D8\u30C3\u30C0\u30FC" },
{ "ruler", "\u30EB\u30FC\u30E9\u30FC" },
{ "scrollbar", "\u30B9\u30AF\u30ED\u30FC\u30EB\u30FB\u30D0\u30FC" },
{ "scrollpane", "\u30B9\u30AF\u30ED\u30FC\u30EB\u533A\u753B" },
{ "selectable", "\u9078\u629E\u53EF\u80FD" },
{ "selected", "\u9078\u629E" },
{ "separator", "\u30BB\u30D1\u30EC\u30FC\u30BF" },
{ "showing", "\u8868\u793A" },
{ "singleline", "\u5358\u4E00\u884C" },
{ "slider", "\u30B9\u30E9\u30A4\u30C0" },
{ "splitpane", "\u5206\u5272\u533A\u753B" },
{ "subwindowOf", "subwindow of" },
{ "swingcomponent", "Swing\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8" },
{ "table", "\u8868" },
{ "text", "\u30C6\u30AD\u30B9\u30C8" },
{ "togglebutton", "\u30C8\u30B0\u30EB\u30FB\u30DC\u30BF\u30F3" },
{ "toggleexpand", "\u5C55\u958B\u306E\u30C8\u30B0\u30EB" },
{ "toolbar", "\u30C4\u30FC\u30EB\u30D0\u30FC" },
{ "tooltip", "\u30C4\u30FC\u30EB\u30C1\u30C3\u30D7" },
{ "transient", "\u4E00\u6642" },
{ "tree", "\u30C4\u30EA\u30FC" },
{ "truncated", "\u4E0D\u5B8C\u5168" },
{ "unknown", "\u4E0D\u660E" },
{ "vertical", "\u5782\u76F4" },
{ "viewport", "\u30D3\u30E5\u30FC\u30DD\u30FC\u30C8" },
{ "visible", "\u53EF\u8996" },
{ "window", "\u30A6\u30A3\u30F3\u30C9\u30A6" },
};
}
}

View File

@@ -0,0 +1,108 @@
package com.sun.accessibility.internal.resources;
import java.util.ListResourceBundle;
public final class accessibility_ko extends ListResourceBundle {
protected final Object[][] getContents() {
return new Object[][] {
{ "active", "\uD65C\uC131" },
{ "alert", "\uACBD\uBCF4" },
{ "armed", "\uD06C\uAE30" },
{ "awtcomponent", "AWT \uAD6C\uC131\uC694\uC18C" },
{ "busy", "\uC0AC\uC6A9 \uC911" },
{ "canvas", "\uCE94\uBC84\uC2A4" },
{ "checkbox", "\uCCB4\uD06C\uBC15\uC2A4" },
{ "checked", "\uC120\uD0DD\uB428" },
{ "childNodeOf", "\uD558\uC704 \uB178\uB4DC" },
{ "collapsed", "\uCD95\uC18C\uB428" },
{ "colorchooser", "\uC0C9\uC0C1 \uC120\uD0DD\uAE30" },
{ "columnheader", "\uC5F4 \uBA38\uB9AC\uAE00" },
{ "combobox", "\uCF64\uBCF4 \uC0C1\uC790" },
{ "controlledBy", "controlledBy" },
{ "controllerFor", "controllerFor" },
{ "desktopicon", "\uBC14\uD0D5\uD654\uBA74 \uC544\uC774\uCF58" },
{ "desktoppane", "\uBC14\uD0D5\uD654\uBA74 \uCC3D" },
{ "dialog", "\uB300\uD654\uC0C1\uC790" },
{ "directorypane", "\uB514\uB809\uD1A0\uB9AC \uCC3D" },
{ "editable", "\uD3B8\uC9D1 \uAC00\uB2A5" },
{ "editbar", "\uD3B8\uC9D1 \uB3C4\uAD6C" },
{ "embeddedBy", "\uD3EC\uD568 \uC8FC\uCCB4" },
{ "embeds", "\uD3EC\uD568" },
{ "enabled", "\uC0AC\uC6A9" },
{ "expandable", "\uD655\uC7A5 \uAC00\uB2A5" },
{ "expanded", "\uD655\uC7A5\uB428" },
{ "filechooser", "\uD30C\uC77C \uC120\uD0DD\uAE30" },
{ "filler", "\uD544\uB7EC" },
{ "flowsFrom", "\uD750\uB984 \uCD9C\uCC98" },
{ "flowsTo", "\uD750\uB984 \uB300\uC0C1" },
{ "focusable", "\uD3EC\uCEE4\uC2A4 \uAC00\uB2A5" },
{ "focused", "\uD3EC\uCEE4\uC2A4\uB428" },
{ "footer", "\uBC14\uB2E5\uAE00" },
{ "frame", "\uD504\uB808\uC784" },
{ "glasspane", "\uAE00\uB798\uC2A4 \uCC3D" },
{ "header", "\uBA38\uB9AC\uAE00" },
{ "horizontal", "\uAC00\uB85C" },
{ "htmlcontainer", "HTML \uCEE8\uD14C\uC774\uB108" },
{ "iconified", "\uC544\uC774\uCF58\uD654\uB428" },
{ "indeterminate", "\uD655\uC815\uB418\uC9C0 \uC54A\uC74C" },
{ "internalframe", "\uB0B4\uBD80 \uD504\uB808\uC784" },
{ "label", "\uB808\uC774\uBE14" },
{ "labelFor", "\uB808\uC774\uBE14 \uB300\uC0C1" },
{ "labeledBy", "\uB808\uC774\uBE14 \uC9C0\uC815\uC790" },
{ "layeredpane", "\uACC4\uCE35\uC801 \uCC3D" },
{ "list", "\uBAA9\uB85D" },
{ "listitem", "\uBAA9\uB85D \uD56D\uBAA9" },
{ "managesDescendants", "\uC885\uC18D \uD56D\uBAA9 \uAD00\uB9AC" },
{ "memberOf", "\uC18C\uC18D \uADF8\uB8F9" },
{ "menu", "\uBA54\uB274" },
{ "menubar", "\uBA54\uB274 \uD45C\uC2DC\uC904" },
{ "menuitem", "\uBA54\uB274 \uD56D\uBAA9" },
{ "modal", "\uBAA8\uB2EC" },
{ "multiline", "\uBCF5\uC218 \uD589" },
{ "multiselectable", "\uB2E4\uC911 \uC120\uD0DD \uAC00\uB2A5" },
{ "opaque", "\uBD88\uD22C\uBA85" },
{ "optionpane", "\uC635\uC158 \uCC3D" },
{ "pagetab", "\uD398\uC774\uC9C0 \uD0ED" },
{ "pagetablist", "\uD398\uC774\uC9C0 \uD0ED \uBAA9\uB85D" },
{ "panel", "\uD328\uB110" },
{ "paragraph", "\uB2E8\uB77D" },
{ "parentWindowOf", "\uC0C1\uC704 \uCC3D" },
{ "passwordtext", "\uBE44\uBC00\uBC88\uD638 \uD14D\uC2A4\uD2B8" },
{ "popupmenu", "\uD31D\uC5C5 \uBA54\uB274" },
{ "pressed", "\uB204\uB984" },
{ "progressMonitor", "\uC9C4\uD589 \uBAA8\uB2C8\uD130" },
{ "progressbar", "\uC9C4\uD589 \uB9C9\uB300" },
{ "pushbutton", "\uB204\uB984 \uB2E8\uCD94" },
{ "radiobutton", "\uB77C\uB514\uC624 \uB2E8\uCD94" },
{ "resizable", "\uD06C\uAE30 \uC870\uC815 \uAC00\uB2A5" },
{ "rootpane", "\uB8E8\uD2B8 \uCC3D" },
{ "rowheader", "\uD589 \uBA38\uB9AC\uAE00" },
{ "ruler", "\uB208\uAE08\uC790" },
{ "scrollbar", "\uC2A4\uD06C\uB864 \uB9C9\uB300" },
{ "scrollpane", "\uC2A4\uD06C\uB864 \uCC3D" },
{ "selectable", "\uC120\uD0DD \uAC00\uB2A5" },
{ "selected", "\uC120\uD0DD\uB428" },
{ "separator", "\uAD6C\uBD84 \uAE30\uD638" },
{ "showing", "\uD45C\uC2DC" },
{ "singleline", "\uD55C \uC904" },
{ "slider", "\uC2AC\uB77C\uC774\uB354" },
{ "splitpane", "\uBD84\uD560 \uCC3D" },
{ "subwindowOf", "\uD558\uC704 \uCC3D" },
{ "swingcomponent", "\uD68C\uC804 \uAD6C\uC131\uC694\uC18C" },
{ "table", "\uD14C\uC774\uBE14" },
{ "text", "\uD14D\uC2A4\uD2B8" },
{ "togglebutton", "\uD1A0\uAE00 \uB2E8\uCD94" },
{ "toggleexpand", "\uD1A0\uAE00 \uD655\uC7A5" },
{ "toolbar", "\uB3C4\uAD6C \uBAA8\uC74C" },
{ "tooltip", "\uB3C4\uAD6C \uC124\uBA85" },
{ "transient", "\uC77C\uC2DC" },
{ "tree", "\uD2B8\uB9AC" },
{ "truncated", "\uC798\uB9BC" },
{ "unknown", "\uC54C \uC218 \uC5C6\uC74C" },
{ "vertical", "\uC138\uB85C" },
{ "viewport", "\uBDF0\uD3EC\uD2B8" },
{ "visible", "\uD45C\uC2DC \uAC00\uB2A5" },
{ "window", "\uCC3D" },
};
}
}

View File

@@ -0,0 +1,108 @@
package com.sun.accessibility.internal.resources;
import java.util.ListResourceBundle;
public final class accessibility_pt_BR extends ListResourceBundle {
protected final Object[][] getContents() {
return new Object[][] {
{ "active", "ativo" },
{ "alert", "alerta" },
{ "armed", "armado" },
{ "awtcomponent", "componente AWT" },
{ "busy", "ocupado" },
{ "canvas", "tela" },
{ "checkbox", "caixa de sele\u00E7\u00E3o" },
{ "checked", "selecionado" },
{ "childNodeOf", "n\u00F3 filho de" },
{ "collapsed", "contra\u00EDdo" },
{ "colorchooser", "seletor de cores" },
{ "columnheader", "cabe\u00E7alho da coluna" },
{ "combobox", "caixa de combina\u00E7\u00E3o" },
{ "controlledBy", "controlledBy" },
{ "controllerFor", "controllerFor" },
{ "desktopicon", "\u00EDcone da \u00E1rea de trabalho" },
{ "desktoppane", "painel da \u00E1rea de trabalho" },
{ "dialog", "caixa de di\u00E1logo" },
{ "directorypane", "painel do diret\u00F3rio" },
{ "editable", "edit\u00E1vel" },
{ "editbar", "barra de edi\u00E7\u00E3o" },
{ "embeddedBy", "integrado por" },
{ "embeds", "integra" },
{ "enabled", "ativado" },
{ "expandable", "expans\u00EDvel" },
{ "expanded", "expandido" },
{ "filechooser", "seletor de arquivos" },
{ "filler", "preenchedor" },
{ "flowsFrom", "fluxos de" },
{ "flowsTo", "fluxos para" },
{ "focusable", "focaliz\u00E1vel" },
{ "focused", "focalizado" },
{ "footer", "rodap\u00E9" },
{ "frame", "quadro" },
{ "glasspane", "painel transparente" },
{ "header", "cabe\u00E7alho" },
{ "horizontal", "horizontal" },
{ "htmlcontainer", "Container de HTML" },
{ "iconified", "iconizado" },
{ "indeterminate", "indeterminado" },
{ "internalframe", "quadro interno" },
{ "label", "r\u00F3tulo" },
{ "labelFor", "r\u00F3tulo de" },
{ "labeledBy", "rotulado por" },
{ "layeredpane", "painel em camadas" },
{ "list", "lista" },
{ "listitem", "item da lista" },
{ "managesDescendants", "gerencia descendentes" },
{ "memberOf", "membro de" },
{ "menu", "menu" },
{ "menubar", "barra de menus" },
{ "menuitem", "item do menu" },
{ "modal", "modal" },
{ "multiline", "v\u00E1rias linhas" },
{ "multiselectable", "m\u00FAltipla escolha" },
{ "opaque", "opaco" },
{ "optionpane", "painel de op\u00E7\u00F5es" },
{ "pagetab", "guia da p\u00E1gina" },
{ "pagetablist", "lista de guias da p\u00E1gina" },
{ "panel", "painel" },
{ "paragraph", "par\u00E1grafo" },
{ "parentWindowOf", "janela pai de" },
{ "passwordtext", "texto da senha" },
{ "popupmenu", "menu pop-up" },
{ "pressed", "pressionado" },
{ "progressMonitor", "monitor de progresso" },
{ "progressbar", "barra de progresso" },
{ "pushbutton", "bot\u00E3o de a\u00E7\u00E3o" },
{ "radiobutton", "bot\u00E3o de op\u00E7\u00E3o" },
{ "resizable", "redimension\u00E1vel" },
{ "rootpane", "painel base" },
{ "rowheader", "cabe\u00E7alho da linha" },
{ "ruler", "r\u00E9gua" },
{ "scrollbar", "barra de rolagem" },
{ "scrollpane", "painel de rolagem" },
{ "selectable", "selecion\u00E1vel" },
{ "selected", "selecionado" },
{ "separator", "separador" },
{ "showing", "mostrando" },
{ "singleline", "linha \u00FAnica" },
{ "slider", "controle deslizante" },
{ "splitpane", "painel dividido" },
{ "subwindowOf", "subjanela de" },
{ "swingcomponent", "componente swing" },
{ "table", "tabela" },
{ "text", "texto" },
{ "togglebutton", "bot\u00E3o de altern\u00E2ncia" },
{ "toggleexpand", "alternar expandir" },
{ "toolbar", "barra de ferramentas" },
{ "tooltip", "dica de ferramenta" },
{ "transient", "transit\u00F3rio" },
{ "tree", "\u00E1rvore" },
{ "truncated", "truncado" },
{ "unknown", "desconhecido" },
{ "vertical", "vertical" },
{ "viewport", "janela de visualiza\u00E7\u00E3o" },
{ "visible", "vis\u00EDvel" },
{ "window", "janela" },
};
}
}

View File

@@ -0,0 +1,108 @@
package com.sun.accessibility.internal.resources;
import java.util.ListResourceBundle;
public final class accessibility_sv extends ListResourceBundle {
protected final Object[][] getContents() {
return new Object[][] {
{ "active", "aktiv" },
{ "alert", "avisering" },
{ "armed", "redo" },
{ "awtcomponent", "AWT-komponent" },
{ "busy", "upptagen" },
{ "canvas", "rityta" },
{ "checkbox", "kryssruta" },
{ "checked", "markerad" },
{ "childNodeOf", "underordnad nod f\u00F6r" },
{ "collapsed", "komprimerad" },
{ "colorchooser", "f\u00E4rgv\u00E4ljare" },
{ "columnheader", "kolumnrubrik" },
{ "combobox", "kombinationsruta" },
{ "controlledBy", "controlledBy" },
{ "controllerFor", "controllerFor" },
{ "desktopicon", "skrivbordsikon" },
{ "desktoppane", "skrivbordsruta" },
{ "dialog", "dialogruta" },
{ "directorypane", "katalogruta" },
{ "editable", "redigerbar" },
{ "editbar", "redigeringslist" },
{ "embeddedBy", "b\u00E4ddas in av" },
{ "embeds", "b\u00E4ddar in" },
{ "enabled", "aktiverad" },
{ "expandable", "ut\u00F6kningsbar" },
{ "expanded", "ut\u00F6kad" },
{ "filechooser", "filv\u00E4ljare" },
{ "filler", "utfyllnad" },
{ "flowsFrom", "fl\u00F6dar fr\u00E5n" },
{ "flowsTo", "fl\u00F6dar till" },
{ "focusable", "fokuseringsbar" },
{ "focused", "fokuserad" },
{ "footer", "sidfot" },
{ "frame", "ram" },
{ "glasspane", "glasruta" },
{ "header", "sidhuvud" },
{ "horizontal", "horisontell" },
{ "htmlcontainer", "HTML-container" },
{ "iconified", "minimerad" },
{ "indeterminate", "obest\u00E4mt" },
{ "internalframe", "intern ram" },
{ "label", "etikett" },
{ "labelFor", "etikett f\u00F6r" },
{ "labeledBy", "etikett av" },
{ "layeredpane", "staplad ruta" },
{ "list", "lista" },
{ "listitem", "listobjekt" },
{ "managesDescendants", "hanterar underordnade" },
{ "memberOf", "medlem i" },
{ "menu", "meny" },
{ "menubar", "menyrad" },
{ "menuitem", "menyalternativ" },
{ "modal", "modal" },
{ "multiline", "flera rader" },
{ "multiselectable", "flerval" },
{ "opaque", "ogenomskinlig" },
{ "optionpane", "alternativruta" },
{ "pagetab", "sidflik" },
{ "pagetablist", "sidflikslista" },
{ "panel", "panel" },
{ "paragraph", "stycke" },
{ "parentWindowOf", "\u00F6verordnat f\u00F6nster f\u00F6r" },
{ "passwordtext", "l\u00F6senordstext" },
{ "popupmenu", "snabbmeny" },
{ "pressed", "nedtryckt" },
{ "progressMonitor", "f\u00F6rlopps\u00F6vervakare" },
{ "progressbar", "statusrad" },
{ "pushbutton", "knapp" },
{ "radiobutton", "alternativknapp" },
{ "resizable", "storleks\u00E4ndringsbar" },
{ "rootpane", "grundruta" },
{ "rowheader", "radrubrik" },
{ "ruler", "linjal" },
{ "scrollbar", "rullningslist" },
{ "scrollpane", "rullningsruta" },
{ "selectable", "valbar" },
{ "selected", "vald" },
{ "separator", "avskiljare" },
{ "showing", "visar" },
{ "singleline", "en rad" },
{ "slider", "skjutreglage" },
{ "splitpane", "delad ruta" },
{ "subwindowOf", "delf\u00F6nster av" },
{ "swingcomponent", "swing-komponent" },
{ "table", "tabell" },
{ "text", "text" },
{ "togglebutton", "v\u00E4xlingsknapp" },
{ "toggleexpand", "v\u00E4xla expandering" },
{ "toolbar", "verktygsrad" },
{ "tooltip", "knappbeskrivning" },
{ "transient", "tillf\u00E4llig" },
{ "tree", "tr\u00E4d" },
{ "truncated", "kapad" },
{ "unknown", "ok\u00E4nd" },
{ "vertical", "vertikal" },
{ "viewport", "vyport" },
{ "visible", "synlig" },
{ "window", "f\u00F6nster" },
};
}
}

View File

@@ -0,0 +1,108 @@
package com.sun.accessibility.internal.resources;
import java.util.ListResourceBundle;
public final class accessibility_zh_CN extends ListResourceBundle {
protected final Object[][] getContents() {
return new Object[][] {
{ "active", "\u6D3B\u52A8" },
{ "alert", "\u9884\u8B66" },
{ "armed", "\u5F85\u547D" },
{ "awtcomponent", "AWT \u7EC4\u4EF6" },
{ "busy", "\u5FD9" },
{ "canvas", "\u753B\u5E03" },
{ "checkbox", "\u590D\u9009\u6846" },
{ "checked", "\u5DF2\u9009\u4E2D" },
{ "childNodeOf", "\u5B50\u8282\u70B9" },
{ "collapsed", "\u5DF2\u6536\u7F29" },
{ "colorchooser", "\u989C\u8272\u9009\u62E9\u5668" },
{ "columnheader", "\u5217\u6807\u9898" },
{ "combobox", "\u7EC4\u5408\u6846" },
{ "controlledBy", "controlledBy" },
{ "controllerFor", "controllerFor" },
{ "desktopicon", "\u684C\u9762\u56FE\u6807" },
{ "desktoppane", "\u684C\u9762\u7A97\u683C" },
{ "dialog", "\u5BF9\u8BDD" },
{ "directorypane", "\u76EE\u5F55\u7A97\u683C" },
{ "editable", "\u53EF\u7F16\u8F91" },
{ "editbar", "\u7F16\u8F91\u680F" },
{ "embeddedBy", "\u5D4C\u5165\u8005" },
{ "embeds", "\u5D4C\u5165\u9879" },
{ "enabled", "\u542F\u7528" },
{ "expandable", "\u53EF\u5C55\u5F00" },
{ "expanded", "\u5DF2\u5C55\u5F00" },
{ "filechooser", "\u6587\u4EF6\u9009\u62E9\u5668" },
{ "filler", "\u6F0F\u6597" },
{ "flowsFrom", "\u6D41\u81EA" },
{ "flowsTo", "\u6D41\u5411" },
{ "focusable", "\u53EF\u96C6\u4E2D" },
{ "focused", "\u5DF2\u96C6\u4E2D" },
{ "footer", "\u9875\u811A" },
{ "frame", "\u6846\u67B6" },
{ "glasspane", "\u73BB\u7483\u7A97\u683C" },
{ "header", "\u9875\u7709" },
{ "horizontal", "\u6C34\u5E73" },
{ "htmlcontainer", "HTML \u5BB9\u5668" },
{ "iconified", "\u56FE\u6807\u5F0F" },
{ "indeterminate", "\u4E0D\u786E\u5B9A" },
{ "internalframe", "\u5185\u90E8\u6846\u67B6" },
{ "label", "\u6807\u7B7E" },
{ "labelFor", "\u6807\u7B7E\u5C5E\u4E8E" },
{ "labeledBy", "\u6807\u7B7E\u5236\u4F5C\u8005" },
{ "layeredpane", "\u5206\u5C42\u7A97\u683C" },
{ "list", "\u5217\u8868" },
{ "listitem", "\u5217\u8868\u9879" },
{ "managesDescendants", "\u7BA1\u7406\u5B50\u9879" },
{ "memberOf", "\u5C5E\u4E8E" },
{ "menu", "\u83DC\u5355" },
{ "menubar", "\u83DC\u5355\u680F" },
{ "menuitem", "\u83DC\u5355\u9879" },
{ "modal", "\u6A21\u6001" },
{ "multiline", "\u591A\u884C" },
{ "multiselectable", "\u591A\u9009\u62E9" },
{ "opaque", "\u4E0D\u900F\u660E" },
{ "optionpane", "\u9009\u9879\u7A97\u683C" },
{ "pagetab", "\u9875\u6807\u7B7E" },
{ "pagetablist", "\u9875\u6807\u7B7E\u5217\u8868" },
{ "panel", "\u9762\u677F" },
{ "paragraph", "\u6BB5\u843D" },
{ "parentWindowOf", "\u7236\u7A97\u53E3" },
{ "passwordtext", "\u53E3\u4EE4\u6587\u672C" },
{ "popupmenu", "\u5F39\u51FA\u5F0F\u83DC\u5355" },
{ "pressed", "\u5DF2\u6309\u4E0B" },
{ "progressMonitor", "\u8FDB\u5EA6\u76D1\u89C6\u5668" },
{ "progressbar", "\u8FDB\u5EA6\u680F" },
{ "pushbutton", "\u6309\u94AE" },
{ "radiobutton", "\u5355\u9009\u6309\u94AE" },
{ "resizable", "\u53EF\u8C03\u6574\u5927\u5C0F" },
{ "rootpane", "\u6839\u7A97\u683C" },
{ "rowheader", "\u884C\u6807\u9898" },
{ "ruler", "\u6807\u5C3A" },
{ "scrollbar", "\u6EDA\u52A8\u6761" },
{ "scrollpane", "\u6EDA\u52A8\u7A97\u683C" },
{ "selectable", "\u53EF\u9009\u62E9" },
{ "selected", "\u6240\u9009" },
{ "separator", "\u5206\u9694\u6761" },
{ "showing", "\u6B63\u5728\u663E\u793A" },
{ "singleline", "\u5355\u884C" },
{ "slider", "\u6ED1\u5757" },
{ "splitpane", "\u62C6\u5206\u7A97\u683C" },
{ "subwindowOf", "\u5B50\u7A97\u53E3" },
{ "swingcomponent", "\u65CB\u8F6C\u7EC4\u4EF6" },
{ "table", "\u8868" },
{ "text", "\u6587\u672C" },
{ "togglebutton", "\u5207\u6362\u6309\u94AE" },
{ "toggleexpand", "\u5207\u6362\u5C55\u5F00" },
{ "toolbar", "\u5DE5\u5177\u680F" },
{ "tooltip", "\u5DE5\u5177\u63D0\u793A" },
{ "transient", "\u77AC\u65F6" },
{ "tree", "\u6811" },
{ "truncated", "\u5DF2\u622A\u65AD" },
{ "unknown", "\u672A\u77E5" },
{ "vertical", "\u5782\u76F4" },
{ "viewport", "\u89C6\u7A97" },
{ "visible", "\u53EF\u89C1" },
{ "window", "\u7A97\u53E3" },
};
}
}

View File

@@ -0,0 +1,108 @@
package com.sun.accessibility.internal.resources;
import java.util.ListResourceBundle;
public final class accessibility_zh_HK extends ListResourceBundle {
protected final Object[][] getContents() {
return new Object[][] {
{ "active", "\u4F5C\u7528\u4E2D" },
{ "alert", "\u8B66\u793A" },
{ "armed", "\u5DF2\u914D\u5099" },
{ "awtcomponent", "AWT \u5143\u4EF6" },
{ "busy", "\u5FD9\u788C\u4E2D" },
{ "canvas", "\u756B\u5E03" },
{ "checkbox", "\u6838\u53D6\u65B9\u584A" },
{ "checked", "\u5DF2\u6838\u9078" },
{ "childNodeOf", "\u5B50\u7BC0\u9EDE" },
{ "collapsed", "\u5DF2\u6536\u7E2E" },
{ "colorchooser", "\u8272\u5F69\u9078\u64C7\u5668" },
{ "columnheader", "\u76F4\u6B04\u6A19\u984C" },
{ "combobox", "\u4E0B\u62C9\u5F0F\u6E05\u55AE\u65B9\u584A" },
{ "controlledBy", "\u63A7\u5236\u8005" },
{ "controllerFor", "\u63A7\u5236\u5C0D\u8C61" },
{ "desktopicon", "\u684C\u9762\u5716\u793A" },
{ "desktoppane", "\u684C\u9762\u7A97\u683C" },
{ "dialog", "\u5C0D\u8A71\u65B9\u584A" },
{ "directorypane", "\u76EE\u9304\u7A97\u683C" },
{ "editable", "\u53EF\u7DE8\u8F2F" },
{ "editbar", "\u7DE8\u8F2F\u5217" },
{ "embeddedBy", "\u5167\u5D4C\u8005" },
{ "embeds", "\u5167\u5D4C" },
{ "enabled", "\u5DF2\u555F\u7528" },
{ "expandable", "\u53EF\u64F4\u5C55" },
{ "expanded", "\u5DF2\u64F4\u5C55" },
{ "filechooser", "\u6A94\u6848\u9078\u64C7\u5668" },
{ "filler", "\u586B\u5145\u7269" },
{ "flowsFrom", "\u6D41\u52D5\u81EA" },
{ "flowsTo", "\u6D41\u52D5\u81F3" },
{ "focusable", "\u53EF\u805A\u7126" },
{ "focused", "\u5DF2\u805A\u7126" },
{ "footer", "\u9801\u5C3E" },
{ "frame", "\u6846\u67B6" },
{ "glasspane", "\u6AA2\u8996\u7A97\u683C" },
{ "header", "\u9801\u9996" },
{ "horizontal", "\u6C34\u5E73" },
{ "htmlcontainer", "HTML \u5BB9\u5668" },
{ "iconified", "\u5DF2\u5716\u793A\u5316" },
{ "indeterminate", "\u4E0D\u78BA\u5B9A" },
{ "internalframe", "\u5167\u90E8\u6846\u67B6" },
{ "label", "\u6A19\u7C64" },
{ "labelFor", "\u6A19\u793A\u5C0D\u8C61" },
{ "labeledBy", "\u6A19\u793A\u8005" },
{ "layeredpane", "\u5206\u5C64\u7A97\u683C" },
{ "list", "\u6E05\u55AE" },
{ "listitem", "\u6E05\u55AE\u9805\u76EE" },
{ "managesDescendants", "\u7BA1\u7406\u5B50\u4EE3" },
{ "memberOf", "\u6240\u5C6C\u6210\u54E1" },
{ "menu", "\u529F\u80FD\u8868" },
{ "menubar", "\u529F\u80FD\u8868\u5217" },
{ "menuitem", "\u529F\u80FD\u8868\u9805\u76EE" },
{ "modal", "\u6A21\u614B" },
{ "multiline", "\u591A\u884C" },
{ "multiselectable", "\u53EF\u591A\u91CD\u9078\u53D6" },
{ "opaque", "\u4E0D\u900F\u660E" },
{ "optionpane", "\u9078\u9805\u7A97\u683C" },
{ "pagetab", "\u9801\u9762\u9801\u7C64" },
{ "pagetablist", "\u9801\u9762\u9801\u7C64\u6E05\u55AE" },
{ "panel", "\u9762\u677F" },
{ "paragraph", "\u6BB5\u843D" },
{ "parentWindowOf", "\u7236\u7CFB\u8996\u7A97" },
{ "passwordtext", "\u5BC6\u78BC\u6587\u5B57" },
{ "popupmenu", "\u5373\u73FE\u5F0F\u529F\u80FD\u8868" },
{ "pressed", "\u5DF2\u6309\u4E0B" },
{ "progressMonitor", "\u9032\u5EA6\u76E3\u8996\u5668" },
{ "progressbar", "\u9032\u5EA6\u5217" },
{ "pushbutton", "\u4E0B\u58D3\u6309\u9215" },
{ "radiobutton", "\u5713\u9215" },
{ "resizable", "\u53EF\u8ABF\u6574\u5927\u5C0F" },
{ "rootpane", "root \u7A97\u683C" },
{ "rowheader", "\u5217\u6A19\u984C" },
{ "ruler", "\u5C3A\u898F" },
{ "scrollbar", "\u6372\u8EF8" },
{ "scrollpane", "\u6372\u52D5\u7A97\u683C" },
{ "selectable", "\u53EF\u9078\u53D6" },
{ "selected", "\u5DF2\u9078\u53D6" },
{ "separator", "\u5206\u9694\u5143" },
{ "showing", "\u986F\u793A" },
{ "singleline", "\u55AE\u884C" },
{ "slider", "\u6ED1\u52D5\u8EF8" },
{ "splitpane", "\u5206\u5272\u7A97\u683C" },
{ "subwindowOf", "\u5B50\u8996\u7A97" },
{ "swingcomponent", "Swing \u5143\u4EF6" },
{ "table", "\u8868\u683C" },
{ "text", "\u6587\u5B57" },
{ "togglebutton", "\u5207\u63DB\u6309\u9215" },
{ "toggleexpand", "\u5207\u63DB\u64F4\u5C55" },
{ "toolbar", "\u5DE5\u5177\u5217" },
{ "tooltip", "\u5DE5\u5177\u63D0\u793A" },
{ "transient", "\u66AB\u6642\u7684" },
{ "tree", "\u6A39\u72C0\u7D50\u69CB" },
{ "truncated", "\u5DF2\u622A\u65B7" },
{ "unknown", "\u4E0D\u660E\u7684" },
{ "vertical", "\u5782\u76F4" },
{ "viewport", "\u6AA2\u8996\u5340" },
{ "visible", "\u53EF\u898B\u7684" },
{ "window", "\u8996\u7A97" },
};
}
}

View File

@@ -0,0 +1,108 @@
package com.sun.accessibility.internal.resources;
import java.util.ListResourceBundle;
public final class accessibility_zh_TW extends ListResourceBundle {
protected final Object[][] getContents() {
return new Object[][] {
{ "active", "\u4F5C\u7528\u4E2D" },
{ "alert", "\u8B66\u793A" },
{ "armed", "\u5DF2\u914D\u5099" },
{ "awtcomponent", "AWT \u5143\u4EF6" },
{ "busy", "\u5FD9\u788C\u4E2D" },
{ "canvas", "\u756B\u5E03" },
{ "checkbox", "\u6838\u53D6\u65B9\u584A" },
{ "checked", "\u5DF2\u6838\u9078" },
{ "childNodeOf", "\u5B50\u7BC0\u9EDE" },
{ "collapsed", "\u5DF2\u6536\u7E2E" },
{ "colorchooser", "\u8272\u5F69\u9078\u64C7\u5668" },
{ "columnheader", "\u76F4\u6B04\u6A19\u984C" },
{ "combobox", "\u4E0B\u62C9\u5F0F\u6E05\u55AE\u65B9\u584A" },
{ "controlledBy", "\u63A7\u5236\u8005" },
{ "controllerFor", "\u63A7\u5236\u5C0D\u8C61" },
{ "desktopicon", "\u684C\u9762\u5716\u793A" },
{ "desktoppane", "\u684C\u9762\u7A97\u683C" },
{ "dialog", "\u5C0D\u8A71\u65B9\u584A" },
{ "directorypane", "\u76EE\u9304\u7A97\u683C" },
{ "editable", "\u53EF\u7DE8\u8F2F" },
{ "editbar", "\u7DE8\u8F2F\u5217" },
{ "embeddedBy", "\u5167\u5D4C\u8005" },
{ "embeds", "\u5167\u5D4C" },
{ "enabled", "\u5DF2\u555F\u7528" },
{ "expandable", "\u53EF\u64F4\u5C55" },
{ "expanded", "\u5DF2\u64F4\u5C55" },
{ "filechooser", "\u6A94\u6848\u9078\u64C7\u5668" },
{ "filler", "\u586B\u5145\u7269" },
{ "flowsFrom", "\u6D41\u52D5\u81EA" },
{ "flowsTo", "\u6D41\u52D5\u81F3" },
{ "focusable", "\u53EF\u805A\u7126" },
{ "focused", "\u5DF2\u805A\u7126" },
{ "footer", "\u9801\u5C3E" },
{ "frame", "\u6846\u67B6" },
{ "glasspane", "\u6AA2\u8996\u7A97\u683C" },
{ "header", "\u9801\u9996" },
{ "horizontal", "\u6C34\u5E73" },
{ "htmlcontainer", "HTML \u5BB9\u5668" },
{ "iconified", "\u5DF2\u5716\u793A\u5316" },
{ "indeterminate", "\u4E0D\u78BA\u5B9A" },
{ "internalframe", "\u5167\u90E8\u6846\u67B6" },
{ "label", "\u6A19\u7C64" },
{ "labelFor", "\u6A19\u793A\u5C0D\u8C61" },
{ "labeledBy", "\u6A19\u793A\u8005" },
{ "layeredpane", "\u5206\u5C64\u7A97\u683C" },
{ "list", "\u6E05\u55AE" },
{ "listitem", "\u6E05\u55AE\u9805\u76EE" },
{ "managesDescendants", "\u7BA1\u7406\u5B50\u4EE3" },
{ "memberOf", "\u6240\u5C6C\u6210\u54E1" },
{ "menu", "\u529F\u80FD\u8868" },
{ "menubar", "\u529F\u80FD\u8868\u5217" },
{ "menuitem", "\u529F\u80FD\u8868\u9805\u76EE" },
{ "modal", "\u6A21\u614B" },
{ "multiline", "\u591A\u884C" },
{ "multiselectable", "\u53EF\u591A\u91CD\u9078\u53D6" },
{ "opaque", "\u4E0D\u900F\u660E" },
{ "optionpane", "\u9078\u9805\u7A97\u683C" },
{ "pagetab", "\u9801\u9762\u9801\u7C64" },
{ "pagetablist", "\u9801\u9762\u9801\u7C64\u6E05\u55AE" },
{ "panel", "\u9762\u677F" },
{ "paragraph", "\u6BB5\u843D" },
{ "parentWindowOf", "\u7236\u7CFB\u8996\u7A97" },
{ "passwordtext", "\u5BC6\u78BC\u6587\u5B57" },
{ "popupmenu", "\u5373\u73FE\u5F0F\u529F\u80FD\u8868" },
{ "pressed", "\u5DF2\u6309\u4E0B" },
{ "progressMonitor", "\u9032\u5EA6\u76E3\u8996\u5668" },
{ "progressbar", "\u9032\u5EA6\u5217" },
{ "pushbutton", "\u4E0B\u58D3\u6309\u9215" },
{ "radiobutton", "\u5713\u9215" },
{ "resizable", "\u53EF\u8ABF\u6574\u5927\u5C0F" },
{ "rootpane", "root \u7A97\u683C" },
{ "rowheader", "\u5217\u6A19\u984C" },
{ "ruler", "\u5C3A\u898F" },
{ "scrollbar", "\u6372\u8EF8" },
{ "scrollpane", "\u6372\u52D5\u7A97\u683C" },
{ "selectable", "\u53EF\u9078\u53D6" },
{ "selected", "\u5DF2\u9078\u53D6" },
{ "separator", "\u5206\u9694\u5143" },
{ "showing", "\u986F\u793A" },
{ "singleline", "\u55AE\u884C" },
{ "slider", "\u6ED1\u52D5\u8EF8" },
{ "splitpane", "\u5206\u5272\u7A97\u683C" },
{ "subwindowOf", "\u5B50\u8996\u7A97" },
{ "swingcomponent", "Swing \u5143\u4EF6" },
{ "table", "\u8868\u683C" },
{ "text", "\u6587\u5B57" },
{ "togglebutton", "\u5207\u63DB\u6309\u9215" },
{ "toggleexpand", "\u5207\u63DB\u64F4\u5C55" },
{ "toolbar", "\u5DE5\u5177\u5217" },
{ "tooltip", "\u5DE5\u5177\u63D0\u793A" },
{ "transient", "\u66AB\u6642\u7684" },
{ "tree", "\u6A39\u72C0\u7D50\u69CB" },
{ "truncated", "\u5DF2\u622A\u65B7" },
{ "unknown", "\u4E0D\u660E\u7684" },
{ "vertical", "\u5782\u76F4" },
{ "viewport", "\u6AA2\u8996\u5340" },
{ "visible", "\u53EF\u898B\u7684" },
{ "window", "\u8996\u7A97" },
};
}
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2003, 2005, 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.activation.registries;
import java.io.*;
import java.util.logging.*;
/**
* Logging related methods.
*/
public class LogSupport {
private static boolean debug = false;
private static Logger logger;
private static final Level level = Level.FINE;
static {
try {
debug = Boolean.getBoolean("javax.activation.debug");
} catch (Throwable t) {
// ignore any errors
}
logger = Logger.getLogger("javax.activation");
}
/**
* Constructor.
*/
private LogSupport() {
// private constructor, can't create instances
}
public static void log(String msg) {
if (debug)
System.out.println(msg);
logger.log(level, msg);
}
public static void log(String msg, Throwable t) {
if (debug)
System.out.println(msg + "; Exception: " + t);
logger.log(level, msg, t);
}
public static boolean isLoggable() {
return debug || logger.isLoggable(level);
}
}

View File

@@ -0,0 +1,563 @@
/*
* Copyright (c) 1997, 2005, 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.activation.registries;
import java.io.*;
import java.util.*;
public class MailcapFile {
/**
* A Map indexed by MIME type (string) that references
* a Map of commands for each type. The comand Map
* is indexed by the command name and references a List of
* class names (strings) for each command.
*/
private Map type_hash = new HashMap();
/**
* Another Map like above, but for fallback entries.
*/
private Map fallback_hash = new HashMap();
/**
* A Map indexed by MIME type (string) that references
* a List of native commands (string) corresponding to the type.
*/
private Map native_commands = new HashMap();
private static boolean addReverse = false;
static {
try {
addReverse = Boolean.getBoolean("javax.activation.addreverse");
} catch (Throwable t) {
// ignore any errors
}
}
/**
* The constructor that takes a filename as an argument.
*
* @param new_fname The file name of the mailcap file.
*/
public MailcapFile(String new_fname) throws IOException {
if (LogSupport.isLoggable())
LogSupport.log("new MailcapFile: file " + new_fname);
FileReader reader = null;
try {
reader = new FileReader(new_fname);
parse(new BufferedReader(reader));
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ex) { }
}
}
}
/**
* The constructor that takes an input stream as an argument.
*
* @param is the input stream
*/
public MailcapFile(InputStream is) throws IOException {
if (LogSupport.isLoggable())
LogSupport.log("new MailcapFile: InputStream");
parse(new BufferedReader(new InputStreamReader(is, "iso-8859-1")));
}
/**
* Mailcap file default constructor.
*/
public MailcapFile() {
if (LogSupport.isLoggable())
LogSupport.log("new MailcapFile: default");
}
/**
* Get the Map of MailcapEntries based on the MIME type.
*
* <p>
* <strong>Semantics:</strong> First check for the literal mime type,
* if that fails looks for wildcard <type>/\* and return that. Return the
* list of all that hit.
*/
public Map getMailcapList(String mime_type) {
Map search_result = null;
Map wildcard_result = null;
// first try the literal
search_result = (Map)type_hash.get(mime_type);
// ok, now try the wildcard
int separator = mime_type.indexOf('/');
String subtype = mime_type.substring(separator + 1);
if (!subtype.equals("*")) {
String type = mime_type.substring(0, separator + 1) + "*";
wildcard_result = (Map)type_hash.get(type);
if (wildcard_result != null) { // damn, we have to merge!!!
if (search_result != null)
search_result =
mergeResults(search_result, wildcard_result);
else
search_result = wildcard_result;
}
}
return search_result;
}
/**
* Get the Map of fallback MailcapEntries based on the MIME type.
*
* <p>
* <strong>Semantics:</strong> First check for the literal mime type,
* if that fails looks for wildcard <type>/\* and return that. Return the
* list of all that hit.
*/
public Map getMailcapFallbackList(String mime_type) {
Map search_result = null;
Map wildcard_result = null;
// first try the literal
search_result = (Map)fallback_hash.get(mime_type);
// ok, now try the wildcard
int separator = mime_type.indexOf('/');
String subtype = mime_type.substring(separator + 1);
if (!subtype.equals("*")) {
String type = mime_type.substring(0, separator + 1) + "*";
wildcard_result = (Map)fallback_hash.get(type);
if (wildcard_result != null) { // damn, we have to merge!!!
if (search_result != null)
search_result =
mergeResults(search_result, wildcard_result);
else
search_result = wildcard_result;
}
}
return search_result;
}
/**
* Return all the MIME types known to this mailcap file.
*/
public String[] getMimeTypes() {
Set types = new HashSet(type_hash.keySet());
types.addAll(fallback_hash.keySet());
types.addAll(native_commands.keySet());
String[] mts = new String[types.size()];
mts = (String[])types.toArray(mts);
return mts;
}
/**
* Return all the native comands for the given MIME type.
*/
public String[] getNativeCommands(String mime_type) {
String[] cmds = null;
List v =
(List)native_commands.get(mime_type.toLowerCase(Locale.ENGLISH));
if (v != null) {
cmds = new String[v.size()];
cmds = (String[])v.toArray(cmds);
}
return cmds;
}
/**
* Merge the first hash into the second.
* This merge will only effect the hashtable that is
* returned, we don't want to touch the one passed in since
* its integrity must be maintained.
*/
private Map mergeResults(Map first, Map second) {
Iterator verb_enum = second.keySet().iterator();
Map clonedHash = new HashMap(first);
// iterate through the verbs in the second map
while (verb_enum.hasNext()) {
String verb = (String)verb_enum.next();
List cmdVector = (List)clonedHash.get(verb);
if (cmdVector == null) {
clonedHash.put(verb, second.get(verb));
} else {
// merge the two
List oldV = (List)second.get(verb);
cmdVector = new ArrayList(cmdVector);
cmdVector.addAll(oldV);
clonedHash.put(verb, cmdVector);
}
}
return clonedHash;
}
/**
* appendToMailcap: Append to this Mailcap DB, use the mailcap
* format:
* Comment == "# <i>comment string</i>
* Entry == "mimetype; javabeanclass<nl>
*
* Example:
* # this is a comment
* image/gif jaf.viewers.ImageViewer
*/
public void appendToMailcap(String mail_cap) {
if (LogSupport.isLoggable())
LogSupport.log("appendToMailcap: " + mail_cap);
try {
parse(new StringReader(mail_cap));
} catch (IOException ex) {
// can't happen
}
}
/**
* parse file into a hash table of MC Type Entry Obj
*/
private void parse(Reader reader) throws IOException {
BufferedReader buf_reader = new BufferedReader(reader);
String line = null;
String continued = null;
while ((line = buf_reader.readLine()) != null) {
// LogSupport.log("parsing line: " + line);
line = line.trim();
try {
if (line.charAt(0) == '#')
continue;
if (line.charAt(line.length() - 1) == '\\') {
if (continued != null)
continued += line.substring(0, line.length() - 1);
else
continued = line.substring(0, line.length() - 1);
} else if (continued != null) {
// handle the two strings
continued = continued + line;
// LogSupport.log("parse: " + continued);
try {
parseLine(continued);
} catch (MailcapParseException e) {
//e.printStackTrace();
}
continued = null;
}
else {
// LogSupport.log("parse: " + line);
try {
parseLine(line);
// LogSupport.log("hash.size = " + type_hash.size());
} catch (MailcapParseException e) {
//e.printStackTrace();
}
}
} catch (StringIndexOutOfBoundsException e) {}
}
}
/**
* A routine to parse individual entries in a Mailcap file.
*
* Note that this routine does not handle line continuations.
* They should have been handled prior to calling this routine.
*/
protected void parseLine(String mailcapEntry)
throws MailcapParseException, IOException {
MailcapTokenizer tokenizer = new MailcapTokenizer(mailcapEntry);
tokenizer.setIsAutoquoting(false);
if (LogSupport.isLoggable())
LogSupport.log("parse: " + mailcapEntry);
// parse the primary type
int currentToken = tokenizer.nextToken();
if (currentToken != MailcapTokenizer.STRING_TOKEN) {
reportParseError(MailcapTokenizer.STRING_TOKEN, currentToken,
tokenizer.getCurrentTokenValue());
}
String primaryType =
tokenizer.getCurrentTokenValue().toLowerCase(Locale.ENGLISH);
String subType = "*";
// parse the '/' between primary and sub
// if it's not present that's ok, we just don't have a subtype
currentToken = tokenizer.nextToken();
if ((currentToken != MailcapTokenizer.SLASH_TOKEN) &&
(currentToken != MailcapTokenizer.SEMICOLON_TOKEN)) {
reportParseError(MailcapTokenizer.SLASH_TOKEN,
MailcapTokenizer.SEMICOLON_TOKEN, currentToken,
tokenizer.getCurrentTokenValue());
}
// only need to look for a sub type if we got a '/'
if (currentToken == MailcapTokenizer.SLASH_TOKEN) {
// parse the sub type
currentToken = tokenizer.nextToken();
if (currentToken != MailcapTokenizer.STRING_TOKEN) {
reportParseError(MailcapTokenizer.STRING_TOKEN,
currentToken, tokenizer.getCurrentTokenValue());
}
subType =
tokenizer.getCurrentTokenValue().toLowerCase(Locale.ENGLISH);
// get the next token to simplify the next step
currentToken = tokenizer.nextToken();
}
String mimeType = primaryType + "/" + subType;
if (LogSupport.isLoggable())
LogSupport.log(" Type: " + mimeType);
// now setup the commands hashtable
Map commands = new LinkedHashMap(); // keep commands in order found
// parse the ';' that separates the type from the parameters
if (currentToken != MailcapTokenizer.SEMICOLON_TOKEN) {
reportParseError(MailcapTokenizer.SEMICOLON_TOKEN,
currentToken, tokenizer.getCurrentTokenValue());
}
// eat it
// parse the required view command
tokenizer.setIsAutoquoting(true);
currentToken = tokenizer.nextToken();
tokenizer.setIsAutoquoting(false);
if ((currentToken != MailcapTokenizer.STRING_TOKEN) &&
(currentToken != MailcapTokenizer.SEMICOLON_TOKEN)) {
reportParseError(MailcapTokenizer.STRING_TOKEN,
MailcapTokenizer.SEMICOLON_TOKEN, currentToken,
tokenizer.getCurrentTokenValue());
}
if (currentToken == MailcapTokenizer.STRING_TOKEN) {
// have a native comand, save the entire mailcap entry
//String nativeCommand = tokenizer.getCurrentTokenValue();
List v = (List)native_commands.get(mimeType);
if (v == null) {
v = new ArrayList();
v.add(mailcapEntry);
native_commands.put(mimeType, v);
} else {
// XXX - check for duplicates?
v.add(mailcapEntry);
}
}
// only have to get the next token if the current one isn't a ';'
if (currentToken != MailcapTokenizer.SEMICOLON_TOKEN) {
currentToken = tokenizer.nextToken();
}
// look for a ';' which will indicate whether
// a parameter list is present or not
if (currentToken == MailcapTokenizer.SEMICOLON_TOKEN) {
boolean isFallback = false;
do {
// eat the ';'
// parse the parameter name
currentToken = tokenizer.nextToken();
if (currentToken != MailcapTokenizer.STRING_TOKEN) {
reportParseError(MailcapTokenizer.STRING_TOKEN,
currentToken, tokenizer.getCurrentTokenValue());
}
String paramName = tokenizer.getCurrentTokenValue().
toLowerCase(Locale.ENGLISH);
// parse the '=' which separates the name from the value
currentToken = tokenizer.nextToken();
if ((currentToken != MailcapTokenizer.EQUALS_TOKEN) &&
(currentToken != MailcapTokenizer.SEMICOLON_TOKEN) &&
(currentToken != MailcapTokenizer.EOI_TOKEN)) {
reportParseError(MailcapTokenizer.EQUALS_TOKEN,
MailcapTokenizer.SEMICOLON_TOKEN,
MailcapTokenizer.EOI_TOKEN,
currentToken, tokenizer.getCurrentTokenValue());
}
// we only have a useful command if it is named
if (currentToken == MailcapTokenizer.EQUALS_TOKEN) {
// eat it
// parse the parameter value (which is autoquoted)
tokenizer.setIsAutoquoting(true);
currentToken = tokenizer.nextToken();
tokenizer.setIsAutoquoting(false);
if (currentToken != MailcapTokenizer.STRING_TOKEN) {
reportParseError(MailcapTokenizer.STRING_TOKEN,
currentToken, tokenizer.getCurrentTokenValue());
}
String paramValue =
tokenizer.getCurrentTokenValue();
// add the class to the list iff it is one we care about
if (paramName.startsWith("x-java-")) {
String commandName = paramName.substring(7);
// 7 == "x-java-".length
if (commandName.equals("fallback-entry") &&
paramValue.equalsIgnoreCase("true")) {
isFallback = true;
} else {
// setup the class entry list
if (LogSupport.isLoggable())
LogSupport.log(" Command: " + commandName +
", Class: " + paramValue);
List classes = (List)commands.get(commandName);
if (classes == null) {
classes = new ArrayList();
commands.put(commandName, classes);
}
if (addReverse)
classes.add(0, paramValue);
else
classes.add(paramValue);
}
}
// set up the next iteration
currentToken = tokenizer.nextToken();
}
} while (currentToken == MailcapTokenizer.SEMICOLON_TOKEN);
Map masterHash = isFallback ? fallback_hash : type_hash;
Map curcommands =
(Map)masterHash.get(mimeType);
if (curcommands == null) {
masterHash.put(mimeType, commands);
} else {
if (LogSupport.isLoggable())
LogSupport.log("Merging commands for type " + mimeType);
// have to merge current and new commands
// first, merge list of classes for commands already known
Iterator cn = curcommands.keySet().iterator();
while (cn.hasNext()) {
String cmdName = (String)cn.next();
List ccv = (List)curcommands.get(cmdName);
List cv = (List)commands.get(cmdName);
if (cv == null)
continue;
// add everything in cv to ccv, if it's not already there
Iterator cvn = cv.iterator();
while (cvn.hasNext()) {
String clazz = (String)cvn.next();
if (!ccv.contains(clazz))
if (addReverse)
ccv.add(0, clazz);
else
ccv.add(clazz);
}
}
// now, add commands not previously known
cn = commands.keySet().iterator();
while (cn.hasNext()) {
String cmdName = (String)cn.next();
if (curcommands.containsKey(cmdName))
continue;
List cv = (List)commands.get(cmdName);
curcommands.put(cmdName, cv);
}
}
} else if (currentToken != MailcapTokenizer.EOI_TOKEN) {
reportParseError(MailcapTokenizer.EOI_TOKEN,
MailcapTokenizer.SEMICOLON_TOKEN,
currentToken, tokenizer.getCurrentTokenValue());
}
}
protected static void reportParseError(int expectedToken, int actualToken,
String actualTokenValue) throws MailcapParseException {
throw new MailcapParseException("Encountered a " +
MailcapTokenizer.nameForToken(actualToken) + " token (" +
actualTokenValue + ") while expecting a " +
MailcapTokenizer.nameForToken(expectedToken) + " token.");
}
protected static void reportParseError(int expectedToken,
int otherExpectedToken, int actualToken, String actualTokenValue)
throws MailcapParseException {
throw new MailcapParseException("Encountered a " +
MailcapTokenizer.nameForToken(actualToken) + " token (" +
actualTokenValue + ") while expecting a " +
MailcapTokenizer.nameForToken(expectedToken) + " or a " +
MailcapTokenizer.nameForToken(otherExpectedToken) + " token.");
}
protected static void reportParseError(int expectedToken,
int otherExpectedToken, int anotherExpectedToken, int actualToken,
String actualTokenValue) throws MailcapParseException {
if (LogSupport.isLoggable())
LogSupport.log("PARSE ERROR: " + "Encountered a " +
MailcapTokenizer.nameForToken(actualToken) + " token (" +
actualTokenValue + ") while expecting a " +
MailcapTokenizer.nameForToken(expectedToken) + ", a " +
MailcapTokenizer.nameForToken(otherExpectedToken) + ", or a " +
MailcapTokenizer.nameForToken(anotherExpectedToken) + " token.");
throw new MailcapParseException("Encountered a " +
MailcapTokenizer.nameForToken(actualToken) + " token (" +
actualTokenValue + ") while expecting a " +
MailcapTokenizer.nameForToken(expectedToken) + ", a " +
MailcapTokenizer.nameForToken(otherExpectedToken) + ", or a " +
MailcapTokenizer.nameForToken(anotherExpectedToken) + " token.");
}
/** for debugging
public static void main(String[] args) throws Exception {
Map masterHash = new HashMap();
for (int i = 0; i < args.length; ++i) {
System.out.println("Entry " + i + ": " + args[i]);
parseLine(args[i], masterHash);
}
Enumeration types = masterHash.keys();
while (types.hasMoreElements()) {
String key = (String)types.nextElement();
System.out.println("MIME Type: " + key);
Map commandHash = (Map)masterHash.get(key);
Enumeration commands = commandHash.keys();
while (commands.hasMoreElements()) {
String command = (String)commands.nextElement();
System.out.println(" Command: " + command);
Vector classes = (Vector)commandHash.get(command);
for (int i = 0; i < classes.size(); ++i) {
System.out.println(" Class: " +
(String)classes.elementAt(i));
}
}
System.out.println("");
}
}
*/
}

View File

@@ -0,0 +1,40 @@
/*
* Copyright (c) 1997, 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.activation.registries;
/**
* A class to encapsulate Mailcap parsing related exceptions
*/
public class MailcapParseException extends Exception {
public MailcapParseException() {
super();
}
public MailcapParseException(String inInfo) {
super(inInfo);
}
}

View File

@@ -0,0 +1,321 @@
/*
* Copyright (c) 1997, 2006, 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.activation.registries;
/**
* A tokenizer for strings in the form of "foo/bar; prop1=val1; ... ".
* Useful for parsing MIME content types.
*/
public class MailcapTokenizer {
public static final int UNKNOWN_TOKEN = 0;
public static final int START_TOKEN = 1;
public static final int STRING_TOKEN = 2;
public static final int EOI_TOKEN = 5;
public static final int SLASH_TOKEN = '/';
public static final int SEMICOLON_TOKEN = ';';
public static final int EQUALS_TOKEN = '=';
/**
* Constructor
*
* @parameter inputString the string to tokenize
*/
public MailcapTokenizer(String inputString) {
data = inputString;
dataIndex = 0;
dataLength = inputString.length();
currentToken = START_TOKEN;
currentTokenValue = "";
isAutoquoting = false;
autoquoteChar = ';';
}
/**
* Set whether auto-quoting is on or off.
*
* Auto-quoting means that all characters after the first
* non-whitespace, non-control character up to the auto-quote
* terminator character or EOI (minus any whitespace immediatley
* preceeding it) is considered a token.
*
* This is required for handling command strings in a mailcap entry.
*/
public void setIsAutoquoting(boolean value) {
isAutoquoting = value;
}
/**
* Retrieve current token.
*
* @returns The current token value
*/
public int getCurrentToken() {
return currentToken;
}
/*
* Get a String that describes the given token.
*/
public static String nameForToken(int token) {
String name = "really unknown";
switch(token) {
case UNKNOWN_TOKEN:
name = "unknown";
break;
case START_TOKEN:
name = "start";
break;
case STRING_TOKEN:
name = "string";
break;
case EOI_TOKEN:
name = "EOI";
break;
case SLASH_TOKEN:
name = "'/'";
break;
case SEMICOLON_TOKEN:
name = "';'";
break;
case EQUALS_TOKEN:
name = "'='";
break;
}
return name;
}
/*
* Retrieve current token value.
*
* @returns A String containing the current token value
*/
public String getCurrentTokenValue() {
return currentTokenValue;
}
/*
* Process the next token.
*
* @returns the next token
*/
public int nextToken() {
if (dataIndex < dataLength) {
// skip white space
while ((dataIndex < dataLength) &&
(isWhiteSpaceChar(data.charAt(dataIndex)))) {
++dataIndex;
}
if (dataIndex < dataLength) {
// examine the current character and see what kind of token we have
char c = data.charAt(dataIndex);
if (isAutoquoting) {
if (c == ';' || c == '=') {
currentToken = c;
currentTokenValue = new Character(c).toString();
++dataIndex;
} else {
processAutoquoteToken();
}
} else {
if (isStringTokenChar(c)) {
processStringToken();
} else if ((c == '/') || (c == ';') || (c == '=')) {
currentToken = c;
currentTokenValue = new Character(c).toString();
++dataIndex;
} else {
currentToken = UNKNOWN_TOKEN;
currentTokenValue = new Character(c).toString();
++dataIndex;
}
}
} else {
currentToken = EOI_TOKEN;
currentTokenValue = null;
}
} else {
currentToken = EOI_TOKEN;
currentTokenValue = null;
}
return currentToken;
}
private void processStringToken() {
// capture the initial index
int initialIndex = dataIndex;
// skip to 1st non string token character
while ((dataIndex < dataLength) &&
isStringTokenChar(data.charAt(dataIndex))) {
++dataIndex;
}
currentToken = STRING_TOKEN;
currentTokenValue = data.substring(initialIndex, dataIndex);
}
private void processAutoquoteToken() {
// capture the initial index
int initialIndex = dataIndex;
// now skip to the 1st non-escaped autoquote termination character
// XXX - doesn't actually consider escaping
boolean foundTerminator = false;
while ((dataIndex < dataLength) && !foundTerminator) {
char c = data.charAt(dataIndex);
if (c != autoquoteChar) {
++dataIndex;
} else {
foundTerminator = true;
}
}
currentToken = STRING_TOKEN;
currentTokenValue =
fixEscapeSequences(data.substring(initialIndex, dataIndex));
}
private static boolean isSpecialChar(char c) {
boolean lAnswer = false;
switch(c) {
case '(':
case ')':
case '<':
case '>':
case '@':
case ',':
case ';':
case ':':
case '\\':
case '"':
case '/':
case '[':
case ']':
case '?':
case '=':
lAnswer = true;
break;
}
return lAnswer;
}
private static boolean isControlChar(char c) {
return Character.isISOControl(c);
}
private static boolean isWhiteSpaceChar(char c) {
return Character.isWhitespace(c);
}
private static boolean isStringTokenChar(char c) {
return !isSpecialChar(c) && !isControlChar(c) && !isWhiteSpaceChar(c);
}
private static String fixEscapeSequences(String inputString) {
int inputLength = inputString.length();
StringBuffer buffer = new StringBuffer();
buffer.ensureCapacity(inputLength);
for (int i = 0; i < inputLength; ++i) {
char currentChar = inputString.charAt(i);
if (currentChar != '\\') {
buffer.append(currentChar);
} else {
if (i < inputLength - 1) {
char nextChar = inputString.charAt(i + 1);
buffer.append(nextChar);
// force a skip over the next character too
++i;
} else {
buffer.append(currentChar);
}
}
}
return buffer.toString();
}
private String data;
private int dataIndex;
private int dataLength;
private int currentToken;
private String currentTokenValue;
private boolean isAutoquoting;
private char autoquoteChar;
/*
public static void main(String[] args) {
for (int i = 0; i < args.length; ++i) {
MailcapTokenizer tokenizer = new MailcapTokenizer(args[i]);
System.out.println("Original: |" + args[i] + "|");
int currentToken = tokenizer.nextToken();
while (currentToken != EOI_TOKEN) {
switch(currentToken) {
case UNKNOWN_TOKEN:
System.out.println(" Unknown Token: |" + tokenizer.getCurrentTokenValue() + "|");
break;
case START_TOKEN:
System.out.println(" Start Token: |" + tokenizer.getCurrentTokenValue() + "|");
break;
case STRING_TOKEN:
System.out.println(" String Token: |" + tokenizer.getCurrentTokenValue() + "|");
break;
case EOI_TOKEN:
System.out.println(" EOI Token: |" + tokenizer.getCurrentTokenValue() + "|");
break;
case SLASH_TOKEN:
System.out.println(" Slash Token: |" + tokenizer.getCurrentTokenValue() + "|");
break;
case SEMICOLON_TOKEN:
System.out.println(" Semicolon Token: |" + tokenizer.getCurrentTokenValue() + "|");
break;
case EQUALS_TOKEN:
System.out.println(" Equals Token: |" + tokenizer.getCurrentTokenValue() + "|");
break;
default:
System.out.println(" Really Unknown Token: |" + tokenizer.getCurrentTokenValue() + "|");
break;
}
currentToken = tokenizer.nextToken();
}
System.out.println("");
}
}
*/
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) 1997, 1998, 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.activation.registries;
import java.lang.*;
public class MimeTypeEntry {
private String type;
private String extension;
public MimeTypeEntry(String mime_type, String file_ext) {
type = mime_type;
extension = file_ext;
}
public String getMIMEType() {
return type;
}
public String getFileExtension() {
return extension;
}
public String toString() {
return "MIMETypeEntry: " + type + ", " + extension;
}
}

View File

@@ -0,0 +1,317 @@
/*
* Copyright (c) 1997, 2003, 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.activation.registries;
import java.io.*;
import java.util.*;
public class MimeTypeFile {
private String fname = null;
private Hashtable type_hash = new Hashtable();
/**
* The construtor that takes a filename as an argument.
*
* @param new_fname The file name of the mime types file.
*/
public MimeTypeFile(String new_fname) throws IOException {
File mime_file = null;
FileReader fr = null;
fname = new_fname; // remember the file name
mime_file = new File(fname); // get a file object
fr = new FileReader(mime_file);
try {
parse(new BufferedReader(fr));
} finally {
try {
fr.close(); // close it
} catch (IOException e) {
// ignore it
}
}
}
public MimeTypeFile(InputStream is) throws IOException {
parse(new BufferedReader(new InputStreamReader(is, "iso-8859-1")));
}
/**
* Creates an empty DB.
*/
public MimeTypeFile() {
}
/**
* get the MimeTypeEntry based on the file extension
*/
public MimeTypeEntry getMimeTypeEntry(String file_ext) {
return (MimeTypeEntry)type_hash.get((Object)file_ext);
}
/**
* Get the MIME type string corresponding to the file extension.
*/
public String getMIMETypeString(String file_ext) {
MimeTypeEntry entry = this.getMimeTypeEntry(file_ext);
if (entry != null)
return entry.getMIMEType();
else
return null;
}
/**
* Appends string of entries to the types registry, must be valid
* .mime.types format.
* A mime.types entry is one of two forms:
*
* type/subtype ext1 ext2 ...
* or
* type=type/subtype desc="description of type" exts=ext1,ext2,...
*
* Example:
* # this is a test
* audio/basic au
* text/plain txt text
* type=application/postscript exts=ps,eps
*/
public void appendToRegistry(String mime_types) {
try {
parse(new BufferedReader(new StringReader(mime_types)));
} catch (IOException ex) {
// can't happen
}
}
/**
* Parse a stream of mime.types entries.
*/
private void parse(BufferedReader buf_reader) throws IOException {
String line = null, prev = null;
while ((line = buf_reader.readLine()) != null) {
if (prev == null)
prev = line;
else
prev += line;
int end = prev.length();
if (prev.length() > 0 && prev.charAt(end - 1) == '\\') {
prev = prev.substring(0, end - 1);
continue;
}
this.parseEntry(prev);
prev = null;
}
if (prev != null)
this.parseEntry(prev);
}
/**
* Parse single mime.types entry.
*/
private void parseEntry(String line) {
String mime_type = null;
String file_ext = null;
line = line.trim();
if (line.length() == 0) // empty line...
return; // BAIL!
// check to see if this is a comment line?
if (line.charAt(0) == '#')
return; // then we are done!
// is it a new format line or old format?
if (line.indexOf('=') > 0) {
// new format
LineTokenizer lt = new LineTokenizer(line);
while (lt.hasMoreTokens()) {
String name = lt.nextToken();
String value = null;
if (lt.hasMoreTokens() && lt.nextToken().equals("=") &&
lt.hasMoreTokens())
value = lt.nextToken();
if (value == null) {
if (LogSupport.isLoggable())
LogSupport.log("Bad .mime.types entry: " + line);
return;
}
if (name.equals("type"))
mime_type = value;
else if (name.equals("exts")) {
StringTokenizer st = new StringTokenizer(value, ",");
while (st.hasMoreTokens()) {
file_ext = st.nextToken();
MimeTypeEntry entry =
new MimeTypeEntry(mime_type, file_ext);
type_hash.put(file_ext, entry);
if (LogSupport.isLoggable())
LogSupport.log("Added: " + entry.toString());
}
}
}
} else {
// old format
// count the tokens
StringTokenizer strtok = new StringTokenizer(line);
int num_tok = strtok.countTokens();
if (num_tok == 0) // empty line
return;
mime_type = strtok.nextToken(); // get the MIME type
while (strtok.hasMoreTokens()) {
MimeTypeEntry entry = null;
file_ext = strtok.nextToken();
entry = new MimeTypeEntry(mime_type, file_ext);
type_hash.put(file_ext, entry);
if (LogSupport.isLoggable())
LogSupport.log("Added: " + entry.toString());
}
}
}
// for debugging
/*
public static void main(String[] argv) throws Exception {
MimeTypeFile mf = new MimeTypeFile(argv[0]);
System.out.println("ext " + argv[1] + " type " +
mf.getMIMETypeString(argv[1]));
System.exit(0);
}
*/
}
class LineTokenizer {
private int currentPosition;
private int maxPosition;
private String str;
private Vector stack = new Vector();
private static final String singles = "="; // single character tokens
/**
* Constructs a tokenizer for the specified string.
* <p>
*
* @param str a string to be parsed.
*/
public LineTokenizer(String str) {
currentPosition = 0;
this.str = str;
maxPosition = str.length();
}
/**
* Skips white space.
*/
private void skipWhiteSpace() {
while ((currentPosition < maxPosition) &&
Character.isWhitespace(str.charAt(currentPosition))) {
currentPosition++;
}
}
/**
* Tests if there are more tokens available from this tokenizer's string.
*
* @return <code>true</code> if there are more tokens available from this
* tokenizer's string; <code>false</code> otherwise.
*/
public boolean hasMoreTokens() {
if (stack.size() > 0)
return true;
skipWhiteSpace();
return (currentPosition < maxPosition);
}
/**
* Returns the next token from this tokenizer.
*
* @return the next token from this tokenizer.
* @exception NoSuchElementException if there are no more tokens in this
* tokenizer's string.
*/
public String nextToken() {
int size = stack.size();
if (size > 0) {
String t = (String)stack.elementAt(size - 1);
stack.removeElementAt(size - 1);
return t;
}
skipWhiteSpace();
if (currentPosition >= maxPosition) {
throw new NoSuchElementException();
}
int start = currentPosition;
char c = str.charAt(start);
if (c == '"') {
currentPosition++;
boolean filter = false;
while (currentPosition < maxPosition) {
c = str.charAt(currentPosition++);
if (c == '\\') {
currentPosition++;
filter = true;
} else if (c == '"') {
String s;
if (filter) {
StringBuffer sb = new StringBuffer();
for (int i = start + 1; i < currentPosition - 1; i++) {
c = str.charAt(i);
if (c != '\\')
sb.append(c);
}
s = sb.toString();
} else
s = str.substring(start + 1, currentPosition - 1);
return s;
}
}
} else if (singles.indexOf(c) >= 0) {
currentPosition++;
} else {
while ((currentPosition < maxPosition) &&
singles.indexOf(str.charAt(currentPosition)) < 0 &&
!Character.isWhitespace(str.charAt(currentPosition))) {
currentPosition++;
}
}
return str.substring(start, currentPosition);
}
public void pushToken(String token) {
stack.addElement(token);
}
}

View File

@@ -0,0 +1,462 @@
/*
* Copyright (c) 2008, 2009, 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.awt;
import java.awt.*;
import sun.awt.AWTAccessor;
import sun.awt.SunToolkit;
/**
* A collection of utility methods for AWT.
*
* The functionality provided by the static methods of the class includes:
* <ul>
* <li>Setting shapes on top-level windows
* <li>Setting a constant alpha value for each pixel of a top-level window
* <li>Making a window non-opaque, after that it paints only explicitly
* painted pixels on the screen, with arbitrary alpha values for every pixel.
* <li>Setting a 'mixing-cutout' shape for a component.
* </ul>
* <p>
* A "top-level window" is an instance of the {@code Window} class (or its
* descendant, such as {@code JFrame}).
* <p>
* Some of the mentioned features may not be supported by the native platform.
* To determine whether a particular feature is supported, the user must use
* the {@code isTranslucencySupported()} method of the class passing a desired
* translucency kind (a member of the {@code Translucency} enum) as an
* argument.
* <p>
* The per-pixel alpha feature also requires the user to create her/his
* windows using a translucency-capable graphics configuration.
* The {@code isTranslucencyCapable()} method must
* be used to verify whether any given GraphicsConfiguration supports
* the trasnlcency effects.
* <p>
* <b>WARNING</b>: This class is an implementation detail and only meant
* for limited use outside of the core platform. This API may change
* drastically between update release, and it may even be
* removed or be moved in some other package(s)/class(es).
*/
public final class AWTUtilities {
/**
* The AWTUtilities class should not be instantiated
*/
private AWTUtilities() {
}
/** Kinds of translucency supported by the underlying system.
* @see #isTranslucencySupported
*/
public static enum Translucency {
/**
* Represents support in the underlying system for windows each pixel
* of which is guaranteed to be either completely opaque, with
* an alpha value of 1.0, or completely transparent, with an alpha
* value of 0.0.
*/
PERPIXEL_TRANSPARENT,
/**
* Represents support in the underlying system for windows all of
* the pixels of which have the same alpha value between or including
* 0.0 and 1.0.
*/
TRANSLUCENT,
/**
* Represents support in the underlying system for windows that
* contain or might contain pixels with arbitrary alpha values
* between and including 0.0 and 1.0.
*/
PERPIXEL_TRANSLUCENT;
}
/**
* Returns whether the given level of translucency is supported by
* the underlying system.
*
* Note that this method may sometimes return the value
* indicating that the particular level is supported, but
* the native windowing system may still not support the
* given level of translucency (due to the bugs in
* the windowing system).
*
* @param translucencyKind a kind of translucency support
* (either PERPIXEL_TRANSPARENT,
* TRANSLUCENT, or PERPIXEL_TRANSLUCENT)
* @return whether the given translucency kind is supported
*/
public static boolean isTranslucencySupported(Translucency translucencyKind) {
switch (translucencyKind) {
case PERPIXEL_TRANSPARENT:
return isWindowShapingSupported();
case TRANSLUCENT:
return isWindowOpacitySupported();
case PERPIXEL_TRANSLUCENT:
return isWindowTranslucencySupported();
}
return false;
}
/**
* Returns whether the windowing system supports changing the opacity
* value of top-level windows.
* Note that this method may sometimes return true, but the native
* windowing system may still not support the concept of
* translucency (due to the bugs in the windowing system).
*/
private static boolean isWindowOpacitySupported() {
Toolkit curToolkit = Toolkit.getDefaultToolkit();
if (!(curToolkit instanceof SunToolkit)) {
return false;
}
return ((SunToolkit)curToolkit).isWindowOpacitySupported();
}
/**
* Set the opacity of the window. The opacity is at the range [0..1].
* Note that setting the opacity level of 0 may or may not disable
* the mouse event handling on this window. This is
* a platform-dependent behavior.
*
* In order for this method to enable the translucency effect,
* the isTranslucencySupported() method should indicate that the
* TRANSLUCENT level of translucency is supported.
*
* <p>Also note that the window must not be in the full-screen mode
* when setting the opacity value &lt; 1.0f. Otherwise
* the IllegalArgumentException is thrown.
*
* @param window the window to set the opacity level to
* @param opacity the opacity level to set to the window
* @throws NullPointerException if the window argument is null
* @throws IllegalArgumentException if the opacity is out of
* the range [0..1]
* @throws IllegalArgumentException if the window is in full screen mode,
* and the opacity is less than 1.0f
* @throws UnsupportedOperationException if the TRANSLUCENT translucency
* kind is not supported
*/
public static void setWindowOpacity(Window window, float opacity) {
if (window == null) {
throw new NullPointerException(
"The window argument should not be null.");
}
AWTAccessor.getWindowAccessor().setOpacity(window, opacity);
}
/**
* Get the opacity of the window. If the opacity has not
* yet being set, this method returns 1.0.
*
* @param window the window to get the opacity level from
* @throws NullPointerException if the window argument is null
*/
public static float getWindowOpacity(Window window) {
if (window == null) {
throw new NullPointerException(
"The window argument should not be null.");
}
return AWTAccessor.getWindowAccessor().getOpacity(window);
}
/**
* Returns whether the windowing system supports changing the shape
* of top-level windows.
* Note that this method may sometimes return true, but the native
* windowing system may still not support the concept of
* shaping (due to the bugs in the windowing system).
*/
public static boolean isWindowShapingSupported() {
Toolkit curToolkit = Toolkit.getDefaultToolkit();
if (!(curToolkit instanceof SunToolkit)) {
return false;
}
return ((SunToolkit)curToolkit).isWindowShapingSupported();
}
/**
* Returns an object that implements the Shape interface and represents
* the shape previously set with the call to the setWindowShape() method.
* If no shape has been set yet, or the shape has been reset to null,
* this method returns null.
*
* @param window the window to get the shape from
* @return the current shape of the window
* @throws NullPointerException if the window argument is null
*/
public static Shape getWindowShape(Window window) {
if (window == null) {
throw new NullPointerException(
"The window argument should not be null.");
}
return AWTAccessor.getWindowAccessor().getShape(window);
}
/**
* Sets a shape for the given window.
* If the shape argument is null, this methods restores
* the default shape making the window rectangular.
* <p>Note that in order to set a shape, the window must be undecorated.
* If the window is decorated, this method ignores the {@code shape}
* argument and resets the shape to null.
* <p>Also note that the window must not be in the full-screen mode
* when setting a non-null shape. Otherwise the IllegalArgumentException
* is thrown.
* <p>Depending on the platform, the method may return without
* effecting the shape of the window if the window has a non-null warning
* string ({@link Window#getWarningString()}). In this case the passed
* shape object is ignored.
*
* @param window the window to set the shape to
* @param shape the shape to set to the window
* @throws NullPointerException if the window argument is null
* @throws IllegalArgumentException if the window is in full screen mode,
* and the shape is not null
* @throws UnsupportedOperationException if the PERPIXEL_TRANSPARENT
* translucency kind is not supported
*/
public static void setWindowShape(Window window, Shape shape) {
if (window == null) {
throw new NullPointerException(
"The window argument should not be null.");
}
AWTAccessor.getWindowAccessor().setShape(window, shape);
}
private static boolean isWindowTranslucencySupported() {
/*
* Per-pixel alpha is supported if all the conditions are TRUE:
* 1. The toolkit is a sort of SunToolkit
* 2. The toolkit supports translucency in general
* (isWindowTranslucencySupported())
* 3. There's at least one translucency-capable
* GraphicsConfiguration
*/
Toolkit curToolkit = Toolkit.getDefaultToolkit();
if (!(curToolkit instanceof SunToolkit)) {
return false;
}
if (!((SunToolkit)curToolkit).isWindowTranslucencySupported()) {
return false;
}
GraphicsEnvironment env =
GraphicsEnvironment.getLocalGraphicsEnvironment();
// If the default GC supports translucency return true.
// It is important to optimize the verification this way,
// see CR 6661196 for more details.
if (isTranslucencyCapable(env.getDefaultScreenDevice()
.getDefaultConfiguration()))
{
return true;
}
// ... otherwise iterate through all the GCs.
GraphicsDevice[] devices = env.getScreenDevices();
for (int i = 0; i < devices.length; i++) {
GraphicsConfiguration[] configs = devices[i].getConfigurations();
for (int j = 0; j < configs.length; j++) {
if (isTranslucencyCapable(configs[j])) {
return true;
}
}
}
return false;
}
/**
* Enables the per-pixel alpha support for the given window.
* Once the window becomes non-opaque (the isOpaque is set to false),
* the drawing sub-system is starting to respect the alpha value of each
* separate pixel. If a pixel gets painted with alpha color component
* equal to zero, it becomes visually transparent, if the alpha of the
* pixel is equal to 255, the pixel is fully opaque. Interim values
* of the alpha color component make the pixel semi-transparent (i.e.
* translucent).
* <p>Note that in order for the window to support the per-pixel alpha
* mode, the window must be created using the GraphicsConfiguration
* for which the {@link #isTranslucencyCapable}
* method returns true.
* <p>Also note that some native systems enable the per-pixel translucency
* mode for any window created using the translucency-compatible
* graphics configuration. However, it is highly recommended to always
* invoke the setWindowOpaque() method for these windows, at least for
* the sake of cross-platform compatibility reasons.
* <p>Also note that the window must not be in the full-screen mode
* when making it non-opaque. Otherwise the IllegalArgumentException
* is thrown.
* <p>If the window is a {@code Frame} or a {@code Dialog}, the window must
* be undecorated prior to enabling the per-pixel translucency effect (see
* {@link Frame#setUndecorated()} and/or {@link Dialog#setUndecorated()}).
* If the window becomes decorated through a subsequent call to the
* corresponding {@code setUndecorated()} method, the per-pixel
* translucency effect will be disabled and the opaque property reset to
* {@code true}.
* <p>Depending on the platform, the method may return without
* effecting the opaque property of the window if the window has a non-null
* warning string ({@link Window#getWarningString()}). In this case
* the passed 'isOpaque' value is ignored.
*
* @param window the window to set the shape to
* @param isOpaque whether the window must be opaque (true),
* or translucent (false)
* @throws NullPointerException if the window argument is null
* @throws IllegalArgumentException if the window uses
* a GraphicsConfiguration for which the
* {@code isTranslucencyCapable()}
* method returns false
* @throws IllegalArgumentException if the window is in full screen mode,
* and the isOpaque is false
* @throws IllegalArgumentException if the window is decorated and the
* isOpaque argument is {@code false}.
* @throws UnsupportedOperationException if the PERPIXEL_TRANSLUCENT
* translucency kind is not supported
*/
public static void setWindowOpaque(Window window, boolean isOpaque) {
if (window == null) {
throw new NullPointerException(
"The window argument should not be null.");
}
if (!isOpaque && !isTranslucencySupported(Translucency.PERPIXEL_TRANSLUCENT)) {
throw new UnsupportedOperationException(
"The PERPIXEL_TRANSLUCENT translucency kind is not supported");
}
AWTAccessor.getWindowAccessor().setOpaque(window, isOpaque);
}
/**
* Returns whether the window is opaque or translucent.
*
* @param window the window to set the shape to
* @return whether the window is currently opaque (true)
* or translucent (false)
* @throws NullPointerException if the window argument is null
*/
public static boolean isWindowOpaque(Window window) {
if (window == null) {
throw new NullPointerException(
"The window argument should not be null.");
}
return window.isOpaque();
}
/**
* Verifies whether a given GraphicsConfiguration supports
* the PERPIXEL_TRANSLUCENT kind of translucency.
* All windows that are intended to be used with the {@link #setWindowOpaque}
* method must be created using a GraphicsConfiguration for which this method
* returns true.
* <p>Note that some native systems enable the per-pixel translucency
* mode for any window created using a translucency-capable
* graphics configuration. However, it is highly recommended to always
* invoke the setWindowOpaque() method for these windows, at least
* for the sake of cross-platform compatibility reasons.
*
* @param gc GraphicsConfiguration
* @throws NullPointerException if the gc argument is null
* @return whether the given GraphicsConfiguration supports
* the translucency effects.
*/
public static boolean isTranslucencyCapable(GraphicsConfiguration gc) {
if (gc == null) {
throw new NullPointerException("The gc argument should not be null");
}
/*
return gc.isTranslucencyCapable();
*/
Toolkit curToolkit = Toolkit.getDefaultToolkit();
if (!(curToolkit instanceof SunToolkit)) {
return false;
}
return ((SunToolkit)curToolkit).isTranslucencyCapable(gc);
}
/**
* Sets a 'mixing-cutout' shape for the given component.
*
* By default a lightweight component is treated as an opaque rectangle for
* the purposes of the Heavyweight/Lightweight Components Mixing feature.
* This method enables developers to set an arbitrary shape to be cut out
* from heavyweight components positioned underneath the lightweight
* component in the z-order.
* <p>
* The {@code shape} argument may have the following values:
* <ul>
* <li>{@code null} - reverts the default cutout shape (the rectangle equal
* to the component's {@code getBounds()})
* <li><i>empty-shape</i> - does not cut out anything from heavyweight
* components. This makes the given lightweight component effectively
* transparent. Note that descendants of the lightweight component still
* affect the shapes of heavyweight components. An example of an
* <i>empty-shape</i> is {@code new Rectangle()}.
* <li><i>non-empty-shape</i> - the given shape will be cut out from
* heavyweight components.
* </ul>
* <p>
* The most common example when the 'mixing-cutout' shape is needed is a
* glass pane component. The {@link JRootPane#setGlassPane()} method
* automatically sets the <i>empty-shape</i> as the 'mixing-cutout' shape
* for the given glass pane component. If a developer needs some other
* 'mixing-cutout' shape for the glass pane (which is rare), this must be
* changed manually after installing the glass pane to the root pane.
* <p>
* Note that the 'mixing-cutout' shape neither affects painting, nor the
* mouse events handling for the given component. It is used exclusively
* for the purposes of the Heavyweight/Lightweight Components Mixing
* feature.
*
* @param component the component that needs non-default
* 'mixing-cutout' shape
* @param shape the new 'mixing-cutout' shape
* @throws NullPointerException if the component argument is {@code null}
*/
public static void setComponentMixingCutoutShape(Component component,
Shape shape)
{
if (component == null) {
throw new NullPointerException(
"The component argument should not be null.");
}
AWTAccessor.getComponentAccessor().setMixingCutoutShape(component,
shape);
}
}

View File

@@ -0,0 +1,169 @@
/*
* Copyright (c) 2008, 2009, 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.awt;
import java.awt.*;
import java.awt.geom.*;
import sun.awt.AWTAccessor;
/**
* Security Warning control interface.
*
* This class provides a couple of methods that help a developer relocate
* the AWT security warning to an appropriate position relative to the current
* window size. A "top-level window" is an instance of the {@code Window}
* class (or its descendant, such as {@code JFrame}). The security warning
* is applied to all windows created by an untrusted code. All such windows
* have a non-null "warning string" (see {@link Window#getWarningString()}).
* <p>
* <b>WARNING</b>: This class is an implementation detail and only meant
* for limited use outside of the core platform. This API may change
* drastically between update release, and it may even be
* removed or be moved to some other packages or classes.
*/
public final class SecurityWarning {
/**
* The SecurityWarning class should not be instantiated
*/
private SecurityWarning() {
}
/**
* Gets the size of the security warning.
*
* The returned value is not valid until the peer has been created. Before
* invoking this method a developer must call the {@link Window#pack()},
* {@link Window#setVisible()}, or some other method that creates the peer.
*
* @param window the window to get the security warning size for
*
* @throws NullPointerException if the window argument is null
* @throws IllegalArgumentException if the window is trusted (i.e.
* the {@code getWarningString()} returns null)
*/
public static Dimension getSize(Window window) {
if (window == null) {
throw new NullPointerException(
"The window argument should not be null.");
}
if (window.getWarningString() == null) {
throw new IllegalArgumentException(
"The window must have a non-null warning string.");
}
// We don't check for a non-null peer since it may be destroyed
// after assigning a valid value to the security warning size.
return AWTAccessor.getWindowAccessor().getSecurityWarningSize(window);
}
/**
* Sets the position of the security warning.
* <p>
* The {@code alignmentX} and {@code alignmentY} arguments specify the
* origin of the coordinate system used to calculate the position of the
* security warning. The values must be in the range [0.0f...1.0f]. The
* {@code 0.0f} value represents the left (top) edge of the rectangular
* bounds of the window. The {@code 1.0f} value represents the right
* (bottom) edge of the bounds. Whenever the size of the window changes,
* the origin of the coordinate system gets relocated accordingly. For
* convenience a developer may use the {@code Component.*_ALIGNMENT}
* constants to pass predefined values for these arguments.
* <p>
* The {@code point} argument specifies the location of the security
* warning in the coordinate system described above. If both {@code x} and
* {@code y} coordinates of the point are equal to zero, the warning will
* be located right in the origin of the coordinate system. On the other
* hand, if both {@code alignmentX} and {@code alignmentY} are equal to
* zero (i.e. the origin of the coordinate system is placed at the top-left
* corner of the window), then the {@code point} argument represents the
* absolute location of the security warning relative to the location of
* the window. The "absolute" in this case means that the position of the
* security warning is not effected by resizing of the window.
* <p>
* Note that the security warning managment code guarantees that:
* <ul>
* <li>The security warning cannot be located farther than two pixels from
* the rectangular bounds of the window (see {@link Window#getBounds}), and
* <li>The security warning is always visible on the screen.
* </ul>
* If either of the conditions is violated, the calculated position of the
* security warning is adjusted by the system to meet both these
* conditions.
* <p>
* The default position of the security warning is in the upper-right
* corner of the window, two pixels to the right from the right edge. This
* corresponds to the following arguments passed to this method:
* <ul>
* <li>{@code alignmentX = Component.RIGHT_ALIGNMENT}
* <li>{@code alignmentY = Component.TOP_ALIGNMENT}
* <li>{@code point = (2, 0)}
* </ul>
*
* @param window the window to set the position of the security warning for
* @param alignmentX the horizontal origin of the coordinate system
* @param alignmentY the vertical origin of the coordinate system
* @param point the position of the security warning in the specified
* coordinate system
*
* @throws NullPointerException if the window argument is null
* @throws NullPointerException if the point argument is null
* @throws IllegalArgumentException if the window is trusted (i.e.
* the {@code getWarningString()} returns null
* @throws IllegalArgumentException if the alignmentX or alignmentY
* arguments are not within the range [0.0f ... 1.0f]
*/
public static void setPosition(Window window, Point2D point,
float alignmentX, float alignmentY)
{
if (window == null) {
throw new NullPointerException(
"The window argument should not be null.");
}
if (window.getWarningString() == null) {
throw new IllegalArgumentException(
"The window must have a non-null warning string.");
}
if (point == null) {
throw new NullPointerException(
"The point argument must not be null");
}
if (alignmentX < 0.0f || alignmentX > 1.0f) {
throw new IllegalArgumentException(
"alignmentX must be in the range [0.0f ... 1.0f].");
}
if (alignmentY < 0.0f || alignmentY > 1.0f) {
throw new IllegalArgumentException(
"alignmentY must be in the range [0.0f ... 1.0f].");
}
AWTAccessor.getWindowAccessor().setSecurityWarningPosition(window,
point, alignmentX, alignmentY);
}
}

View File

@@ -0,0 +1,378 @@
/*
* Copyright (c) 2003, 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.beans;
import java.lang.reflect.Array;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType;
import java.util.HashMap;
import java.util.Map;
import sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl;
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
/**
* This is utility class to resolve types.
*
* @since 1.7
*
* @author Eamonn McManus
* @author Sergey Malenkov
*/
public final class TypeResolver {
private static final WeakCache<Type, Map<Type, Type>> CACHE = new WeakCache<>();
/**
* Replaces the given {@code type} in an inherited method
* with the actual type it has in the given {@code inClass}.
*
* <p>Although type parameters are not inherited by subclasses in the Java
* language, they <em>are</em> effectively inherited when using reflection.
* For example, if you declare an interface like this...</p>
*
* <pre>
* public interface StringToIntMap extends Map&lt;String,Integer> {}
* </pre>
*
* <p>...then StringToIntMap.class.getMethods() will show that it has methods
* like put(K,V) even though StringToIntMap has no type parameters. The K
* and V variables are the ones declared by Map, so
* {@link TypeVariable#getGenericDeclaration()} will return Map.class.</p>
*
* <p>The purpose of this method is to take a Type from a possibly-inherited
* method and replace it with the correct Type for the inheriting class.
* So given parameters of K and StringToIntMap.class in the above example,
* this method will return String.</p>
*
* @param inClass the base class used to resolve
* @param type the type to resolve
* @return a resolved type
*
* @see #getActualType(Class)
* @see #resolve(Type,Type)
*/
public static Type resolveInClass(Class<?> inClass, Type type) {
return resolve(getActualType(inClass), type);
}
/**
* Replaces all {@code types} in the given array
* with the actual types they have in the given {@code inClass}.
*
* @param inClass the base class used to resolve
* @param types the array of types to resolve
* @return an array of resolved types
*
* @see #getActualType(Class)
* @see #resolve(Type,Type[])
*/
public static Type[] resolveInClass(Class<?> inClass, Type[] types) {
return resolve(getActualType(inClass), types);
}
/**
* Replaces type variables of the given {@code formal} type
* with the types they stand for in the given {@code actual} type.
*
* <p>A ParameterizedType is a class with type parameters, and the values
* of those parameters. For example, Map&lt;K,V> is a generic class, and
* a corresponding ParameterizedType might look like
* Map&lt;K=String,V=Integer>. Given such a ParameterizedType, this method
* will replace K with String, or List&lt;K> with List&ltString;, or
* List&lt;? super K> with List&lt;? super String>.</p>
*
* <p>The {@code actual} argument to this method can also be a Class.
* In this case, either it is equivalent to a ParameterizedType with
* no parameters (for example, Integer.class), or it is equivalent to
* a "raw" ParameterizedType (for example, Map.class). In the latter
* case, every type parameter declared or inherited by the class is replaced
* by its "erasure". For a type parameter declared as &lt;T>, the erasure
* is Object. For a type parameter declared as &lt;T extends Number>,
* the erasure is Number.</p>
*
* <p>Although type parameters are not inherited by subclasses in the Java
* language, they <em>are</em> effectively inherited when using reflection.
* For example, if you declare an interface like this...</p>
*
* <pre>
* public interface StringToIntMap extends Map&lt;String,Integer> {}
* </pre>
*
* <p>...then StringToIntMap.class.getMethods() will show that it has methods
* like put(K,V) even though StringToIntMap has no type parameters. The K
* and V variables are the ones declared by Map, so
* {@link TypeVariable#getGenericDeclaration()} will return {@link Map Map.class}.</p>
*
* <p>For this reason, this method replaces inherited type parameters too.
* Therefore if this method is called with {@code actual} being
* StringToIntMap.class and {@code formal} being the K from Map,
* it will return {@link String String.class}.</p>
*
* <p>In the case where {@code actual} is a "raw" ParameterizedType, the
* inherited type parameters will also be replaced by their erasures.
* The erasure of a Class is the Class itself, so a "raw" subinterface of
* StringToIntMap will still show the K from Map as String.class. But
* in a case like this...
*
* <pre>
* public interface StringToIntListMap extends Map&lt;String,List&lt;Integer>> {}
* public interface RawStringToIntListMap extends StringToIntListMap {}
* </pre>
*
* <p>...the V inherited from Map will show up as List&lt;Integer> in
* StringToIntListMap, but as plain List in RawStringToIntListMap.</p>
*
* @param actual the type that supplies bindings for type variables
* @param formal the type where occurrences of the variables
* in {@code actual} will be replaced by the corresponding bound values
* @return a resolved type
*/
public static Type resolve(Type actual, Type formal) {
if (formal instanceof Class) {
return formal;
}
if (formal instanceof GenericArrayType) {
Type comp = ((GenericArrayType) formal).getGenericComponentType();
comp = resolve(actual, comp);
return (comp instanceof Class)
? Array.newInstance((Class<?>) comp, 0).getClass()
: GenericArrayTypeImpl.make(comp);
}
if (formal instanceof ParameterizedType) {
ParameterizedType fpt = (ParameterizedType) formal;
Type[] actuals = resolve(actual, fpt.getActualTypeArguments());
return ParameterizedTypeImpl.make(
(Class<?>) fpt.getRawType(), actuals, fpt.getOwnerType());
}
if (formal instanceof WildcardType) {
WildcardType fwt = (WildcardType) formal;
Type[] upper = resolve(actual, fwt.getUpperBounds());
Type[] lower = resolve(actual, fwt.getLowerBounds());
return new WildcardTypeImpl(upper, lower);
}
if (formal instanceof TypeVariable) {
Map<Type, Type> map;
synchronized (CACHE) {
map = CACHE.get(actual);
if (map == null) {
map = new HashMap<>();
prepare(map, actual);
CACHE.put(actual, map);
}
}
Type result = map.get(formal);
if (result == null || result.equals(formal)) {
return formal;
}
result = fixGenericArray(result);
// A variable can be bound to another variable that is itself bound
// to something. For example, given:
// class Super<T> {...}
// class Mid<X> extends Super<T> {...}
// class Sub extends Mid<String>
// the variable T is bound to X, which is in turn bound to String.
// So if we have to resolve T, we need the tail recursion here.
return resolve(actual, result);
}
throw new IllegalArgumentException("Bad Type kind: " + formal.getClass());
}
/**
* Replaces type variables of all formal types in the given array
* with the types they stand for in the given {@code actual} type.
*
* @param actual the type that supplies bindings for type variables
* @param formals the array of types to resolve
* @return an array of resolved types
*/
public static Type[] resolve(Type actual, Type[] formals) {
int length = formals.length;
Type[] actuals = new Type[length];
for (int i = 0; i < length; i++) {
actuals[i] = resolve(actual, formals[i]);
}
return actuals;
}
/**
* Converts the given {@code type} to the corresponding class.
* This method implements the concept of type erasure,
* that is described in section 4.6 of
* <cite>The Java&trade; Language Specification</cite>.
*
* @param type the array of types to convert
* @return a corresponding class
*/
public static Class<?> erase(Type type) {
if (type instanceof Class) {
return (Class<?>) type;
}
if (type instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) type;
return (Class<?>) pt.getRawType();
}
if (type instanceof TypeVariable) {
TypeVariable tv = (TypeVariable)type;
Type[] bounds = tv.getBounds();
return (0 < bounds.length)
? erase(bounds[0])
: Object.class;
}
if (type instanceof WildcardType) {
WildcardType wt = (WildcardType)type;
Type[] bounds = wt.getUpperBounds();
return (0 < bounds.length)
? erase(bounds[0])
: Object.class;
}
if (type instanceof GenericArrayType) {
GenericArrayType gat = (GenericArrayType)type;
return Array.newInstance(erase(gat.getGenericComponentType()), 0).getClass();
}
throw new IllegalArgumentException("Unknown Type kind: " + type.getClass());
}
/**
* Converts all {@code types} in the given array
* to the corresponding classes.
*
* @param types the array of types to convert
* @return an array of corresponding classes
*
* @see #erase(Type)
*/
public static Class[] erase(Type[] types) {
int length = types.length;
Class[] classes = new Class[length];
for (int i = 0; i < length; i++) {
classes[i] = TypeResolver.erase(types[i]);
}
return classes;
}
/**
* Fills the map from type parameters
* to types as seen by the given {@code type}.
* The method is recursive because the {@code type}
* inherits mappings from its parent classes and interfaces.
* The {@code type} can be either a {@link Class Class}
* or a {@link ParameterizedType ParameterizedType}.
* If it is a {@link Class Class}, it is either equivalent
* to a {@link ParameterizedType ParameterizedType} with no parameters,
* or it represents the erasure of a {@link ParameterizedType ParameterizedType}.
*
* @param map the mappings of all type variables
* @param type the next type in the hierarchy
*/
private static void prepare(Map<Type, Type> map, Type type) {
Class<?> raw = (Class<?>)((type instanceof Class<?>)
? type
: ((ParameterizedType)type).getRawType());
TypeVariable<?>[] formals = raw.getTypeParameters();
Type[] actuals = (type instanceof Class<?>)
? formals
: ((ParameterizedType)type).getActualTypeArguments();
assert formals.length == actuals.length;
for (int i = 0; i < formals.length; i++) {
map.put(formals[i], actuals[i]);
}
Type gSuperclass = raw.getGenericSuperclass();
if (gSuperclass != null) {
prepare(map, gSuperclass);
}
for (Type gInterface : raw.getGenericInterfaces()) {
prepare(map, gInterface);
}
// If type is the raw version of a parameterized class, we type-erase
// all of its type variables, including inherited ones.
if (type instanceof Class<?> && formals.length > 0) {
for (Map.Entry<Type, Type> entry : map.entrySet()) {
entry.setValue(erase(entry.getValue()));
}
}
}
/**
* Replaces a {@link GenericArrayType GenericArrayType}
* with plain array class where it is possible.
* Bug <a href="http://bugs.sun.com/view_bug.do?bug_id=5041784">5041784</a>
* is that arrays of non-generic type sometimes show up
* as {@link GenericArrayType GenericArrayType} when using reflection.
* For example, a {@code String[]} might show up
* as a {@link GenericArrayType GenericArrayType}
* where {@link GenericArrayType#getGenericComponentType getGenericComponentType}
* is {@code String.class}. This violates the specification,
* which says that {@link GenericArrayType GenericArrayType}
* is used when the component type is a type variable or parameterized type.
* We fit the specification here.
*
* @param type the type to fix
* @return a corresponding type for the generic array type,
* or the same type as {@code type}
*/
private static Type fixGenericArray(Type type) {
if (type instanceof GenericArrayType) {
Type comp = ((GenericArrayType)type).getGenericComponentType();
comp = fixGenericArray(comp);
if (comp instanceof Class) {
return Array.newInstance((Class<?>)comp, 0).getClass();
}
}
return type;
}
/**
* Replaces a {@link Class Class} with type parameters
* with a {@link ParameterizedType ParameterizedType}
* where every parameter is bound to itself.
* When calling {@link #resolveInClass} in the context of {@code inClass},
* we can't just pass {@code inClass} as the {@code actual} parameter,
* because if {@code inClass} has type parameters
* that would be interpreted as accessing the raw type,
* so we would get unwanted erasure.
* This is why we bind each parameter to itself.
* If {@code inClass} does have type parameters and has methods
* where those parameters appear in the return type or argument types,
* we will correctly leave those types alone.
*
* @param inClass the base class used to resolve
* @return a parameterized type for the class,
* or the same class as {@code inClass}
*/
private static Type getActualType(Class<?> inClass) {
Type[] params = inClass.getTypeParameters();
return (params.length == 0)
? inClass
: ParameterizedTypeImpl.make(
inClass, params, inClass.getEnclosingClass());
}
}

View File

@@ -0,0 +1,91 @@
/*
* Copyright (c) 2008, 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.beans;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.Map;
import java.util.WeakHashMap;
/**
* A hashtable-based cache with weak keys and weak values.
* An entry in the map will be automatically removed
* when its key is no longer in the ordinary use.
* A value will be automatically removed as well
* when it is no longer in the ordinary use.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
public final class WeakCache<K, V> {
private final Map<K, Reference<V>> map = new WeakHashMap<K, Reference<V>>();
/**
* Returns a value to which the specified {@code key} is mapped,
* or {@code null} if this map contains no mapping for the {@code key}.
*
* @param key the key whose associated value is returned
* @return a value to which the specified {@code key} is mapped
*/
public V get(K key) {
Reference<V> reference = this.map.get(key);
if (reference == null) {
return null;
}
V value = reference.get();
if (value == null) {
this.map.remove(key);
}
return value;
}
/**
* Associates the specified {@code value} with the specified {@code key}.
* Removes the mapping for the specified {@code key} from this cache
* if it is present and the specified {@code value} is {@code null}.
* If the cache previously contained a mapping for the {@code key},
* the old value is replaced by the specified {@code value}.
*
* @param key the key with which the specified value is associated
* @param value the value to be associated with the specified key
*/
public void put(K key, V value) {
if (value != null) {
this.map.put(key, new WeakReference<V>(value));
}
else {
this.map.remove(key);
}
}
/**
* Removes all of the mappings from this cache.
*/
public void clear() {
this.map.clear();
}
}

View File

@@ -0,0 +1,161 @@
/*
* Copyright (c) 2003, 2006, 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.beans;
import java.lang.reflect.Type;
import java.lang.reflect.WildcardType;
import java.util.Arrays;
/**
* This class implements {@link WildcardType WildcardType} compatibly with the JDK's
* {@link sun.reflect.generics.reflectiveObjects.WildcardTypeImpl WildcardTypeImpl}.
* Unfortunately we can't use the JDK's
* {@link sun.reflect.generics.reflectiveObjects.WildcardTypeImpl WildcardTypeImpl} here as we do for
* {@link sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl ParameterizedTypeImpl} and
* {@link sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl GenericArrayTypeImpl},
* because {@link sun.reflect.generics.reflectiveObjects.WildcardTypeImpl WildcardTypeImpl}'s
* constructor takes parameters representing intermediate structures obtained during class-file parsing.
* We could reconstruct versions of those structures but it would be more trouble than it's worth.
*
* @since 1.7
*
* @author Eamonn McManus
* @author Sergey Malenkov
*/
final class WildcardTypeImpl implements WildcardType {
private final Type[] upperBounds;
private final Type[] lowerBounds;
/**
* Creates a wildcard type with the requested bounds.
* Note that the array arguments are not cloned
* because instances of this class are never constructed
* from outside the containing package.
*
* @param upperBounds the array of types representing
* the upper bound(s) of this type variable
* @param lowerBounds the array of types representing
* the lower bound(s) of this type variable
*/
WildcardTypeImpl(Type[] upperBounds, Type[] lowerBounds) {
this.upperBounds = upperBounds;
this.lowerBounds = lowerBounds;
}
/**
* Returns an array of {@link Type Type} objects
* representing the upper bound(s) of this type variable.
* Note that if no upper bound is explicitly declared,
* the upper bound is {@link Object Object}.
*
* @return an array of types representing
* the upper bound(s) of this type variable
*/
public Type[] getUpperBounds() {
return this.upperBounds.clone();
}
/**
* Returns an array of {@link Type Type} objects
* representing the lower bound(s) of this type variable.
* Note that if no lower bound is explicitly declared,
* the lower bound is the type of {@code null}.
* In this case, a zero length array is returned.
*
* @return an array of types representing
* the lower bound(s) of this type variable
*/
public Type[] getLowerBounds() {
return this.lowerBounds.clone();
}
/**
* Indicates whether some other object is "equal to" this one.
* It is implemented compatibly with the JDK's
* {@link sun.reflect.generics.reflectiveObjects.WildcardTypeImpl WildcardTypeImpl}.
*
* @param object the reference object with which to compare
* @return {@code true} if this object is the same as the object argument;
* {@code false} otherwise
* @see sun.reflect.generics.reflectiveObjects.WildcardTypeImpl#equals
*/
@Override
public boolean equals(Object object) {
if (object instanceof WildcardType) {
WildcardType type = (WildcardType) object;
return Arrays.equals(this.upperBounds, type.getUpperBounds())
&& Arrays.equals(this.lowerBounds, type.getLowerBounds());
}
return false;
}
/**
* Returns a hash code value for the object.
* It is implemented compatibly with the JDK's
* {@link sun.reflect.generics.reflectiveObjects.WildcardTypeImpl WildcardTypeImpl}.
*
* @return a hash code value for this object
* @see sun.reflect.generics.reflectiveObjects.WildcardTypeImpl#hashCode
*/
@Override
public int hashCode() {
return Arrays.hashCode(this.upperBounds)
^ Arrays.hashCode(this.lowerBounds);
}
/**
* Returns a string representation of the object.
* It is implemented compatibly with the JDK's
* {@link sun.reflect.generics.reflectiveObjects.WildcardTypeImpl WildcardTypeImpl}.
*
* @return a string representation of the object
* @see sun.reflect.generics.reflectiveObjects.WildcardTypeImpl#toString
*/
@Override
public String toString() {
StringBuilder sb;
Type[] bounds;
if (this.lowerBounds.length == 0) {
if (this.upperBounds.length == 0 || Object.class == this.upperBounds[0]) {
return "?";
}
bounds = this.upperBounds;
sb = new StringBuilder("? extends ");
}
else {
bounds = this.lowerBounds;
sb = new StringBuilder("? super ");
}
for (int i = 0; i < bounds.length; i++) {
if (i > 0) {
sb.append(" & ");
}
sb.append((bounds[i] instanceof Class)
? ((Class) bounds[i]).getName()
: bounds[i].toString());
}
return sb.toString();
}
}

View File

@@ -0,0 +1,105 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
/**
* This is base class that simplifies access to entities (fields or properties).
* The {@code name} attribute specifies the name of the accessible entity.
* The element defines getter if it contains no argument
* or setter if it contains one argument.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
abstract class AccessorElementHandler extends ElementHandler {
private String name;
private ValueObject value;
/**
* Parses attributes of the element.
* The following attributes are supported:
* <dl>
* <dt>name
* <dd>the name of the accessible entity
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @param name the attribute name
* @param value the attribute value
*/
@Override
public void addAttribute(String name, String value) {
if (name.equals("name")) { // NON-NLS: the attribute name
this.name = value;
} else {
super.addAttribute(name, value);
}
}
/**
* Adds the argument that is used to set the value of this element.
*
* @param argument the value of the element that contained in this one
*/
@Override
protected final void addArgument(Object argument) {
if (this.value != null) {
throw new IllegalStateException("Could not add argument to evaluated element");
}
setValue(this.name, argument);
this.value = ValueObjectImpl.VOID;
}
/**
* Returns the value of this element.
*
* @return the value of this element
*/
@Override
protected final ValueObject getValueObject() {
if (this.value == null) {
this.value = ValueObjectImpl.create(getValue(this.name));
}
return this.value;
}
/**
* Returns the value of the entity with specified {@code name}.
*
* @param name the name of the accessible entity
* @return the value of the specified entity
*/
protected abstract Object getValue(String name);
/**
* Sets the new value for the entity with specified {@code name}.
*
* @param name the name of the accessible entity
* @param value the new value for the specified entity
*/
protected abstract void setValue(String name, Object value);
}

View File

@@ -0,0 +1,147 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
import java.lang.reflect.Array;
/**
* This class is intended to handle &lt;array&gt; element,
* that is used to array creation.
* The {@code length} attribute specifies the length of the array.
* The {@code class} attribute specifies the elements type.
* The {@link Object} type is used by default.
* For example:<pre>
* &lt;array length="10"/&gt;</pre>
* is equivalent to {@code new Component[10]} in Java code.
* The {@code set} and {@code get} methods,
* as defined in the {@link java.util.List} interface,
* can be used as if they could be applied to array instances.
* The {@code index} attribute can thus be used with arrays.
* For example:<pre>
* &lt;array length="3" class="java.lang.String"&gt;
* &lt;void index="1"&gt;
* &lt;string&gt;Hello, world&lt;/string&gt;
* &lt;/void&gt;
* &lt;/array&gt;</pre>
* is equivalent to the following Java code:<pre>
* String[] s = new String[3];
* s[1] = "Hello, world";</pre>
* It is possible to omit the {@code length} attribute and
* specify the values directly, without using {@code void} tags.
* The length of the array is equal to the number of values specified.
* For example:<pre>
* &lt;array id="array" class="int"&gt;
* &lt;int&gt;123&lt;/int&gt;
* &lt;int&gt;456&lt;/int&gt;
* &lt;/array&gt;</pre>
* is equivalent to {@code int[] array = {123, 456}} in Java code.
* <p>The following attributes are supported:
* <dl>
* <dt>length
* <dd>the array length
* <dt>class
* <dd>the type of object for instantiation
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class ArrayElementHandler extends NewElementHandler {
private Integer length;
/**
* Parses attributes of the element.
* The following attributes are supported:
* <dl>
* <dt>length
* <dd>the array length
* <dt>class
* <dd>the type of object for instantiation
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @param name the attribute name
* @param value the attribute value
*/
@Override
public void addAttribute(String name, String value) {
if (name.equals("length")) { // NON-NLS: the attribute name
this.length = Integer.valueOf(value);
} else {
super.addAttribute(name, value);
}
}
/**
* Calculates the value of this element
* if the lentgh attribute is set.
*/
@Override
public void startElement() {
if (this.length != null) {
getValueObject();
}
}
/**
* Tests whether the value of this element can be used
* as an argument of the element that contained in this one.
*
* @return {@code true} if the value of this element can be used
* as an argument of the element that contained in this one,
* {@code false} otherwise
*/
@Override
protected boolean isArgument() {
return true; // hack for compatibility
}
/**
* Creates an instance of the array.
*
* @param type the base class
* @param args the array of arguments
* @return the value of this element
*/
@Override
protected ValueObject getValueObject(Class<?> type, Object[] args) {
if (type == null) {
type = Object.class;
}
if (this.length != null) {
return ValueObjectImpl.create(Array.newInstance(type, this.length));
}
Object array = Array.newInstance(type, args.length);
for (int i = 0; i < args.length; i++) {
Array.set(array, i, args[i]);
}
return ValueObjectImpl.create(array);
}
}

View File

@@ -0,0 +1,69 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;boolean&gt; element.
* This element specifies {@code boolean} values.
* The class {@link Boolean} is used as wrapper for these values.
* The result value is created from text of the body of this element.
* The body parsing is described in the class {@link StringElementHandler}.
* For example:<pre>
* &lt;boolean&gt;true&lt;/boolean&gt;</pre>
* is shortcut to<pre>
* &lt;method name="valueOf" class="java.lang.Boolean"&gt;
* &lt;string&gt;true&lt;/string&gt;
* &lt;/method&gt;</pre>
* which is equivalent to {@code Boolean.valueOf("true")} in Java code.
* <p>The following attribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class BooleanElementHandler extends StringElementHandler {
/**
* Creates {@code boolean} value from
* the text of the body of this element.
*
* @param argument the text of the body
* @return evaluated {@code boolean} value
*/
@Override
public Object getValue(String argument) {
if (Boolean.TRUE.toString().equalsIgnoreCase(argument)) {
return Boolean.TRUE;
}
if (Boolean.FALSE.toString().equalsIgnoreCase(argument)) {
return Boolean.FALSE;
}
throw new IllegalArgumentException("Unsupported boolean argument: " + argument);
}
}

View File

@@ -0,0 +1,63 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;byte&gt; element.
* This element specifies {@code byte} values.
* The class {@link Byte} is used as wrapper for these values.
* The result value is created from text of the body of this element.
* The body parsing is described in the class {@link StringElementHandler}.
* For example:<pre>
* &lt;byte&gt;127&lt;/byte&gt;</pre>
* is shortcut to<pre>
* &lt;method name="decode" class="java.lang.Byte"&gt;
* &lt;string&gt;127&lt;/string&gt;
* &lt;/method&gt;</pre>
* which is equivalent to {@code Byte.decode("127")} in Java code.
* <p>The following attribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class ByteElementHandler extends StringElementHandler {
/**
* Creates {@code byte} value from
* the text of the body of this element.
*
* @param argument the text of the body
* @return evaluated {@code byte} value
*/
@Override
public Object getValue(String argument) {
return Byte.decode(argument);
}
}

View File

@@ -0,0 +1,92 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;char&gt; element.
* This element specifies {@code char} values.
* The class {@link Character} is used as wrapper for these values.
* The result value is created from text of the body of this element.
* The body parsing is described in the class {@link StringElementHandler}.
* For example:<pre>
* &lt;char&gt;X&lt;/char&gt;</pre>
* which is equivalent to {@code Character.valueOf('X')} in Java code.
* <p>The following attributes are supported:
* <dl>
* <dt>code
* <dd>this attribute specifies character code
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
* The {@code code} attribute can be used for characters
* that are illegal in XML document, for example:<pre>
* &lt;char code="0"/&gt;</pre>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class CharElementHandler extends StringElementHandler {
/**
* Parses attributes of the element.
* The following attributes are supported:
* <dl>
* <dt>code
* <dd>this attribute specifies character code
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @param name the attribute name
* @param value the attribute value
*/
@Override
public void addAttribute(String name, String value) {
if (name.equals("code")) { // NON-NLS: the attribute name
int code = Integer.decode(value);
for (char ch : Character.toChars(code)) {
addCharacter(ch);
}
} else {
super.addAttribute(name, value);
}
}
/**
* Creates {@code char} value from
* the text of the body of this element.
*
* @param argument the text of the body
* @return evaluated {@code char} value
*/
@Override
public Object getValue(String argument) {
if (argument.length() != 1) {
throw new IllegalArgumentException("Wrong characters count");
}
return Character.valueOf(argument.charAt(0));
}
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;class&gt; element.
* This element specifies {@link Class} values.
* The result value is created from text of the body of this element.
* The body parsing is described in the class {@link StringElementHandler}.
* For example:<pre>
* &lt;class&gt;java.lang.Class&lt;/class&gt;</pre>
* is shortcut to<pre>
* &lt;method name="forName" class="java.lang.Class"&gt;
* &lt;string&gt;java.lang.Class&lt;/string&gt;
* &lt;/method&gt;</pre>
* which is equivalent to {@code Class.forName("java.lang.Class")} in Java code.
* <p>The following attribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class ClassElementHandler extends StringElementHandler {
/**
* Creates class by the name from
* the text of the body of this element.
*
* @param argument the text of the body
* @return evaluated {@code Class} value
*/
@Override
public Object getValue(String argument) {
return getOwner().findClass(argument);
}
}

View File

@@ -0,0 +1,411 @@
/*
* Copyright (c) 2008, 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.beans.decoder;
import com.sun.beans.finder.ClassFinder;
import java.beans.ExceptionListener;
import java.io.IOException;
import java.io.StringReader;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import sun.misc.SharedSecrets;
/**
* The main class to parse JavaBeans XML archive.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*
* @see ElementHandler
*/
public final class DocumentHandler extends DefaultHandler {
private final AccessControlContext acc = AccessController.getContext();
private final Map<String, Class<? extends ElementHandler>> handlers = new HashMap<>();
private final Map<String, Object> environment = new HashMap<>();
private final List<Object> objects = new ArrayList<>();
private Reference<ClassLoader> loader;
private ExceptionListener listener;
private Object owner;
private ElementHandler handler;
/**
* Creates new instance of document handler.
*/
public DocumentHandler() {
setElementHandler("java", JavaElementHandler.class); // NON-NLS: the element name
setElementHandler("null", NullElementHandler.class); // NON-NLS: the element name
setElementHandler("array", ArrayElementHandler.class); // NON-NLS: the element name
setElementHandler("class", ClassElementHandler.class); // NON-NLS: the element name
setElementHandler("string", StringElementHandler.class); // NON-NLS: the element name
setElementHandler("object", ObjectElementHandler.class); // NON-NLS: the element name
setElementHandler("void", VoidElementHandler.class); // NON-NLS: the element name
setElementHandler("char", CharElementHandler.class); // NON-NLS: the element name
setElementHandler("byte", ByteElementHandler.class); // NON-NLS: the element name
setElementHandler("short", ShortElementHandler.class); // NON-NLS: the element name
setElementHandler("int", IntElementHandler.class); // NON-NLS: the element name
setElementHandler("long", LongElementHandler.class); // NON-NLS: the element name
setElementHandler("float", FloatElementHandler.class); // NON-NLS: the element name
setElementHandler("double", DoubleElementHandler.class); // NON-NLS: the element name
setElementHandler("boolean", BooleanElementHandler.class); // NON-NLS: the element name
// some handlers for new elements
setElementHandler("new", NewElementHandler.class); // NON-NLS: the element name
setElementHandler("var", VarElementHandler.class); // NON-NLS: the element name
setElementHandler("true", TrueElementHandler.class); // NON-NLS: the element name
setElementHandler("false", FalseElementHandler.class); // NON-NLS: the element name
setElementHandler("field", FieldElementHandler.class); // NON-NLS: the element name
setElementHandler("method", MethodElementHandler.class); // NON-NLS: the element name
setElementHandler("property", PropertyElementHandler.class); // NON-NLS: the element name
}
/**
* Returns the class loader used to instantiate objects.
* If the class loader has not been explicitly set
* then {@code null} is returned.
*
* @return the class loader used to instantiate objects
*/
public ClassLoader getClassLoader() {
return (this.loader != null)
? this.loader.get()
: null;
}
/**
* Sets the class loader used to instantiate objects.
* If the class loader is not set
* then default class loader will be used.
*
* @param loader a classloader to use
*/
public void setClassLoader(ClassLoader loader) {
this.loader = new WeakReference<ClassLoader>(loader);
}
/**
* Returns the exception listener for parsing.
* The exception listener is notified
* when handler catches recoverable exceptions.
* If the exception listener has not been explicitly set
* then default exception listener is returned.
*
* @return the exception listener for parsing
*/
public ExceptionListener getExceptionListener() {
return this.listener;
}
/**
* Sets the exception listener for parsing.
* The exception listener is notified
* when handler catches recoverable exceptions.
*
* @param listener the exception listener for parsing
*/
public void setExceptionListener(ExceptionListener listener) {
this.listener = listener;
}
/**
* Returns the owner of this document handler.
*
* @return the owner of this document handler
*/
public Object getOwner() {
return this.owner;
}
/**
* Sets the owner of this document handler.
*
* @param owner the owner of this document handler
*/
public void setOwner(Object owner) {
this.owner = owner;
}
/**
* Returns the handler for the element with specified name.
*
* @param name the name of the element
* @return the corresponding element handler
*/
public Class<? extends ElementHandler> getElementHandler(String name) {
Class<? extends ElementHandler> type = this.handlers.get(name);
if (type == null) {
throw new IllegalArgumentException("Unsupported element: " + name);
}
return type;
}
/**
* Sets the handler for the element with specified name.
*
* @param name the name of the element
* @param handler the corresponding element handler
*/
public void setElementHandler(String name, Class<? extends ElementHandler> handler) {
this.handlers.put(name, handler);
}
/**
* Indicates whether the variable with specified identifier is defined.
*
* @param id the identifier
* @return @{code true} if the variable is defined;
* @{code false} otherwise
*/
public boolean hasVariable(String id) {
return this.environment.containsKey(id);
}
/**
* Returns the value of the variable with specified identifier.
*
* @param id the identifier
* @return the value of the variable
*/
public Object getVariable(String id) {
if (!this.environment.containsKey(id)) {
throw new IllegalArgumentException("Unbound variable: " + id);
}
return this.environment.get(id);
}
/**
* Sets new value of the variable with specified identifier.
*
* @param id the identifier
* @param value new value of the variable
*/
public void setVariable(String id, Object value) {
this.environment.put(id, value);
}
/**
* Returns the array of readed objects.
*
* @return the array of readed objects
*/
public Object[] getObjects() {
return this.objects.toArray();
}
/**
* Adds the object to the list of readed objects.
*
* @param object the object that is readed from XML document
*/
void addObject(Object object) {
this.objects.add(object);
}
/**
* Disables any external entities.
*/
@Override
public InputSource resolveEntity(String publicId, String systemId) {
return new InputSource(new StringReader(""));
}
/**
* Prepares this handler to read objects from XML document.
*/
@Override
public void startDocument() {
this.objects.clear();
this.handler = null;
}
/**
* Parses opening tag of XML element
* using corresponding element handler.
*
* @param uri the namespace URI, or the empty string
* if the element has no namespace URI or
* if namespace processing is not being performed
* @param localName the local name (without prefix), or the empty string
* if namespace processing is not being performed
* @param qName the qualified name (with prefix), or the empty string
* if qualified names are not available
* @param attributes the attributes attached to the element
*/
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
ElementHandler parent = this.handler;
try {
this.handler = getElementHandler(qName).newInstance();
this.handler.setOwner(this);
this.handler.setParent(parent);
}
catch (Exception exception) {
throw new SAXException(exception);
}
for (int i = 0; i < attributes.getLength(); i++)
try {
String name = attributes.getQName(i);
String value = attributes.getValue(i);
this.handler.addAttribute(name, value);
}
catch (RuntimeException exception) {
handleException(exception);
}
this.handler.startElement();
}
/**
* Parses closing tag of XML element
* using corresponding element handler.
*
* @param uri the namespace URI, or the empty string
* if the element has no namespace URI or
* if namespace processing is not being performed
* @param localName the local name (without prefix), or the empty string
* if namespace processing is not being performed
* @param qName the qualified name (with prefix), or the empty string
* if qualified names are not available
*/
@Override
public void endElement(String uri, String localName, String qName) {
try {
this.handler.endElement();
}
catch (RuntimeException exception) {
handleException(exception);
}
finally {
this.handler = this.handler.getParent();
}
}
/**
* Parses character data inside XML element.
*
* @param chars the array of characters
* @param start the start position in the character array
* @param length the number of characters to use
*/
@Override
public void characters(char[] chars, int start, int length) {
if (this.handler != null) {
try {
while (0 < length--) {
this.handler.addCharacter(chars[start++]);
}
}
catch (RuntimeException exception) {
handleException(exception);
}
}
}
/**
* Handles an exception using current exception listener.
*
* @param exception an exception to handle
* @see #setExceptionListener
*/
public void handleException(Exception exception) {
if (this.listener == null) {
throw new IllegalStateException(exception);
}
this.listener.exceptionThrown(exception);
}
/**
* Starts parsing of the specified input source.
*
* @param input the input source to parse
*/
public void parse(final InputSource input) {
if ((this.acc == null) && (null != System.getSecurityManager())) {
throw new SecurityException("AccessControlContext is not set");
}
AccessControlContext stack = AccessController.getContext();
SharedSecrets.getJavaSecurityAccess().doIntersectionPrivilege(new PrivilegedAction<Void>() {
public Void run() {
try {
SAXParserFactory.newInstance().newSAXParser().parse(input, DocumentHandler.this);
}
catch (ParserConfigurationException exception) {
handleException(exception);
}
catch (SAXException wrapper) {
Exception exception = wrapper.getException();
if (exception == null) {
exception = wrapper;
}
handleException(exception);
}
catch (IOException exception) {
handleException(exception);
}
return null;
}
}, stack, this.acc);
}
/**
* Resolves class by name using current class loader.
* This method handles exception using current exception listener.
*
* @param name the name of the class
* @return the object that represents the class
*/
public Class<?> findClass(String name) {
try {
return ClassFinder.resolveClass(name, getClassLoader());
}
catch (ClassNotFoundException exception) {
handleException(exception);
return null;
}
}
}

View File

@@ -0,0 +1,63 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;double&gt; element.
* This element specifies {@code double} values.
* The class {@link Double} is used as wrapper for these values.
* The result value is created from text of the body of this element.
* The body parsing is described in the class {@link StringElementHandler}.
* For example:<pre>
* &lt;double&gt;1.23e45&lt;/double&gt;</pre>
* is shortcut to<pre>
* &lt;method name="valueOf" class="java.lang.Double"&gt;
* &lt;string&gt;1.23e45&lt;/string&gt;
* &lt;/method&gt;</pre>
* which is equivalent to {@code Double.valueOf("1.23e45")} in Java code.
* <p>The following attribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class DoubleElementHandler extends StringElementHandler {
/**
* Creates {@code double} value from
* the text of the body of this element.
*
* @param argument the text of the body
* @return evaluated {@code double} value
*/
@Override
public Object getValue(String argument) {
return Double.valueOf(argument);
}
}

View File

@@ -0,0 +1,224 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
/**
* The base class for element handlers.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*
* @see DocumentHandler
*/
public abstract class ElementHandler {
private DocumentHandler owner;
private ElementHandler parent;
private String id;
/**
* Returns the document handler that creates this element handler.
*
* @return the owner document handler
*/
public final DocumentHandler getOwner() {
return this.owner;
}
/**
* Sets the document handler that creates this element handler.
* The owner document handler should be set after instantiation.
* Such approach is used to simplify the extensibility.
*
* @param owner the owner document handler
* @see DocumentHandler#startElement
*/
final void setOwner(DocumentHandler owner) {
if (owner == null) {
throw new IllegalArgumentException("Every element should have owner");
}
this.owner = owner;
}
/**
* Returns the element handler that contains this one.
*
* @return the parent element handler
*/
public final ElementHandler getParent() {
return this.parent;
}
/**
* Sets the element handler that contains this one.
* The parent element handler should be set after instantiation.
* Such approach is used to simplify the extensibility.
*
* @param parent the parent element handler
* @see DocumentHandler#startElement
*/
final void setParent(ElementHandler parent) {
this.parent = parent;
}
/**
* Returns the value of the variable with specified identifier.
*
* @param id the identifier
* @return the value of the variable
*/
protected final Object getVariable(String id) {
if (id.equals(this.id)) {
ValueObject value = getValueObject();
if (value.isVoid()) {
throw new IllegalStateException("The element does not return value");
}
return value.getValue();
}
return (this.parent != null)
? this.parent.getVariable(id)
: this.owner.getVariable(id);
}
/**
* Returns the value of the parent element.
*
* @return the value of the parent element
*/
protected Object getContextBean() {
if (this.parent != null) {
ValueObject value = this.parent.getValueObject();
if (!value.isVoid()) {
return value.getValue();
}
throw new IllegalStateException("The outer element does not return value");
} else {
Object value = this.owner.getOwner();
if (value != null) {
return value;
}
throw new IllegalStateException("The topmost element does not have context");
}
}
/**
* Parses attributes of the element.
* By default, the following attribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @param name the attribute name
* @param value the attribute value
*/
public void addAttribute(String name, String value) {
if (name.equals("id")) { // NON-NLS: the attribute name
this.id = value;
} else {
throw new IllegalArgumentException("Unsupported attribute: " + name);
}
}
/**
* This method is called before parsing of the element's body.
* All attributes are parsed at this point.
* By default, do nothing.
*/
public void startElement() {
}
/**
* This method is called after parsing of the element's body.
* By default, it calculates the value of this element.
* The following tasks are executing for any non-void value:
* <ol>
* <li>If the {@code id} attribute is set
* the value of the variable with the specified identifier
* is set to the value of this element.</li>
* <li>This element is used as an argument of parent element if it is possible.</li>
* </ol>
*
* @see #isArgument
*/
public void endElement() {
// do nothing if no value returned
ValueObject value = getValueObject();
if (!value.isVoid()) {
if (this.id != null) {
this.owner.setVariable(this.id, value.getValue());
}
if (isArgument()) {
if (this.parent != null) {
this.parent.addArgument(value.getValue());
} else {
this.owner.addObject(value.getValue());
}
}
}
}
/**
* Adds the character that contained in this element.
* By default, only whitespaces are acceptable.
*
* @param ch the character
*/
public void addCharacter(char ch) {
if ((ch != ' ') && (ch != '\n') && (ch != '\t') && (ch != '\r')) {
throw new IllegalStateException("Illegal character with code " + (int) ch);
}
}
/**
* Adds the argument that is used to calculate the value of this element.
* By default, no arguments are acceptable.
*
* @param argument the value of the element that contained in this one
*/
protected void addArgument(Object argument) {
throw new IllegalStateException("Could not add argument to simple element");
}
/**
* Tests whether the value of this element can be used
* as an argument of the element that contained in this one.
*
* @return {@code true} if the value of this element can be used
* as an argument of the element that contained in this one,
* {@code false} otherwise
*/
protected boolean isArgument() {
return this.id == null;
}
/**
* Returns the value of this element.
*
* @return the value of this element
*/
protected abstract ValueObject getValueObject();
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;false&gt; element.
* This element specifies {@code false} value.
* It should not contain body or inner elements.
* For example:<pre>
* &lt;false/&gt;</pre>
* is equivalent to {@code false} in Java code.
* <p>The following attribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class FalseElementHandler extends NullElementHandler {
/**
* Returns {@code Boolean.FALSE}
* as a value of &lt;false&gt; element.
*
* @return {@code Boolean.FALSE} by default
*/
@Override
public Object getValue() {
return Boolean.FALSE;
}
}

View File

@@ -0,0 +1,189 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
import com.sun.beans.finder.FieldFinder;
import java.lang.reflect.Field;
/**
* This class is intended to handle &lt;field&gt; element.
* This element simplifies access to the fields.
* If the {@code class} attribute is specified
* this element accesses static field of specified class.
* This element defines getter if it contains no argument.
* It returns the value of the field in this case.
* For example:<pre>
* &lt;field name="TYPE" class="java.lang.Long"/&gt;</pre>
* is equivalent to {@code Long.TYPE} in Java code.
* This element defines setter if it contains one argument.
* It does not return the value of the field in this case.
* For example:<pre>
* &lt;field name="id"&gt;&lt;int&gt;0&lt;/int&gt;&lt;/field&gt;</pre>
* is equivalent to {@code id = 0} in Java code.
* <p>The following attributes are supported:
* <dl>
* <dt>name
* <dd>the field name
* <dt>class
* <dd>the type is used for static fields only
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class FieldElementHandler extends AccessorElementHandler {
private Class<?> type;
/**
* Parses attributes of the element.
* The following attributes are supported:
* <dl>
* <dt>name
* <dd>the field name
* <dt>class
* <dd>the type is used for static fields only
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @param name the attribute name
* @param value the attribute value
*/
@Override
public void addAttribute(String name, String value) {
if (name.equals("class")) { // NON-NLS: the attribute name
this.type = getOwner().findClass(value);
} else {
super.addAttribute(name, value);
}
}
/**
* Tests whether the value of this element can be used
* as an argument of the element that contained in this one.
*
* @return {@code true} if the value of this element should be used
* as an argument of the element that contained in this one,
* {@code false} otherwise
*/
@Override
protected boolean isArgument() {
return super.isArgument() && (this.type != null); // only static accessor can be used an argument
}
/**
* Returns the context of the field.
* The context of the static field is the class object.
* The context of the non-static field is the value of the parent element.
*
* @return the context of the field
*/
@Override
protected Object getContextBean() {
return (this.type != null)
? this.type
: super.getContextBean();
}
/**
* Returns the value of the field with specified {@code name}.
*
* @param name the name of the field
* @return the value of the specified field
*/
@Override
protected Object getValue(String name) {
try {
return getFieldValue(getContextBean(), name);
}
catch (Exception exception) {
getOwner().handleException(exception);
}
return null;
}
/**
* Sets the new value for the field with specified {@code name}.
*
* @param name the name of the field
* @param value the new value for the specified field
*/
@Override
protected void setValue(String name, Object value) {
try {
setFieldValue(getContextBean(), name, value);
}
catch (Exception exception) {
getOwner().handleException(exception);
}
}
/**
* Performs the search of the field with specified {@code name}
* in specified context and returns its value.
*
* @param bean the context bean that contains field
* @param name the name of the field
* @return the value of the field
* @throws IllegalAccessException if the field is not accesible
* @throws NoSuchFieldException if the field is not found
*/
static Object getFieldValue(Object bean, String name) throws IllegalAccessException, NoSuchFieldException {
return findField(bean, name).get(bean);
}
/**
* Performs the search of the field with specified {@code name}
* in specified context and updates its value.
*
* @param bean the context bean that contains field
* @param name the name of the field
* @param value the new value for the field
* @throws IllegalAccessException if the field is not accesible
* @throws NoSuchFieldException if the field is not found
*/
private static void setFieldValue(Object bean, String name, Object value) throws IllegalAccessException, NoSuchFieldException {
findField(bean, name).set(bean, value);
}
/**
* Performs the search of the field
* with specified {@code name} in specified context.
*
* @param bean the context bean that contains field
* @param name the name of the field
* @return field object that represents found field
* @throws NoSuchFieldException if the field is not found
*/
private static Field findField(Object bean, String name) throws NoSuchFieldException {
return (bean instanceof Class<?>)
? FieldFinder.findStaticField((Class<?>) bean, name)
: FieldFinder.findField(bean.getClass(), name);
}
}

View File

@@ -0,0 +1,63 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;float&gt; element.
* This element specifies {@code float} values.
* The class {@link Float} is used as wrapper for these values.
* The result value is created from text of the body of this element.
* The body parsing is described in the class {@link StringElementHandler}.
* For example:<pre>
* &lt;float&gt;-1.23&lt;/float&gt;</pre>
* is shortcut to<pre>
* &lt;method name="valueOf" class="java.lang.Float"&gt;
* &lt;string&gt;-1.23&lt;/string&gt;
* &lt;/method&gt;</pre>
* which is equivalent to {@code Float.valueOf("-1.23")} in Java code.
* <p>The following attribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class FloatElementHandler extends StringElementHandler {
/**
* Creates {@code float} value from
* the text of the body of this element.
*
* @param argument the text of the body
* @return evaluated {@code float} value
*/
@Override
public Object getValue(String argument) {
return Float.valueOf(argument);
}
}

View File

@@ -0,0 +1,63 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;int&gt; element.
* This element specifies {@code int} values.
* The class {@link Integer} is used as wrapper for these values.
* The result value is created from text of the body of this element.
* The body parsing is described in the class {@link StringElementHandler}.
* For example:<pre>
* &lt;int&gt;-1&lt;/int&gt;</pre>
* is shortcut to<pre>
* &lt;method name="decode" class="java.lang.Integer"&gt;
* &lt;string&gt;-1&lt;/string&gt;
* &lt;/method&gt;</pre>
* which is equivalent to {@code Integer.decode("-1")} in Java code.
* <p>The following attribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class IntElementHandler extends StringElementHandler {
/**
* Creates {@code int} value from
* the text of the body of this element.
*
* @param argument the text of the body
* @return evaluated {@code int} value
*/
@Override
public Object getValue(String argument) {
return Integer.decode(argument);
}
}

View File

@@ -0,0 +1,151 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
import java.beans.XMLDecoder;
/**
* This class is intended to handle &lt;java&gt; element.
* Each element that appears in the body of this element
* is evaluated in the context of the decoder itself.
* Typically this outer context is used to retrieve the owner of the decoder,
* which can be set before reading the archive.
* <p>The following attributes are supported:
* <dl>
* <dt>version
* <dd>the Java version (not supported)
* <dt>class
* <dd>the type of preferable parser (not supported)
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @see DocumentHandler#getOwner
* @see DocumentHandler#setOwner
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class JavaElementHandler extends ElementHandler {
private Class<?> type;
private ValueObject value;
/**
* Parses attributes of the element.
* The following attributes are supported:
* <dl>
* <dt>version
* <dd>the Java version (not supported)
* <dt>class
* <dd>the type of preferable parser (not supported)
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @param name the attribute name
* @param value the attribute value
*/
@Override
public void addAttribute(String name, String value) {
if (name.equals("version")) { // NON-NLS: the attribute name
// unsupported attribute
} else if (name.equals("class")) { // NON-NLS: the attribute name
// check class for owner
this.type = getOwner().findClass(value);
} else {
super.addAttribute(name, value);
}
}
/**
* Adds the argument to the list of readed objects.
*
* @param argument the value of the element that contained in this one
*/
@Override
protected void addArgument(Object argument) {
getOwner().addObject(argument);
}
/**
* Tests whether the value of this element can be used
* as an argument of the element that contained in this one.
*
* @return {@code true} if the value of this element should be used
* as an argument of the element that contained in this one,
* {@code false} otherwise
*/
@Override
protected boolean isArgument() {
return false; // do not use owner as object
}
/**
* Returns the value of this element.
*
* @return the value of this element
*/
@Override
protected ValueObject getValueObject() {
if (this.value == null) {
this.value = ValueObjectImpl.create(getValue());
}
return this.value;
}
/**
* Returns the owner of the owner document handler
* as a value of &lt;java&gt; element.
*
* @return the owner of the owner document handler
*/
private Object getValue() {
Object owner = getOwner().getOwner();
if ((this.type == null) || isValid(owner)) {
return owner;
}
if (owner instanceof XMLDecoder) {
XMLDecoder decoder = (XMLDecoder) owner;
owner = decoder.getOwner();
if (isValid(owner)) {
return owner;
}
}
throw new IllegalStateException("Unexpected owner class: " + owner.getClass().getName());
}
/**
* Validates the owner of the &lt;java&gt; element.
* The owner is valid if it is {@code null} or an instance
* of the class specified by the {@code class} attribute.
*
* @param owner the owner of the &lt;java&gt; element
* @return {@code true} if the {@code owner} is valid;
* {@code false} otherwise
*/
private boolean isValid(Object owner) {
return (owner == null) || this.type.isInstance(owner);
}
}

View File

@@ -0,0 +1,63 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;long&gt; element.
* This element specifies {@code long} values.
* The class {@link Long} is used as wrapper for these values.
* The result value is created from text of the body of this element.
* The body parsing is described in the class {@link StringElementHandler}.
* For example:<pre>
* &lt;long&gt;0xFFFF&lt;/long&gt;</pre>
* is shortcut to<pre>
* &lt;method name="decode" class="java.lang.Long"&gt;
* &lt;string&gt;0xFFFF&lt;/string&gt;
* &lt;/method&gt;</pre>
* which is equivalent to {@code Long.decode("0xFFFF")} in Java code.
* <p>The following attribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class LongElementHandler extends StringElementHandler {
/**
* Creates {@code long} value from
* the text of the body of this element.
*
* @param argument the text of the body
* @return evaluated {@code long} value
*/
@Override
public Object getValue(String argument) {
return Long.decode(argument);
}
}

View File

@@ -0,0 +1,111 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
import com.sun.beans.finder.MethodFinder;
import java.lang.reflect.Method;
import sun.reflect.misc.MethodUtil;
/**
* This class is intended to handle &lt;method&gt; element.
* It describes invocation of the method.
* The {@code name} attribute denotes
* the name of the method to invoke.
* If the {@code class} attribute is specified
* this element invokes static method of specified class.
* The inner elements specifies the arguments of the method.
* For example:<pre>
* &lt;method name="valueOf" class="java.lang.Long"&gt;
* &lt;string&gt;10&lt;/string&gt;
* &lt;/method&gt;</pre>
* is equivalent to {@code Long.valueOf("10")} in Java code.
* <p>The following attributes are supported:
* <dl>
* <dt>name
* <dd>the method name
* <dt>class
* <dd>the type of object for instantiation
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class MethodElementHandler extends NewElementHandler {
private String name;
/**
* Parses attributes of the element.
* The following attributes are supported:
* <dl>
* <dt>name
* <dd>the method name
* <dt>class
* <dd>the type of object for instantiation
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @param name the attribute name
* @param value the attribute value
*/
@Override
public void addAttribute(String name, String value) {
if (name.equals("name")) { // NON-NLS: the attribute name
this.name = value;
} else {
super.addAttribute(name, value);
}
}
/**
* Returns the result of method execution.
*
* @param type the base class
* @param args the array of arguments
* @return the value of this element
* @throws Exception if calculation is failed
*/
@Override
protected ValueObject getValueObject(Class<?> type, Object[] args) throws Exception {
Object bean = getContextBean();
Class<?>[] types = getArgumentTypes(args);
Method method = (type != null)
? MethodFinder.findStaticMethod(type, this.name, types)
: MethodFinder.findMethod(bean.getClass(), this.name, types);
if (method.isVarArgs()) {
args = getArguments(args, method.getParameterTypes());
}
Object value = MethodUtil.invoke(method, bean, args);
return method.getReturnType().equals(void.class)
? ValueObjectImpl.VOID
: ValueObjectImpl.create(value);
}
}

View File

@@ -0,0 +1,205 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
import com.sun.beans.finder.ConstructorFinder;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;
/**
* This class is intended to handle &lt;new&gt; element.
* It describes instantiation of the object.
* The {@code class} attribute denotes
* the name of the class to instantiate.
* The inner elements specifies the arguments of the constructor.
* For example:<pre>
* &lt;new class="java.lang.Long"&gt;
* &lt;string&gt;10&lt;/string&gt;
* &lt;/new&gt;</pre>
* is equivalent to {@code new Long("10")} in Java code.
* <p>The following attributes are supported:
* <dl>
* <dt>class
* <dd>the type of object for instantiation
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
class NewElementHandler extends ElementHandler {
private List<Object> arguments = new ArrayList<Object>();
private ValueObject value = ValueObjectImpl.VOID;
private Class<?> type;
/**
* Parses attributes of the element.
* The following attributes are supported:
* <dl>
* <dt>class
* <dd>the type of object for instantiation
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @param name the attribute name
* @param value the attribute value
*/
@Override
public void addAttribute(String name, String value) {
if (name.equals("class")) { // NON-NLS: the attribute name
this.type = getOwner().findClass(value);
} else {
super.addAttribute(name, value);
}
}
/**
* Adds the argument to the list of arguments
* that is used to calculate the value of this element.
*
* @param argument the value of the element that contained in this one
*/
@Override
protected final void addArgument(Object argument) {
if (this.arguments == null) {
throw new IllegalStateException("Could not add argument to evaluated element");
}
this.arguments.add(argument);
}
/**
* Returns the context of the method.
* The context of the static method is the class object.
* The context of the non-static method is the value of the parent element.
*
* @return the context of the method
*/
@Override
protected final Object getContextBean() {
return (this.type != null)
? this.type
: super.getContextBean();
}
/**
* Returns the value of this element.
*
* @return the value of this element
*/
@Override
protected final ValueObject getValueObject() {
if (this.arguments != null) {
try {
this.value = getValueObject(this.type, this.arguments.toArray());
}
catch (Exception exception) {
getOwner().handleException(exception);
}
finally {
this.arguments = null;
}
}
return this.value;
}
/**
* Calculates the value of this element
* using the base class and the array of arguments.
* By default, it creates an instance of the base class.
* This method should be overridden in those handlers
* that extend behavior of this element.
*
* @param type the base class
* @param args the array of arguments
* @return the value of this element
* @throws Exception if calculation is failed
*/
ValueObject getValueObject(Class<?> type, Object[] args) throws Exception {
if (type == null) {
throw new IllegalArgumentException("Class name is not set");
}
Class<?>[] types = getArgumentTypes(args);
Constructor<?> constructor = ConstructorFinder.findConstructor(type, types);
if (constructor.isVarArgs()) {
args = getArguments(args, constructor.getParameterTypes());
}
return ValueObjectImpl.create(constructor.newInstance(args));
}
/**
* Converts the array of arguments to the array of corresponding classes.
* If argument is {@code null} the class is {@code null} too.
*
* @param arguments the array of arguments
* @return the array of corresponding classes
*/
static Class<?>[] getArgumentTypes(Object[] arguments) {
Class<?>[] types = new Class<?>[arguments.length];
for (int i = 0; i < arguments.length; i++) {
if (arguments[i] != null) {
types[i] = arguments[i].getClass();
}
}
return types;
}
/**
* Resolves variable arguments.
*
* @param arguments the array of arguments
* @param types the array of parameter types
* @return the resolved array of arguments
*/
static Object[] getArguments(Object[] arguments, Class<?>[] types) {
int index = types.length - 1;
if (types.length == arguments.length) {
Object argument = arguments[index];
if (argument == null) {
return arguments;
}
Class<?> type = types[index];
if (type.isAssignableFrom(argument.getClass())) {
return arguments;
}
}
int length = arguments.length - index;
Class<?> type = types[index].getComponentType();
Object array = Array.newInstance(type, length);
System.arraycopy(arguments, index, array, 0, length);
Object[] args = new Object[types.length];
System.arraycopy(arguments, 0, args, 0, index);
args[index] = array;
return args;
}
}

View File

@@ -0,0 +1,76 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;null&gt; element.
* This element specifies {@code null} value.
* It should not contain body or inner elements.
* For example:<pre>
* &lt;null/&gt;</pre>
* is equivalent to {@code null} in Java code.
* <p>The following attribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
class NullElementHandler extends ElementHandler implements ValueObject {
/**
* Returns the value of this element.
*
* @return the value of this element
*/
@Override
protected final ValueObject getValueObject() {
return this;
}
/**
* Returns {@code null}
* as a value of &lt;null&gt; element.
* This method should be overridden in those handlers
* that extend behavior of this element.
*
* @return {@code null} by default
*/
public Object getValue() {
return null;
}
/**
* Returns {@code void} state of this value object.
*
* @return {@code false} always
*/
public final boolean isVoid() {
return false;
}
}

View File

@@ -0,0 +1,168 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
import java.beans.Expression;
import static java.util.Locale.ENGLISH;
/**
* This class is intended to handle &lt;object&gt; element.
* This element looks like &lt;void&gt; element,
* but its value is always used as an argument for element
* that contains this one.
* <p>The following attributes are supported:
* <dl>
* <dt>class
* <dd>the type is used for static methods and fields
* <dt>method
* <dd>the method name
* <dt>property
* <dd>the property name
* <dt>index
* <dd>the property index
* <dt>field
* <dd>the field name
* <dt>idref
* <dd>the identifier to refer to the variable
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
class ObjectElementHandler extends NewElementHandler {
private String idref;
private String field;
private Integer index;
private String property;
private String method;
/**
* Parses attributes of the element.
* The following attributes are supported:
* <dl>
* <dt>class
* <dd>the type is used for static methods and fields
* <dt>method
* <dd>the method name
* <dt>property
* <dd>the property name
* <dt>index
* <dd>the property index
* <dt>field
* <dd>the field name
* <dt>idref
* <dd>the identifier to refer to the variable
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @param name the attribute name
* @param value the attribute value
*/
@Override
public final void addAttribute(String name, String value) {
if (name.equals("idref")) { // NON-NLS: the attribute name
this.idref = value;
} else if (name.equals("field")) { // NON-NLS: the attribute name
this.field = value;
} else if (name.equals("index")) { // NON-NLS: the attribute name
this.index = Integer.valueOf(value);
addArgument(this.index); // hack for compatibility
} else if (name.equals("property")) { // NON-NLS: the attribute name
this.property = value;
} else if (name.equals("method")) { // NON-NLS: the attribute name
this.method = value;
} else {
super.addAttribute(name, value);
}
}
/**
* Calculates the value of this element
* if the field attribute or the idref attribute is set.
*/
@Override
public final void startElement() {
if ((this.field != null) || (this.idref != null)) {
getValueObject();
}
}
/**
* Tests whether the value of this element can be used
* as an argument of the element that contained in this one.
*
* @return {@code true} if the value of this element can be used
* as an argument of the element that contained in this one,
* {@code false} otherwise
*/
@Override
protected boolean isArgument() {
return true; // hack for compatibility
}
/**
* Creates the value of this element.
*
* @param type the base class
* @param args the array of arguments
* @return the value of this element
* @throws Exception if calculation is failed
*/
@Override
protected final ValueObject getValueObject(Class<?> type, Object[] args) throws Exception {
if (this.field != null) {
return ValueObjectImpl.create(FieldElementHandler.getFieldValue(getContextBean(), this.field));
}
if (this.idref != null) {
return ValueObjectImpl.create(getVariable(this.idref));
}
Object bean = getContextBean();
String name;
if (this.index != null) {
name = (args.length == 2)
? PropertyElementHandler.SETTER
: PropertyElementHandler.GETTER;
} else if (this.property != null) {
name = (args.length == 1)
? PropertyElementHandler.SETTER
: PropertyElementHandler.GETTER;
if (0 < this.property.length()) {
name += this.property.substring(0, 1).toUpperCase(ENGLISH) + this.property.substring(1);
}
} else {
name = (this.method != null) && (0 < this.method.length())
? this.method
: "new"; // NON-NLS: the constructor marker
}
Expression expression = new Expression(bean, name, args);
return ValueObjectImpl.create(expression.getValue());
}
}

View File

@@ -0,0 +1,289 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
import com.sun.beans.finder.MethodFinder;
import java.beans.IndexedPropertyDescriptor;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import sun.reflect.misc.MethodUtil;
/**
* This class is intended to handle &lt;property&gt; element.
* This element simplifies access to the properties.
* If the {@code index} attribute is specified
* this element uses additional {@code int} parameter.
* If the {@code name} attribute is not specified
* this element uses method "get" as getter
* and method "set" as setter.
* This element defines getter if it contains no argument.
* It returns the value of the property in this case.
* For example:<pre>
* &lt;property name="object" index="10"/&gt;</pre>
* is shortcut to<pre>
* &lt;method name="getObject"&gt;
* &lt;int&gt;10&lt;/int&gt;
* &lt;/method&gt;</pre>
* which is equivalent to {@code getObject(10)} in Java code.
* This element defines setter if it contains one argument.
* It does not return the value of the property in this case.
* For example:<pre>
* &lt;property&gt;&lt;int&gt;0&lt;/int&gt;&lt;/property&gt;</pre>
* is shortcut to<pre>
* &lt;method name="set"&gt;
* &lt;int&gt;0&lt;/int&gt;
* &lt;/method&gt;</pre>
* which is equivalent to {@code set(0)} in Java code.
* <p>The following attributes are supported:
* <dl>
* <dt>name
* <dd>the property name
* <dt>index
* <dd>the property index
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class PropertyElementHandler extends AccessorElementHandler {
static final String GETTER = "get"; // NON-NLS: the getter prefix
static final String SETTER = "set"; // NON-NLS: the setter prefix
private Integer index;
/**
* Parses attributes of the element.
* The following attributes are supported:
* <dl>
* <dt>name
* <dd>the property name
* <dt>index
* <dd>the property index
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @param name the attribute name
* @param value the attribute value
*/
@Override
public void addAttribute(String name, String value) {
if (name.equals("index")) { // NON-NLS: the attribute name
this.index = Integer.valueOf(value);
} else {
super.addAttribute(name, value);
}
}
/**
* Tests whether the value of this element can be used
* as an argument of the element that contained in this one.
*
* @return {@code true} if the value of this element should be used
* as an argument of the element that contained in this one,
* {@code false} otherwise
*/
@Override
protected boolean isArgument() {
return false; // non-static accessor cannot be used an argument
}
/**
* Returns the value of the property with specified {@code name}.
*
* @param name the name of the property
* @return the value of the specified property
*/
@Override
protected Object getValue(String name) {
try {
return getPropertyValue(getContextBean(), name, this.index);
}
catch (Exception exception) {
getOwner().handleException(exception);
}
return null;
}
/**
* Sets the new value for the property with specified {@code name}.
*
* @param name the name of the property
* @param value the new value for the specified property
*/
@Override
protected void setValue(String name, Object value) {
try {
setPropertyValue(getContextBean(), name, this.index, value);
}
catch (Exception exception) {
getOwner().handleException(exception);
}
}
/**
* Performs the search of the getter for the property
* with specified {@code name} in specified class
* and returns value of the property.
*
* @param bean the context bean that contains property
* @param name the name of the property
* @param index the index of the indexed property
* @return the value of the property
* @throws IllegalAccessException if the property is not accesible
* @throws IntrospectionException if the bean introspection is failed
* @throws InvocationTargetException if the getter cannot be invoked
* @throws NoSuchMethodException if the getter is not found
*/
private static Object getPropertyValue(Object bean, String name, Integer index) throws IllegalAccessException, IntrospectionException, InvocationTargetException, NoSuchMethodException {
Class<?> type = bean.getClass();
if (index == null) {
return MethodUtil.invoke(findGetter(type, name), bean, new Object[] {});
} else if (type.isArray() && (name == null)) {
return Array.get(bean, index);
} else {
return MethodUtil.invoke(findGetter(type, name, int.class), bean, new Object[] {index});
}
}
/**
* Performs the search of the setter for the property
* with specified {@code name} in specified class
* and updates value of the property.
*
* @param bean the context bean that contains property
* @param name the name of the property
* @param index the index of the indexed property
* @param value the new value for the property
* @throws IllegalAccessException if the property is not accesible
* @throws IntrospectionException if the bean introspection is failed
* @throws InvocationTargetException if the setter cannot be invoked
* @throws NoSuchMethodException if the setter is not found
*/
private static void setPropertyValue(Object bean, String name, Integer index, Object value) throws IllegalAccessException, IntrospectionException, InvocationTargetException, NoSuchMethodException {
Class<?> type = bean.getClass();
Class<?> param = (value != null)
? value.getClass()
: null;
if (index == null) {
MethodUtil.invoke(findSetter(type, name, param), bean, new Object[] {value});
} else if (type.isArray() && (name == null)) {
Array.set(bean, index, value);
} else {
MethodUtil.invoke(findSetter(type, name, int.class, param), bean, new Object[] {index, value});
}
}
/**
* Performs the search of the getter for the property
* with specified {@code name} in specified class.
*
* @param type the class that contains method
* @param name the name of the property
* @param args the method arguments
* @return method object that represents found getter
* @throws IntrospectionException if the bean introspection is failed
* @throws NoSuchMethodException if method is not found
*/
private static Method findGetter(Class<?> type, String name, Class<?>...args) throws IntrospectionException, NoSuchMethodException {
if (name == null) {
return MethodFinder.findInstanceMethod(type, GETTER, args);
}
PropertyDescriptor pd = getProperty(type, name);
if (args.length == 0) {
Method method = pd.getReadMethod();
if (method != null) {
return method;
}
} else if (pd instanceof IndexedPropertyDescriptor) {
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
Method method = ipd.getIndexedReadMethod();
if (method != null) {
return method;
}
}
throw new IntrospectionException("Could not find getter for the " + name + " property");
}
/**
* Performs the search of the setter for the property
* with specified {@code name} in specified class.
*
* @param type the class that contains method
* @param name the name of the property
* @param args the method arguments
* @return method object that represents found setter
* @throws IntrospectionException if the bean introspection is failed
* @throws NoSuchMethodException if method is not found
*/
private static Method findSetter(Class<?> type, String name, Class<?>...args) throws IntrospectionException, NoSuchMethodException {
if (name == null) {
return MethodFinder.findInstanceMethod(type, SETTER, args);
}
PropertyDescriptor pd = getProperty(type, name);
if (args.length == 1) {
Method method = pd.getWriteMethod();
if (method != null) {
return method;
}
} else if (pd instanceof IndexedPropertyDescriptor) {
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
Method method = ipd.getIndexedWriteMethod();
if (method != null) {
return method;
}
}
throw new IntrospectionException("Could not find setter for the " + name + " property");
}
/**
* Performs the search of the descriptor for the property
* with specified {@code name} in specified class.
*
* @param type the class to introspect
* @param name the property name
* @return descriptor for the named property
* @throws IntrospectionException if property descriptor is not found
*/
private static PropertyDescriptor getProperty(Class<?> type, String name) throws IntrospectionException {
for (PropertyDescriptor pd : Introspector.getBeanInfo(type).getPropertyDescriptors()) {
if (name.equals(pd.getName())) {
return pd;
}
}
throw new IntrospectionException("Could not find the " + name + " property descriptor");
}
}

View File

@@ -0,0 +1,63 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;short&gt; element.
* This element specifies {@code short} values.
* The class {@link Short} is used as wrapper for these values.
* The result value is created from text of the body of this element.
* The body parsing is described in the class {@link StringElementHandler}.
* For example:<pre>
* &lt;short&gt;200&lt;/short&gt;</pre>
* is shortcut to<pre>
* &lt;method name="decode" class="java.lang.Short"&gt;
* &lt;string&gt;200&lt;/string&gt;
* &lt;/method&gt;</pre>
* which is equivalent to {@code Short.decode("200")} in Java code.
* <p>The following attribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class ShortElementHandler extends StringElementHandler {
/**
* Creates {@code short} value from
* the text of the body of this element.
*
* @param argument the text of the body
* @return evaluated {@code short} value
*/
@Override
public Object getValue(String argument) {
return Short.decode(argument);
}
}

View File

@@ -0,0 +1,116 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;string&gt; element.
* This element specifies {@link String} values.
* The result value is created from text of the body of this element.
* For example:<pre>
* &lt;string&gt;description&lt;/string&gt;</pre>
* is equivalent to {@code "description"} in Java code.
* The value of inner element is calculated
* before adding to the string using {@link String#valueOf(Object)}.
* Note that all characters are used including whitespaces (' ', '\t', '\n', '\r').
* So the value of the element<pre>
* &lt;string&gt&lt;true&gt&lt;/string&gt;</pre>
* is not equal to the value of the element<pre>
* &lt;string&gt;
* &lt;true&gt;
* &lt;/string&gt;</pre>
* <p>The following attribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
public class StringElementHandler extends ElementHandler {
private StringBuilder sb = new StringBuilder();
private ValueObject value = ValueObjectImpl.NULL;
/**
* Adds the character that contained in this element.
*
* @param ch the character
*/
@Override
public final void addCharacter(char ch) {
if (this.sb == null) {
throw new IllegalStateException("Could not add chararcter to evaluated string element");
}
this.sb.append(ch);
}
/**
* Adds the string value of the argument to the string value of this element.
*
* @param argument the value of the element that contained in this one
*/
@Override
protected final void addArgument(Object argument) {
if (this.sb == null) {
throw new IllegalStateException("Could not add argument to evaluated string element");
}
this.sb.append(argument);
}
/**
* Returns the value of this element.
*
* @return the value of this element
*/
@Override
protected final ValueObject getValueObject() {
if (this.sb != null) {
try {
this.value = ValueObjectImpl.create(getValue(this.sb.toString()));
}
catch (RuntimeException exception) {
getOwner().handleException(exception);
}
finally {
this.sb = null;
}
}
return this.value;
}
/**
* Returns the text of the body of this element.
* This method evaluates value from text of the body,
* and should be overridden in those handlers
* that extend behavior of this element.
*
* @param argument the text of the body
* @return evaluated value
*/
protected Object getValue(String argument) {
return argument;
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;true&gt; element.
* This element specifies {@code true} value.
* It should not contain body or inner elements.
* For example:<pre>
* &lt;true/&gt;</pre>
* is equivalent to {@code true} in Java code.
* <p>The following attribute is supported:
* <dl>
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class TrueElementHandler extends NullElementHandler {
/**
* Returns {@code Boolean.TRUE}
* as a value of &lt;true&gt; element.
*
* @return {@code Boolean.TRUE} by default
*/
@Override
public Object getValue() {
return Boolean.TRUE;
}
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) 2008, 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.beans.decoder;
/**
* This interface represents the result of method execution.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
public interface ValueObject {
/**
* Returns the result of method execution.
*
* @return the result of method execution
*/
Object getValue();
/**
* Returns {@code void} state of this value object.
*
* @return {@code true} if value can be ignored,
* {@code false} otherwise
*/
boolean isVoid();
}

View File

@@ -0,0 +1,88 @@
/*
* Copyright (c) 2008, 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.beans.decoder;
/**
* This utility class provides {@code static} method
* to create the object that contains the result of method execution.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class ValueObjectImpl implements ValueObject {
static final ValueObject NULL = new ValueObjectImpl(null);
static final ValueObject VOID = new ValueObjectImpl();
/**
* Returns the object that describes returning value.
*
* @param value the result of method execution
* @return the object that describes value
*/
static ValueObject create(Object value) {
return (value != null)
? new ValueObjectImpl(value)
: NULL;
}
private Object value;
private boolean isVoid;
/**
* Creates the object that describes returning void value.
*/
private ValueObjectImpl() {
this.isVoid = true;
}
/**
* Creates the object that describes returning non-void value.
*
* @param value the result of method execution
*/
private ValueObjectImpl(Object value) {
this.value = value;
}
/**
* Returns the result of method execution.
*
* @return the result of method execution
*/
public Object getValue() {
return this.value;
}
/**
* Returns {@code void} state of this value object.
*
* @return {@code true} if value should be ignored,
* {@code false} otherwise
*/
public boolean isVoid() {
return this.isVoid;
}
}

View File

@@ -0,0 +1,82 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;var&gt; element.
* This element retrieves the value of specified variable.
* For example:<pre>
* &lt;var id="id1" idref="id2"/&gt;</pre>
* is equivalent to {@code id1 = id2} in Java code.
* <p>The following attributes are supported:
* <dl>
* <dt>idref
* <dd>the identifier to refer to the variable
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class VarElementHandler extends ElementHandler {
private ValueObject value;
/**
* Parses attributes of the element.
* The following attributes are supported:
* <dl>
* <dt>idref
* <dd>the identifier to refer to the variable
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @param name the attribute name
* @param value the attribute value
*/
@Override
public void addAttribute(String name, String value) {
if (name.equals("idref")) { // NON-NLS: the attribute name
this.value = ValueObjectImpl.create(getVariable(value));
} else {
super.addAttribute(name, value);
}
}
/**
* Returns the value of this element.
*
* @return the value of this element
*/
@Override
protected ValueObject getValueObject() {
if (this.value == null) {
throw new IllegalArgumentException("Variable name is not set");
}
return this.value;
}
}

View File

@@ -0,0 +1,68 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.decoder;
/**
* This class is intended to handle &lt;void&gt; element.
* This element looks like &lt;object&gt; element,
* but its value is not used as an argument for element
* that contains this one.
* <p>The following attributes are supported:
* <dl>
* <dt>class
* <dd>the type is used for static methods and fields
* <dt>method
* <dd>the method name
* <dt>property
* <dd>the property name
* <dt>index
* <dd>the property index
* <dt>field
* <dd>the field name
* <dt>idref
* <dd>the identifier to refer to the variable
* <dt>id
* <dd>the identifier of the variable that is intended to store the result
* </dl>
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class VoidElementHandler extends ObjectElementHandler {
/**
* Tests whether the value of this element can be used
* as an argument of the element that contained in this one.
*
* @return {@code true} if the value of this element should be used
* as an argument of the element that contained in this one,
* {@code false} otherwise
*/
@Override
protected boolean isArgument() {
return false; // hack for compatibility
}
}

View File

@@ -0,0 +1,76 @@
/*
* Copyright (c) 2006, 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.beans.editors;
/**
* Property editor for a java builtin "boolean" type.
*/
import java.beans.*;
public class BooleanEditor extends PropertyEditorSupport {
public String getJavaInitializationString() {
Object value = getValue();
return (value != null)
? value.toString()
: "null";
}
public String getAsText() {
Object value = getValue();
return (value instanceof Boolean)
? getValidName((Boolean) value)
: null;
}
public void setAsText(String text) throws java.lang.IllegalArgumentException {
if (text == null) {
setValue(null);
} else if (isValidName(true, text)) {
setValue(Boolean.TRUE);
} else if (isValidName(false, text)) {
setValue(Boolean.FALSE);
} else {
throw new java.lang.IllegalArgumentException(text);
}
}
public String[] getTags() {
return new String[] {getValidName(true), getValidName(false)};
}
// the following method should be localized (4890258)
private String getValidName(boolean value) {
return value ? "True" : "False";
}
private boolean isValidName(boolean value, String name) {
return getValidName(value).equalsIgnoreCase(name);
}
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright (c) 1996, 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.beans.editors;
/**
* Property editor for a java builtin "byte" type.
*
*/
import java.beans.*;
public class ByteEditor extends NumberEditor {
public String getJavaInitializationString() {
Object value = getValue();
return (value != null)
? "((byte)" + value + ")"
: "null";
}
public void setAsText(String text) throws IllegalArgumentException {
setValue((text == null) ? null : Byte.decode(text));
}
}

View File

@@ -0,0 +1,214 @@
/*
* Copyright (c) 1996, 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.beans.editors;
import java.awt.*;
import java.beans.*;
public class ColorEditor extends Panel implements PropertyEditor {
private static final long serialVersionUID = 1781257185164716054L;
public ColorEditor() {
setLayout(null);
ourWidth = hPad;
// Create a sample color block bordered in black
Panel p = new Panel();
p.setLayout(null);
p.setBackground(Color.black);
sample = new Canvas();
p.add(sample);
sample.reshape(2, 2, sampleWidth, sampleHeight);
add(p);
p.reshape(ourWidth, 2, sampleWidth+4, sampleHeight+4);
ourWidth += sampleWidth + 4 + hPad;
text = new TextField("", 14);
add(text);
text.reshape(ourWidth,0,100,30);
ourWidth += 100 + hPad;
choser = new Choice();
int active = 0;
for (int i = 0; i < colorNames.length; i++) {
choser.addItem(colorNames[i]);
}
add(choser);
choser.reshape(ourWidth,0,100,30);
ourWidth += 100 + hPad;
resize(ourWidth,40);
}
public void setValue(Object o) {
Color c = (Color)o;
changeColor(c);
}
public Dimension preferredSize() {
return new Dimension(ourWidth, 40);
}
public boolean keyUp(Event e, int key) {
if (e.target == text) {
try {
setAsText(text.getText());
} catch (IllegalArgumentException ex) {
// Quietly ignore.
}
}
return (false);
}
public void setAsText(String s) throws java.lang.IllegalArgumentException {
if (s == null) {
changeColor(null);
return;
}
int c1 = s.indexOf(',');
int c2 = s.indexOf(',', c1+1);
if (c1 < 0 || c2 < 0) {
// Invalid string.
throw new IllegalArgumentException(s);
}
try {
int r = Integer.parseInt(s.substring(0,c1));
int g = Integer.parseInt(s.substring(c1+1, c2));
int b = Integer.parseInt(s.substring(c2+1));
Color c = new Color(r,g,b);
changeColor(c);
} catch (Exception ex) {
throw new IllegalArgumentException(s);
}
}
public boolean action(Event e, Object arg) {
if (e.target == choser) {
changeColor(colors[choser.getSelectedIndex()]);
}
return false;
}
public String getJavaInitializationString() {
return (this.color != null)
? "new java.awt.Color(" + this.color.getRGB() + ",true)"
: "null";
}
private void changeColor(Color c) {
if (c == null) {
this.color = null;
this.text.setText("");
return;
}
color = c;
text.setText("" + c.getRed() + "," + c.getGreen() + "," + c.getBlue());
int active = 0;
for (int i = 0; i < colorNames.length; i++) {
if (color.equals(colors[i])) {
active = i;
}
}
choser.select(active);
sample.setBackground(color);
sample.repaint();
support.firePropertyChange("", null, null);
}
public Object getValue() {
return color;
}
public boolean isPaintable() {
return true;
}
public void paintValue(java.awt.Graphics gfx, java.awt.Rectangle box) {
Color oldColor = gfx.getColor();
gfx.setColor(Color.black);
gfx.drawRect(box.x, box.y, box.width-3, box.height-3);
gfx.setColor(color);
gfx.fillRect(box.x+1, box.y+1, box.width-4, box.height-4);
gfx.setColor(oldColor);
}
public String getAsText() {
return (this.color != null)
? this.color.getRed() + "," + this.color.getGreen() + "," + this.color.getBlue()
: null;
}
public String[] getTags() {
return null;
}
public java.awt.Component getCustomEditor() {
return this;
}
public boolean supportsCustomEditor() {
return true;
}
public void addPropertyChangeListener(PropertyChangeListener l) {
support.addPropertyChangeListener(l);
}
public void removePropertyChangeListener(PropertyChangeListener l) {
support.removePropertyChangeListener(l);
}
private String colorNames[] = { " ", "white", "lightGray", "gray", "darkGray",
"black", "red", "pink", "orange",
"yellow", "green", "magenta", "cyan",
"blue"};
private Color colors[] = { null, Color.white, Color.lightGray, Color.gray, Color.darkGray,
Color.black, Color.red, Color.pink, Color.orange,
Color.yellow, Color.green, Color.magenta, Color.cyan,
Color.blue};
private Canvas sample;
private int sampleHeight = 20;
private int sampleWidth = 40;
private int hPad = 5;
private int ourWidth;
private Color color;
private TextField text;
private Choice choser;
private PropertyChangeSupport support = new PropertyChangeSupport(this);
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright (c) 1996, 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.beans.editors;
/**
* Property editor for a java builtin "double" type.
*
*/
import java.beans.*;
public class DoubleEditor extends NumberEditor {
public void setAsText(String text) throws IllegalArgumentException {
setValue((text == null) ? null : Double.valueOf(text));
}
}

View File

@@ -0,0 +1,143 @@
/*
* Copyright (c) 2006, 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.beans.editors;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyEditor;
import java.util.ArrayList;
import java.util.List;
/**
* Property editor for java.lang.Enum subclasses.
*
* @see PropertyEditor
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
public final class EnumEditor implements PropertyEditor {
private final List<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>();
private final Class type;
private final String[] tags;
private Object value;
public EnumEditor( Class type ) {
Object[] values = type.getEnumConstants();
if ( values == null ) {
throw new IllegalArgumentException( "Unsupported " + type );
}
this.type = type;
this.tags = new String[values.length];
for ( int i = 0; i < values.length; i++ ) {
this.tags[i] = ( ( Enum )values[i] ).name();
}
}
public Object getValue() {
return this.value;
}
public void setValue( Object value ) {
if ( ( value != null ) && !this.type.isInstance( value ) ) {
throw new IllegalArgumentException( "Unsupported value: " + value );
}
Object oldValue;
PropertyChangeListener[] listeners;
synchronized ( this.listeners ) {
oldValue = this.value;
this.value = value;
if ( ( value == null ) ? oldValue == null : value.equals( oldValue ) ) {
return; // do not fire event if value is not changed
}
int size = this.listeners.size();
if ( size == 0 ) {
return; // do not fire event if there are no any listener
}
listeners = this.listeners.toArray( new PropertyChangeListener[size] );
}
PropertyChangeEvent event = new PropertyChangeEvent( this, null, oldValue, value );
for ( PropertyChangeListener listener : listeners ) {
listener.propertyChange( event );
}
}
public String getAsText() {
return ( this.value != null )
? ( ( Enum )this.value ).name()
: null;
}
public void setAsText( String text ) {
setValue( ( text != null )
? Enum.valueOf( this.type, text )
: null );
}
public String[] getTags() {
return this.tags.clone();
}
public String getJavaInitializationString() {
String name = getAsText();
return ( name != null )
? this.type.getName() + '.' + name
: "null";
}
public boolean isPaintable() {
return false;
}
public void paintValue( Graphics gfx, Rectangle box ) {
}
public boolean supportsCustomEditor() {
return false;
}
public Component getCustomEditor() {
return null;
}
public void addPropertyChangeListener( PropertyChangeListener listener ) {
synchronized ( this.listeners ) {
this.listeners.add( listener );
}
}
public void removePropertyChangeListener( PropertyChangeListener listener ) {
synchronized ( this.listeners ) {
this.listeners.remove( listener );
}
}
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright (c) 1996, 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.beans.editors;
/**
* Property editor for a java builtin "float" type.
*
*/
import java.beans.*;
public class FloatEditor extends NumberEditor {
public String getJavaInitializationString() {
Object value = getValue();
return (value != null)
? value + "F"
: "null";
}
public void setAsText(String text) throws IllegalArgumentException {
setValue((text == null) ? null : Float.valueOf(text));
}
}

View File

@@ -0,0 +1,219 @@
/*
* Copyright (c) 1996, 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.beans.editors;
import java.awt.*;
import java.beans.*;
public class FontEditor extends Panel implements java.beans.PropertyEditor {
private static final long serialVersionUID = 6732704486002715933L;
public FontEditor() {
setLayout(null);
toolkit = Toolkit.getDefaultToolkit();
fonts = toolkit.getFontList();
familyChoser = new Choice();
for (int i = 0; i < fonts.length; i++) {
familyChoser.addItem(fonts[i]);
}
add(familyChoser);
familyChoser.reshape(20, 5, 100, 30);
styleChoser = new Choice();
for (int i = 0; i < styleNames.length; i++) {
styleChoser.addItem(styleNames[i]);
}
add(styleChoser);
styleChoser.reshape(145, 5, 70, 30);
sizeChoser = new Choice();
for (int i = 0; i < pointSizes.length; i++) {
sizeChoser.addItem("" + pointSizes[i]);
}
add(sizeChoser);
sizeChoser.reshape(220, 5, 70, 30);
resize(300,40);
}
public Dimension preferredSize() {
return new Dimension(300, 40);
}
public void setValue(Object o) {
font = (Font) o;
if (this.font == null)
return;
changeFont(font);
// Update the current GUI choices.
for (int i = 0; i < fonts.length; i++) {
if (fonts[i].equals(font.getFamily())) {
familyChoser.select(i);
break;
}
}
for (int i = 0; i < styleNames.length; i++) {
if (font.getStyle() == styles[i]) {
styleChoser.select(i);
break;
}
}
for (int i = 0; i < pointSizes.length; i++) {
if (font.getSize() <= pointSizes[i]) {
sizeChoser.select(i);
break;
}
}
}
private void changeFont(Font f) {
font = f;
if (sample != null) {
remove(sample);
}
sample = new Label(sampleText);
sample.setFont(font);
add(sample);
Component p = getParent();
if (p != null) {
p.invalidate();
p.layout();
}
invalidate();
layout();
repaint();
support.firePropertyChange("", null, null);
}
public Object getValue() {
return (font);
}
public String getJavaInitializationString() {
if (this.font == null)
return "null";
return "new java.awt.Font(\"" + font.getName() + "\", " +
font.getStyle() + ", " + font.getSize() + ")";
}
public boolean action(Event e, Object arg) {
String family = familyChoser.getSelectedItem();
int style = styles[styleChoser.getSelectedIndex()];
int size = pointSizes[sizeChoser.getSelectedIndex()];
try {
Font f = new Font(family, style, size);
changeFont(f);
} catch (Exception ex) {
System.err.println("Couldn't create font " + family + "-" +
styleNames[style] + "-" + size);
}
return (false);
}
public boolean isPaintable() {
return true;
}
public void paintValue(java.awt.Graphics gfx, java.awt.Rectangle box) {
// Silent noop.
Font oldFont = gfx.getFont();
gfx.setFont(font);
FontMetrics fm = gfx.getFontMetrics();
int vpad = (box.height - fm.getAscent())/2;
gfx.drawString(sampleText, 0, box.height-vpad);
gfx.setFont(oldFont);
}
public String getAsText() {
if (this.font == null) {
return null;
}
StringBuilder sb = new StringBuilder();
sb.append(this.font.getName());
sb.append(' ');
boolean b = this.font.isBold();
if (b) {
sb.append("BOLD");
}
boolean i = this.font.isItalic();
if (i) {
sb.append("ITALIC");
}
if (b || i) {
sb.append(' ');
}
sb.append(this.font.getSize());
return sb.toString();
}
public void setAsText(String text) throws IllegalArgumentException {
setValue((text == null) ? null : Font.decode(text));
}
public String[] getTags() {
return null;
}
public java.awt.Component getCustomEditor() {
return this;
}
public boolean supportsCustomEditor() {
return true;
}
public void addPropertyChangeListener(PropertyChangeListener l) {
support.addPropertyChangeListener(l);
}
public void removePropertyChangeListener(PropertyChangeListener l) {
support.removePropertyChangeListener(l);
}
private Font font;
private Toolkit toolkit;
private String sampleText = "Abcde...";
private Label sample;
private Choice familyChoser;
private Choice styleChoser;
private Choice sizeChoser;
private String fonts[];
private String[] styleNames = { "plain", "bold", "italic" };
private int[] styles = { Font.PLAIN, Font.BOLD, Font.ITALIC };
private int[] pointSizes = { 3, 5, 8, 10, 12, 14, 18, 24, 36, 48 };
private PropertyChangeSupport support = new PropertyChangeSupport(this);
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright (c) 2006, 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.beans.editors;
/**
* Property editor for a java builtin "int" type.
*
*/
import java.beans.*;
public class IntegerEditor extends NumberEditor {
public void setAsText(String text) throws IllegalArgumentException {
setValue((text == null) ? null : Integer.decode(text));
}
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright (c) 1996, 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.beans.editors;
/**
* Property editor for a java builtin "long" type.
*
*/
import java.beans.*;
public class LongEditor extends NumberEditor {
public String getJavaInitializationString() {
Object value = getValue();
return (value != null)
? value + "L"
: "null";
}
public void setAsText(String text) throws IllegalArgumentException {
setValue((text == null) ? null : Long.decode(text));
}
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 1996, 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.beans.editors;
/**
* Abstract Property editor for a java builtin number types.
*
*/
import java.beans.*;
abstract public class NumberEditor extends PropertyEditorSupport {
public String getJavaInitializationString() {
Object value = getValue();
return (value != null)
? value.toString()
: "null";
}
}

View File

@@ -0,0 +1,49 @@
/*
* Copyright (c) 1996, 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.beans.editors;
/**
* Property editor for a java builtin "short" type.
*
*/
import java.beans.*;
public class ShortEditor extends NumberEditor {
public String getJavaInitializationString() {
Object value = getValue();
return (value != null)
? "((short)" + value + ")"
: "null";
}
public void setAsText(String text) throws IllegalArgumentException {
setValue((text == null) ? null : Short.decode(text));
}
}

View File

@@ -0,0 +1,74 @@
/*
* Copyright (c) 1996, 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.beans.editors;
import java.beans.*;
public class StringEditor extends PropertyEditorSupport {
public String getJavaInitializationString() {
Object value = getValue();
if (value == null)
return "null";
String str = value.toString();
int length = str.length();
StringBuilder sb = new StringBuilder(length + 2);
sb.append('"');
for (int i = 0; i < length; i++) {
char ch = str.charAt(i);
switch (ch) {
case '\b': sb.append("\\b"); break;
case '\t': sb.append("\\t"); break;
case '\n': sb.append("\\n"); break;
case '\f': sb.append("\\f"); break;
case '\r': sb.append("\\r"); break;
case '\"': sb.append("\\\""); break;
case '\\': sb.append("\\\\"); break;
default:
if ((ch < ' ') || (ch > '~')) {
sb.append("\\u");
String hex = Integer.toHexString((int) ch);
for (int len = hex.length(); len < 4; len++) {
sb.append('0');
}
sb.append(hex);
} else {
sb.append(ch);
}
break;
}
}
sb.append('"');
return sb.toString();
}
public void setAsText(String text) {
setValue(text);
}
}

View File

@@ -0,0 +1,207 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.finder;
import java.lang.reflect.Executable;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;
/**
* This abstract class provides functionality
* to find a public method or constructor
* with specified parameter types.
* It supports a variable number of parameters.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
abstract class AbstractFinder<T extends Executable> {
private final Class<?>[] args;
/**
* Creates finder for array of classes of arguments.
* If a particular element of array equals {@code null},
* than the appropriate pair of classes
* does not take into consideration.
*
* @param args array of classes of arguments
*/
protected AbstractFinder(Class<?>[] args) {
this.args = args;
}
/**
* Checks validness of the method.
* At least the valid method should be public.
*
* @param method the object that represents method
* @return {@code true} if the method is valid,
* {@code false} otherwise
*/
protected boolean isValid(T method) {
return Modifier.isPublic(method.getModifiers());
}
/**
* Performs a search in the {@code methods} array.
* The one method is selected from the array of the valid methods.
* The list of parameters of the selected method shows
* the best correlation with the list of arguments
* specified at class initialization.
* If more than one method is both accessible and applicable
* to a method invocation, it is necessary to choose one
* to provide the descriptor for the run-time method dispatch.
* The most specific method should be chosen.
*
* @param methods the array of methods to search within
* @return the object that represents found method
* @throws NoSuchMethodException if no method was found or several
* methods meet the search criteria
* @see #isAssignable
*/
final T find(T[] methods) throws NoSuchMethodException {
Map<T, Class<?>[]> map = new HashMap<T, Class<?>[]>();
T oldMethod = null;
Class<?>[] oldParams = null;
boolean ambiguous = false;
for (T newMethod : methods) {
if (isValid(newMethod)) {
Class<?>[] newParams = newMethod.getParameterTypes();
if (newParams.length == this.args.length) {
PrimitiveWrapperMap.replacePrimitivesWithWrappers(newParams);
if (isAssignable(newParams, this.args)) {
if (oldMethod == null) {
oldMethod = newMethod;
oldParams = newParams;
} else {
boolean useNew = isAssignable(oldParams, newParams);
boolean useOld = isAssignable(newParams, oldParams);
if (useOld && useNew) {
// only if parameters are equal
useNew = !newMethod.isSynthetic();
useOld = !oldMethod.isSynthetic();
}
if (useOld == useNew) {
ambiguous = true;
} else if (useNew) {
oldMethod = newMethod;
oldParams = newParams;
ambiguous = false;
}
}
}
}
if (newMethod.isVarArgs()) {
int length = newParams.length - 1;
if (length <= this.args.length) {
Class<?>[] array = new Class<?>[this.args.length];
System.arraycopy(newParams, 0, array, 0, length);
if (length < this.args.length) {
Class<?> type = newParams[length].getComponentType();
if (type.isPrimitive()) {
type = PrimitiveWrapperMap.getType(type.getName());
}
for (int i = length; i < this.args.length; i++) {
array[i] = type;
}
}
map.put(newMethod, array);
}
}
}
}
for (T newMethod : methods) {
Class<?>[] newParams = map.get(newMethod);
if (newParams != null) {
if (isAssignable(newParams, this.args)) {
if (oldMethod == null) {
oldMethod = newMethod;
oldParams = newParams;
} else {
boolean useNew = isAssignable(oldParams, newParams);
boolean useOld = isAssignable(newParams, oldParams);
if (useOld && useNew) {
// only if parameters are equal
useNew = !newMethod.isSynthetic();
useOld = !oldMethod.isSynthetic();
}
if (useOld == useNew) {
if (oldParams == map.get(oldMethod)) {
ambiguous = true;
}
} else if (useNew) {
oldMethod = newMethod;
oldParams = newParams;
ambiguous = false;
}
}
}
}
}
if (ambiguous) {
throw new NoSuchMethodException("Ambiguous methods are found");
}
if (oldMethod == null) {
throw new NoSuchMethodException("Method is not found");
}
return oldMethod;
}
/**
* Determines if every class in {@code min} array is either the same as,
* or is a superclass of, the corresponding class in {@code max} array.
* The length of every array must equal the number of arguments.
* This comparison is performed in the {@link #find} method
* before the first call of the isAssignable method.
* If an argument equals {@code null}
* the appropriate pair of classes does not take into consideration.
*
* @param min the array of classes to be checked
* @param max the array of classes that is used to check
* @return {@code true} if all classes in {@code min} array
* are assignable from corresponding classes in {@code max} array,
* {@code false} otherwise
*
* @see Class#isAssignableFrom
*/
private boolean isAssignable(Class<?>[] min, Class<?>[] max) {
for (int i = 0; i < this.args.length; i++) {
if (null != this.args[i]) {
if (!min[i].isAssignableFrom(max[i])) {
return false;
}
}
}
return true;
}
}

View File

@@ -0,0 +1,102 @@
/*
* Copyright (c) 2009, 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.beans.finder;
import java.beans.BeanDescriptor;
import java.beans.BeanInfo;
import java.beans.MethodDescriptor;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
/**
* This is utility class that provides functionality
* to find a {@link BeanInfo} for a JavaBean specified by its type.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
public final class BeanInfoFinder
extends InstanceFinder<BeanInfo> {
private static final String DEFAULT = "sun.beans.infos";
private static final String DEFAULT_NEW = "com.sun.beans.infos";
public BeanInfoFinder() {
super(BeanInfo.class, true, "BeanInfo", DEFAULT);
}
private static boolean isValid(Class<?> type, Method method) {
return (method != null) && method.getDeclaringClass().isAssignableFrom(type);
}
@Override
protected BeanInfo instantiate(Class<?> type, String prefix, String name) {
if (DEFAULT.equals(prefix)) {
prefix = DEFAULT_NEW;
}
// this optimization will only use the BeanInfo search path
// if is has changed from the original
// or trying to get the ComponentBeanInfo
BeanInfo info = !DEFAULT_NEW.equals(prefix) || "ComponentBeanInfo".equals(name)
? super.instantiate(type, prefix, name)
: null;
if (info != null) {
// make sure that the returned BeanInfo matches the class
BeanDescriptor bd = info.getBeanDescriptor();
if (bd != null) {
if (type.equals(bd.getBeanClass())) {
return info;
}
}
else {
PropertyDescriptor[] pds = info.getPropertyDescriptors();
if (pds != null) {
for (PropertyDescriptor pd : pds) {
Method method = pd.getReadMethod();
if (method == null) {
method = pd.getWriteMethod();
}
if (isValid(type, method)) {
return info;
}
}
}
else {
MethodDescriptor[] mds = info.getMethodDescriptors();
if (mds != null) {
for (MethodDescriptor md : mds) {
if (isValid(type, md.getMethod())) {
return info;
}
}
}
}
}
}
return null;
}
}

View File

@@ -0,0 +1,180 @@
/*
* Copyright (c) 2006, 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.beans.finder;
import static sun.reflect.misc.ReflectUtil.checkPackageAccess;
/**
* This is utility class that provides {@code static} methods
* to find a class with the specified name using the specified class loader.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
public final class ClassFinder {
/**
* Returns the {@code Class} object associated
* with the class or interface with the given string name,
* using the default class loader.
* <p>
* The {@code name} can denote an array class
* (see {@link Class#getName} for details).
*
* @param name fully qualified name of the desired class
* @return class object representing the desired class
*
* @throws ClassNotFoundException if the class cannot be located
* by the specified class loader
*
* @see Class#forName(String)
* @see Class#forName(String,boolean,ClassLoader)
* @see ClassLoader#getSystemClassLoader()
* @see Thread#getContextClassLoader()
*/
public static Class<?> findClass(String name) throws ClassNotFoundException {
checkPackageAccess(name);
try {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader == null) {
// can be null in IE (see 6204697)
loader = ClassLoader.getSystemClassLoader();
}
if (loader != null) {
return Class.forName(name, false, loader);
}
} catch (ClassNotFoundException exception) {
// use current class loader instead
} catch (SecurityException exception) {
// use current class loader instead
}
return Class.forName(name);
}
/**
* Returns the {@code Class} object associated with
* the class or interface with the given string name,
* using the given class loader.
* <p>
* The {@code name} can denote an array class
* (see {@link Class#getName} for details).
* <p>
* If the parameter {@code loader} is null,
* the class is loaded through the default class loader.
*
* @param name fully qualified name of the desired class
* @param loader class loader from which the class must be loaded
* @return class object representing the desired class
*
* @throws ClassNotFoundException if the class cannot be located
* by the specified class loader
*
* @see #findClass(String,ClassLoader)
* @see Class#forName(String,boolean,ClassLoader)
*/
public static Class<?> findClass(String name, ClassLoader loader) throws ClassNotFoundException {
checkPackageAccess(name);
if (loader != null) {
try {
return Class.forName(name, false, loader);
} catch (ClassNotFoundException exception) {
// use default class loader instead
} catch (SecurityException exception) {
// use default class loader instead
}
}
return findClass(name);
}
/**
* Returns the {@code Class} object associated
* with the class or interface with the given string name,
* using the default class loader.
* <p>
* The {@code name} can denote an array class
* (see {@link Class#getName} for details).
* <p>
* This method can be used to obtain
* any of the {@code Class} objects
* representing {@code void} or primitive Java types:
* {@code char}, {@code byte}, {@code short},
* {@code int}, {@code long}, {@code float},
* {@code double} and {@code boolean}.
*
* @param name fully qualified name of the desired class
* @return class object representing the desired class
*
* @throws ClassNotFoundException if the class cannot be located
* by the specified class loader
*
* @see #resolveClass(String,ClassLoader)
*/
public static Class<?> resolveClass(String name) throws ClassNotFoundException {
return resolveClass(name, null);
}
/**
* Returns the {@code Class} object associated with
* the class or interface with the given string name,
* using the given class loader.
* <p>
* The {@code name} can denote an array class
* (see {@link Class#getName} for details).
* <p>
* If the parameter {@code loader} is null,
* the class is loaded through the default class loader.
* <p>
* This method can be used to obtain
* any of the {@code Class} objects
* representing {@code void} or primitive Java types:
* {@code char}, {@code byte}, {@code short},
* {@code int}, {@code long}, {@code float},
* {@code double} and {@code boolean}.
*
* @param name fully qualified name of the desired class
* @param loader class loader from which the class must be loaded
* @return class object representing the desired class
*
* @throws ClassNotFoundException if the class cannot be located
* by the specified class loader
*
* @see #findClass(String,ClassLoader)
* @see PrimitiveTypeMap#getType(String)
*/
public static Class<?> resolveClass(String name, ClassLoader loader) throws ClassNotFoundException {
Class<?> type = PrimitiveTypeMap.getType(name);
return (type == null)
? findClass(name, loader)
: type;
}
/**
* Disable instantiation.
*/
private ClassFinder() {
}
}

View File

@@ -0,0 +1,100 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.finder;
import com.sun.beans.util.Cache;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import static com.sun.beans.util.Cache.Kind.SOFT;
import static sun.reflect.misc.ReflectUtil.isPackageAccessible;
/**
* This utility class provides {@code static} methods
* to find a public constructor with specified parameter types
* in specified class.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
public final class ConstructorFinder extends AbstractFinder<Constructor<?>> {
private static final Cache<Signature, Constructor<?>> CACHE = new Cache<Signature, Constructor<?>>(SOFT, SOFT) {
@Override
public Constructor create(Signature signature) {
try {
ConstructorFinder finder = new ConstructorFinder(signature.getArgs());
return finder.find(signature.getType().getConstructors());
}
catch (Exception exception) {
throw new SignatureException(exception);
}
}
};
/**
* Finds public constructor
* that is declared in public class.
*
* @param type the class that can have constructor
* @param args parameter types that is used to find constructor
* @return object that represents found constructor
* @throws NoSuchMethodException if constructor could not be found
* or some constructors are found
*/
public static Constructor<?> findConstructor(Class<?> type, Class<?>...args) throws NoSuchMethodException {
if (type.isPrimitive()) {
throw new NoSuchMethodException("Primitive wrapper does not contain constructors");
}
if (type.isInterface()) {
throw new NoSuchMethodException("Interface does not contain constructors");
}
if (Modifier.isAbstract(type.getModifiers())) {
throw new NoSuchMethodException("Abstract class cannot be instantiated");
}
if (!Modifier.isPublic(type.getModifiers()) || !isPackageAccessible(type)) {
throw new NoSuchMethodException("Class is not accessible");
}
PrimitiveWrapperMap.replacePrimitivesWithWrappers(args);
Signature signature = new Signature(type, args);
try {
return CACHE.get(signature);
}
catch (SignatureException exception) {
throw exception.toNoSuchMethodException("Constructor is not found");
}
}
/**
* Creates constructor finder with specified array of parameter types.
*
* @param args the array of parameter types
*/
private ConstructorFinder(Class<?>[] args) {
super(args);
}
}

View File

@@ -0,0 +1,109 @@
/*
* Copyright (c) 2008, 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.beans.finder;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import static sun.reflect.misc.ReflectUtil.isPackageAccessible;
/**
* This utility class provides {@code static} methods
* to find a public field with specified name
* in specified class.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
public final class FieldFinder {
/**
* Finds public field (static or non-static)
* that is declared in public class.
*
* @param type the class that can have field
* @param name the name of field to find
* @return object that represents found field
* @throws NoSuchFieldException if field is not found
* @see Class#getField
*/
public static Field findField(Class<?> type, String name) throws NoSuchFieldException {
if (name == null) {
throw new IllegalArgumentException("Field name is not set");
}
Field field = type.getField(name);
if (!Modifier.isPublic(field.getModifiers())) {
throw new NoSuchFieldException("Field '" + name + "' is not public");
}
type = field.getDeclaringClass();
if (!Modifier.isPublic(type.getModifiers()) || !isPackageAccessible(type)) {
throw new NoSuchFieldException("Field '" + name + "' is not accessible");
}
return field;
}
/**
* Finds public non-static field
* that is declared in public class.
*
* @param type the class that can have field
* @param name the name of field to find
* @return object that represents found field
* @throws NoSuchFieldException if field is not found
* @see Class#getField
*/
public static Field findInstanceField(Class<?> type, String name) throws NoSuchFieldException {
Field field = findField(type, name);
if (Modifier.isStatic(field.getModifiers())) {
throw new NoSuchFieldException("Field '" + name + "' is static");
}
return field;
}
/**
* Finds public static field
* that is declared in public class.
*
* @param type the class that can have field
* @param name the name of field to find
* @return object that represents found field
* @throws NoSuchFieldException if field is not found
* @see Class#getField
*/
public static Field findStaticField(Class<?> type, String name) throws NoSuchFieldException {
Field field = findField(type, name);
if (!Modifier.isStatic(field.getModifiers())) {
throw new NoSuchFieldException("Field '" + name + "' is not static");
}
return field;
}
/**
* Disable instantiation.
*/
private FieldFinder() {
}
}

View File

@@ -0,0 +1,109 @@
/*
* Copyright (c) 2009, 2010, 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.beans.finder;
/**
* This is utility class that provides basic functionality
* to find an auxiliary class for a JavaBean specified by its type.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
class InstanceFinder<T> {
private static final String[] EMPTY = { };
private final Class<? extends T> type;
private final boolean allow;
private final String suffix;
private volatile String[] packages;
InstanceFinder(Class<? extends T> type, boolean allow, String suffix, String... packages) {
this.type = type;
this.allow = allow;
this.suffix = suffix;
this.packages = packages.clone();
}
public String[] getPackages() {
return this.packages.clone();
}
public void setPackages(String... packages) {
this.packages = (packages != null) && (packages.length > 0)
? packages.clone()
: EMPTY;
}
public T find(Class<?> type) {
if (type == null) {
return null;
}
String name = type.getName() + this.suffix;
T object = instantiate(type, name);
if (object != null) {
return object;
}
if (this.allow) {
object = instantiate(type, null);
if (object != null) {
return object;
}
}
int index = name.lastIndexOf('.') + 1;
if (index > 0) {
name = name.substring(index);
}
for (String prefix : this.packages) {
object = instantiate(type, prefix, name);
if (object != null) {
return object;
}
}
return null;
}
protected T instantiate(Class<?> type, String name) {
if (type != null) {
try {
if (name != null) {
type = ClassFinder.findClass(name, type.getClassLoader());
}
if (this.type.isAssignableFrom(type)) {
return (T) type.newInstance();
}
}
catch (Exception exception) {
// ignore any exceptions
}
}
return null;
}
protected T instantiate(Class<?> type, String prefix, String name) {
return instantiate(type, prefix + '.' + name);
}
}

View File

@@ -0,0 +1,220 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.finder;
import com.sun.beans.TypeResolver;
import com.sun.beans.util.Cache;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Arrays;
import static com.sun.beans.util.Cache.Kind.SOFT;
import static sun.reflect.misc.ReflectUtil.isPackageAccessible;
/**
* This utility class provides {@code static} methods
* to find a public method with specified name and parameter types
* in specified class.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
public final class MethodFinder extends AbstractFinder<Method> {
private static final Cache<Signature, Method> CACHE = new Cache<Signature, Method>(SOFT, SOFT) {
@Override
public Method create(Signature signature) {
try {
MethodFinder finder = new MethodFinder(signature.getName(), signature.getArgs());
return findAccessibleMethod(finder.find(signature.getType().getMethods()));
}
catch (Exception exception) {
throw new SignatureException(exception);
}
}
};
/**
* Finds public method (static or non-static)
* that is accessible from public class.
*
* @param type the class that can have method
* @param name the name of method to find
* @param args parameter types that is used to find method
* @return object that represents found method
* @throws NoSuchMethodException if method could not be found
* or some methods are found
*/
public static Method findMethod(Class<?> type, String name, Class<?>...args) throws NoSuchMethodException {
if (name == null) {
throw new IllegalArgumentException("Method name is not set");
}
PrimitiveWrapperMap.replacePrimitivesWithWrappers(args);
Signature signature = new Signature(type, name, args);
try {
Method method = CACHE.get(signature);
return (method == null) || isPackageAccessible(method.getDeclaringClass()) ? method : CACHE.create(signature);
}
catch (SignatureException exception) {
throw exception.toNoSuchMethodException("Method '" + name + "' is not found");
}
}
/**
* Finds public non-static method
* that is accessible from public class.
*
* @param type the class that can have method
* @param name the name of method to find
* @param args parameter types that is used to find method
* @return object that represents found method
* @throws NoSuchMethodException if method could not be found
* or some methods are found
*/
public static Method findInstanceMethod(Class<?> type, String name, Class<?>... args) throws NoSuchMethodException {
Method method = findMethod(type, name, args);
if (Modifier.isStatic(method.getModifiers())) {
throw new NoSuchMethodException("Method '" + name + "' is static");
}
return method;
}
/**
* Finds public static method
* that is accessible from public class.
*
* @param type the class that can have method
* @param name the name of method to find
* @param args parameter types that is used to find method
* @return object that represents found method
* @throws NoSuchMethodException if method could not be found
* or some methods are found
*/
public static Method findStaticMethod(Class<?> type, String name, Class<?>...args) throws NoSuchMethodException {
Method method = findMethod(type, name, args);
if (!Modifier.isStatic(method.getModifiers())) {
throw new NoSuchMethodException("Method '" + name + "' is not static");
}
return method;
}
/**
* Finds method that is accessible from public class or interface through class hierarchy.
*
* @param method object that represents found method
* @return object that represents accessible method
* @throws NoSuchMethodException if method is not accessible or is not found
* in specified superclass or interface
*/
public static Method findAccessibleMethod(Method method) throws NoSuchMethodException {
Class<?> type = method.getDeclaringClass();
if (Modifier.isPublic(type.getModifiers()) && isPackageAccessible(type)) {
return method;
}
if (Modifier.isStatic(method.getModifiers())) {
throw new NoSuchMethodException("Method '" + method.getName() + "' is not accessible");
}
for (Type generic : type.getGenericInterfaces()) {
try {
return findAccessibleMethod(method, generic);
}
catch (NoSuchMethodException exception) {
// try to find in superclass or another interface
}
}
return findAccessibleMethod(method, type.getGenericSuperclass());
}
/**
* Finds method that accessible from specified class.
*
* @param method object that represents found method
* @param generic generic type that is used to find accessible method
* @return object that represents accessible method
* @throws NoSuchMethodException if method is not accessible or is not found
* in specified superclass or interface
*/
private static Method findAccessibleMethod(Method method, Type generic) throws NoSuchMethodException {
String name = method.getName();
Class<?>[] params = method.getParameterTypes();
if (generic instanceof Class) {
Class<?> type = (Class<?>) generic;
return findAccessibleMethod(type.getMethod(name, params));
}
if (generic instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) generic;
Class<?> type = (Class<?>) pt.getRawType();
for (Method m : type.getMethods()) {
if (m.getName().equals(name)) {
Class<?>[] pts = m.getParameterTypes();
if (pts.length == params.length) {
if (Arrays.equals(params, pts)) {
return findAccessibleMethod(m);
}
Type[] gpts = m.getGenericParameterTypes();
if (params.length == gpts.length) {
if (Arrays.equals(params, TypeResolver.erase(TypeResolver.resolve(pt, gpts)))) {
return findAccessibleMethod(m);
}
}
}
}
}
}
throw new NoSuchMethodException("Method '" + name + "' is not accessible");
}
private final String name;
/**
* Creates method finder with specified array of parameter types.
*
* @param name the name of method to find
* @param args the array of parameter types
*/
private MethodFinder(String name, Class<?>[] args) {
super(args);
this.name = name;
}
/**
* Checks validness of the method.
* The valid method should be public and
* should have the specified name.
*
* @param method the object that represents method
* @return {@code true} if the method is valid,
* {@code false} otherwise
*/
@Override
protected boolean isValid(Method method) {
return super.isValid(method) && method.getName().equals(this.name);
}
}

View File

@@ -0,0 +1,68 @@
/*
* Copyright (c) 2009, 2010, 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.beans.finder;
import java.beans.PersistenceDelegate;
import java.util.HashMap;
import java.util.Map;
/**
* This is utility class that provides functionality
* to find a {@link PersistenceDelegate} for a JavaBean specified by its type.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
public final class PersistenceDelegateFinder
extends InstanceFinder<PersistenceDelegate> {
private final Map<Class<?>, PersistenceDelegate> registry;
public PersistenceDelegateFinder() {
super(PersistenceDelegate.class, true, "PersistenceDelegate");
this.registry = new HashMap<Class<?>, PersistenceDelegate>();
}
public void register(Class<?> type, PersistenceDelegate delegate) {
synchronized (this.registry) {
if (delegate != null) {
this.registry.put(type, delegate);
}
else {
this.registry.remove(type);
}
}
}
@Override
public PersistenceDelegate find(Class<?> type) {
PersistenceDelegate delegate;
synchronized (this.registry) {
delegate = this.registry.get(type);
}
return (delegate != null) ? delegate : super.find(type);
}
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2006, 2008, 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.beans.finder;
import java.util.HashMap;
import java.util.Map;
/**
* This utility class associates
* name of primitive type with appropriate class.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class PrimitiveTypeMap {
/**
* Returns primitive type class by its name.
*
* @param name the name of primitive type
* @return found primitive type class,
* or {@code null} if not found
*/
static Class<?> getType(String name) {
return map.get(name);
}
private static final Map<String, Class<?>> map = new HashMap<String, Class<?>>(9);
static {
map.put(boolean.class.getName(), boolean.class);
map.put(char.class.getName(), char.class);
map.put(byte.class.getName(), byte.class);
map.put(short.class.getName(), short.class);
map.put(int.class.getName(), int.class);
map.put(long.class.getName(), long.class);
map.put(float.class.getName(), float.class);
map.put(double.class.getName(), double.class);
map.put(void.class.getName(), void.class);
}
/**
* Disable instantiation.
*/
private PrimitiveTypeMap() {
}
}

View File

@@ -0,0 +1,86 @@
/*
* Copyright (c) 2008, 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.beans.finder;
import java.util.HashMap;
import java.util.Map;
/**
* This utility class associates
* name of primitive type with appropriate wrapper.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
public final class PrimitiveWrapperMap {
/**
* Replaces all primitive types in specified array with wrappers.
*
* @param types array of classes where all primitive types
* will be replaced by appropriate wrappers
*/
static void replacePrimitivesWithWrappers(Class<?>[] types) {
for (int i = 0; i < types.length; i++) {
if (types[i] != null) {
if (types[i].isPrimitive()) {
types[i] = getType(types[i].getName());
}
}
}
}
/**
* Returns wrapper for primitive type by its name.
*
* @param name the name of primitive type
* @return found wrapper for primitive type,
* or {@code null} if not found
*/
public static Class<?> getType(String name) {
return map.get(name);
}
private static final Map<String, Class<?>> map = new HashMap<String, Class<?>>(9);
static {
map.put(Boolean.TYPE.getName(), Boolean.class);
map.put(Character.TYPE.getName(), Character.class);
map.put(Byte.TYPE.getName(), Byte.class);
map.put(Short.TYPE.getName(), Short.class);
map.put(Integer.TYPE.getName(), Integer.class);
map.put(Long.TYPE.getName(), Long.class);
map.put(Float.TYPE.getName(), Float.class);
map.put(Double.TYPE.getName(), Double.class);
map.put(Void.TYPE.getName(), Void.class);
}
/**
* Disable instantiation.
*/
private PrimitiveWrapperMap() {
}
}

View File

@@ -0,0 +1,95 @@
/*
* Copyright (c) 2009, 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.beans.finder;
import com.sun.beans.WeakCache;
import java.beans.PropertyEditor;
import com.sun.beans.editors.BooleanEditor;
import com.sun.beans.editors.ByteEditor;
import com.sun.beans.editors.DoubleEditor;
import com.sun.beans.editors.EnumEditor;
import com.sun.beans.editors.FloatEditor;
import com.sun.beans.editors.IntegerEditor;
import com.sun.beans.editors.LongEditor;
import com.sun.beans.editors.ShortEditor;
/**
* This is utility class that provides functionality
* to find a {@link PropertyEditor} for a JavaBean specified by its type.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
public final class PropertyEditorFinder
extends InstanceFinder<PropertyEditor> {
private static final String DEFAULT = "sun.beans.editors";
private static final String DEFAULT_NEW = "com.sun.beans.editors";
private final WeakCache<Class<?>, Class<?>> registry;
public PropertyEditorFinder() {
super(PropertyEditor.class, false, "Editor", DEFAULT);
this.registry = new WeakCache<Class<?>, Class<?>>();
this.registry.put(Byte.TYPE, ByteEditor.class);
this.registry.put(Short.TYPE, ShortEditor.class);
this.registry.put(Integer.TYPE, IntegerEditor.class);
this.registry.put(Long.TYPE, LongEditor.class);
this.registry.put(Boolean.TYPE, BooleanEditor.class);
this.registry.put(Float.TYPE, FloatEditor.class);
this.registry.put(Double.TYPE, DoubleEditor.class);
}
public void register(Class<?> type, Class<?> editor) {
synchronized (this.registry) {
this.registry.put(type, editor);
}
}
@Override
public PropertyEditor find(Class<?> type) {
Class<?> predefined;
synchronized (this.registry) {
predefined = this.registry.get(type);
}
PropertyEditor editor = instantiate(predefined, null);
if (editor == null) {
editor = super.find(type);
if ((editor == null) && (null != type.getEnumConstants())) {
editor = new EnumEditor(type);
}
}
return editor;
}
@Override
protected PropertyEditor instantiate(Class<?> type, String prefix, String name) {
return super.instantiate(type, DEFAULT.equals(prefix) ? DEFAULT_NEW : prefix, name);
}
}

View File

@@ -0,0 +1,181 @@
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.finder;
/**
* This class is designed to be a key of a cache
* of constructors or methods.
*
* @since 1.7
*
* @author Sergey A. Malenkov
*/
final class Signature {
private final Class<?> type;
private final String name;
private final Class<?>[] args;
private volatile int code;
/**
* Constructs signature for constructor.
*
* @param type the class that contains constructor
* @param args the types of constructor's parameters
*/
Signature(Class<?> type, Class<?>[] args) {
this(type, null, args);
}
/**
* Constructs signature for method.
*
* @param type the class that contains method
* @param name the name of the method
* @param args the types of method's parameters
*/
Signature(Class<?> type, String name, Class<?>[] args) {
this.type = type;
this.name = name;
this.args = args;
}
Class<?> getType() {
return this.type;
}
String getName() {
return this.name;
}
Class<?>[] getArgs() {
return this.args;
}
/**
* Indicates whether some other object is "equal to" this one.
*
* @param object the reference object with which to compare
* @return {@code true} if this object is the same as the
* {@code object} argument, {@code false} otherwise
* @see #hashCode()
*/
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object instanceof Signature) {
Signature signature = (Signature) object;
return isEqual(signature.type, this.type)
&& isEqual(signature.name, this.name)
&& isEqual(signature.args, this.args);
}
return false;
}
/**
* Indicates whether some object is "equal to" another one.
* This method supports {@code null} values.
*
* @param obj1 the first reference object that will compared
* @param obj2 the second reference object that will compared
* @return {@code true} if first object is the same as the second object,
* {@code false} otherwise
*/
private static boolean isEqual(Object obj1, Object obj2) {
return (obj1 == null)
? obj2 == null
: obj1.equals(obj2);
}
/**
* Indicates whether some array is "equal to" another one.
* This method supports {@code null} values.
*
* @param args1 the first reference array that will compared
* @param args2 the second reference array that will compared
* @return {@code true} if first array is the same as the second array,
* {@code false} otherwise
*/
private static boolean isEqual(Class<?>[] args1, Class<?>[] args2) {
if ((args1 == null) || (args2 == null)) {
return args1 == args2;
}
if (args1.length != args2.length) {
return false;
}
for (int i = 0; i < args1.length; i++) {
if (!isEqual(args1[i], args2[i])) {
return false;
}
}
return true;
}
/**
* Returns a hash code value for the object.
* This method is supported for the benefit of hashtables
* such as {@link java.util.HashMap} or {@link java.util.HashSet}.
* Hash code computed using algorithm
* suggested in Effective Java, Item 8.
*
* @return a hash code value for this object
* @see #equals(Object)
*/
@Override
public int hashCode() {
if (this.code == 0) {
int code = 17;
code = addHashCode(code, this.type);
code = addHashCode(code, this.name);
if (this.args != null) {
for (Class<?> arg : this.args) {
code = addHashCode(code, arg);
}
}
this.code = code;
}
return this.code;
}
/**
* Adds hash code value if specified object.
* This is a part of the algorithm
* suggested in Effective Java, Item 8.
*
* @param code current hash code value
* @param object object that updates hash code value
* @return updated hash code value
* @see #hashCode()
*/
private static int addHashCode(int code, Object object) {
code *= 37;
return (object != null)
? code + object.hashCode()
: code;
}
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.finder;
final class SignatureException extends RuntimeException {
SignatureException(Throwable cause) {
super(cause);
}
NoSuchMethodException toNoSuchMethodException(String message) {
Throwable throwable = getCause();
if (throwable instanceof NoSuchMethodException) {
return (NoSuchMethodException) throwable;
}
NoSuchMethodException exception = new NoSuchMethodException(message);
exception.initCause(throwable);
return exception;
}
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 1996, 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.beans.infos;
import java.beans.*;
/**
* BeanInfo descriptor for a standard AWT component.
*/
public class ComponentBeanInfo extends SimpleBeanInfo {
private static final Class<java.awt.Component> beanClass = java.awt.Component.class;
public PropertyDescriptor[] getPropertyDescriptors() {
try {
PropertyDescriptor
name = new PropertyDescriptor("name", beanClass),
background = new PropertyDescriptor("background", beanClass),
foreground = new PropertyDescriptor("foreground", beanClass),
font = new PropertyDescriptor("font", beanClass),
enabled = new PropertyDescriptor("enabled", beanClass),
visible = new PropertyDescriptor("visible", beanClass),
focusable = new PropertyDescriptor("focusable", beanClass);
enabled.setExpert(true);
visible.setHidden(true);
background.setBound(true);
foreground.setBound(true);
font.setBound(true);
focusable.setBound(true);
PropertyDescriptor[] rv = {name, background, foreground, font, enabled, visible, focusable };
return rv;
} catch (IntrospectionException e) {
throw new Error(e.toString());
}
}
}

View File

@@ -0,0 +1,613 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.beans.util;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.Objects;
/**
* Hash table based implementation of the cache,
* which allows to use weak or soft references for keys and values.
* An entry in a {@code Cache} will automatically be removed
* when its key or value is no longer in ordinary use.
*
* @author Sergey Malenkov
* @since 1.8
*/
public abstract class Cache<K,V> {
private static final int MAXIMUM_CAPACITY = 1 << 30; // maximum capacity MUST be a power of two <= 1<<30
private final boolean identity; // defines whether the identity comparison is used
private final Kind keyKind; // a reference kind for the cache keys
private final Kind valueKind; // a reference kind for the cache values
private final ReferenceQueue<Object> queue = new ReferenceQueue<>(); // queue for references to remove
private volatile CacheEntry<K,V>[] table = newTable(1 << 3); // table's length MUST be a power of two
private int threshold = 6; // the next size value at which to resize
private int size; // the number of key-value mappings contained in this map
/**
* Creates a corresponding value for the specified key.
*
* @param key a key that can be used to create a value
* @return a corresponding value for the specified key
*/
public abstract V create(K key);
/**
* Constructs an empty {@code Cache}.
* The default initial capacity is 8.
* The default load factor is 0.75.
*
* @param keyKind a reference kind for keys
* @param valueKind a reference kind for values
*
* @throws NullPointerException if {@code keyKind} or {@code valueKind} are {@code null}
*/
public Cache(Kind keyKind, Kind valueKind) {
this(keyKind, valueKind, false);
}
/**
* Constructs an empty {@code Cache}
* with the specified comparison method.
* The default initial capacity is 8.
* The default load factor is 0.75.
*
* @param keyKind a reference kind for keys
* @param valueKind a reference kind for values
* @param identity defines whether reference-equality
* is used in place of object-equality
*
* @throws NullPointerException if {@code keyKind} or {@code valueKind} are {@code null}
*/
public Cache(Kind keyKind, Kind valueKind, boolean identity) {
Objects.requireNonNull(keyKind, "keyKind");
Objects.requireNonNull(valueKind, "valueKind");
this.keyKind = keyKind;
this.valueKind = valueKind;
this.identity = identity;
}
/**
* Returns the value to which the specified key is mapped,
* or {@code null} if there is no mapping for the key.
*
* @param key the key whose cached value is to be returned
* @return a value to which the specified key is mapped,
* or {@code null} if there is no mapping for {@code key}
*
* @throws NullPointerException if {@code key} is {@code null}
* or corresponding value is {@code null}
*/
public final V get(K key) {
Objects.requireNonNull(key, "key");
removeStaleEntries();
int hash = hash(key);
// unsynchronized search improves performance
// the null value does not mean that there are no needed entry
CacheEntry<K,V>[] table = this.table; // unsynchronized access
V current = getEntryValue(key, hash, table[index(hash, table)]);
if (current != null) {
return current;
}
synchronized (this.queue) {
// synchronized search improves stability
// we must create and add new value if there are no needed entry
current = getEntryValue(key, hash, this.table[index(hash, this.table)]);
if (current != null) {
return current;
}
V value = create(key);
Objects.requireNonNull(value, "value");
int index = index(hash, this.table);
this.table[index] = new CacheEntry<>(hash, key, value, this.table[index]);
if (++this.size >= this.threshold) {
if (this.table.length == MAXIMUM_CAPACITY) {
this.threshold = Integer.MAX_VALUE;
} else {
removeStaleEntries();
table = newTable(this.table.length << 1);
transfer(this.table, table);
// If ignoring null elements and processing ref queue caused massive
// shrinkage, then restore old table. This should be rare, but avoids
// unbounded expansion of garbage-filled tables.
if (this.size >= this.threshold / 2) {
this.table = table;
this.threshold <<= 1;
} else {
transfer(table, this.table);
}
removeStaleEntries();
}
}
return value;
}
}
/**
* Removes the cached value that corresponds to the specified key.
*
* @param key the key whose mapping is to be removed from this cache
*/
public final void remove(K key) {
if (key != null) {
synchronized (this.queue) {
removeStaleEntries();
int hash = hash(key);
int index = index(hash, this.table);
CacheEntry<K,V> prev = this.table[index];
CacheEntry<K,V> entry = prev;
while (entry != null) {
CacheEntry<K,V> next = entry.next;
if (entry.matches(hash, key)) {
if (entry == prev) {
this.table[index] = next;
} else {
prev.next = next;
}
entry.unlink();
break;
}
prev = entry;
entry = next;
}
}
}
}
/**
* Removes all of the mappings from this cache.
* It will be empty after this call returns.
*/
public final void clear() {
synchronized (this.queue) {
int index = this.table.length;
while (0 < index--) {
CacheEntry<K,V> entry = this.table[index];
while (entry != null) {
CacheEntry<K,V> next = entry.next;
entry.unlink();
entry = next;
}
this.table[index] = null;
}
while (null != this.queue.poll()) {
// Clear out the reference queue.
}
}
}
/**
* Retrieves object hash code and applies a supplemental hash function
* to the result hash, which defends against poor quality hash functions.
* This is critical because {@code Cache} uses power-of-two length hash tables,
* that otherwise encounter collisions for hashCodes that do not differ
* in lower bits.
*
* @param key the object which hash code is to be calculated
* @return a hash code value for the specified object
*/
private int hash(Object key) {
if (this.identity) {
int hash = System.identityHashCode(key);
return (hash << 1) - (hash << 8);
}
int hash = key.hashCode();
// This function ensures that hashCodes that differ only by
// constant multiples at each bit position have a bounded
// number of collisions (approximately 8 at default load factor).
hash ^= (hash >>> 20) ^ (hash >>> 12);
return hash ^ (hash >>> 7) ^ (hash >>> 4);
}
/**
* Returns index of the specified hash code in the given table.
* Note that the table size must be a power of two.
*
* @param hash the hash code
* @param table the table
* @return an index of the specified hash code in the given table
*/
private static int index(int hash, Object[] table) {
return hash & (table.length - 1);
}
/**
* Creates a new array for the cache entries.
*
* @param size requested capacity MUST be a power of two
* @return a new array for the cache entries
*/
@SuppressWarnings("unchecked")
private CacheEntry<K,V>[] newTable(int size) {
return (CacheEntry<K,V>[]) new CacheEntry[size];
}
private V getEntryValue(K key, int hash, CacheEntry<K,V> entry) {
while (entry != null) {
if (entry.matches(hash, key)) {
return entry.value.getReferent();
}
entry = entry.next;
}
return null;
}
private void removeStaleEntries() {
Object reference = this.queue.poll();
if (reference != null) {
synchronized (this.queue) {
do {
if (reference instanceof Ref) {
Ref ref = (Ref) reference;
@SuppressWarnings("unchecked")
CacheEntry<K,V> owner = (CacheEntry<K,V>) ref.getOwner();
if (owner != null) {
int index = index(owner.hash, this.table);
CacheEntry<K,V> prev = this.table[index];
CacheEntry<K,V> entry = prev;
while (entry != null) {
CacheEntry<K,V> next = entry.next;
if (entry == owner) {
if (entry == prev) {
this.table[index] = next;
} else {
prev.next = next;
}
entry.unlink();
break;
}
prev = entry;
entry = next;
}
}
}
reference = this.queue.poll();
}
while (reference != null);
}
}
}
private void transfer(CacheEntry<K,V>[] oldTable, CacheEntry<K,V>[] newTable) {
int oldIndex = oldTable.length;
while (0 < oldIndex--) {
CacheEntry<K,V> entry = oldTable[oldIndex];
oldTable[oldIndex] = null;
while (entry != null) {
CacheEntry<K,V> next = entry.next;
if (entry.key.isStale() || entry.value.isStale()) {
entry.unlink();
} else {
int newIndex = index(entry.hash, newTable);
entry.next = newTable[newIndex];
newTable[newIndex] = entry;
}
entry = next;
}
}
}
/**
* Represents a cache entry (key-value pair).
*/
private final class CacheEntry<K,V> {
private final int hash;
private final Ref<K> key;
private final Ref<V> value;
private volatile CacheEntry<K,V> next;
/**
* Constructs an entry for the cache.
*
* @param hash the hash code calculated for the entry key
* @param key the entry key
* @param value the initial value of the entry
* @param next the next entry in a chain
*/
private CacheEntry(int hash, K key, V value, CacheEntry<K,V> next) {
this.hash = hash;
this.key = Cache.this.keyKind.create(this, key, Cache.this.queue);
this.value = Cache.this.valueKind.create(this, value, Cache.this.queue);
this.next = next;
}
/**
* Determines whether the entry has the given key with the given hash code.
*
* @param hash an expected hash code
* @param object an object to be compared with the entry key
* @return {@code true} if the entry has the given key with the given hash code;
* {@code false} otherwise
*/
private boolean matches(int hash, Object object) {
if (this.hash != hash) {
return false;
}
Object key = this.key.getReferent();
return (key == object) || !Cache.this.identity && (key != null) && key.equals(object);
}
/**
* Marks the entry as actually removed from the cache.
*/
private void unlink() {
this.next = null;
this.key.removeOwner();
this.value.removeOwner();
Cache.this.size--;
}
}
/**
* Basic interface for references.
* It defines the operations common for the all kind of references.
*
* @param <T> the type of object to refer
*/
private static interface Ref<T> {
/**
* Returns the object that possesses information about the reference.
*
* @return the owner of the reference or {@code null} if the owner is unknown
*/
Object getOwner();
/**
* Returns the object to refer.
*
* @return the referred object or {@code null} if it was collected
*/
T getReferent();
/**
* Determines whether the referred object was taken by the garbage collector or not.
*
* @return {@code true} if the referred object was collected
*/
boolean isStale();
/**
* Marks this reference as removed from the cache.
*/
void removeOwner();
}
/**
* Represents a reference kind.
*/
public static enum Kind {
STRONG {
<T> Ref<T> create(Object owner, T value, ReferenceQueue<? super T> queue) {
return new Strong<>(owner, value);
}
},
SOFT {
<T> Ref<T> create(Object owner, T referent, ReferenceQueue<? super T> queue) {
return (referent == null)
? new Strong<>(owner, referent)
: new Soft<>(owner, referent, queue);
}
},
WEAK {
<T> Ref<T> create(Object owner, T referent, ReferenceQueue<? super T> queue) {
return (referent == null)
? new Strong<>(owner, referent)
: new Weak<>(owner, referent, queue);
}
};
/**
* Creates a reference to the specified object.
*
* @param <T> the type of object to refer
* @param owner the owner of the reference, if needed
* @param referent the object to refer
* @param queue the queue to register the reference with,
* or {@code null} if registration is not required
* @return the reference to the specified object
*/
abstract <T> Ref<T> create(Object owner, T referent, ReferenceQueue<? super T> queue);
/**
* This is an implementation of the {@link Cache.Ref} interface
* that uses the strong references that prevent their referents
* from being made finalizable, finalized, and then reclaimed.
*
* @param <T> the type of object to refer
*/
private static final class Strong<T> implements Ref<T> {
private Object owner;
private final T referent;
/**
* Creates a strong reference to the specified object.
*
* @param owner the owner of the reference, if needed
* @param referent the non-null object to refer
*/
private Strong(Object owner, T referent) {
this.owner = owner;
this.referent = referent;
}
/**
* Returns the object that possesses information about the reference.
*
* @return the owner of the reference or {@code null} if the owner is unknown
*/
public Object getOwner() {
return this.owner;
}
/**
* Returns the object to refer.
*
* @return the referred object
*/
public T getReferent() {
return this.referent;
}
/**
* Determines whether the referred object was taken by the garbage collector or not.
*
* @return {@code true} if the referred object was collected
*/
public boolean isStale() {
return false;
}
/**
* Marks this reference as removed from the cache.
*/
public void removeOwner() {
this.owner = null;
}
}
/**
* This is an implementation of the {@link Cache.Ref} interface
* that uses the soft references that are cleared at the discretion
* of the garbage collector in response to a memory request.
*
* @param <T> the type of object to refer
* @see java.lang.ref.SoftReference
*/
private static final class Soft<T> extends SoftReference<T> implements Ref<T> {
private Object owner;
/**
* Creates a soft reference to the specified object.
*
* @param owner the owner of the reference, if needed
* @param referent the non-null object to refer
* @param queue the queue to register the reference with,
* or {@code null} if registration is not required
*/
private Soft(Object owner, T referent, ReferenceQueue<? super T> queue) {
super(referent, queue);
this.owner = owner;
}
/**
* Returns the object that possesses information about the reference.
*
* @return the owner of the reference or {@code null} if the owner is unknown
*/
public Object getOwner() {
return this.owner;
}
/**
* Returns the object to refer.
*
* @return the referred object or {@code null} if it was collected
*/
public T getReferent() {
return get();
}
/**
* Determines whether the referred object was taken by the garbage collector or not.
*
* @return {@code true} if the referred object was collected
*/
public boolean isStale() {
return null == get();
}
/**
* Marks this reference as removed from the cache.
*/
public void removeOwner() {
this.owner = null;
}
}
/**
* This is an implementation of the {@link Cache.Ref} interface
* that uses the weak references that do not prevent their referents
* from being made finalizable, finalized, and then reclaimed.
*
* @param <T> the type of object to refer
* @see java.lang.ref.WeakReference
*/
private static final class Weak<T> extends WeakReference<T> implements Ref<T> {
private Object owner;
/**
* Creates a weak reference to the specified object.
*
* @param owner the owner of the reference, if needed
* @param referent the non-null object to refer
* @param queue the queue to register the reference with,
* or {@code null} if registration is not required
*/
private Weak(Object owner, T referent, ReferenceQueue<? super T> queue) {
super(referent, queue);
this.owner = owner;
}
/**
* Returns the object that possesses information about the reference.
*
* @return the owner of the reference or {@code null} if the owner is unknown
*/
public Object getOwner() {
return this.owner;
}
/**
* Returns the object to refer.
*
* @return the referred object or {@code null} if it was collected
*/
public T getReferent() {
return get();
}
/**
* Determines whether the referred object was taken by the garbage collector or not.
*
* @return {@code true} if the referred object was collected
*/
public boolean isStale() {
return null == get();
}
/**
* Marks this reference as removed from the cache.
*/
public void removeOwner() {
this.owner = null;
}
}
}
}

View File

@@ -0,0 +1,49 @@
/*
* Copyright (c) 1997, 2010, 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.codemodel.internal;
/**
* This helps enable whether the JDefinedClass is a Class or Interface or
* AnnotationTypeDeclaration or Enum
*
* @author
* Bhakti Mehta (bhakti.mehta@sun.com)
*/
public final class ClassType {
/**
* The keyword used to declare this type.
*/
final String declarationToken;
private ClassType(String token) {
this.declarationToken = token;
}
public static final ClassType CLASS = new ClassType("class");
public static final ClassType INTERFACE = new ClassType("interface");
public static final ClassType ANNOTATION_TYPE_DECL = new ClassType("@interface");
public static final ClassType ENUM = new ClassType("enum");
}

View File

@@ -0,0 +1,114 @@
/*
* 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.codemodel.internal;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.CharsetEncoder;
import com.sun.codemodel.internal.util.EncoderFactory;
import com.sun.codemodel.internal.util.UnicodeEscapeWriter;
/**
* Receives generated code and writes to the appropriate storage.
*
* @author
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
*/
public abstract class CodeWriter {
/**
* Encoding to be used by the writer. Null means platform specific encoding.
*
* @since 2.5
*/
protected String encoding = null;
/**
* Called by CodeModel to store the specified file.
* The callee must allocate a storage to store the specified file.
*
* <p>
* The returned stream will be closed before the next file is
* stored. So the callee can assume that only one OutputStream
* is active at any given time.
*
* @param pkg
* The package of the file to be written.
* @param fileName
* File name without the path. Something like
* "Foo.java" or "Bar.properties"
*/
public abstract OutputStream openBinary( JPackage pkg, String fileName ) throws IOException;
/**
* Called by CodeModel to store the specified file.
* The callee must allocate a storage to store the specified file.
*
* <p>
* The returned stream will be closed before the next file is
* stored. So the callee can assume that only one OutputStream
* is active at any given time.
*
* @param pkg
* The package of the file to be written.
* @param fileName
* File name without the path. Something like
* "Foo.java" or "Bar.properties"
*/
public Writer openSource( JPackage pkg, String fileName ) throws IOException {
final OutputStreamWriter bw = encoding != null
? new OutputStreamWriter(openBinary(pkg,fileName), encoding)
: new OutputStreamWriter(openBinary(pkg,fileName));
// create writer
try {
return new UnicodeEscapeWriter(bw) {
// can't change this signature to Encoder because
// we can't have Encoder in method signature
private final CharsetEncoder encoder = EncoderFactory.createEncoder(bw.getEncoding());
@Override
protected boolean requireEscaping(int ch) {
// control characters
if( ch<0x20 && " \t\r\n".indexOf(ch)==-1 ) return true;
// check ASCII chars, for better performance
if( ch<0x80 ) return false;
return !encoder.canEncode((char)ch);
}
};
} catch( Throwable t ) {
return new UnicodeEscapeWriter(bw);
}
}
/**
* Called by CodeModel at the end of the process.
*/
public abstract void close() throws IOException;
}

View File

@@ -0,0 +1,65 @@
/*
* Copyright (c) 1997, 2010, 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.codemodel.internal;
import java.lang.annotation.Annotation;
import java.util.Collection;
/**
* Annotatable program elements.
*
* @author Kohsuke Kawaguchi
*/
public interface JAnnotatable {
/**
* Adds an annotation to this program element.
* @param clazz
* The annotation class to annotate the program element with
*/
JAnnotationUse annotate(JClass clazz);
/**
* Adds an annotation to this program element.
*
* @param clazz
* The annotation class to annotate the program element with
*/
JAnnotationUse annotate(Class <? extends Annotation> clazz);
/**
* Adds an annotation to this program element
* and returns a type-safe writer to fill in the values of such annotations.
*/
<W extends JAnnotationWriter> W annotate2(Class<W> clazz);
/**
* Read-only live view of all annotations on this {@link JAnnotatable}
*
* @return
* Can be empty but never null.
*/
Collection<JAnnotationUse> annotations();
}

View File

@@ -0,0 +1,298 @@
/*
* Copyright (c) 1997, 2010, 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.codemodel.internal;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
import java.util.Collection;
import java.util.Collections;
/**
* Represents an arrays as annotation members
*
* <p>
* This class implements {@link JAnnotatable} to allow
* new annotations to be added as a member of the array.
*
* @author
* Bhakti Mehta (bhakti.mehta@sun.com)
*/
public final class JAnnotationArrayMember extends JAnnotationValue implements JAnnotatable {
private final List<JAnnotationValue> values = new ArrayList<JAnnotationValue>();
private final JCodeModel owner;
JAnnotationArrayMember(JCodeModel owner) {
this.owner = owner;
}
/**
* Adds an array member to this annotation
*
* @param value Adds a string value to the array member
* @return The JAnnotationArrayMember. More elements can be added by calling
* the same method multiple times
*/
public JAnnotationArrayMember param(String value) {
JAnnotationValue annotationValue = new JAnnotationStringValue(JExpr.lit(value));
values.add(annotationValue);
return this;
}
/**
* Adds an array member to this annotation
*
* @param value Adds a boolean value to the array member
* @return The JAnnotationArrayMember. More elements can be added by calling
* the same method multiple times
*/
public JAnnotationArrayMember param(boolean value) {
JAnnotationValue annotationValue = new JAnnotationStringValue(JExpr.lit(value));
values.add(annotationValue);
return this;
}
/**
* Adds an array member to this annotation
*
* @param value Adds a byte value to the array member
* @return The JAnnotationArrayMember. More elements can be added by calling
* the same method multiple times
*/
public JAnnotationArrayMember param(byte value) {
JAnnotationValue annotationValue = new JAnnotationStringValue(JExpr.lit(value));
values.add(annotationValue);
return this;
}
/**
* Adds an array member to this annotation
*
* @param value Adds a char value to the array member
* @return The JAnnotationArrayMember. More elements can be added by calling
* the same method multiple times
*/
public JAnnotationArrayMember param(char value) {
JAnnotationValue annotationValue = new JAnnotationStringValue(JExpr.lit(value));
values.add(annotationValue);
return this;
}
/**
* Adds an array member to this annotation
*
* @param value Adds a double value to the array member
* @return The JAnnotationArrayMember. More elements can be added by calling
* the same method multiple times
*/
public JAnnotationArrayMember param(double value) {
JAnnotationValue annotationValue = new JAnnotationStringValue(JExpr.lit(value));
values.add(annotationValue);
return this;
}
/**
* Adds an array member to this annotation
*
* @param value Adds a long value to the array member
* @return The JAnnotationArrayMember. More elements can be added by calling
* the same method multiple times
*/
public JAnnotationArrayMember param(long value) {
JAnnotationValue annotationValue = new JAnnotationStringValue(JExpr.lit(value));
values.add(annotationValue);
return this;
}
/**
* Adds an array member to this annotation
*
* @param value Adds a short value to the array member
* @return The JAnnotationArrayMember. More elements can be added by calling
* the same method multiple times
*/
public JAnnotationArrayMember param(short value) {
JAnnotationValue annotationValue = new JAnnotationStringValue(JExpr.lit(value));
values.add(annotationValue);
return this;
}
/**
* Adds an array member to this annotation
*
* @param value Adds an int value to the array member
* @return The JAnnotationArrayMember. More elements can be added by calling
* the same method multiple times
*/
public JAnnotationArrayMember param(int value) {
JAnnotationValue annotationValue = new JAnnotationStringValue(JExpr.lit(value));
values.add(annotationValue);
return this;
}
/**
* Adds an array member to this annotation
*
* @param value Adds a float value to the array member
* @return The JAnnotationArrayMember. More elements can be added by calling
* the same method multiple times
*/
public JAnnotationArrayMember param(float value) {
JAnnotationValue annotationValue = new JAnnotationStringValue(JExpr.lit(value));
values.add(annotationValue);
return this;
}
/**
* Adds a enum array member to this annotation
*
* @param value Adds a enum value to the array member
* @return The JAnnotationArrayMember. More elements can be added by calling
* the same method multiple times
*/
public JAnnotationArrayMember param(final Enum<?> value) {
JAnnotationValue annotationValue = new JAnnotationValue() {
public void generate(JFormatter f) {
f.t(owner.ref(value.getDeclaringClass())).p('.').p(value.name());
}
};
values.add(annotationValue);
return this;
}
/**
* Adds a enum array member to this annotation
*
* @param value Adds a enum value to the array member
* @return The JAnnotationArrayMember. More elements can be added by calling
* the same method multiple times
*/
public JAnnotationArrayMember param(final JEnumConstant value) {
JAnnotationValue annotationValue = new JAnnotationStringValue(value);
values.add(annotationValue);
return this;
}
/**
* Adds an expression array member to this annotation
*
* @param value Adds an expression value to the array member
* @return The JAnnotationArrayMember. More elements can be added by calling
* the same method multiple times
*/
public JAnnotationArrayMember param(final JExpression value) {
JAnnotationValue annotationValue = new JAnnotationStringValue(value);
values.add(annotationValue);
return this;
}
/**
* Adds a class array member to this annotation
*
* @param value Adds a class value to the array member
* @return The JAnnotationArrayMember. More elements can be added by calling
* the same method multiple times
*/
public JAnnotationArrayMember param(final Class<?> value){
JAnnotationValue annotationValue = new JAnnotationStringValue(
new JExpressionImpl() {
public void generate(JFormatter f) {
f.p(value.getName().replace('$', '.'));
f.p(".class");
}
});
values.add(annotationValue);
return this;
}
public JAnnotationArrayMember param(JType type){
JClass clazz = type.boxify();
JAnnotationValue annotationValue = new JAnnotationStringValue ( clazz.dotclass() );
values.add(annotationValue);
return this;
}
/**
* Adds a new annotation to the array.
*/
public JAnnotationUse annotate(Class<? extends Annotation> clazz){
return annotate(owner.ref(clazz));
}
/**
* Adds a new annotation to the array.
*/
public JAnnotationUse annotate(JClass clazz){
JAnnotationUse a = new JAnnotationUse(clazz);
values.add(a);
return a;
}
public <W extends JAnnotationWriter> W annotate2(Class<W> clazz) {
return TypedAnnotationWriter.create(clazz,this);
}
/**
* {@link JAnnotatable#annotations()}
*/
@SuppressWarnings("unchecked")
public Collection<JAnnotationUse> annotations() {
// this invocation is invalid if the caller isn't adding annotations into an array
// so this potentially type-unsafe conversion would be justified.
return Collections.<JAnnotationUse>unmodifiableList((List)values);
}
/**
* Adds an annotation member to this annotation array
* This can be used for e.g &#64;XmlCollection(values= &#64;XmlCollectionItem(type=Foo.class))
* @param value
* Adds a annotation to the array member
* @return
* The JAnnotationArrayMember. More elements can be added by calling
* the same method multiple times
*
* @deprecated
* use {@link #annotate}
*/
public JAnnotationArrayMember param (JAnnotationUse value ){
values.add(value);
return this;
}
public void generate(JFormatter f) {
f.p('{').nl().i();
boolean first = true;
for (JAnnotationValue aValue : values) {
if (!first)
f.p(',').nl();
f.g(aValue);
first = false;
}
f.nl().o().p('}');
}
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) 1997, 2010, 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.codemodel.internal;
/**
* Captures the value of the annotation.
*
* @author
* Bhakti Mehta (bhakti.mehta@sun.com)
*/
final class JAnnotationStringValue extends JAnnotationValue {
/**
* The value of the Annotation member
*/
private final JExpression value;
JAnnotationStringValue(JExpression value) {
this.value = value;
}
public void generate(JFormatter f) {
f.g(value);
}
}

View File

@@ -0,0 +1,426 @@
/*
* 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.codemodel.internal;
import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Represents an annotation on a program element.
*
* TODO
* How to add enums to the annotations
* @author
* Bhakti Mehta (bhakti.mehta@sun.com)
*/
public final class JAnnotationUse extends JAnnotationValue {
/**
* The {@link Annotation} class
*/
private final JClass clazz;
/**
* Map of member values.
*/
private Map<String,JAnnotationValue> memberValues;
JAnnotationUse(JClass clazz){
this.clazz = clazz;
}
public JClass getAnnotationClass() {
return clazz;
}
public Map<String, JAnnotationValue> getAnnotationMembers() {
return Collections.unmodifiableMap(memberValues);
}
private JCodeModel owner() {
return clazz.owner();
}
private void addValue(String name, JAnnotationValue annotationValue) {
// Use ordered map to keep the code generation the same on any JVM.
// Lazily created.
if(memberValues==null)
memberValues = new LinkedHashMap<String, JAnnotationValue>();
memberValues.put(name,annotationValue);
}
/**
* Adds a member value pair to this annotation
*
* @param name
* The simple name for this annotation
*
* @param value
* The boolean value for this annotation
* @return
* The JAnnotationUse. More member value pairs can
* be added to it using the same or the overloaded methods.
*
*/
public JAnnotationUse param(String name, boolean value){
addValue(name, new JAnnotationStringValue(JExpr.lit(value)));
return this;
}
/**
* Adds a member value pair to this annotation
* @param name
* The simple name for this annotation
*
* @param value
* The byte member value for this annotation
* @return
* The JAnnotationUse. More member value pairs can
* be added to it using the same or the overloaded methods.
*
*/
public JAnnotationUse param(String name, byte value){
addValue(name, new JAnnotationStringValue(JExpr.lit(value)));
return this;
}
/**
* Adds a member value pair to this annotation
* @param name
* The simple name for this annotation
*
* @param value
* The char member value for this annotation
* @return
* The JAnnotationUse. More member value pairs can
* be added to it using the same or the overloaded methods.
*
*/
public JAnnotationUse param(String name, char value){
addValue(name, new JAnnotationStringValue(JExpr.lit(value)));
return this;
}
/**
* Adds a member value pair to this annotation
* @param name
* The simple name for this annotation
*
* @param value
* The double member value for this annotation
* @return
* The JAnnotationUse. More member value pairs can
* be added to it using the same or the overloaded methods.
*
*/
public JAnnotationUse param(String name, double value){
addValue(name, new JAnnotationStringValue(JExpr.lit(value)));
return this;
}
/**
* Adds a member value pair to this annotation
* @param name
* The simple name for this annotation
*
* @param value
* The float member value for this annotation
* @return
* The JAnnotationUse. More member value pairs can
* be added to it using the same or the overloaded methods.
*
*/
public JAnnotationUse param(String name, float value){
addValue(name, new JAnnotationStringValue(JExpr.lit(value)));
return this;
}
/**
* Adds a member value pair to this annotation
* @param name
* The simple name for this annotation
*
* @param value
* The long member value for this annotation
* @return
* The JAnnotationUse. More member value pairs can
* be added to it using the same or the overloaded methods.
*
*/
public JAnnotationUse param(String name, long value){
addValue(name, new JAnnotationStringValue(JExpr.lit(value)));
return this;
}
/**
* Adds a member value pair to this annotation
* @param name
* The simple name for this annotation
*
* @param value
* The short member value for this annotation
* @return
* The JAnnotationUse. More member value pairs can
* be added to it using the same or the overloaded methods.
*
*/
public JAnnotationUse param(String name, short value){
addValue(name, new JAnnotationStringValue(JExpr.lit(value)));
return this;
}
/**
* Adds a member value pair to this annotation
* @param name
* The simple name for this annotation
*
* @param value
* The int member value for this annotation
* @return
* The JAnnotationUse. More member value pairs can
* be added to it using the same or the overloaded methods.
*
*/
public JAnnotationUse param(String name, int value){
addValue(name, new JAnnotationStringValue(JExpr.lit(value)));
return this;
}
/**
* Adds a member value pair to this annotation
* @param name
* The simple name for this annotation
*
* @param value
* The String member value for this annotation
* @return
* The JAnnotationUse. More member value pairs can
* be added to it using the same or the overloaded methods.
*
*/
public JAnnotationUse param(String name, String value){
//Escape string values with quotes so that they can
//be generated accordingly
addValue(name, new JAnnotationStringValue(JExpr.lit(value)));
return this;
}
/**
* Adds a member value pair to this annotation
* For adding class values as param
* @see #param(String, Class)
* @param name
* The simple name for this annotation
*
* @param value
* The annotation class which is member value for this annotation
* @return
* The JAnnotationUse. More member value pairs can
* be added to it using the same or the overloaded methods.
*
*/
public JAnnotationUse annotationParam(String name, Class<? extends Annotation> value) {
JAnnotationUse annotationUse = new JAnnotationUse(owner().ref(value));
addValue(name, annotationUse);
return annotationUse;
}
/**
* Adds a member value pair to this annotation
* @param name
* The simple name for this annotation
*
* @param value
* The enum class which is member value for this annotation
* @return
* The JAnnotationUse. More member value pairs can
* be added to it using the same or the overloaded methods.
*
*/
public JAnnotationUse param(String name, final Enum<?> value) {
addValue(name, new JAnnotationValue() {
public void generate(JFormatter f) {
f.t(owner().ref(value.getDeclaringClass())).p('.').p(value.name());
}
});
return this;
}
/**
* Adds a member value pair to this annotation
* @param name
* The simple name for this annotation
*
* @param value
* The JEnumConstant which is member value for this annotation
* @return
* The JAnnotationUse. More member value pairs can
* be added to it using the same or the overloaded methods.
*
*/
public JAnnotationUse param(String name, JEnumConstant value){
addValue(name, new JAnnotationStringValue(value));
return this;
}
/**
* Adds a member value pair to this annotation
* This can be used for e.g to specify
* <pre>
* &#64;XmlCollectionItem(type=Integer.class);
* <pre>
* For adding a value of Class<? extends Annotation>
* @link
* #annotationParam(java.lang.String, java.lang.Class<? extends java.lang.annotation.Annotation>)
* @param name
* The simple name for this annotation param
*
* @param value
* The class type of the param
* @return
* The JAnnotationUse. More member value pairs can
* be added to it using the same or the overloaded methods.
*
*
*
*/
public JAnnotationUse param(String name, final Class<?> value){
addValue(name, new JAnnotationStringValue(
new JExpressionImpl() {
public void generate(JFormatter f) {
f.p(value.getName().replace('$', '.'));
f.p(".class");
}
}));
return this;
}
/**
* Adds a member value pair to this annotation based on the
* type represented by the given JType
*
* @param name The simple name for this annotation param
* @param type the JType representing the actual type
* @return The JAnnotationUse. More member value pairs can
* be added to it using the same or the overloaded methods.
*/
public JAnnotationUse param(String name, JType type){
JClass c = type.boxify();
addValue(name, new JAnnotationStringValue ( c.dotclass() ));
return this;
}
/**
* Adds a member value pair to this annotation.
* @param name
* The simple name for this annotation
*
* @param value
* The JExpression which provides the contant value for this annotation
* @return
* The JAnnotationUse. More member value pairs can
* be added to it using the same or the overloaded methods.
*
*/
public JAnnotationUse param(String name, JExpression value){
addValue(name, new JAnnotationStringValue(value));
return this;
}
/**
* Adds a member value pair which is of type array to this annotation
* @param name
* The simple name for this annotation
*
* @return
* The JAnnotationArrayMember. For adding array values
* @see JAnnotationArrayMember
*
*/
public JAnnotationArrayMember paramArray(String name){
JAnnotationArrayMember arrayMember = new JAnnotationArrayMember(owner());
addValue(name, arrayMember);
return arrayMember;
}
// /**
// * This can be used to add annotations inside annotations
// * for e.g &#64;XmlCollection(values= &#64;XmlCollectionItem(type=Foo.class))
// * @param className
// * The classname of the annotation to be included
// * @return
// * The JAnnotationUse that can be used as a member within this JAnnotationUse
// * @deprecated
// * use {@link JAnnotationArrayMember#annotate}
// */
// public JAnnotationUse annotate(String className) {
// JAnnotationUse annotationUse = new JAnnotationUse(owner().ref(className));
// return annotationUse;
// }
/**
* This can be used to add annotations inside annotations
* for e.g &#64;XmlCollection(values= &#64;XmlCollectionItem(type=Foo.class))
* @param clazz
* The annotation class to be included
* @return
* The JAnnotationUse that can be used as a member within this JAnnotationUse
* @deprecated
* use {@link JAnnotationArrayMember#annotate}
*/
public JAnnotationUse annotate(Class <? extends Annotation> clazz) {
JAnnotationUse annotationUse = new JAnnotationUse(owner().ref(clazz));
return annotationUse;
}
public void generate(JFormatter f) {
f.p('@').g(clazz);
if(memberValues!=null) {
f.p('(');
boolean first = true;
if(isOptimizable()) {
// short form
f.g(memberValues.get("value"));
} else {
for (Map.Entry<String, JAnnotationValue> mapEntry : memberValues.entrySet()) {
if (!first) f.p(',');
f.p(mapEntry.getKey()).p('=').g(mapEntry.getValue());
first = false;
}
}
f.p(')');
}
}
private boolean isOptimizable() {
return memberValues.size()==1 && memberValues.containsKey("value");
}
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright (c) 1997, 2010, 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.codemodel.internal;
/**
* Things that can be values of an annotation element.
*
* @author
* Bhakti Mehta (bhakti.mehta@sun.com)
*/
public abstract class JAnnotationValue implements JGenerable {
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (c) 1997, 2010, 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.codemodel.internal;
import java.lang.annotation.Annotation;
/**
* Base interface for typed annotation writer.
*
* <p>
* Annotation compiler can generate a strongly typed annotation
* writer to assist applications to write uses of annotations.
* Such typed annotation writer interfaces all derive from
* this common interface.
*
* <p>
* The type parameter 'A' represents the
* @author Kohsuke Kawaguchi
*/
public interface JAnnotationWriter<A extends Annotation> {
/**
* Gets the underlying annotation use object to which we are writing.
*/
JAnnotationUse getAnnotationUse();
/**
* The type of the annotation that this writer is writing.
*/
Class<A> getAnnotationType();
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright (c) 1997, 2010, 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.codemodel.internal;
/**
* Anonymous class quick hack.
*
* @author
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
*/
class JAnonymousClass extends JDefinedClass {
/**
* Base interface/class from which this anonymous class is built.
*/
private final JClass base;
JAnonymousClass( JClass _base) {
super(_base.owner(), 0, null);
this.base = _base;
}
@Override
public String fullName() {
return base.fullName();
}
@Override
public void generate(JFormatter f) {
f.t(base);
}
}

View File

@@ -0,0 +1,87 @@
/*
* Copyright (c) 1997, 2010, 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.codemodel.internal;
import java.util.ArrayList;
import java.util.List;
/**
* array creation and initialization.
*/
public final class JArray extends JExpressionImpl {
private final JType type;
private final JExpression size;
private List<JExpression> exprs = null;
/**
* Add an element to the array initializer
*/
public JArray add(JExpression e) {
if (exprs == null)
exprs = new ArrayList<JExpression>();
exprs.add(e);
return this;
}
JArray(JType type, JExpression size) {
this.type = type;
this.size = size;
}
public void generate(JFormatter f) {
// generally we produce new T[x], but when T is an array type (T=T'[])
// then new T'[][x] is wrong. It has to be new T'[x][].
int arrayCount = 0;
JType t = type;
while( t.isArray() ) {
t = t.elementType();
arrayCount++;
}
f.p("new").g(t).p('[');
if (size != null)
f.g(size);
f.p(']');
for( int i=0; i<arrayCount; i++ )
f.p("[]");
if ((size == null) || (exprs != null))
f.p('{');
if (exprs != null) {
f.g(exprs);
} else {
f.p(' ');
}
if ((size == null) || (exprs != null))
f.p('}');
}
}

View File

@@ -0,0 +1,123 @@
/*
* Copyright (c) 1997, 2010, 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.codemodel.internal;
import java.util.Iterator;
import java.util.Collections;
import java.util.List;
/**
* Array class.
*
* @author
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
*/
final class JArrayClass extends JClass {
// array component type
private final JType componentType;
JArrayClass( JCodeModel owner, JType component ) {
super(owner);
this.componentType = component;
}
public String name() {
return componentType.name()+"[]";
}
public String fullName() {
return componentType.fullName()+"[]";
}
public String binaryName() {
return componentType.binaryName()+"[]";
}
public void generate(JFormatter f) {
f.g(componentType).p("[]");
}
public JPackage _package() {
return owner().rootPackage();
}
public JClass _extends() {
return owner().ref(Object.class);
}
public Iterator<JClass> _implements() {
return Collections.<JClass>emptyList().iterator();
}
public boolean isInterface() {
return false;
}
public boolean isAbstract() {
return false;
}
public JType elementType() {
return componentType;
}
public boolean isArray() {
return true;
}
//
// Equality is based on value
//
public boolean equals(Object obj) {
if(!(obj instanceof JArrayClass)) return false;
if( componentType.equals( ((JArrayClass)obj).componentType ) )
return true;
return false;
}
public int hashCode() {
return componentType.hashCode();
}
protected JClass substituteParams(JTypeVar[] variables, List<JClass> bindings) {
if( componentType.isPrimitive() )
return this;
JClass c = ((JClass)componentType).substituteParams(variables,bindings);
if(c==componentType)
return this;
return new JArrayClass(owner(),c);
}
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (c) 1997, 2010, 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.codemodel.internal;
/**
* array component reference.
*/
final class JArrayCompRef extends JExpressionImpl implements JAssignmentTarget {
/**
* JArray expression upon which this component will be accessed.
*/
private final JExpression array;
/**
* Integer expression representing index of the component
*/
private final JExpression index;
/**
* JArray component reference constructor given an array expression
* and index.
*
* @param array
* JExpression for the array upon which
* the component will be accessed,
*
* @param index
* JExpression for index of component to access
*/
JArrayCompRef(JExpression array, JExpression index) {
if ((array == null) || (index == null)) {
throw new NullPointerException();
}
this.array = array;
this.index = index;
}
public void generate(JFormatter f) {
f.g(array).p('[').g(index).p(']');
}
public JExpression assign(JExpression rhs) {
return JExpr.assign(this,rhs);
}
public JExpression assignPlus(JExpression rhs) {
return JExpr.assignPlus(this,rhs);
}
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright (c) 1997, 2010, 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.codemodel.internal;
/**
* Assignment statements, which are also expressions.
*/
public class JAssignment extends JExpressionImpl implements JStatement {
JAssignmentTarget lhs;
JExpression rhs;
String op = "";
JAssignment(JAssignmentTarget lhs, JExpression rhs) {
this.lhs = lhs;
this.rhs = rhs;
}
JAssignment(JAssignmentTarget lhs, JExpression rhs, String op) {
this.lhs = lhs;
this.rhs = rhs;
this.op = op;
}
public void generate(JFormatter f) {
f.g(lhs).p(op + '=').g(rhs);
}
public void state(JFormatter f) {
f.g(this).p(';').nl();
}
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright (c) 1997, 2010, 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.codemodel.internal;
/**
* Marker interface for code components that can be placed to
* the left of '=' in an assignment.
*
* A left hand value can always be a right hand value, so
* this interface derives from {@link JExpression}.
*/
public interface JAssignmentTarget extends JGenerable, JExpression {
JExpression assign(JExpression rhs);
JExpression assignPlus(JExpression rhs);
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 1997, 2010, 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.codemodel.internal;
/**
* JAtoms: Simple code components that merely generate themselves.
*/
final class JAtom extends JExpressionImpl {
private final String what;
JAtom(String what) {
this.what = what;
}
public void generate(JFormatter f) {
f.p(what);
}
}

View File

@@ -0,0 +1,454 @@
/*
* Copyright (c) 1997, 2010, 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.codemodel.internal;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
/**
* A block of Java code, which may contain statements and local declarations.
*
* <p>
* {@link JBlock} contains a large number of factory methods that creates new
* statements/declarations. Those newly created statements/declarations are
* inserted into the {@link #pos() "current position"}. The position advances
* one every time you add a new instruction.
*/
public final class JBlock implements JGenerable, JStatement {
/**
* Declarations and statements contained in this block.
* Either {@link JStatement} or {@link JDeclaration}.
*/
private final List<Object> content = new ArrayList<Object>();
/**
* Whether or not this block must be braced and indented
*/
private boolean bracesRequired = true;
private boolean indentRequired = true;
/**
* Current position.
*/
private int pos;
public JBlock() {
this(true,true);
}
public JBlock(boolean bracesRequired, boolean indentRequired) {
this.bracesRequired = bracesRequired;
this.indentRequired = indentRequired;
}
/**
* Returns a read-only view of {@link JStatement}s and {@link JDeclaration}
* in this block.
*/
public List<Object> getContents() {
return Collections.unmodifiableList(content);
}
private <T> T insert( T statementOrDeclaration ) {
content.add(pos,statementOrDeclaration);
pos++;
return statementOrDeclaration;
}
/**
* Gets the current position to which new statements will be inserted.
*
* For example if the value is 0, newly created instructions will be
* inserted at the very beginning of the block.
*
* @see #pos(int)
*/
public int pos() {
return pos;
}
/**
* Sets the current position.
*
* @return
* the old value of the current position.
* @throws IllegalArgumentException
* if the new position value is illegal.
*
* @see #pos()
*/
public int pos(int newPos) {
int r = pos;
if(newPos>content.size() || newPos<0)
throw new IllegalArgumentException();
pos = newPos;
return r;
}
/**
* Returns true if this block is empty and does not contain
* any statement.
*/
public boolean isEmpty() {
return content.isEmpty();
}
/**
* Adds a local variable declaration to this block
*
* @param type
* JType of the variable
*
* @param name
* Name of the variable
*
* @return Newly generated JVar
*/
public JVar decl(JType type, String name) {
return decl(JMod.NONE, type, name, null);
}
/**
* Adds a local variable declaration to this block
*
* @param type
* JType of the variable
*
* @param name
* Name of the variable
*
* @param init
* Initialization expression for this variable. May be null.
*
* @return Newly generated JVar
*/
public JVar decl(JType type, String name, JExpression init) {
return decl(JMod.NONE, type, name, init);
}
/**
* Adds a local variable declaration to this block
*
* @param mods
* Modifiers for the variable
*
* @param type
* JType of the variable
*
* @param name
* Name of the variable
*
* @param init
* Initialization expression for this variable. May be null.
*
* @return Newly generated JVar
*/
public JVar decl(int mods, JType type, String name, JExpression init) {
JVar v = new JVar(JMods.forVar(mods), type, name, init);
insert(v);
bracesRequired = true;
indentRequired = true;
return v;
}
/**
* Creates an assignment statement and adds it to this block.
*
* @param lhs
* Assignable variable or field for left hand side of expression
*
* @param exp
* Right hand side expression
*/
public JBlock assign(JAssignmentTarget lhs, JExpression exp) {
insert(new JAssignment(lhs, exp));
return this;
}
public JBlock assignPlus(JAssignmentTarget lhs, JExpression exp) {
insert(new JAssignment(lhs, exp, "+"));
return this;
}
/**
* Creates an invocation statement and adds it to this block.
*
* @param expr
* JExpression evaluating to the class or object upon which
* the named method will be invoked
*
* @param method
* Name of method to invoke
*
* @return Newly generated JInvocation
*/
public JInvocation invoke(JExpression expr, String method) {
JInvocation i = new JInvocation(expr, method);
insert(i);
return i;
}
/**
* Creates an invocation statement and adds it to this block.
*
* @param expr
* JExpression evaluating to the class or object upon which
* the method will be invoked
*
* @param method
* JMethod to invoke
*
* @return Newly generated JInvocation
*/
public JInvocation invoke(JExpression expr, JMethod method) {
return insert(new JInvocation(expr, method));
}
/**
* Creates a static invocation statement.
*/
public JInvocation staticInvoke(JClass type, String method) {
return insert(new JInvocation(type, method));
}
/**
* Creates an invocation statement and adds it to this block.
*
* @param method
* Name of method to invoke
*
* @return Newly generated JInvocation
*/
public JInvocation invoke(String method) {
return insert(new JInvocation((JExpression)null, method));
}
/**
* Creates an invocation statement and adds it to this block.
*
* @param method
* JMethod to invoke
*
* @return Newly generated JInvocation
*/
public JInvocation invoke(JMethod method) {
return insert(new JInvocation((JExpression)null, method));
}
/**
* Adds a statement to this block
*
* @param s
* JStatement to be added
*
* @return This block
*/
public JBlock add(JStatement s) { // ## Needed?
insert(s);
return this;
}
/**
* Create an If statement and add it to this block
*
* @param expr
* JExpression to be tested to determine branching
*
* @return Newly generated conditional statement
*/
public JConditional _if(JExpression expr) {
return insert(new JConditional(expr));
}
/**
* Create a For statement and add it to this block
*
* @return Newly generated For statement
*/
public JForLoop _for() {
return insert(new JForLoop());
}
/**
* Create a While statement and add it to this block
*
* @return Newly generated While statement
*/
public JWhileLoop _while(JExpression test) {
return insert(new JWhileLoop(test));
}
/**
* Create a switch/case statement and add it to this block
*/
public JSwitch _switch(JExpression test) {
return insert(new JSwitch(test));
}
/**
* Create a Do statement and add it to this block
*
* @return Newly generated Do statement
*/
public JDoLoop _do(JExpression test) {
return insert(new JDoLoop(test));
}
/**
* Create a Try statement and add it to this block
*
* @return Newly generated Try statement
*/
public JTryBlock _try() {
return insert(new JTryBlock());
}
/**
* Create a return statement and add it to this block
*/
public void _return() {
insert(new JReturn(null));
}
/**
* Create a return statement and add it to this block
*/
public void _return(JExpression exp) {
insert(new JReturn(exp));
}
/**
* Create a throw statement and add it to this block
*/
public void _throw(JExpression exp) {
insert(new JThrow(exp));
}
/**
* Create a break statement and add it to this block
*/
public void _break() {
_break(null);
}
public void _break(JLabel label) {
insert(new JBreak(label));
}
/**
* Create a label, which can be referenced from
* <code>continue</code> and <code>break</code> statements.
*/
public JLabel label(String name) {
JLabel l = new JLabel(name);
insert(l);
return l;
}
/**
* Create a continue statement and add it to this block
*/
public void _continue(JLabel label) {
insert(new JContinue(label));
}
public void _continue() {
_continue(null);
}
/**
* Create a sub-block and add it to this block
*/
public JBlock block() {
JBlock b = new JBlock();
b.bracesRequired = false;
b.indentRequired = false;
return insert(b);
}
/**
* Creates a "literal" statement directly.
*
* <p>
* Specified string is printed as-is.
* This is useful as a short-cut.
*
* <p>
* For example, you can invoke this method as:
* <code>directStatement("a=b+c;")</code>.
*/
public JStatement directStatement(final String source) {
JStatement s = new JStatement() {
public void state(JFormatter f) {
f.p(source).nl();
}
};
add(s);
return s;
}
public void generate(JFormatter f) {
if (bracesRequired)
f.p('{').nl();
if (indentRequired)
f.i();
generateBody(f);
if (indentRequired)
f.o();
if (bracesRequired)
f.p('}');
}
void generateBody(JFormatter f) {
for (Object o : content) {
if (o instanceof JDeclaration)
f.d((JDeclaration) o);
else
f.s((JStatement) o);
}
}
/**
* Creates an enhanced For statement based on j2se 1.5 JLS
* and add it to this block
*
* @return Newly generated enhanced For statement per j2se 1.5
* specification
*/
public JForEach forEach(JType varType, String name, JExpression collection) {
return insert(new JForEach( varType, name, collection));
}
public void state(JFormatter f) {
f.g(this);
if (bracesRequired)
f.nl();
}
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) 1997, 2010, 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.codemodel.internal;
/**
* JBreak statement
*/
final class JBreak implements JStatement {
private final JLabel label;
/**
* JBreak constructor
*
* @param _label
* break label or null.
*/
JBreak( JLabel _label ) {
this.label = _label;
}
public void state(JFormatter f) {
if( label==null )
f.p("break;").nl();
else
f.p("break").p(label.label).p(';').nl();
}
}

View File

@@ -0,0 +1,84 @@
/*
* Copyright (c) 1997, 2010, 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.codemodel.internal;
/**
* Case statement
*/
public final class JCase implements JStatement {
/**
* label part of the case statement
*/
private JExpression label;
/**
* JBlock of statements which makes up body of this While statement
*/
private JBlock body = null;
/**
* is this a regular case statement or a default case statement?
*/
private boolean isDefaultCase = false;
/**
* Construct a case statement
*/
JCase(JExpression label) {
this(label, false);
}
/**
* Construct a case statement. If isDefaultCase is true, then
* label should be null since default cases don't have a label.
*/
JCase(JExpression label, boolean isDefaultCase) {
this.label = label;
this.isDefaultCase = isDefaultCase;
}
public JExpression label() {
return label;
}
public JBlock body() {
if (body == null) body=new JBlock( false, true );
return body;
}
public void state(JFormatter f) {
f.i();
if( !isDefaultCase ) {
f.p("case ").g(label).p(':').nl();
} else {
f.p("default:").nl();
}
if (body != null)
f.s(body);
f.o();
}
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 1997, 2010, 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.codemodel.internal;
/**
* A cast operation.
*/
final class JCast extends JExpressionImpl {
/**
* JType to which the expression is to be cast.
*/
private final JType type;
/**
* JExpression to be cast.
*/
private final JExpression object;
/**
* JCast constructor
*
* @param type
* JType to which the expression is cast
*
* @param object
* JExpression for the object upon which
* the cast is applied
*/
JCast(JType type, JExpression object) {
this.type = type;
this.object = object;
}
public void generate(JFormatter f) {
f.p("((").g(type).p(')').g(object).p(')');
}
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright (c) 1997, 2010, 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.codemodel.internal;
/**
* Catch block for a try/catch/finally statement
*/
public class JCatchBlock implements JGenerable {
JClass exception;
private JVar var = null;
private JBlock body = new JBlock();
JCatchBlock(JClass exception) {
this.exception = exception;
}
public JVar param(String name) {
if (var != null) throw new IllegalStateException();
var = new JVar(JMods.forVar(JMod.NONE), exception, name, null);
return var;
}
public JBlock body() {
return body;
}
public void generate(JFormatter f) {
if (var == null)
var = new JVar(JMods.forVar(JMod.NONE),
exception, "_x", null);
f.p("catch (").b(var).p(')').g(body);
}
}

View File

@@ -0,0 +1,356 @@
/*
* Copyright (c) 1997, 2010, 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.codemodel.internal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* Represents a Java reference type, such as a class, an interface,
* an enum, an array type, a parameterized type.
*
* <p>
* To be exact, this object represents an "use" of a reference type,
* not necessarily a declaration of it, which is modeled as {@link JDefinedClass}.
*/
public abstract class JClass extends JType
{
protected JClass( JCodeModel _owner ) {
this._owner = _owner;
}
/**
* Gets the name of this class.
*
* @return
* name of this class, without any qualification.
* For example, this method returns "String" for
* <code>java.lang.String</code>.
*/
abstract public String name();
/**
* Gets the package to which this class belongs.
* TODO: shall we move move this down?
*/
abstract public JPackage _package();
/**
* Returns the class in which this class is nested, or <tt>null</tt> if
* this is a top-level class.
*/
public JClass outer() {
return null;
}
private final JCodeModel _owner;
/** Gets the JCodeModel object to which this object belongs. */
public final JCodeModel owner() { return _owner; }
/**
* Gets the super class of this class.
*
* @return
* Returns the JClass representing the superclass of the
* entity (class or interface) represented by this {@link JClass}.
* Even if no super class is given explicitly or this {@link JClass}
* is not a class, this method still returns
* {@link JClass} for {@link Object}.
* If this JClass represents {@link Object}, return null.
*/
abstract public JClass _extends();
/**
* Iterates all super interfaces directly implemented by
* this class/interface.
*
* @return
* A non-null valid iterator that iterates all
* {@link JClass} objects that represents those interfaces
* implemented by this object.
*/
abstract public Iterator<JClass> _implements();
/**
* Iterates all the type parameters of this class/interface.
*
* <p>
* For example, if this {@link JClass} represents
* <code>Set&lt;T></code>, this method returns an array
* that contains single {@link JTypeVar} for 'T'.
*/
public JTypeVar[] typeParams() {
return EMPTY_ARRAY;
}
/**
* Sometimes useful reusable empty array.
*/
protected static final JTypeVar[] EMPTY_ARRAY = new JTypeVar[0];
/**
* Checks if this object represents an interface.
*/
abstract public boolean isInterface();
/**
* Checks if this class is an abstract class.
*/
abstract public boolean isAbstract();
/**
* If this class represents one of the wrapper classes
* defined in the java.lang package, return the corresponding
* primitive type. Otherwise null.
*/
public JPrimitiveType getPrimitiveType() { return null; }
/**
* @deprecated calling this method from {@link JClass}
* would be meaningless, since it's always guaranteed to
* return <tt>this</tt>.
*/
public JClass boxify() { return this; }
public JType unboxify() {
JPrimitiveType pt = getPrimitiveType();
return pt==null ? (JType)this : pt;
}
public JClass erasure() {
return this;
}
/**
* Checks the relationship between two classes.
* <p>
* This method works in the same way as {@link Class#isAssignableFrom(Class)}
* works. For example, baseClass.isAssignableFrom(derivedClass)==true.
*/
public final boolean isAssignableFrom( JClass derived ) {
// to avoid the confusion, always use "this" explicitly in this method.
// null can be assigned to any type.
if( derived instanceof JNullType ) return true;
if( this==derived ) return true;
// the only class that is assignable from an interface is
// java.lang.Object
if( this==_package().owner().ref(Object.class) ) return true;
JClass b = derived._extends();
if( b!=null && this.isAssignableFrom(b) )
return true;
if( this.isInterface() ) {
Iterator<JClass> itfs = derived._implements();
while( itfs.hasNext() )
if( this.isAssignableFrom(itfs.next()) )
return true;
}
return false;
}
/**
* Gets the parameterization of the given base type.
*
* <p>
* For example, given the following
* <pre><xmp>
* interface Foo<T> extends List<List<T>> {}
* interface Bar extends Foo<String> {}
* </xmp></pre>
* This method works like this:
* <pre><xmp>
* getBaseClass( Bar, List ) = List<List<String>
* getBaseClass( Bar, Foo ) = Foo<String>
* getBaseClass( Foo<? extends Number>, Collection ) = Collection<List<? extends Number>>
* getBaseClass( ArrayList<? extends BigInteger>, List ) = List<? extends BigInteger>
* </xmp></pre>
*
* @param baseType
* The class whose parameterization we are interested in.
* @return
* The use of {@code baseType} in {@code this} type.
* or null if the type is not assignable to the base type.
*/
public final JClass getBaseClass( JClass baseType ) {
if( this.erasure().equals(baseType) )
return this;
JClass b = _extends();
if( b!=null ) {
JClass bc = b.getBaseClass(baseType);
if(bc!=null)
return bc;
}
Iterator<JClass> itfs = _implements();
while( itfs.hasNext() ) {
JClass bc = itfs.next().getBaseClass(baseType);
if(bc!=null)
return bc;
}
return null;
}
public final JClass getBaseClass( Class<?> baseType ) {
return getBaseClass(owner().ref(baseType));
}
private JClass arrayClass;
public JClass array() {
if(arrayClass==null)
arrayClass = new JArrayClass(owner(),this);
return arrayClass;
}
/**
* "Narrows" a generic class to a concrete class by specifying
* a type argument.
*
* <p>
* <code>.narrow(X)</code> builds <code>Set&lt;X></code> from <code>Set</code>.
*/
public JClass narrow( Class<?> clazz ) {
return narrow(owner().ref(clazz));
}
public JClass narrow( Class<?>... clazz ) {
JClass[] r = new JClass[clazz.length];
for( int i=0; i<clazz.length; i++ )
r[i] = owner().ref(clazz[i]);
return narrow(r);
}
/**
* "Narrows" a generic class to a concrete class by specifying
* a type argument.
*
* <p>
* <code>.narrow(X)</code> builds <code>Set&lt;X></code> from <code>Set</code>.
*/
public JClass narrow( JClass clazz ) {
return new JNarrowedClass(this,clazz);
}
public JClass narrow( JType type ) {
return narrow(type.boxify());
}
public JClass narrow( JClass... clazz ) {
return new JNarrowedClass(this,Arrays.asList(clazz.clone()));
}
public JClass narrow( List<? extends JClass> clazz ) {
return new JNarrowedClass(this,new ArrayList<JClass>(clazz));
}
/**
* If this class is parameterized, return the type parameter of the given index.
*/
public List<JClass> getTypeParameters() {
return Collections.emptyList();
}
/**
* Returns true if this class is a parameterized class.
*/
public final boolean isParameterized() {
return erasure()!=this;
}
/**
* Create "? extends T" from T.
*
* @return never null
*/
public final JClass wildcard() {
return new JTypeWildcard(this);
}
/**
* Substitutes the type variables with their actual arguments.
*
* <p>
* For example, when this class is Map&lt;String,Map&lt;V>>,
* (where V then doing
* substituteParams( V, Integer ) returns a {@link JClass}
* for <code>Map&lt;String,Map&lt;Integer>></code>.
*
* <p>
* This method needs to work recursively.
*/
protected abstract JClass substituteParams( JTypeVar[] variables, List<JClass> bindings );
public String toString() {
return this.getClass().getName() + '(' + name() + ')';
}
public final JExpression dotclass() {
return JExpr.dotclass(this);
}
/** Generates a static method invocation. */
public final JInvocation staticInvoke(JMethod method) {
return new JInvocation(this,method);
}
/** Generates a static method invocation. */
public final JInvocation staticInvoke(String method) {
return new JInvocation(this,method);
}
/** Static field reference. */
public final JFieldRef staticRef(String field) {
return new JFieldRef(this, field);
}
/** Static field reference. */
public final JFieldRef staticRef(JVar field) {
return new JFieldRef(this, field);
}
public void generate(JFormatter f) {
f.t(this);
}
/**
* Prints the class name in javadoc @link format.
*/
void printLink(JFormatter f) {
f.p("{@link ").g(this).p('}');
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (c) 1997, 2010, 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.codemodel.internal;
/**
* Indicates that the class is already created.
*
* @author
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
*/
public class JClassAlreadyExistsException extends Exception {
private static final long serialVersionUID = 1L;
private final JDefinedClass existing;
public JClassAlreadyExistsException( JDefinedClass _existing ) {
this.existing = _existing;
}
/**
* Gets a reference to the existing {@link JDefinedClass}.
*
* @return
* This method always return non-null valid object.
*/
public JDefinedClass getExistingClass() {
return existing;
}
}

Some files were not shown because too many files have changed in this diff Show More