KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > api > persistence > enhancer > impl > ClassControl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24
25 package com.sun.jdo.api.persistence.enhancer.impl;
26
27 import java.io.*;
28
29 import java.util.Map JavaDoc;
30 import java.util.Hashtable JavaDoc;
31 import java.util.Iterator JavaDoc;
32
33 import com.sun.jdo.api.persistence.enhancer.classfile.ClassFile;
34 import com.sun.jdo.api.persistence.enhancer.classfile.ClassField;
35 import com.sun.jdo.api.persistence.enhancer.classfile.ClassMethod;
36 import com.sun.jdo.api.persistence.enhancer.classfile.ConstClass;
37
38 import com.sun.jdo.api.persistence.enhancer.util.Support;
39 import com.sun.jdo.api.persistence.enhancer.util.UserException;
40 import com.sun.jdo.api.persistence.enhancer.util.ClassFileSource;
41
42 //@olsen: added import
43
import com.sun.jdo.api.persistence.enhancer.meta.JDOMetaData;
44
45
46 //@olsen: cosmetics
47
//@olsen: moved: this class -> package impl
48
//@olsen: subst: [iI]Persistent -> [pP]ersistenceCapable
49
//@olsen: subst: jdo/ -> com/sun/forte4j/persistence/internal/
50
//@olsen: subst: /* ... */ -> // ...
51
//@olsen: subst: filterEnv -> env
52
//@olsen: subst: FilterEnv -> Environment
53
//@olsen: dropped parameter 'Environment env', use association instead
54
//@olsen: subst: Hashtable -> Map, HashMap
55
//@olsen: subst: Enumeration,... -> Iterator, hasNext(), next()
56
//@olsen: subst: absolut jdo types and names -> constants from JDOMetaData
57
//@olsen: subst: persistType() -> persistenceType
58
//@olsen: subst: ClassControl. ->
59
//@olsen: added: support for I18N
60
//@olsen: subst: FilterError -> UserException, affirm()
61
//@olsen: removed: support for [No]AnnotateField
62
//@olsen: removed: old, disabled ODI code
63

64
65 /**
66  * ClassControl acts as the primary handle for a class within the
67  * filter tool. ClassControl instances are typically accessed through
68  * various methods on Environment.
69  */

70 public final class ClassControl
71     extends Support {
72
73     /* Valid persistence types */
74
75     /* The user didn't tell us to make this persistence-capable or
76      * persistence-aware and it doesn't appear to be annotated */

77     //@olsen: changed value 3 -> -1
78
static public final int TransientOnly = -1;
79
80     /* The user made no explicit statement about the persistence capability. */
81     static public final int PersistUnknown = 0;
82
83     /* The user said that this class needs to be annotated for fetch/dirty
84      * but the class doesn't need to be stored persistently */

85     //@olsen: changed value 2 -> 1
86
static public final int PersistAware = 1;
87
88     /* The user said this class should be persistence capable or it was
89      * promoted to persistence-capable status as a result of being a base
90      * class of an explicitly persistence capable class */

91     //@olsen: changed value 1 -> 2
92
static public final int PersistCapable = 2;
93
94     /* A filtered version of this class exists and is up to date w.r.t.
95      * the unfiltered versionr - filtering will NOT be required.
96      */

97     //@olsen: changed value 3 -> -1
98
static public final int UpdateNotNeeded = -1;
99
100     /* It is not yet known whether the current filtered version of this
101      * class exists or if it is up-to-date w.r.t. the unfiltered version.
102      */

103     static public final int UpdateUnknown = 0;
104
105     /* No filtered version of this class exists - filtering will be required.
106      */

107     static public final int UpdateNew = 1;
108
109     /* A filtered version of this class exists but the unfiltered version
110      * is newer - filtering will be required.
111      */

112     static public final int UpdateNewer = 2;
113
114     /* Central repository for the options and classes */
115     //@olsen: added association
116
//@olsen: made final
117
private final Environment env;
118
119     /* The class to be annotated */
120     //@olsen: made final
121
private final ClassFileSource theClassSource;
122
123     /* The classfile to be annotated */
124     private ClassFile theClass;
125
126     /* What type of class is this w.r.t. persistence */
127     private int persistenceType = PersistUnknown;
128
129     /* What type of class is this w.r.t. persistence as defined on cmd line */
130 //@olsen: disabled feature
131
/*
132     private int initialPersistenceType = PersistUnknown;
133 */

134
135     /* Was this class promoted to persistent capable? */
136 //@olsen: disabled feature
137
/*
138     private boolean implicitlyPersistent = false;
139 */

140
141     /* Was this class explicitly listed on the command line? */
142 //@olsen: disabled feature
143
/*
144     private boolean explicitlyMentioned = false;
145 */

146
147     /* What is the update state of the class */
148     private int updateType = UpdateUnknown;
149
150     /* What annotation related actions are to be performed for the class */
151     //@olsen: made final
152
private final ClassAction classAction;
153
154     /* If true, this class is believed to have been modified in some way */
155     private boolean classUpdated;
156
157     /* If true, this class was renamed via repackaging */
158 //@olsen: disabled feature
159
/*
160     private boolean classRenamed;
161 */

162
163     // public accessors
164

165     /**
166      * Return true if the classfile has been updated
167      */

168     public boolean updated() {
169         return classUpdated;
170     }
171
172     /**
173      * Return true if the classfile has been renamed
174      */

175 //@olsen: disabled feature
176
/*
177     public boolean renamed() {
178         return classRenamed;
179     }
180 */

181
182     /**
183      * Record a modification of the class
184      */

185     public void noteUpdate() {
186         classUpdated = true;
187     }
188
189     /**
190      * Get the ClassFile data structure for the class
191      */

192     public ClassFile classFile() {
193         return theClass;
194     }
195
196     /**
197      * Return the persistence type for this class
198      */

199     public int persistType() {
200         return persistenceType;
201     }
202
203     /**
204      * Return the initial persistence type for this class
205      */

206 //@olsen: disabled feature
207
/*
208     public int initialPersistType() {
209         return initialPersistenceType;
210     }
211 */

212
213     /**
214      * Return true if the persistence type for this class is either
215      * PersistAware or PersistCapable.
216      */

217 //@olsen: not used
218
//@olsen: disabled feature
219
/*
220     public boolean persistAware() {
221         if (persistenceType == PersistUnknown)
222             checkPersistAware();
223         return (persistenceType == PersistCapable ||
224                 persistenceType == PersistAware);
225     }
226 */

227
228     /**
229      * Return true if the persistence type for this class is PersistCapable.
230      */

231 //@olsen: disabled feature
232
/*
233     public boolean persistCapable() {
234         if (persistenceType == PersistUnknown)
235             checkPersistAware();
236         return persistenceType == PersistCapable;
237     }
238 */

239
240     /**
241      * Return true if filtering of the class is required.
242      * This checks only whether the filtered version of the class is
243      * up to date w.r.t. its input class.
244      */

245     public boolean filterRequired() {
246         if (updateType == UpdateUnknown)
247             checkUpdateType();
248 //@olsen: optimized code
249
return (updateType > UpdateUnknown || env.forceOverwrite());
250 /*
251         return (updateType == UpdateNew
252                 || updateType == UpdateNewer
253                 || env.forceOverwrite());
254 */

255     }
256
257     /**
258      * Mark the class as requiring update.
259      */

260     public void requireUpdate() {
261         updateType = UpdateNew;
262     }
263
264     /**
265      * Return true if the class is one which should be a candidate for
266      * annotation.
267      */

268     public boolean annotateable() {
269 //@olsen: disabled feature: isImplicitlyPersistent()
270
/*
271         return (initialPersistenceType == PersistCapable ||
272                 initialPersistenceType == PersistAware ||
273                 isImplicitlyPersistent());
274 */

275         //@olsen: changed to check each class not explicitly known as transient
276
return (persistenceType >= PersistUnknown);
277     }
278
279     /**
280      * Set the peristence type for this class
281      */

282 //@olsen: disabled feature: -> setPersistenceType()
283
/*
284     public void setPersistType(int ptype) {
285         persistenceType = ptype;
286     }
287 */

288
289     /**
290      * Set the initial peristence type for this class
291      */

292 //@olsen: disabled feature
293
/*
294     public void setInitialPersistType(int ptype) {
295         initialPersistenceType = ptype;
296         persistenceType = ptype;
297     }
298 */

299
300     /**
301      * Returns true if this class was promoted to persistent implicitly
302      */

303 //@olsen: disabled feature
304
/*
305     public boolean isImplicitlyPersistent() {
306         return implicitlyPersistent;
307     }
308 */

309
310     /**
311      * Record that this class was promoted to persistence capable
312      */

313 //@olsen: disabled feature
314
/*
315     public void setImplicitlyPersistent(boolean wasPromoted) {
316         implicitlyPersistent = wasPromoted;
317     }
318 */

319
320     /**
321      * Returns true if this class was explicitly named on the command line
322      */

323 //@olsen: disabled feature
324
/*
325     public boolean isExplicitlyNamed() {
326         return explicitlyMentioned;
327     }
328 */

329
330     /**
331      * Record whether this class was explicitly listed as a class on the
332      * command line.
333      */

334 //@olsen: disabled feature
335
/*
336     public void setExplicitlyNamed(boolean wasNamed) {
337         explicitlyMentioned = wasNamed;
338     }
339 */

340
341     /**
342      * Get the ClassAction for this class
343      */

344     public ClassAction action() {
345         return classAction;
346     }
347
348     /**
349      * Constructor
350      */

351     //@olsen: added parameter 'env' for association
352
public ClassControl(ClassFileSource theSource,
353                         Environment env) {
354         theClassSource = theSource;
355         buildTheClass(true /* allowJDK12ClassFiles */);
356         theClassSource.setExpectedClassName(className());
357         classAction = new ClassAction(this, env);
358         this.env = env;
359
360         if (false) {
361             System.out.println("ClassControl(): new class = " + className());//NOI18N
362
}
363     }
364
365     /**
366      * Constructor
367      */

368     //@olsen: added parameter 'env' for association
369
public ClassControl(ClassFileSource theSource,
370                         ClassFile theFile,
371                         Environment env) {
372         theClassSource = theSource;
373         theClass = theFile;
374         theClassSource.setExpectedClassName(className());
375         classAction = new ClassAction(this, env);
376         this.env = env;
377
378         if (false) {
379             System.out.println("ClassControl(): new class = " + className());//NOI18N
380
}
381     }
382
383
384     /**
385      * Sets the persistence type of a class by JDO meta-data.
386      */

387     //@olsen: added method
388
private void setPersistenceType() {
389         final JDOMetaData meta = env.getJDOMetaData();
390
391         //@olsen: skip class if its persistence type is already known
392
if (persistenceType != PersistUnknown) {
393             return;
394         }
395
396         //@olsen: check whether class is an interface
397
if (classFile().isInterface()) {
398             persistenceType = TransientOnly;
399             return;
400         }
401
402         //@olsen: check whether class is known to be transient
403
final String JavaDoc className = className();
404         if (meta.isTransientClass(className)) {
405             persistenceType = TransientOnly;
406             return;
407         }
408
409         //@olsen: check whether class is persistence-capable
410
if (meta.isPersistenceCapableClass(className)) {
411             persistenceType = PersistCapable;
412
413             //@olsen: for Dogwood, check limitation on PC-inheritance
414
affirm(meta.isPersistenceCapableRootClass(className),
415                    ("Sorry, not supported yet: the persistent-capable class "//NOI18N
416
+ userClassName()
417                     + "cannot extend a persistent-capable super-class."));//NOI18N
418
}
419     }
420
421     /**
422      * Note the class characteristics
423      */

424     public void scan1() {
425         //@olsen: added support for timing statistics
426
try{
427             if (env.doTimingStatistics()) {
428                 Support.timer.push("ClassControl.scan1()");//NOI18N
429
}
430             //@olsen: added: set the persistent type of class
431
setPersistenceType();
432
433 //@olsen: disabled feature
434
/*
435             if (annotateable() || implementsPersistenceCapable()) {
436 */

437
438             if (annotateable()) {
439                 //@olsen: dropped argument: boolean filterRequired
440
//classAction.scan1(filterRequired());
441
if (filterRequired()) {
442                     classAction.scan1();
443                 } else {
444                     //@olsen: added output
445
env.message("skipping " + userClassName() + //NOI18N
446
" because it is already up to date.");//NOI18N
447
}
448             }
449         } finally {
450             if (env.doTimingStatistics()) {
451                 Support.timer.pop();
452             }
453         }
454     }
455
456     /**
457      * Check the class to see what actions need to be performed
458      */

459 //@olsen: disabled feature
460
/*
461     public void scan2() {
462         if (annotateable()) {
463             env.message("computing annotations for " + userClassName());
464             classAction.scan2(filterRequired());
465         }
466     }
467 */

468
469     /**
470      * Reparent class if needed
471      */

472     //@olsen: subst: augmentInterfaces -> augment
473
public void augment() {
474         //@olsen: added support for timing statistics
475
try{
476             if (env.doTimingStatistics()) {
477                 Support.timer.push("ClassControl.augment()");//NOI18N
478
}
479             if (annotateable()) {
480                 //@olsen: dropped argument: boolean filterRequired
481
//classAction.augment(filterRequired());
482
if (filterRequired()) {
483                     classAction.augment();
484                 } else {
485                     //@olsen: added output
486
env.message("skipping " + userClassName() + //NOI18N
487
" because it is already up to date.");//NOI18N
488
}
489             }
490         } finally {
491             if (env.doTimingStatistics()) {
492                 Support.timer.pop();
493             }
494         }
495     }
496
497     /**
498      * Retarget the class if needed
499      */

500 //@olsen: disabled feature
501
/*
502     public void retarget(Map classTranslations) {
503         // Trust our caller on this one
504         // The check for filterRequired is pushed down into ClassAction
505         // for this method to allow any special considerations to be made
506         // there.
507         if (classTranslations.get(className()) != null)
508             classRenamed = true;
509
510         env.message("retargetting class references for " + userClassName());
511         classAction.retarget(classTranslations,
512                              filterRequired());
513
514         // update our class source to reflect our new name if it has changed
515         // We need to do this even if filtering is not required
516         theClassSource.setExpectedClassName(className());
517     }
518 */

519
520     /**
521      * perform necessary annotation actions on the class
522      */

523     public void annotate() {
524         //@olsen: added support for timing statistics
525
try{
526             if (env.doTimingStatistics()) {
527                 Support.timer.push("ClassControl.annotate()");//NOI18N
528
}
529             if (annotateable()) {
530                 if (filterRequired()) {
531                     classAction.annotate();
532                 } else {
533                     env.message("skipping " + userClassName() + //NOI18N
534
" because it is already up to date.");//NOI18N
535
}
536             }
537         } finally {
538             if (env.doTimingStatistics()) {
539                 Support.timer.pop();
540             }
541         }
542     }
543
544     // package accessors
545

546     /**
547      * Return the class name in VM form
548      */

549     public String JavaDoc className() {
550         ConstClass cname = theClass.className();
551         return (cname == null) ? null : cname.asString();
552     }
553
554     /**
555      * Return the class name in user ('.' delimited) form
556      */

557     public String JavaDoc userClassName() {
558         return userClassFromVMClass(className());
559     }
560
561     /**
562      * Return the class name in user ('.' delimited) form
563      */

564     //^olsen: move to -> classfile.Descriptor ?
565
static public String JavaDoc userClassFromVMClass(String JavaDoc vmName) {
566         return vmName.replace('/', '.');
567     }
568
569     /**
570      * Return the class name in VM ('/' delimited) form
571      */

572     //^olsen: move to -> classfile.Descriptor ?
573
static public String JavaDoc vmClassFromUserClass(String JavaDoc userName) {
574         return userName.replace('.', '/');
575     }
576
577     /**
578      * Return the vm package name for this class
579      */

580     public String JavaDoc pkg() {
581         return packageOf(className());
582     }
583
584     /**
585      * Return the vm package name for the vm class name
586      */

587     static public String JavaDoc packageOf(String JavaDoc vmName) {
588         int last = vmName.lastIndexOf('/');
589         if (last < 0)
590             return "";//NOI18N
591
return vmName.substring(0, last);
592     }
593
594     /**
595      * Return the unpackaged name for this class
596      */

597 //@olsen: disabled feature
598
/*
599     public String unpackagedName() {
600         return unpackagedNameOf(className());
601     }
602 */

603
604     /**
605      * Return the unpackaged name for the vm class name
606      */

607 //@olsen: disabled feature
608
/*
609     static public String unpackagedNameOf(String vmName) {
610         int last = vmName.lastIndexOf('/');
611         if (last < 0)
612             return vmName;
613         return vmName.substring(last+1);
614     }
615 */

616
617     /**
618      * Return the name of the class source
619      */

620     public String JavaDoc sourceName() {
621         return theClassSource.containingFilePath();
622     }
623
624     /**
625      * Return the source of the class
626      */

627     public ClassFileSource source() {
628         return theClassSource;
629     }
630
631     /**
632      * Check whether the class already implements PersistenceCapable.
633      * Drag in new classes if needed.
634      */

635 //@olsen: disabled feature
636
/*
637     public boolean implementsPersistenceCapable() {
638         return implementsInterface(JDOMetaData.JDOPersistenceCapablePath,
639                                    null);
640     }
641 */

642
643 //@olsen: disabled feature
644
/*
645     abstract class Checker {
646         abstract boolean checkClass(ClassControl aClass);
647     }
648 */

649
650     /**
651      * Check whether the class will implement PersistenceCapableHooks
652      * in the absence of the postprocessor doing it.
653      * Drag in new classes if needed. Must not be called until scan2 phase
654      */

655 //@olsen: disabled feature
656
/*
657     public boolean hasPersistenceCapableHooksProvided() {
658         return implementsInterface(JDOMetaData.JDOInstanceCallbacksPath,
659                                    new Checker() {
660                                            boolean checkClass(ClassControl aClass) {
661                                                return (aClass != ClassControl.this &&
662                                                        aClass.action().getImplementsPersistenceHooks());
663                                            }
664                                        });
665     }
666 */

667
668     /**
669      * Check whether the class implements the specified class or
670      * is the specified class.
671      * If ccCheck is non-null, it is called on each ClassControl visited
672      * during the traversal to the base class as an additional predicate
673      * which, if it returns true, causes termination of the walk with
674      * a return value of true.
675      *
676      * TBD: modify this method and its callers to move all checking to
677      * the Checker predicate.
678      */

679 //@olsen: disabled feature
680
/*
681     boolean implementsInterface(String implementClassName,
682                                 Checker ccChecker) {
683         String currClassName = className();
684         while (currClassName != null) {
685             ClassControl cc = env.findClass(currClassName);
686             if (cc == null)
687                 return false;
688
689             ClassFile cf = cc.classFile();
690
691             Iterator interfaces = cf.interfaces().iterator();
692             while (interfaces.hasNext()) {
693                 ConstClass i = (ConstClass)interfaces.next();
694                 String interfaceName = i.asString();
695                 ClassControl icc = env.findClass(interfaceName);
696                 if (icc == null) {
697                     env.error("Class " + interfaceName
698                               + " could not be found.");
699                     return false;
700                 }
701                 if (interfaceName.equals(implementClassName) ||
702                     icc.implementsInterface(implementClassName, ccChecker))
703                     return true;
704             }
705
706             if (ccChecker != null && ccChecker.checkClass(cc))
707                 return true;
708
709             ConstClass superClass = cf.superName();
710             if (superClass == null)
711                 // java/lang/Object has no super class
712                 return false;
713
714             currClassName = superClass.asString();
715         }
716
717         return false;
718     }
719 */

720
721     /**
722      * Check whether the class derives from the specified class or
723      * is the specified class.
724      */

725 //@olsen: disabled feature
726
/*
727     //@olsen: made public
728     public boolean inherits(String inheritClassName) {
729         String currClassName = className();
730         while (currClassName != null) {
731             if (currClassName.equals(inheritClassName))
732                 return true;
733
734             ClassControl cc = env.findClass(currClassName);
735             if (cc == null)
736                 return false;
737
738             ClassFile cf = cc.classFile();
739             ConstClass superClass = cf.superName();
740             if (superClass == null)
741                 // java/lang/Object has no super class
742                 return false;
743
744             currClassName = superClass.asString();
745         }
746
747         return false;
748     }
749 */

750
751     /**
752      * Find the class which implements the given method and signature.
753      * Search up the class hierarchy from "this" until either java.lang.Object
754      * is found or a class which implements the method is found. Return
755      * null if the method has no implementation.
756      */

757 //@olsen: disabled feature
758
/*
759     ClassControl findMethodClass(String methodName,
760                                  String methodSig) {
761         String currClassName = className();
762
763         while (currClassName != null) {
764             ClassControl cc = env.findClass(currClassName);
765             if (cc == null)
766                 break;
767
768             ClassFile cf = cc.classFile();
769             if (cf.findMethod(methodName, methodSig) != null)
770                 return cc;
771             ConstClass superClass = cf.superName();
772             if (superClass == null)
773                 // java/lang/Object has no super class
774                 return null;
775
776             currClassName = superClass.asString();
777         }
778         env.error("Class " + userClassFromVMClass(currClassName) +
779                   " could not be found while trying to locate method " +
780                   methodName);
781
782         return null;
783     }
784 */

785
786 //@olsen: disabled feature -> get this information from JDOMetaData
787
/*
788     ClassControl findBasestPersistCapable() {
789         String currClassName = className();
790
791         ClassControl ret = null;
792         while (currClassName != null) {
793             ClassControl cc = env.findClass(currClassName);
794             if (cc == null)
795                 break;
796
797             if (cc.persistCapable()) {
798                 ret = cc;
799             }
800             ConstClass superClass = cc.classFile().superName();
801             if (superClass == null)
802                 // java/lang/Object has no super class
803                 return ret;
804
805             currClassName = superClass.asString();
806         }
807         env.error("Class " + userClassFromVMClass(currClassName) +
808                   " could not be found while trying to locate Base class.");
809
810         return null;
811     }
812 */

813
814     /**
815      * Write the file. If destination directory is non-null, write the
816      * file relative to that directory, else write it relative to its
817      * original location.
818      */

819     //@olsen: made public
820
public void write(File destFile)
821         throws IOException, FileNotFoundException {
822         DataOutputStream dos =
823             theClassSource.getOutputStream(destFile);
824         theClass.write(dos);
825         dos.close();
826     }
827
828     // private methods
829

830     /**
831      * Check to see if this class appears to be annotated. If so,
832      * update PersistUnknown to PersistAware.
833      */

834 //@olsen: disabled feature
835
/*
836     private void checkPersistAware() {
837         if (persistenceType == PersistUnknown) {
838             if (action().hasAnnotatedAttribute()) {
839                 // The class is annotated - it is either
840                 // persistence-aware or persistence-capable.
841                 if (implementsPersistenceCapable())
842                     persistenceType = PersistCapable;
843                 else
844                     persistenceType = PersistAware;
845             } else {
846                 // Either unannotated or manually annotated.
847                 // We used to check for the presence of a ClassInfo class
848                 // but the fact that we are relying now on dynamic classinfo
849                 // means that we encounter increasing numbers of false
850                 // warnings so for now, we'll just assume that the
851                 // PersistenceCapable is sufficient and defer error detection
852                 // until runtime.
853                 if (implementsPersistenceCapable()
854                     || classFile().isInterface())
855                     persistenceType = PersistCapable;
856
857                 // This code still needs to be implemented but not being
858                 // implemented simply means that more array fetches might
859                 // occur than are really necessary.
860                 //else if (this class appears to be annotated)
861                 // persistenceType = PersistAware;
862                 else
863                     persistenceType = TransientOnly;
864             }
865         }
866     }
867 */

868
869     /**
870      * Check to see if output class for this class is up-to-date with
871      * respect to its input class. Set updateType to reflect what
872      * type of update of the output class is needed, if any.
873      */

874     private void checkUpdateType() {
875         if (updateType == UpdateUnknown) {
876             String JavaDoc lookupName;
877
878             //@olsen: added inplace of disable featured
879
lookupName = className();
880 //@olsen: disabled feature
881
/*
882             // check to see if it exists in the updated form
883             String pkg = pkg();
884             String xlat = (String) env.translations().get(pkg);
885             if (xlat != null) {
886                 if (xlat.length() == 0)
887                     lookupName = unpackagedName();
888                 else
889                     lookupName = xlat + "/" + unpackagedName();
890             } else {
891                 lookupName = className();
892             }
893 */

894
895             ClassFileSource annotatedSource;
896             if (env.updateInPlace() && !theClassSource.isZipped())
897                 annotatedSource = theClassSource;
898             else
899                 annotatedSource = env.lookupDestClass(lookupName);
900
901             if (annotatedSource == null) {
902                 // No annotated class exists
903
updateType = UpdateNew;
904             } else {
905                 try {
906                     long annModDate = annotatedSource.modificationDate();
907                     long srcModDate = source().modificationDate();
908                     if (annModDate < srcModDate) {
909                         // An annotated class exists, but it is older than
910
// the input
911
updateType = UpdateNewer;
912                     } else {
913                         if (annotatedSource == theClassSource
914                             && !action().hasAnnotatedAttribute()) {
915                             // An unannotated class file to be updated
916
// in-place
917
if (persistenceType == PersistCapable
918                                 || persistenceType == PersistAware)
919                                 updateType = UpdateNewer;
920                             else
921                                 updateType = UpdateNotNeeded;
922                         } else {
923                             //@olsen: an annotated class exists, which is
924
// newer than the input
925
updateType = UpdateNotNeeded;
926                         }
927                     }
928                 } catch (FileNotFoundException e) {
929                     // shouldn't occur, but if it does, handle it
930
updateType = UpdateNew;
931                 }
932             }
933         }
934     }
935
936     /**
937      * Constructs the ClassFile for the class
938      */

939     private void buildTheClass(boolean allowJDK12ClassFiles) {
940         if (false) {
941             System.out.println("Reading class "//NOI18N
942
+ theClassSource.expectedClassName());
943         }
944
945         //@olsen: cosmetics
946
//try {
947
// try {
948
// } catch (FileNotFoundException e) {
949
// }
950
//} catch (IOException e) {
951
//}
952
try {
953             DataInputStream dis = theClassSource.classFileContents();
954             theClass = new ClassFile(dis);
955             dis.close();
956         } catch (FileNotFoundException e) {
957             // File should already have been tested for existence
958
//@olsen: support for I18N
959
throw new UserException(
960                 getI18N("enhancer.file_not_found",//NOI18N
961
sourceName()),
962                 e);
963         } catch (IOException e) {
964             //@olsen: support for I18N
965
throw new UserException(
966                 getI18N("enhancer.io_error_while_reading_file",//NOI18N
967
sourceName()),
968                 e);
969         }
970     }
971 }
972
Popular Tags